Repository navigation
perf(Breadcrumbs): rebuild overflow menu for fewer renders, cheaper layout and better SSR - #8683
Conversation
…ut work Crumbs stay mounted as keyed list items, the count rule applies during render (including SSR), widths are measured once per content change, and resizes only re-render when the collapse point moves. The overflow menu mounts its items and document listeners only while open. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…y menu, cheaper resize layout - Collapsed crumbs render no content while the overflow menu shows them, so each crumb exists once in the DOM. Widths are cached by key so they survive that. - Crumbs below the count rule at full width are not rendered at all. - The overflow menu only renders when it has items (main showed an empty menu for 4-crumb and some 2-crumb menu-with-root cases). - Hidden measurable crumbs are zero-size in-flow flex items instead of absolute boxes, which cut resize layout time from ~1.7x to ~1.1x of main. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Server-rendered markup now clips crumbs that don't fit at the start (the leaf stays visible, nothing paints outside the nav) and applies the narrow rule with a viewport media query. JS sets data-hydrated in its first layout effect, so none of this applies afterwards. A container query was rejected: its size containment renders content-sized containers at 0px before hydration. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🦋 Changeset detectedLatest commit: f5456b6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
There was a problem hiding this comment.
🟡 Changes recommended
Fit-dependent width remeasurement can repeatedly reverse collapse decisions near layout boundaries, causing a render loop that can hit React’s maximum update depth.
5 open issues
What changed in this PR
Rebuilds Breadcrumbs overflow handling to reduce renders, preserve crumb identity as collapse points change, and improve server-rendered layout without adding public API or a feature flag.
Changes:
- Caches crumb widths and updates collapse state only when needed.
- Uses a button-triggered overflow menu with lazily mounted content and listeners.
- Adds pre-hydration layout rules and regression coverage for overflow, rendering, and SSR.
| File | Description |
|---|---|
packages/react/src/Breadcrumbs/Breadcrumbs.tsx |
Reworks measurement, collapse state, keyed crumbs, and the overflow menu. |
packages/react/src/Breadcrumbs/Breadcrumbs.module.css |
Adds collapsed-item styling and pre-hydration clipping and narrow-layout rules. |
packages/react/src/Breadcrumbs/__tests__/BreadcrumbsOverflow.test.tsx |
Adds real-layout, render-count, DOM identity, and hydration tests. |
packages/react/src/Breadcrumbs/__tests__/Breadcrumbs.test.tsx |
Updates menu selectors for the replacement markup. |
packages/react/src/Breadcrumbs/__tests__/__snapshots__/BreadcrumbsItem.test.tsx.snap |
Refreshes the generated CSS class snapshot. |
packages/react/src/__tests__/ssr.test.tsx |
Tests server-rendered collapse and the hidden standby menu. |
.changeset/breadcrumbs-overflow-performance.md |
Documents the patch release’s performance and behavior changes. |
Review effort: Balanced
|
One or more custom setup steps configured for this repository failed during this Copilot code review run: Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review. Note You can configure setup steps for Copilot code review separately from Copilot cloud agent with a |
Real-layout repros: update-depth loop with large text, unhydrated Tab focus offscreen, hide/show remeasure, content-box width, menuOpen reset. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Measure plain and collapsed separators independently, keep focused crumbs visible via focus-within wrapping, preserve fit on zero-width hide/show, use consistent content-box width, and reset menuOpen when wrapping. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A pointer left over the spot where the overflow menu button appears opens its tooltip, causing an unrelated render. Park the pointer there, then move it away before measuring. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…n't oscillate A collapsed crumb sits in a zero-width grid item, so a crumb with a min-width below its content shrank to that minimum and measured narrower than it is when shown. The fit then flipped between the two states until React threw 'Maximum update depth exceeded'. Size the collapsed item's grid track to max-content so the measurement is the natural width. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve the overflow rewrite and natural-width measurement fix while adopting upstream browser locators and popup accessibility semantics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Integration test results from github/github-ui PR:
All checks passed! |


Closes #
Supersedes #8610.
Rebuilds
overflow="menu"/"menu-with-root"so React renders only when the collapse point moves, crumbs never remount, and server-rendered markup is close to the hydrated result. There is no new public API and no feature flag.How it works
<li>per crumb. Collapsing flips adata-collapsedattribute; it never remounts the crumb. A collapsed crumb that can come back at wider sizes stays in the row as a zero-size, invisible item, soscrollWidthstill reports its natural width. Crumbs that can never come back aren't rendered.data-hydratedin its first layout effect, so none of this applies afterwards.Measurements
Production build with React Compiler, 100 instances (half
menu, halfmenu-with-root, 7 crumbs), Chromium, median of 7 runs with implementations interleaved. Task time (ms):mainResize layout time is on par with
main(4×: 76ms vs 75ms). #8610's CSS path used 456ms.SSR: server markup is rendered in the browser, then hydrated. The probe counts cases where visible crumbs, the menu, or the nav's size change on hydration. 220 cases per row: both modes, 2 to 7 crumbs, 160 to 1000px; viewport ≈ container width.
mainChangelog
New
menu/menu-with-rootmarkup applies the count rule, clips crumbs that don't fit at the start, and applies the narrow rule on viewports under 544px.Changed
<button>; it was a<summary>inside<details>. Its items and document listeners mount only while it's open.mainshowed a "0 more breadcrumb items" button for 4-crumbmenu-with-rootand some 2-crumb cases.main's estimate (16px per crumb, 32px button) to keep visual parity. A sweep of 5,352 width × mode × variant × content combinations againstmainfound 0 position differences. 13 combinations collapse one crumb up to 4px earlier; none are at VRT widths.Removed
Rollout strategy
The global nav (
ContextRegion, server-rendered byui-service) is the main consumer. Its overflow test queries by role, so it should pass unchanged (inferred, not run). Please verify with the integration workflow.Testing & Reviewing
Commands run:
npx vitest run --config vitest.config.browser.mts src/Breadcrumbs: passed, 40 testsnpx vitest run --config vitest.config.mts src/__tests__/ssr.test.tsx: passed, 4 testsnpm run type-check: passednpx eslint packages/react/src/Breadcrumbs packages/react/src/__tests__/ssr.test.tsx --max-warnings=0: passednpx stylelint packages/react/src/Breadcrumbs/Breadcrumbs.module.css: passednpm run lint:react-compiler -w @primer/react: passednpm run format:diff: passedNew tests:
BreadcrumbsOverflow.test.tsx(real layout):main's implementation; the two pre-hydration tests also fail against this branch's first commit.ssr.test.tsx: collapsed server markup and the hidden standby menu.Known gaps:
main).data-hydratedwrite runs before each instance's width read. When many instances mount in one commit, that adds layout passes. 100 instances at 4× take 211ms vs 194ms without it; one instance pays nothing extra (inferred).Container queries were evaluated and rejected. They match the narrow rule exactly, but size containment renders content-sized containers (inline-block, grid
autocolumns) at 0px before hydration: 220/220 probe cases, also present in #8610.