Skip to content

Commit d17ace1

Browse files
tahierhussainclaude
andcommitted
FIX: Debounce name/description state updates to prevent stale closure
- 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>
1 parent 03f4609 commit d17ace1

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

frontend/src/base/components/environment/CreateConnection.jsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState, useCallback, useMemo } from "react";
2+
import { debounce } from "lodash";
23
import Cookies from "js-cookie";
34
import PropTypes from "prop-types";
45

@@ -118,9 +119,26 @@ const CreateConnection = ({
118119
getConnectionFields();
119120
}, [getConnectionFields]);
120121

121-
const handleConnectionNameDesc = useCallback((name, value) => {
122-
setDbSelectionInfo((prev) => ({ ...prev, [name]: value }));
123-
}, []);
122+
const debouncedSetDbSelectionInfo = useMemo(
123+
() =>
124+
debounce((name, value) => {
125+
setDbSelectionInfo((prev) => ({ ...prev, [name]: value }));
126+
}, 300),
127+
[]
128+
);
129+
130+
useEffect(() => {
131+
return () => {
132+
debouncedSetDbSelectionInfo.cancel();
133+
};
134+
}, [debouncedSetDbSelectionInfo]);
135+
136+
const handleConnectionNameDesc = useCallback(
137+
(name, value) => {
138+
debouncedSetDbSelectionInfo(name, value);
139+
},
140+
[debouncedSetDbSelectionInfo]
141+
);
124142

125143
const handleCreateOrUpdate = useCallback(async () => {
126144
setIsCreateOrUpdateLoading(true);

0 commit comments

Comments
 (0)