Repository navigation
Keep search auto-highlight on the first result when results render out of order - #2007
David Pine (IEvangelist) merged 3 commits into
Conversation
…t of order Pagefind renders each result after its own fragment loads, so a later result can render before the first one. SearchKeyboardNav auto-highlighted that later result, then preserved it on the next render as if the user had navigated there, and cleared the stale activeIndex against the new target list, which marked the first result aria-selected=false. Enter then opened the wrong result and the site-search arrow-key E2E test flaked. Only preserve highlights the user moved (keyboard or focus), reset on new query input, and re-index the surviving active element before setActive. Add an E2E test that holds the first fragment to reproduce deterministically. Co-authored-by: Copilot <[email protected]>
Frontend HTML artifact readyThe latest frontend build uploaded the This comment updates automatically when a new frontend build artifact is uploaded. |
There was a problem hiding this comment.
🟡 Changes recommended
Focusing an already highlighted search result does not mark user navigation, allowing a later-loading earlier result to move the highlight out of sync with keyboard focus and arrow navigation.
1 open issue
What changed in this PR
This PR fixes site-search selection when Pagefind results render out of order, so automatic highlighting follows the first result rather than the first one loaded.
Changes:
- Distinguishes automatic highlighting from user navigation and resets that state when the query changes.
- Re-indexes the previously active element before updating selection.
- Adds a request-gated regression test covering highlight state, accessibility attributes, and Enter navigation.
| File | Description |
|---|---|
src/frontend/tests/e2e/site-search.spec.ts |
Adds regression coverage for out-of-order result rendering. |
src/frontend/src/components/starlight/Search.astro |
Updates highlight preservation and active-element tracking. |
Review effort: Balanced
Focusing a result that was already auto-highlighted skipped setting userNavigated, so an earlier result that finished loading later took the highlight while keyboard focus stayed on the focused result. Co-authored-by: Copilot <[email protected]>
Project docs review — not applicableReviewed PR #2007 against Phase A — claim verification: No changed documentation claims found. The complete diff changes only the search implementation in Phase B — blind documentation testing: Not applicable: there are no changed documentation pages, sections, or executable examples to exercise. Routes exercised: none. No docs server, browser, CLI example, or sample project was run, and no documentation checks are represented as passed. Critical issues, warnings, recommendations, and knowledge gaps: not assessed (no applicable documentation scope). Search UI behavior belongs to the subsequent code review, not an invented documentation test. Outcome: Documentation applicability assessment complete; no documentation-accuracy finding. This is a top-level informational comment, not an approval or change request. The applicable code review follows separately. This one-time docs stage is recorded for the lifetime of this PR, not per head SHA. |
Project code review — two coverage gapsReviewed the complete two-file diff against High — important test coverage
Reviewed behavior and existing discussionAutomatic selection now follows the first rendered result until explicit navigation; surviving active elements are re-indexed before their old marker is cleared. Arrow/Home/End navigation records intent, focus events record intent even when the target is already active, and native Enter on a focused link remains native. Pointer-triggered focus follows the same focus handler; hover alone does not count as navigation. The input reset listener has matching cleanup. The earlier already-active focus finding is addressed at this head: Test coverage and evidenceI inspected the existing CI run for this exact head. The two new tests executed and passed, rather than skipped, along with both existing arrow-navigation cases on desktop, tablet, and mobile. The CI command was Limits and cleanup: No local tests, browser session, assistive-technology test, physical-device test, dependency restore, or local production build was performed. Bun and frontend dependencies are absent in this worktree; a dev server would not provide the production Pagefind index needed by these regressions. Viewport evidence is CI Chromium emulation, not real devices. No source changes, checkout switch, server, fixes, push, formal approval/change request, or merge. This is the one-time top-level code report for this PR, independent of future head SHAs. |
Add a deterministic regression where a refined query keeps the user's selection in its results; the new first result must take the highlight and receive Enter. Run a scoped WCAG A/AA axe audit after out-of-order insertion, focused-result preservation and the query change. The audit exposed Pagefind's list items and paragraphs sitting between the listbox and its options, so mark those wrappers presentational. Co-authored-by: Copilot <[email protected]>
|
Thanks David Pine (@IEvangelist). Both coverage gaps are addressed in 02a054f, and the new audit found a real issue that's fixed too. 1. Query-change reset regression. The new test 2. Open-dialog axe audit. Defect found by the audit. In every populated state, axe reported Validation. I ran the tests locally with Playwright against
Out of scope. An unscoped dialog scan on mobile also flags Starlight's mobile Cancel button for color contrast: 🤖 Posted by AspireAgent (AI Agent) |
- TypeScript API parameter descriptions (#2009) - No locale prefix or hreflang alternates for English-only pages: the footer language picker (#1988), hreflang (#1987) and the sidebar Glossary link (#1989) - Footer link to the Aspire MIT license - Homepage: environment fade (#1993), stale AppHost animations (#1950), the dashboard carousel keeps the selected slide on activation - Search: first-result highlight with out-of-order renders (#2007), hover cursor flicker (#1977) - Live status over WebSocket (#1942) and twoslash hover, merged into the copies of the frontend scripts - Icon data 5.40.0 and the regenerated sprite - src/frontend now uses Bun: README and script usage updated

Summary
Fixes a site search bug that also caused an intermittent E2E failure. When Pagefind results render out of order, the dialog highlights a later result instead of the first one. Pressing Enter then opens that wrong result.
CI evidence: the test "arrow keys cycle through results, Tab keeps state, and Escape closes the dialog" passed only on retry on tablet in run 41162894318, job 124426002917. It hit the same failure once more in the Oct 27–30 retry-only scan:
Root cause: Pagefind UI 1.5.2 renders each result's
.pagefind-ui__result-linkonly after that result's own fragment loads, so links can appear out of order.SearchKeyboardNav.refresh()inSearch.astrothen went wrong in two ways:activeIndexstill held the old index whiletargetswas already the new list.setActivetherefore "cleared" whichever new target sat at that index, which setaria-selected="false"on result 1.Fix (
Search.astro):inputevent) resets this, and auto-highlights always go to the first result.setActive, so the correct element is cleared.The intended preservation still works: after ArrowDown/Tab, re-renders keep the user's selection. The existing arrow-key, Tab and API-button navigation tests are unchanged and pass.
Regression test (
site-search.spec.ts): "auto-highlights the first result when later results render first". It holds the firstpagefind/fragmentrequest until a later result has rendered and been highlighted, then releases it. It asserts that:data-search-active="true"andaria-selected="true"aria-activedescendantpoints at result 1The test uses request gating, not sleeps or timeouts.
Review follow-up (c6e30bb): focusing a result that was already auto-highlighted did not count as user navigation, so an earlier result that loaded later could take the highlight while focus stayed on the focused result.
handleFocusInnow marks any focused target as user navigation and only callssetActivewhen the index changes. The second regression test, "keeps the highlight on a focused result when an earlier result renders later", covers this.Screenshots: Playwright, tablet 1024×768, light theme, search
aspirewith the first fragment held and then released.Before (main): the second result (ASPIRE010) stays highlighted.
After: the first result (ASPIRE009) is highlighted.
Third-party links and affiliations
None.
Validation
Local runs used
astro previewserving main's CIfrontend-distartifact (run 41090849945,f05f5561), with retries disabled. The extraction excludedreference/and most locale folders for disk space.toHaveAttribute('data-search-active', 'true')and the element was<a role="option" aria-selected="false" id="aspire-search-target-0" href="/diagnostics/aspire009/">, identical to the CI failure. The existing arrow-key test passed 9/9 in the same run.aria-selected="false". At natural timing, 3/3 were correct.Searchchunk. The new test and the arrow-key test passed 30/30 (×5 on each of 3 viewports).site-search.spec.tson all 3 projects gave 42 passed and 6 skipped. 6 failed, all from 2 tests that need the omitted/reference/API pages ("initializes when entering from API pages", "typed query is forwarded…"). Both fail identically on the unpatched main build in the same setup, so the failure comes from the local setup, not this change. CI covers them with the full build.data-search-active="true"while focus stayed on the later result. With the fix applied to the built chunk, both new tests and both arrow-key tests passed 60/60 (×5 on 3 viewports).npx eslint . --max-warnings 0is clean, andnpx vitest runpassed 84 files with 1,120 tests passed and 1 skipped.test.skipmessages in this spec.🤖 Posted by AspireAgent (AI Agent)