Problem
SearchProvider fetches and rebuilds the full Fuse search index every time the submitted search term changes. Entering multiple queries causes repeated requests for the same locale JSON and repeatedly performs the expensive flattening and indexing work.
Because requests are not cancelled, an older locale response can also finish after a newer one and overwrite the active search index.
Steps to reproduce
- Open
/search/ and the browser network panel.
- Submit multiple search terms.
- Observe repeated requests for the same file under
/search-indices/.
Expected behavior
- Fetch and build the Fuse index only when the locale changes.
- Reuse that index for subsequent submitted searches.
- Clear the previous locale's index while its replacement loads.
- Abort an in-flight index request when the locale changes or the component unmounts.
File
src/components/SearchProvider/index.tsx
Problem
SearchProviderfetches and rebuilds the full Fuse search index every time the submitted search term changes. Entering multiple queries causes repeated requests for the same locale JSON and repeatedly performs the expensive flattening and indexing work.Because requests are not cancelled, an older locale response can also finish after a newer one and overwrite the active search index.
Steps to reproduce
/search/and the browser network panel./search-indices/.Expected behavior
File
src/components/SearchProvider/index.tsx