Skip to content

🐛 fix: race condition in search query execution#2929

Open
kamilsi wants to merge 1 commit into
nunocoracao:mainfrom
kamilsi:fix/search-race-condition
Open

🐛 fix: race condition in search query execution#2929
kamilsi wants to merge 1 commit into
nunocoracao:mainfrom
kamilsi:fix/search-race-condition

Conversation

@kamilsi
Copy link
Copy Markdown

@kamilsi kamilsi commented May 5, 2026

Problem

When a user opens the search modal and starts typing immediately, executeQuery() is triggered. Since buildIndex() is asynchronous (fetching index.json), the fuse variable might still be undefined when .search() is called, resulting in Uncaught TypeError: Cannot read properties of undefined (reading 'search').

Solution

  • Added a safety check in executeQuery() to ensure indexed is true and fuse is initialized before proceeding.
  • Added a check to output.firstChild before attempting to set focus targets for keyboard navigation, preventing secondary errors when results are empty or still rendering.

When a user opens the search modal and starts typing immediately, executeQuery() is triggered. Since buildIndex() is asynchronous, the fuse variable might still be undefined when .search() is called. Added safety checks for fuse initialization.
@kamilsi kamilsi requested a review from nunocoracao as a code owner May 5, 2026 09:53
@netlify
Copy link
Copy Markdown

netlify Bot commented May 5, 2026

Deploy Preview for snazzy-dango-efb2ec ready!

Name Link
🔨 Latest commit db9fb58
🔍 Latest deploy log https://app.netlify.com/projects/snazzy-dango-efb2ec/deploys/69f9be0ff525bc0008a7af51
😎 Deploy Preview https://deploy-preview-2929--snazzy-dango-efb2ec.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant