Skip to content

Commit ebd75c9

Browse files
committed
fix deduplication
1 parent 7b8ceff commit ebd75c9

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/webviews/webview-side/selectInputSettings/SelectInputSettingsPanel.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,23 @@ export const SelectInputSettingsPanel: React.FC<ISelectInputSettingsPanelProps>
6565
return;
6666
}
6767

68-
// Normalize for comparison (case-insensitive)
69-
const normalizedValue = trimmedValue.toLowerCase();
68+
// Add the trimmed value if not duplicate, using functional updater to avoid race conditions
69+
setSettings((prev) => {
70+
// Normalize for comparison (case-insensitive)
71+
const normalizedValue = trimmedValue.toLowerCase();
7072

71-
// Check if the normalized value is already present in options
72-
const isDuplicate = settings.options.some((option) => option.toLowerCase() === normalizedValue);
73+
// Check if the normalized value is already present in options
74+
const isDuplicate = prev.options.some((option) => option.toLowerCase() === normalizedValue);
7375

74-
if (isDuplicate) {
75-
return;
76-
}
76+
if (isDuplicate) {
77+
return prev;
78+
}
7779

78-
// Add the trimmed value and clear input
79-
setSettings((prev) => ({
80-
...prev,
81-
options: [...prev.options, trimmedValue]
82-
}));
80+
return {
81+
...prev,
82+
options: [...prev.options, trimmedValue]
83+
};
84+
});
8385
setNewOption('');
8486
};
8587

0 commit comments

Comments
 (0)