Skip to content

perf(ui): cache search keyboard navigation targets#6

Closed
trivikr wants to merge 2 commits intomainfrom
get-focusable-elements
Closed

perf(ui): cache search keyboard navigation targets#6
trivikr wants to merge 2 commits intomainfrom
get-focusable-elements

Conversation

@trivikr
Copy link
Copy Markdown
Owner

@trivikr trivikr commented Mar 25, 2026

Context

The search page supported keyboard navigation across org/user suggestions and package results, but it rebuilt the focusable target list on every ArrowUp / ArrowDown key press by querying the document, filtering for visible elements, and sorting them. That made navigation cost grow with the number of rendered results and suggestions, even though the navigation order is already reflected in DOM order.

Description

This change makes search keyboard navigation use a cached, container-scoped list of focusable result elements instead of recomputing that list on each key event.

The results section now keeps track of focusable suggestion/result elements under a dedicated container ref. That cache is refreshed when the results DOM changes via a MutationObserver, with updates coalesced through requestAnimationFrame to avoid redundant work during rapid UI changes. Keyboard handlers then read from the cached array directly, preserving the existing behavior while removing repeated whole-document queries and sorts from the hot path.

It also includes the necessary lifecycle cleanup for the observer and any pending scheduled refresh when the page state changes or the component unmounts.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes /search keyboard navigation by caching the set of keyboard-focusable result targets instead of querying/sorting the DOM on every keypress.

Changes:

  • Introduces a resultsContainerRef root and a cached focusableElements list.
  • Adds a MutationObserver + requestAnimationFrame scheduling to refresh the cached list when the results DOM changes.
  • Updates keyboard navigation to use the cached list and adds cleanup on unmount.

Comment thread app/pages/search.vue
Comment thread app/pages/search.vue
@trivikr
Copy link
Copy Markdown
Owner Author

trivikr commented Mar 25, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Copy Markdown

Copilot AI commented Mar 25, 2026

@trivikr I've opened a new pull request, #7, to work on those changes. Once the pull request is ready, I'll request review from you.

trivikr and others added 2 commits April 12, 2026 11:14
…sly on start (#7)

Co-authored-by: trivikr <16024985+trivikr@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@trivikr trivikr force-pushed the get-focusable-elements branch from 5c2d673 to 3dafbd7 Compare April 12, 2026 18:14
@trivikr trivikr closed this Apr 12, 2026
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.

3 participants