File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed
src/webviews/webview-side/selectInputSettings Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments