Skip to content

fix(theme/Search): await FlexSearch addAsync before init resolves - #3678

Merged
SoonIter merged 2 commits into
web-infra-dev:mainfrom
devtechedge:fix/local-provider-await-add-async
Sep 14, 2026
Merged

SoonIter merged 2 commits into
web-infra-dev:mainfrom
devtechedge:fix/local-provider-await-add-async

Conversation

@devtechedge

@devtechedge devtechedge commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

LocalProvider.init() issues addAsync() on the three FlexSearch indexes for every page but never awaits the returned promises. SearchPanel.initSearch() awaits init() and sets initStatus to 'inited' while indexing is still running, so on a medium site a query typed shortly after opening search can render "No matching results" until the user retypes. This reproduces with 952 documents per locale, as described in #3658.

Changes

Collect the addAsync() promises for each page's three indexes into a pending array and await Promise.all(pending) before init() resolves. The panel therefore keeps its loading state until the index is ready and then runs the pending query. No other behavior changes.

Related to #1725
Fixes #3658

Verification

  • tsc --noEmit on packages/core passes.
  • Repo build and diff checks pass.

@SoonIter
SoonIter enabled auto-merge (squash) September 14, 2026 06:01

@SoonIter SoonIter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ♥️, thanks~

@SoonIter
SoonIter merged commit 26f6cd4 into web-infra-dev:main Sep 14, 2026
6 checks passed
@devtechedge

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and merging #3678, and for maintaining Rspress.

This was an interesting race condition where LocalProvider.init() did not await FlexSearch addAsync() calls, allowing search initialization to finish before indexing was complete and causing intermittent empty results on larger sites.

I’m glad we could address it with a focused fix while preserving existing behavior.

Thanks again for the review and for the opportunity to contribute to Rspress!

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.

[Bug]: LocalProvider.init() does not await FlexSearch addAsync, so the first search query can report "No matching results"

2 participants