@digitransit-component/digitransit-component-autosuggest 9.0.1 → 9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -7465,6 +7465,8 @@ function DTAutosuggest({
7465
7465
  // not something that should itself trigger a render or round-trip through
7466
7466
  // another dispatch.
7467
7467
  const pendingEnterRef = useRef(false);
7468
+ // Identifies the latest search so results of superseded searches are ignored.
7469
+ const searchIdRef = useRef(0);
7468
7470
  useEffect(() => {
7469
7471
  if (storeRef) {
7470
7472
  storeRef(inputRef.current);
@@ -7482,9 +7484,14 @@ function DTAutosuggest({
7482
7484
  });
7483
7485
  // remove location favourites in desktop search (collection item replaces it in target array)
7484
7486
  const newSources = state.sources ? state.sources.filter(s => !isLocationSearch || !s === 'Favourite' || state.showOwnPlaces || isMobile) : state.sources;
7487
+ searchIdRef.current += 1;
7488
+ const searchId = searchIdRef.current;
7485
7489
  executeSearch(newTargets, newSources, transportMode, searchContext, filterResults, geocodingSize, {
7486
7490
  input: state.value || ''
7487
7491
  }, searchResult => {
7492
+ if (searchId !== searchIdRef.current) {
7493
+ return;
7494
+ }
7488
7495
  if (searchResult == null) {
7489
7496
  dispatch({
7490
7497
  type: 'FETCH_SUGGESTIONS',