Skip to content

Put the page content before the navigation tree in the preview shell - #5023

Merged
reakaleek merged 6 commits into
mainfrom
docs-nav-after-content-1bc3f486
Nov 23, 2026
Merged

reakaleek merged 6 commits into
mainfrom
docs-nav-after-content-1bc3f486

Conversation

@reakaleek

@reakaleek reakaleek commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

The preview shell now writes the page content before the navigation tree in the HTML. A crawler or LLM fetcher that stops early gets the article, and the page looks the same.

Affects: Site UI, API reference

Part of: elastic/docs-eng-team#1183. This does not shrink any page. It puts the article before the navigation tree, so a cut at 2 MB takes the tree and not the content.

Prompt summary: Crawlers and LLM fetchers may never reach the main content of a docs page, because the navigation tree is huge. The ask is to check that idea, then move the navigation after the main content in the markup and restore the visual order with CSS.

Why

The preview shell (NAVIGATION_PREVIEW) writes <aside class="layout__nav"> ahead of <main>. The tree is large: on the assembled docs the navigation is about 98% of each page's bytes, so a fetcher with a size or token limit can cut the page off before the article. The legacy layouts already put the content first. The preview shell is the one that does not, and it is the layout the site is moving to.

What

Docs shell

The navigation tree now follows the content and the rail in the markup. The tree moves from _DesignSystemShellStart.cshtml to _DesignSystemShellEnd.cshtml, just before the closing .layout element. .layout__nav already takes its column through grid-area: nav, so no CSS changes and the page looks the same.

API explorer shell

The preview branch of src/Elastic.ApiExplorer/_Layout.cshtml gets the same move. The nav stays a sibling of .layout__main, so the drawer toggle selector .layout__drawer-toggle:checked ~ .layout__nav still matches.

Keyboard focus in the drawer

On a narrow screen the drawer opens from a checkbox. With the tree after the article, the next Tab after opening went into the page behind the scrim. bindDrawerFocus in ds/nav.ts now moves focus to the drawer itself when it opens, so the next Tab reaches its first control, the tree keeps its scroll position and no search field raises a phone's keyboard. Escape closes the drawer and focus returns to the checkbox. Above the 860px breakpoint the handler does nothing. It keys on the #pages-nav-hamburger and #pages-nav ids, which both shells share.

Order tests

NavigationFollowsTheContent asserts that id="pages-nav" comes after the closing </article> in the docs shell. Layout_PutsTheNavigationAfterTheArticleWhenPreviewEnabled asserts the same for the API layout. Each fails on the old order.

Out of scope: The navigation tree is still the same size. Shrinking it, and compressing HTML for /docs at the CDN, would help more and are separate changes. The legacy layouts keep the same drawer focus behaviour as before. The drawer has no focus trap, so Shift+Tab from it still reaches the article.

Verify

dotnet test --project tests/Elastic.Authoring.Tests --treenode-filter "/*/*/*/NavigationFollowsTheContent"
dotnet test --project tests/Elastic.ApiExplorer.Tests --treenode-filter "/*/*/ApiPagesNavRenderingTests/Layout_*"
mise run site:test
FEATURE_NAVIGATION_PREVIEW=true mise run serve
curl -s http://localhost:3000/ | grep -bo -E 'id="markdown-content"|id="pages-nav"'

The article offset is lower than the navigation offset. At desktop, tablet and mobile widths the page matches main, apart from 6 pixels of anti-aliasing on one icon. At 600px, focus the menu checkbox and press Space, then Tab: focus stays inside the drawer. Escape closes it and focus returns to the checkbox.

🤖 Generated with Claude Code

The preview shell wrote the navigation tree ahead of the page. On a large docset the tree is megabytes, so a crawler or LLM fetcher that stops early never reaches the article. The tree now follows the content in the markup, and `grid-area` keeps it in the left column, so the page looks the same.

The docs shell and the API explorer shell both change. The legacy layouts already put the content first. `NavigationFollowsTheContent` guards the order.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 23, 2026 21:45
@reakaleek
reakaleek requested a review from theletterf November 23, 2026 21:45
Comment thread src/Elastic.ApiExplorer/_Layout.cshtml Resolved
…y Libra)

The order test rendered the Markdown shell only, so moving the API explorer tree back ahead of the article left it green. `Layout_PutsTheNavigationAfterTheArticleWhenPreviewEnabled` renders the API layout with the preview on.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

…iew by Libra)

The drawer checkbox now comes before the article, not before the tree, so the next Tab after opening the drawer went into the page behind the scrim. `bindDrawerFocus` moves focus to the drawer's first control on open and back to the checkbox on close.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
reakaleek and others added 3 commits November 23, 2026 23:02
…view by Libra)

Above 860px the sidebar is always open, but its transparent checkbox is still in the tab order, so a Space on it moved focus past the article into the sidebar. `bindDrawerFocus` now acts only when the `max-width: 860px` query matches.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…er review by Libra)

Focusing the first control scrolled the tree back to the top on every reopen and, on a single-version API page, put focus in the "Jump to API" field, which raises a phone's keyboard. The drawer takes focus instead, so the tree keeps its scroll position and the next Tab reaches its first control. This answers both review threads, which have the same cause.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Once focus moves into the drawer, Space no longer reaches the checkbox and the drawer has no close control. Escape now closes it and the change handler puts focus back on the checkbox. A focus trap stays out of scope.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@reakaleek
reakaleek merged commit 3e3f3e5 into main Nov 23, 2026
44 checks passed
@reakaleek
reakaleek deleted the docs-nav-after-content-1bc3f486 branch November 23, 2026 22:27
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