Skip to content

fix: route API sidebar links through HTMX instead of full page reload - #4155

Open
akira28 wants to merge 2 commits into
mainfrom
fix/api-blinking
Open

akira28 wants to merge 2 commits into
mainfrom
fix/api-blinking

Conversation

@akira28

@akira28 akira28 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

API sidebar links were doing a full-page reload on every click, causing the top nav and sidebar accordion to visibly redraw and reset their state between operations.

Affects: Site UI, API reference

Prompt summary: The user noticed that clicking sidebar links in the API section causes the top menu to redraw and the sidebar submenu to collapse and reopen — a blinking effect that does not happen in the regular docs section.

Why

assemblerStrategy.isExternalDocsUrl returned true for any path under /docs/api/. In main.ts, a boosted link that isExternalDocsUrl classifies as external skips HTMX entirely and calls window.location.assign. Every API sidebar click therefore triggered a full-page reload: the secondary nav, the sidebar, and its accordion state were all rebuilt from scratch on landing.

What

HTMX now handles API navigation

isExternalDocsUrl in assembler.ts returns false unconditionally. API links on the assembler build are same-origin docs paths and belong in the HTMX navigation flow. The comment that described /docs/api as "a separate app" is no longer accurate — the API explorer is rendered by the same docs-builder server.

The existing retargeting logic now fires for API-to-API navigation

shouldRetargetApiContentSwap in pages-nav.ts was already wired up to detect API-page-to-API-page navigations and retarget the HTMX swap to #api-content-grid only. With the full-page-reload bypass removed, this logic now runs. Only the content column is swapped; #pages-nav and the secondary nav are left untouched.

Verify

Run the assembler locally with the API explorer enabled:

FEATURE_ASSEMBLER_API_EXPLORER=true dotnet run --project src/tooling/docs-builder -- assembler serve

Open an API operation page (e.g. /docs/api/doc/elasticsearch/operation/operation-search-application-get-behavioral-analytics) and click several sidebar links. The top nav and sidebar should stay in place without any redraw or accordion collapse between navigations.

🤖 Generated with Claude Code

API paths (`/docs/api/…`) were classified as external URLs in
`assemblerStrategy.isExternalDocsUrl`, so every sidebar click on an API
page bypassed HTMX and called `window.location.assign`. That caused a
full-page reload — the top nav and sidebar visibly redrew and the
accordion state reset on every navigation.

Returning `false` from `isExternalDocsUrl` lets HTMX handle these links.
The existing `shouldRetargetApiContentSwap` logic then swaps only
`#api-content-grid`, leaving `#pages-nav` and the secondary nav untouched.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview (local build)

Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4155/

@github-actions github-actions Bot 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.

Requesting changes: please align the HTMX link behavior tests with the new assembler API-link routing contract before merge.


What is this? | From workflow: PR Review

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

export const assemblerStrategy: HtmxUrlStrategy = {
isExternalDocsUrl: (url) =>
url === apiRoot || url.startsWith(`${apiRoot}/`),
isExternalDocsUrl: () => false,

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.

[MEDIUM] Update assembler HTMX link tests to match this new contract

This change flips API links from external to internal for assembler, but the existing suite still asserts the old behavior in useHtmxLink.test.tsx (for example, isExternalDocsUrl('/docs/api') === true and expecting hx-disable on /docs/api/...). That makes the test suite inconsistent with this implementation and likely to fail once those tests run. Please update those assertions to validate HTMX handling for API links instead of external-link handling.

`useHtmxLink` and `useHtmxContainer` tests expected `hx-disable` on
`/docs/api/…` paths. Since `isExternalDocsUrl` now returns `false` for
all docs paths, API links are treated as internal: `htmx.process` is
called and no `hx-disable` attribute is set.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@github-actions github-actions Bot 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.

Approved.


What is this? | From workflow: PR Review

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant