FIX: Connection Name and Description Losing Last Character When Editing#57
FIX: Connection Name and Description Losing Last Character When Editing#57tahierhussain wants to merge 9 commits intomainfrom
Conversation
- 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>
|
| 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
Reviews (8): Last reviewed commit: "FIX: Apply collapseSpaces when populatin..." | Re-trigger Greptile
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>
There was a problem hiding this comment.
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:
- Flush on submit — call
debouncedHandleConnectionNameDesc.flush()at the start ofhandleCreateOrUpdateinCreateConnection.jsx - Read from form directly — use
form.getFieldsValue()in the submit handler instead of relying ondbSelectionInfofor name/description
Option 2 would be cleaner since the form already has the correct value at all times.
What
Why
valueprop) that conflicted with Ant Design Form's internal state managementgetValueFromEventprop on Form.Item interfering with the onChange flowHow
namepropForm.useForm()hook to get a form instanceform.setFieldsValue()to populate fields when editing existing connectionsgetValueFromEventpropcollapseSpacestransformation to the onChange handlerhandleCreateOrUpdatecallback captures the latest state valueCan 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)
Database Migrations
Env Config
Relevant Docs
Related Issues or PRs
Dependencies Versions
Notes on Testing
Screenshots
The "name" field value modified but yet to click on the "Update" button

After clicking on the "Update" button

Checklist
I have read and understood the Contribution Guidelines.