You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(search): Fix popup and pagination races, version handling and error paths - #1180
Resolves#1179. This follows up #1164, where @yurishkuro confirmed Copilot's three findings as valid and merged to unblock search.
After the merge I ran an adversarial review of the search code. Five reviewers each covered one area: async races, accessibility, version scoping, security, and templates/tests. Two independent skeptics then tried to refute each finding. All 20 findings survived, including Copilot's 3, so all 20 are fixed here.
Description of the changes
Races and error paths (assets/js/search.js)
Pending search reopens a closed popup (Copilot). A per-box generation counter is bumped by every keystroke and every close, and a search that is no longer current never renders. Escape now cancels a pending search even before the popup has opened.
Typing while the index loads drops the final query.pf.init() resolves before the index, metadata and WASM have loaded. Each keystroke's filters() call then polls until ready and resumes in timer order, so the final query was superseded and nothing rendered. Pagefind and the page scope now resolve once per page, behind one shared promise.
Load failures.
Index, metadata and WASM failures now show the "unavailable" message. Before, the results page stuck on "Searching…" and the popup stayed silent.
A failed load is no longer cached. The next search calls destroy() and retries with a fresh module URL.
Duplicate "Show more" results (Copilot). One batch loads at a time. Focus still moves to the first new result.
Versions
Mobile search link (Copilot).navbar.html now links to /search/?v=<version> on versioned docs pages. The version comes from a new docs-version.html partial, which head-end.html now shares.
Navbar box on /search/?v=…. It searches, and Enter navigates, within that page's v instead of the latest version.
"See all" link. It uses the same scope as Enter, so "latest" stays unpinned in the URL.
Keyboard and accessibility
Editing the query clears the highlighted option, so Enter searches the new text instead of opening a stale result.
ArrowDown reopens a closed popup.
Keys pressed during IME composition are ignored.
Result counts are announced from a live region outside the popup. A live region inside the hidden popup was not announced.
The version <select> no longer submits on change. Before, every arrow key reloaded the page on Windows and Linux (WCAG 3.2.2). The Search button applies the choice.
The active option has a transparent outline, which forced-colors mode paints.
Layout
Excerpts wrap long tokens. A feature-gates search used to widen the page by 770px at 375px wide.
Every response is served with the production CSP parsed from netlify.toml.
A test fails on any CSP violation, or on Pagefind's "falling back to main thread" warning, which would hide a blocked worker or WASM. The Google Fonts violation is allowlisted until the font is self-hosted.
New tests cover:
the worker actually running
typing while the WASM is held back
Escape and blur during a pending search
ArrowDown and Enter selection
editing after highlighting
double "Show more"
the select not submitting
the navbar box on the results page
an index 404
the mobile navbar link and sidebar box
excerpt overflow at 375px
How was this change tested?
Red check: I ran the new spec against the old search.js, templates and SCSS. 10 tests fail, one per regression fixed here, which confirms they catch the bugs. The other 5 cover behavior that already worked.
With the fix:npm run test:search passes 15 of 15. With --repeat-each=3, 45 of 45 pass with no flakes.
Repo checks:check:links:all, check:links:internal, check:spelling, check:filenames and prettier on the changed files all pass.
Rendered output: the mobile link is /search/?v=1.76 and /search/?v=2.dev on versioned pages, and /search/ on /docs/latest/ and non-docs pages.
…or paths
Follow-up to jaegertracing#1164. Fixes the three Copilot review findings and 17 more
from an adversarial review, each with a regression test.
- Invalidate pending searches on close, so Escape, Tab or an outside
click keeps the popup closed. Resolve Pagefind and the page scope once,
so keystrokes typed while the index loads still show the final query.
- Serialize "Show more results", so quick clicks add each result once.
- Carry the docs version in the mobile search link and in the navbar box
on the results page. Keep "See all" unpinned to the latest version.
- Report index, metadata and WASM load failures instead of hanging on
"Searching…", and retry after a failed load instead of caching it.
- Clear the highlighted option on edit, reopen with ArrowDown, ignore
keys during IME composition, announce counts from a live region outside
the popup, and stop the version select from submitting on change.
- Wrap long excerpt tokens; mark the active option in forced-colors mode.
- serve:search indexes once; correct the copied Docsy template headers.
- Run the Playwright search tests under the production CSP from
netlify.toml, failing on violations or Pagefind's main-thread fallback.
Resolvesjaegertracing#1179
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonah Kowall <jkowall@kowall.net>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Active issues leave cancelled searches without results on refocus, allow stale-result selection after query changes, and discard CSP violation records during navigation tests.
A test that ends on a navigation to /search/ leaves the Pagefind worker
fetch in flight in the CSP route handler. On slower CI runners it ended
after the test, and Playwright reported "route.fetch: Test ended" against
the next test. Tolerate a closed page in the handler and unroute with
ignoreErrors in afterEach.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonah Kowall <jkowall@kowall.net>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Refocusing fails to restart a canceled search, leaving the popup empty, while navigation discards earlier CSP violations and allows affected tests to pass incorrectly.
This checks only the final document's CSP violations. addInitScript recreates __cspViolations on every navigation, so tests that navigate after searching (for example, the Enter-key and mobile-link tests) discard violations from the original page and can pass despite them. Please accumulate events in a per-test collector outside the page, such as through an exposed binding, and assert that collector in teardown.
…arches
Addresses the Copilot review of jaegertracing#1180.
- While a search for edited text is pending, the listed options belong to
the old text: arrow keys no longer select them and Enter no longer opens
them.
- Returning to the box (focus or click) restarts a search that leaving the
box cancelled before results arrived. Only text the reader typed counts,
so the results page's prefilled navbar box still opens nothing on focus.
- Tests collect CSP violations in the test process, so violations on a page
a test navigates away from are no longer lost.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonah Kowall <jkowall@kowall.net>
Resolves conflicts with jaegertracing#1201 (hide the 1.x docs from version navigation):
- search.js: keep the selector entry jaegertracing#1201 adds for an unlisted requested
version, and keep this branch's removal of submit-on-change (WCAG 3.2.2).
- search.spec.ts: keep both the archived-version test from jaegertracing#1201 and this
branch's tests.
Also drop the Google Fonts entry from the search tests' known CSP
violations, since jaegertracing#1178 self-hosts the font.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonah Kowall <jkowall@kowall.net>
The reason will be displayed to describe this comment to others. Learn more.
Nice, this covers all three of the Copilot ones from #1164 plus a bunch I wouldn't have spotted (the hidden live region and the select reloading on every arrow key especially). The generation counter is a clean way to kill the "Escape then popup comes back" race, and pulling the version regex into docs-version.html so the navbar and head-end.html share it is a nice bonus.
CI's green and Copilot's threads are all sorted, so LGTM.
One tiny thing: the PR description still says the Google Fonts CSP violation is allowlisted, but KNOWN_VIOLATIONS in tests/search.spec.ts is empty now after the merge from main. Might be worth dropping that line so it doesn't confuse anyone later.
Resolves conflicts with jaegertracing#1170, which fixed a subset of the same issues
(popup dismissal, Show more duplicates, navbar scope on the results page):
- search.js: keep this branch's implementation, which covers jaegertracing#1170's
behavior (generation token, serialized Show more, results-page scope)
plus the other fixes here. To match jaegertracing#1170's tests, Escape now clears the
typed query, so returning to the box after an explicit dismissal does
not restart the search; leaving the box mid-search still does.
- search.spec.ts: keep jaegertracing#1170's nine regression tests alongside this
branch's tests; merge the header comments.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonah Kowall <jkowall@kowall.net>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A transient navbar search failure destroys the Pagefind instance still used by results-page pagination, causing “Show more” to fail and pagination to disappear until reload.
…navbar failure
Addresses the Copilot review of jaegertracing#1180. A failed navbar search reset the
shared Pagefind instance with destroy(), which terminated the worker the
results page's results still use, so the next "Show more" failed and hid
pagination until reload.
forgetPagefind() still drops the instance and destroys it to stop its
worker, except the instance the results page pinned. A retry imports the
bundle under a new URL, so it gets a fresh instance either way.
Adds a browser test that fails the navbar search's fragments on the
results page and checks that "Show more" still loads the next batch; it
fails without this change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonah Kowall <jkowall@kowall.net>
Closing as superseded by #1203. That PR replaced the hand-written search UI with Pagefind's prebuilt components, and most of the fixes here (popup dismissal and typing races, keyboard and live-region handling, Show more serialization, load-error handling) targeted the code it removed.
Three items here still apply to main and are tracked in #1179:
The mobile navbar search link drops the docs version (/search/ instead of /search/?v=<version>).
serve:search indexes the site twice (npm run build already runs Pagefind in postbuild).
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
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.
Which problem is this PR solving?
Resolves #1179. This follows up #1164, where @yurishkuro confirmed Copilot's three findings as valid and merged to unblock search.
After the merge I ran an adversarial review of the search code. Five reviewers each covered one area: async races, accessibility, version scoping, security, and templates/tests. Two independent skeptics then tried to refute each finding. All 20 findings survived, including Copilot's 3, so all 20 are fixed here.
Description of the changes
Races and error paths (
assets/js/search.js)pf.init()resolves before the index, metadata and WASM have loaded. Each keystroke'sfilters()call then polls until ready and resumes in timer order, so the final query was superseded and nothing rendered. Pagefind and the page scope now resolve once per page, behind one shared promise.destroy()and retries with a fresh module URL.Versions
navbar.htmlnow links to/search/?v=<version>on versioned docs pages. The version comes from a newdocs-version.htmlpartial, whichhead-end.htmlnow shares./search/?v=…. It searches, and Enter navigates, within that page'svinstead of the latest version.Keyboard and accessibility
hiddenpopup was not announced.<select>no longer submits on change. Before, every arrow key reloaded the page on Windows and Linux (WCAG 3.2.2). The Search button applies the choice.Layout
feature-gatessearch used to widen the page by 770px at 375px wide.Tooling
serve:searchindexes once instead of twice..Descriptionfrom fix(build): Replace template and config keys deprecated by Hugo 0.169 #1174.Tests (
tests/search.spec.ts, 3 to 15)netlify.toml.How was this change tested?
search.js, templates and SCSS. 10 tests fail, one per regression fixed here, which confirms they catch the bugs. The other 5 cover behavior that already worked.npm run test:searchpasses 15 of 15. With--repeat-each=3, 45 of 45 pass with no flakes.check:links:all,check:links:internal,check:spelling,check:filenamesand prettier on the changed files all pass./search/?v=1.76and/search/?v=2.devon versioned pages, and/search/on/docs/latest/and non-docs pages.Checklist
🤖 Generated with Claude Code