Skip to content

fix(search): Fix popup and pagination races, version handling and error paths - #1180

Closed
jkowall wants to merge 6 commits into
jaegertracing:mainfrom
jkowall:search-followups
Closed

jkowall wants to merge 6 commits into
jaegertracing:mainfrom
jkowall:search-followups

Conversation

@jkowall

@jkowall jkowall commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

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)

  • 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.

Tooling

Tests (tests/search.spec.ts, 3 to 15)

  • 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.

Checklist

🤖 Generated with Claude Code

…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.

Resolves jaegertracing#1179

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jonah Kowall <jkowall@kowall.net>
Copilot AI balanced review requested due to automatic review settings November 4, 2026 22:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

3 open issues
What changed in this PR

This PR follows up the Pagefind search rollout, addressing popup and pagination races, version scoping, accessibility, and load failures.

Changes:

  • Adds search cancellation, retry handling, and serialized pagination.
  • Preserves version scope across search entry points and improves keyboard behavior, announcements, and excerpt wrapping.
  • Expands browser regression tests with production CSP checks and removes duplicate indexing from serve:search.
File Description
themes/​docsy-overrides/​layouts/​docs/​list.html Updates comments documenting local Docsy customizations.
themes/​docsy-overrides/​layouts/​_td-content.html Updates comments documenting local Docsy customizations.
themes/​docsy-overrides/​layouts/​_partials/​search-input.html Moves result announcements outside the hidden popup.
themes/​docsy-overrides/​layouts/​_partials/​navbar.html Preserves the docs version in mobile search links.
themes/​docsy-overrides/​layouts/​_partials/​hooks/​head-end.html Uses shared version detection for search metadata.
themes/​docsy-overrides/​layouts/​_partials/​docs-version.html Adds a shared docs-version helper.
tests/​search.spec.ts Adds CSP checks and search regression coverage.
package.json Avoids indexing twice when serving search locally.
assets/​scss/​_site_search.scss Improves forced-colors highlighting and excerpt wrapping.
assets/​js/​search.js Updates async handling, pagination, version scope, and keyboard interactions.

Review effort: Balanced

Comment thread assets/js/search.js Resolved
Comment thread assets/js/search.js Resolved
Comment thread tests/search.spec.ts Resolved
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>
Copilot AI balanced review requested due to automatic review settings November 4, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity CSP violations from earlier pages are discarded

tests/​search.spec.ts:91

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.

Review effort: Balanced

…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>
Copilot AI balanced review requested due to automatic review settings November 4, 2026 22:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are identified for the documentation-search changes.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

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>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 21:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the search reliability, accessibility, and version-scoping changes.

No open issues 🎉

Review effort: Balanced

@albertteoh albertteoh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

1 open issue

Review effort: Balanced

Comment thread assets/js/search.js Resolved
…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>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 23:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the search-hardening changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@jkowall

jkowall commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

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).
  • The header comments of the copied Docsy templates (_td-content.html, docs/list.html) list only the data-pagefind-body change and miss the .Description change from fix(build): Replace template and config keys deprecated by Hugo 0.169 #1174.

The dismissal race that #1203 lists as a limitation belongs in Pagefind's component.

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.

Site search follow-ups after #1203: mobile link version, serve:search, template comments

3 participants