Skip to content

FIX: Connection Name and Description Losing Last Character When Editing#57

Open
tahierhussain wants to merge 9 commits intomainfrom
fix/connection-name-description-edit-losing-last-character
Open

FIX: Connection Name and Description Losing Last Character When Editing#57
tahierhussain wants to merge 9 commits intomainfrom
fix/connection-name-description-edit-losing-last-character

Conversation

@tahierhussain
Copy link
Copy Markdown
Contributor

@tahierhussain tahierhussain commented Apr 13, 2026

What

  • Fixed a bug where editing the connection name or description would lose the last character
  • Example: Changing "test_pg" to "test_pg_edited" would save as "test_pg_edite"

Why

  • The issue was caused by:
    1. Using controlled inputs (value prop) that conflicted with Ant Design Form's internal state management
    2. The getValueFromEvent prop on Form.Item interfering with the onChange flow

How

  • ConnectionDetailsSection.jsx:
    • Replaced controlled inputs with Ant Design's Form-managed inputs using name prop
    • Added Form.useForm() hook to get a form instance
    • Used form.setFieldsValue() to populate fields when editing existing connections
    • Removed problematic getValueFromEvent prop
    • Moved collapseSpaces transformation to the onChange handler
    • Added debounce (300ms) to parent state updates to ensure the handleCreateOrUpdate callback captures the latest state value

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

  • No, this PR should not break existing features
  • The form behavior remains the same from a user perspective
  • The changes only affect the internal state management pattern
  • Creating new connections still works as before
  • Editing existing connections now correctly preserves all characters

Database Migrations

  • None

Env Config

  • None

Relevant Docs

Related Issues or PRs

  • None

Dependencies Versions

  • No new dependencies

Notes on Testing

  1. Edit an existing connection
  2. Modify the name field (e.g., add "_edited" suffix)
  3. Click Update
  4. Verify the full name is saved correctly (no missing characters)
  5. Test the same for the description field
  6. Test creating a new connection to ensure it still works

Screenshots

The "name" field value modified but yet to click on the "Update" button
image

After clicking on the "Update" button
image

Checklist

I have read and understood the Contribution Guidelines.

tahierhussain and others added 2 commits April 13, 2026 21:01
- Replace controlled inputs (value prop) with Form-managed inputs (name prop)
- Use Form.useForm() hook and form.setFieldsValue() to set values when
  editing existing connections
- Remove getValueFromEvent which conflicted with controlled input pattern
- Move collapseSpaces transformation to onChange handler

This fixes the issue where the form fields wouldn't properly display
values when editing existing connections.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add debounced state update for name and description fields (300ms)
- Prevents the handleCreateOrUpdate callback from capturing stale
  dbSelectionInfo values during rapid typing
- Ensures the last character is not lost when updating a connection

This fixes the bug where editing connection name from "test_pg" to
"test_pg_edited" would save as "test_pg_edite" (missing last character).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@tahierhussain tahierhussain self-assigned this Apr 13, 2026
@tahierhussain tahierhussain requested a review from a team as a code owner April 13, 2026 15:38
@tahierhussain tahierhussain added the bug Something isn't working label Apr 13, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 13, 2026

Greptile Summary

This PR fixes the "last character lost" bug by replacing React-controlled value inputs with Ant Design Form-managed inputs (name prop + Form.useForm()), removing the conflicting getValueFromEvent handler, and using form.setFieldsValue() for initial field population. The collapseSpaces transform is preserved via normalize={collapseSpaces} on the name Form.Item and manually in handleNameChange.

Confidence Score: 4/5

The core fix is correct and the form management approach is sound, but an existing thread flags a P1 stale-data risk from the 300ms debounce that has not been addressed in this version.

The root-cause fix (removing controlled value + getValueFromEvent) is correctly implemented. The normalize/setFieldsValue combination is consistent. The isUserEditingRef guard works correctly across connection switches. Score is 4 rather than 5 because the debounce introduced in this PR — flagged as a P1 in an existing review thread — is still present and can cause handleCreateOrUpdate to submit stale name/description if the user clicks Update within 300ms of finishing typing.

frontend/src/base/components/environment/ConnectionDetailsSection.jsx — specifically the debouncedHandleConnectionNameDesc logic and its interaction with the parent's handleCreateOrUpdate closure.

Important Files Changed

Filename Overview
frontend/src/base/components/environment/ConnectionDetailsSection.jsx Replaces controlled inputs with Ant Design Form-managed inputs; adds useForm, setFieldsValue effect, isUserEditingRef guard, and a 300ms debounce on parent state updates. Core fix is correct, though the debounce introduces a stale-data window noted in an existing review thread.

Sequence Diagram

sequenceDiagram
    participant User
    participant AntInput as Ant Design Input
    participant FormItem as Form.Item (normalize)
    participant FormStore as Form Store
    participant Parent as dbSelectionInfo (parent state)
    participant API as Backend API

    Note over User,API: Loading existing connection
    API-->>Parent: getSingleConnectionDetails() → setDbSelectionInfo
    Parent->>FormStore: setFieldsValue({ name: collapseSpaces(name), description })
    FormStore->>AntInput: controlled value updated

    Note over User,API: User edits name field
    User->>AntInput: type character
    AntInput->>FormItem: onChange(rawEvent)
    FormItem->>FormStore: store normalize(e.target.value) = collapseSpaces(value)
    FormStore->>AntInput: re-render with normalized value
    FormItem->>Parent: handleNameChange(e) → collapseSpaces(e.target.value)
    Note over Parent: debounced 300ms
    Parent->>Parent: setDbSelectionInfo({ name: value })

    Note over User,API: User clicks Update
    User->>Parent: handleCreateOrUpdate()
    Parent->>API: PUT /connections/{id} with dbSelectionInfo
    API-->>Parent: 200 OK
Loading

Reviews (8): Last reviewed commit: "FIX: Apply collapseSpaces when populatin..." | Re-trigger Greptile

tahierhussain and others added 7 commits April 13, 2026 21:30
The debounce was introduced to fix stale closure issues, but it
actually creates a worse bug - a 300ms window where clicking Update
could submit pre-edit values.

The root cause is already fixed in ConnectionDetailsSection.jsx by
using Ant Design's Form pattern (Form.useForm + form.setFieldsValue).
With uncontrolled inputs, the direct state update works correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Debounce the handleConnectionNameDesc callback (300ms) to ensure the
parent's handleCreateOrUpdate closure captures the latest state value.

The form input remains responsive since Ant Design manages the input
internally, while the parent state update is debounced.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update form value synchronously with collapsed spaces so the validator
always sees the processed value, preventing spurious validation errors
when consecutive spaces are typed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Change useEffect dependency from dbSelectionInfo fields to connectionId
to prevent form values from being overwritten during typing due to
debounced state updates.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Restore debounce for parent state updates
- Add isUserEditingRef to track when user is actively editing
- Only populate form values when not in editing mode
- Reset editing flag when connectionId changes (new connection loaded)

This ensures:
1. Form populates correctly when async connection data arrives
2. User edits are not overwritten by the useEffect
3. Parent state updates are debounced to prevent stale closure issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Replace manual form.setFieldValue with normalize prop on Form.Item.
This ensures collapseSpaces is applied before storage and validation,
preventing false validation errors when consecutive spaces are typed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
setFieldsValue bypasses the normalize prop, so apply collapseSpaces
manually when loading connection data to ensure consistent formatting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@wicky-zipstack wicky-zipstack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix for the root cause — switching to Ant Design's Form pattern (Form.useForm + name prop + normalize) is the right approach.

One concern — debounce race condition:

The 300ms debounce on debouncedHandleConnectionNameDesc means if a user types and clicks "Update" within 300ms, dbSelectionInfo in the parent still has the old value. Since handleCreateOrUpdate reads from dbSelectionInfo, the last few characters could still be lost — which is essentially the same bug with a different timing window.

Two options to fix:

  1. Flush on submit — call debouncedHandleConnectionNameDesc.flush() at the start of handleCreateOrUpdate in CreateConnection.jsx
  2. Read from form directly — use form.getFieldsValue() in the submit handler instead of relying on dbSelectionInfo for name/description

Option 2 would be cleaner since the form already has the correct value at all times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants