feat(nextra): add maxResults prop to Search component#4998
Open
assanee wants to merge 1 commit into
Open
Conversation
Cap how many Pagefind results are hydrated via .data() and rendered. On large docs sites a short query can match hundreds of pages, and the previous code fetched fragment JSON for every result and rendered each on the main thread — long enough to block the tab and trigger Chrome's "Page Unresponsive" dialog. The dropdown only shows ~10 results at a time, so most of that work was never visible to the user. Default: 12. Backwards compatible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
<Search>(packages/nextra/src/client/components/search.tsx) currently fetches the fragment JSON for every result Pagefind returns, then renders every one as a DOM node withdangerouslySetInnerHTML:On large docs sites a short query can match hundreds of pages. The browser then:
.data()for each one<Result>components on the main threadIn practice this blocks the main thread for 15+ seconds and Chrome shows the "Page Unresponsive" dialog.
The dropdown itself only shows ~10 results at a time, so 99% of that work is hydrating fragments the user will never see.
Reproduction
Docs site with several hundred indexed pages. Typing any 1–2 character query (very common at the start of typing) returns hundreds of matches, and the search dropdown hangs the tab.
Solution
Add an optional
maxResultsprop to<Search>(default 12) and sliceresponse.resultsbefore calling.data()on each:This caps the per-query work (fragment fetches + result DOM nodes) at a sensible default while letting consumers opt back into the previous behavior by passing a higher value (e.g.
<Search maxResults={Infinity} />).Pagefind already returns results in relevance order, so slicing the top N is the right cut — and matches what users actually scan in the dropdown anyway.