Skip to content

Keep the API search open until the clicked page loads - #4839

Merged
reakaleek merged 2 commits into
mainfrom
search-dropdown-htmx-nav-83315d4a
Nov 12, 2026
Merged

reakaleek merged 2 commits into
mainfrom
search-dropdown-htmx-nav-83315d4a

Conversation

@reakaleek

@reakaleek reakaleek commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

The API sidebar search now stays open after a reader clicks a result or presses Enter, and closes once htmx has swapped the new page in. Meanwhile the search input shows its spinner, so the reader sees that the page is loading.

Affects: Site UI, API reference

Prompt summary: Clicking a result in the API navigation search closes the dropdown at once, while the next page can still take a moment to load, which feels odd. The ask is to close the dropdown only when the page has loaded, in the way that fits htmx best.

Why

A click on a result closes the dropdown in the same click event. The boosted htmx request for the next page is still in flight, so the reader sees the old page with no dropdown and no sign of progress. On a slow response that gap is long enough to look like the click did nothing.

What

Wait for the request of the clicked link

htmx sends the request from its own listener on the link, before the React onClick runs. NavigationSearch listens for htmx:beforeSend from its own result links and remembers the link. It closes the dropdown on htmx:afterRequest for that link. htmx fires that event after the swap, and also on an error, abort or timeout, so the dropdown cannot stay stuck. The component uses beforeSend, not beforeRequest, because preloads and the new-tab and full-page-load paths in htmx-hooks.ts cancel beforeRequest and never send.

Close at once when nothing is sent

A click that starts no htmx request still closes the dropdown at once, as before. A same-page #fragment link is an example. Cmd, Ctrl and Shift clicks still open a new tab and leave the dropdown open.

Cancel and loading state

Escape during the load aborts the request and closes the dropdown. Typing aborts the request and keeps the results open. The input shows its spinner and the result list is aria-busy and ignores further clicks. The component also cancels htmx:beforeRequest for any other result while one is pending, so a result reached with Tab and Enter cannot race the first request. Enter now clicks the selected link and goes through the same path as a mouse click.

Out of scope: ModalSearch has a similar pattern that closes on htmx:afterSwap only. A shared hook for both components is a possible follow-up.

Verify

mise run site:test
# NavigationSearchWrapper while htmx loads the result — stays open, Enter, Escape abort, typing abort

The search box renders only on assembler builds. To see it, run an assembler build with FEATURE_ASSEMBLER_API_EXPLORER=true and serve it. Then open /docs/api/doc/elasticsearch/, set network throttling to Slow 3G, type in the sidebar search and click a result.

🤖 Generated with Claude Code

A click on a result closed the dropdown at once, while the boosted
htmx request was still in flight. The reader saw the old page with no
cue for a moment. The dropdown now waits for `htmx:afterRequest` of
the clicked link and shows the input spinner meanwhile. Escape or
typing aborts the request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 12, 2026 15:00
@reakaleek
reakaleek requested a review from Mpdreamz November 12, 2026 15:00
@github-actions

Copy link
Copy Markdown
Contributor

`pointer-events: none` stops mouse clicks on the other results, but a
reader can still focus another result link and press Enter. Its
request then races the one in flight. `NavigationSearch` now cancels
`htmx:beforeRequest` for any other result while a navigation is
pending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@reakaleek
reakaleek merged commit 2b16fb6 into main Nov 12, 2026
43 checks passed
@reakaleek
reakaleek deleted the search-dropdown-htmx-nav-83315d4a branch November 12, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant