Repository navigation
perf(Breadcrumbs): remove render cascades; add CSS-driven overflow behind a feature flag - #8610
mattcosta7 wants to merge 3 commits into
Conversation
…hind a feature flag
🦋 Changeset detectedLatest commit: 7002c75 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 |
|
|
🤖 Lint issues have been automatically fixed and committed to this PR. |
…unique landmarks in dev story)
…g; add side-by-side comparison story
|
Superseded by #8683. Same goals, measured against both implementations in one production benchmark (100 instances, 4x CPU): the CSS-overflow path here was slower on resize (2,470ms vs 975ms task, layout 456ms vs 76ms), parent re-render (487ms vs 176ms) and mount (305ms vs 211ms). It does produce fewer SSR hydration changes (6 vs 29 of 220 block-container cases), but its pre-hydration container query renders content-sized containers at 0px. #8683 keeps runtime cost lowest and narrows the SSR gap with pre-hydration-only CSS (start-clipping and a viewport narrow rule). Details and numbers are in #8683. |
Closes #
Breadcrumbs (
overflow="menu"/"menu-with-root") decides which crumbs collapse by measuring the DOM in a layout effect and re-rendering. That produces render cascades: extra mount passes that render every crumb just to measure it, a React re-render on every pixel of a resize, an extra pass on every navigation, and remounts of every crumb when the collapse point moves.This PR does two things:
primer_react_breadcrumbs_css_overflow(off by default). The browser decides which crumbs fit, so there's no measurement pass. JS only fills the overflow menu and hides collapsed crumbs from assistive tech. The first paint, including SSR, is correct before any JS runs.Render cascade: before / after
React Profiler, 50 instances (half
menu, halfmenu-with-root, 7 crumbs each), Chromium. "nested" = updates scheduled during a commit, i.e. the cascade.mainOther measurements (100 instances, Chromium):
main: 130–160msChangelog
New
primer_react_breadcrumbs_css_overflowfeature flag (defaultfalse) for a CSS-driven overflow implementation inmenuandmenu-with-rootmodes:flex-wraprow laid out leaf-first (row-reverse+order), so leading crumbs wrap onto a hidden line and the leaf always stays visible.IntersectionObserverper instance counts the clipped leading crumbs. That count is the only React state, and it only changes when a crumb crosses the edge.inert,data-overflowing,data-narrow,data-root-collapsed, the row height) is written directly to the DOM, so it never lags behind layout. This is documented inuseBreadcrumbsOverflow.ts, and a test guards that re-renders don't clobber it.menu-with-root, the root moves into the menu before the leaf is squeezed, matching current behavior.packages/react/src/Breadcrumbs/useBreadcrumbsOverflow.ts.Components/Breadcrumbs/Dev/ResizableOverflowstory: a resizable container with anoverflowcontrol; toggle the flag in the toolbar to compare implementations.Components/Breadcrumbs/Dev/CssOverflowComparisonstory: both implementations stacked in one resizable container, in both modes, for side-by-side checks. It's excluded from the generic axe sweep because two "Breadcrumbs" landmarks are inherent to showing both; the flagged implementation is axe-tested ine2e/components/Breadcrumbs.test.ts.Changed
button[...]selector never matched the<summary>, so the 32px fallback was always used. The same 32px is now an explicit constant.Removed
Rollout strategy
primer_react_breadcrumbs_css_overflowThe default-path changes ship as a patch with no flag. The CSS implementation stays off until it has been validated in Safari, in Firefox, and with screen readers.
Testing & Reviewing
Automated
BreadcrumbsCssOverflow.test.tsx(real layout in Chromium). It covers:inline-block/fit-content/ gridautocolumns)ResizeObserverloop errorsBreadcrumbs.test.tsxcases for the default path: no remounts on collapse, render counts on mount and resize.lint:react-compilerpasses. The component compiles with React Compiler; an earlier bailout caught during this work is fixed.e2e/components/Breadcrumbs.test.tsre-runs every existing overflow VRT scenario withprimer_react_breadcrumbs_css_overflowenabled against the same baseline snapshots (narrow and widemenu,menu-with-root, two-item variants), so CI fails if the flagged implementation drifts visually. The same scenarios also run axe (@aat) with the flag on.Verified with temporary probes (not committed)
menu-with-root, spacious).Behavior differences with the flag on (need design sign-off)
mainover-collapses.menu-with-rootwith exactly 4 items no longer shows an empty menu button.menu-with-rootshows all crumbs instead of degrading to leaf-only.Not yet done
How to review
Components/Breadcrumbs/Dev/CssOverflowComparison: drag the container corner and check each pair matches.Components/Breadcrumbs/Dev/ResizableOverflowfor one instance at a time (switchoverflowand the flag).