@@ -131,16 +131,48 @@ export const CommandPalette = () => {
131131 }
132132 } , [ delayedOpened , isOpened ] )
133133
134- const handleSuggestionsFetchRequested = async ( options : SuggestionsFetchRequestedParams ) => {
135- const foundItems = await cpm . getItems ( {
136- term : options . value ,
134+ const latestParamsRef = useRef ( {
135+ repository,
136+ device,
137+ uiSettings,
138+ location : history . location ,
139+ snRoute,
140+ } )
141+
142+ useEffect ( ( ) => {
143+ latestParamsRef . current = {
137144 repository,
138145 device,
139146 uiSettings,
140147 location : history . location ,
141148 snRoute,
142- } )
143- setItems ( foundItems )
149+ }
150+ } , [ repository , device , uiSettings , history . location , snRoute ] )
151+
152+ const debouncedFetchRef = useRef (
153+ debounce ( async ( term : string ) => {
154+ const {
155+ repository : currentRepository ,
156+ device : currentDevice ,
157+ uiSettings : currentUiSettings ,
158+ location : currentLocation ,
159+ snRoute : currentSnRoute ,
160+ } = latestParamsRef . current
161+
162+ const foundItems = await cpm . getItems ( {
163+ term,
164+ repository : currentRepository ,
165+ device : currentDevice ,
166+ uiSettings : currentUiSettings ,
167+ location : currentLocation ,
168+ snRoute : currentSnRoute ,
169+ } )
170+ setItems ( foundItems )
171+ } , 200 ) ,
172+ )
173+
174+ const handleSuggestionsFetchRequested = ( options : SuggestionsFetchRequestedParams ) => {
175+ debouncedFetchRef . current ( options . value )
144176 }
145177
146178 const handleSelectSuggestion = ( ev : SyntheticEvent , suggestion : SuggestionSelectedEventData < CommandPaletteItem > ) => {
0 commit comments