Repository navigation
[tabs] Consider 3D transforms when positioning the indicator - #4852
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,324.26 ms +45.20 ms(+3.5%) | Renders: 76 (+0) | Paint: 2,054.93 ms +33.40 ms(+1.7%)
14 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
flaviendelangle
left a comment
There was a problem hiding this comment.
PR #4852 Review Summary — [Tabs] Consider 3D transforms when positioning the indicator
Branch: tabs-indicator-3d · Author: @michaldudak · Diff: +132 / −46 across 4 files
Critical Issues (1)
- pr-test-analyzer: Tautological test — TabsIndicator.test.tsx:44-66 re-implements
getElementOffset/getRelativeLayoutOffsetbyte-for-byte identical to the production code at TabsIndicator.tsx:23-45. A formula regression would pass. Worse: the previous helper usedgetBoundingClientRect+ scale division, which was an independent oracle — that independence is now lost for every existing case routed throughassertBubblePositionVariables(lines 94, 116, 144, 175, 222, 271).
Important Issues (3)
- silent-failure-hunter:
offsetParent === nullis handled silently — TabsIndicator.tsx:23-34. Forposition: fixedtab lists with non-zero size, the existing width/height guards do not catch it; the function returns(0, 0)and the indicator anchors to viewport origin. The deletedhasNonZeroScaleelse-branch and the oldgetBoundingClientRect()-returns-zero path used to absorb this. Consider returningnulland bailing in the caller, or a dev-mode assertion. - pr-test-analyzer: Prehydration script has zero behavioral coverage — the only test (TabsIndicator.test.tsx:462-473) verifies the
<script>tag exists but never executes it. The duplicated math in prehydrationScript.template.js and.min.tscan drift fromTabsIndicator.tsxundetected. - silent-failure-hunter: Prehydration loop has no type guard — prehydrationScript.template.js:47-56. A non-
HTMLElementoffsetParent(e.g., SVG root) yieldsundefinedarithmetic →NaNCSS variables. The TSX-sideas HTMLElement | nullcast at TabsIndicator.tsx:25 masks rather than validates this.
Suggestions (4)
- pr-test-analyzer: Harden the 3D test (TabsIndicator.test.tsx:222-268) with fixture-derived literal expectations, e.g.
expectedLeft = 2*120 + 2*8 = 256. The 3D ancestor provesgetBoundingClientRect()math would be wrong; offset-walk should still return the literal CSS-box value — that's the assertion that catches drift. - pr-test-analyzer: Add coverage for
orientation="vertical", RTL, an intermediateposition: relativewrapper between tab and tab list, and a tab list that is itself the transformed element (transform makes it its descendants'offsetParent). - silent-failure-hunter: Add a
scaleX(0)regression test — the deletedhasNonZeroScalebranch was reachable. The new offset-walk handles it correctly, but only therotateYcase is exercised. - comment-analyzer: One-line comment justified on
- ancestor.clientLeft/- ancestor.clientTopat TabsIndicator.tsx:42-44 (and mirrors in template + test). The loop adds the ancestor's ownclientLeftonce, so the final subtraction is the non-obvious "remove ancestor's own border" step.
Strengths
- code-reviewer (full trace): Algorithm is mathematically correct across all traced cases — direct child, non-positioned wrapper, positioned wrapper with borders, no-
offsetParentroot. Common-ancestor contributions cancel exactly in the subtraction. - code-reviewer: Dropping
tabList.scrollLeft/scrollTopis correct —offsetLeftis unaffected by ancestor scrolling (unlikegetBoundingClientRect), so the old compensation is no longer needed. - code-reviewer: Removing the
hasNonZeroScalefallback is a net improvement — the old fallback to rawactiveTab.offsetLeftwas buggy for non-direct-child tabs anyway. - comment-analyzer: No stale comments left behind; no superfluous new ones added — consistent with project's default-no-comments stance.
- Bonus: minified prehydration script is smaller.
Recommended Action
- Address the tautology — replace the test's recomputed helper with literal pixel expectations derived from the CSS box model. This is the highest-leverage fix because it strengthens every case in the file, not just the new one.
- Decide on the
offsetParent === nullpolicy — either an early-bail (preferred) or a dev-mode assertion. Quick, low-risk. - Add a
scaleX(0)test alongside the 3D one to close the gap left by removinghasNonZeroScale. - Optional: one-line comment on the ancestor-
clientLeftsubtraction and aninstanceof HTMLElementguard in the prehydration loop.
The core change is sound and fixes a real bug (#4837). The blocking concern is test independence — fix that and the PR is in good shape.
|
Sizing is less ideal: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db87dce5f8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0972d5dd1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return hasTransform(element) || | ||
| (Math.abs(rectOffset[0] - layoutOffset[0]) <= 1 && | ||
| Math.abs(rectOffset[1] - layoutOffset[1]) <= 1) | ||
| ? rectOffset |
There was a problem hiding this comment.
Use layout fallback for transformed tabs under 3D skew
getIndicatorOffset unconditionally returns rectOffset whenever the active tab has any transform, which reintroduces the projection bug this change is trying to avoid when the tab list is inside a 3D-transformed ancestor. In that mixed case (e.g., a transformed active tab for visual state + parent rotateY(...)), getBoundingClientRect() deltas are skewed, but this branch bypasses layoutOffset even when the mismatch is large, so the indicator can visibly drift from the tab; the same logic is mirrored in the prehydration script, so SSR/hydration can jump too.
Useful? React with 👍 / 👎.
Codex Review (GPT-5.5)Reviewed the full PR 4852 branch against freshly fetched 1. Bugs / Issues1. 🟡 CSS
|
The script runs once to prevent a flash of a mispositioned indicator before hydration; the component recomputes the CSS variables with sub-pixel precision as soon as React hydrates. The layout offsets are within ~1px and correct under any transform, so the rect-based path is unnecessary there. Co-Authored-By: Claude Fable 5 <[email protected]>
|
I tried a different approach, and the bundle size went down substantially. The downside is that the indicator position may be slightly off (1px) before hydration. |
|
The tests are correctly inside the Chromium-only Review: mui/base-ui#4852 — [Tabs] Consider 3D transforms when positioning the indicatorOverviewThe fix is sound. The component now computes transform-immune layout offsets (cumulative Your question: can the prehydration "1px off" show a transient scrollbar?Yes, in principle — and it's a regression window the PR introduces, though a narrow one. The reasoning:
Cheap mitigation (a few bytes in the template, eliminates the entire overshoot class): left = Math.min(layoutOffset.left, tabsList.scrollWidth - width);
top = Math.min(layoutOffset.top, tabsList.scrollHeight - height);This is safe because the indicator still has Correctness of the new paths
TestsGood coverage and thoughtful design: activating tab 3 so the buggy math couldn't vacuously pass at (0,0), covering Minor notes
VerdictApprove with one suggestion: the prehydration overshoot is real, newly introduced, and fixable with the two-line |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7feffd438
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e40afe519e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| expect(Math.abs(bubbleRect.left - tabRect.left)).toBeLessThanOrEqual(1); | ||
| expect(Math.abs(bubbleRect.top - tabRect.top)).toBeLessThanOrEqual(1); | ||
| expect(Math.abs(bubbleRect.right - tabRect.right)).toBeLessThanOrEqual(1); | ||
| expect(Math.abs(bubbleRect.bottom - tabRect.bottom)).toBeLessThanOrEqual(1); |
There was a problem hiding this comment.
These four assertions are grouped in assertBubbleOverlapsActiveTab, which the new tests call from waitFor callbacks. The repository's AGENTS.md testing guidance explicitly says not to group multiple expect() assertions in a single waitFor() callback, because retries should be scoped to the one condition that may change asynchronously; if only one edge is still settling, this helper keeps retrying all four checks and obscures which condition actually needed waiting. Split these into separate waitFor calls or assert a single combined condition.
Useful? React with 👍 / 👎.
| function getActiveTabTranslation(element: HTMLElement) { | ||
| const cs = getComputedStyle(element); | ||
| let x = 0; | ||
| let y = 0; |
There was a problem hiding this comment.
I think Toast/Drawer use something similar?
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9a204f12d6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ac034d5a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ( | ||
| activeTabStyle.transform !== 'none' || | ||
| activeTabStyle.translate !== 'none' || | ||
| activeTabStyle.rotate !== 'none' || | ||
| activeTabStyle.scale !== 'none' | ||
| ) { |
There was a problem hiding this comment.
Preserve prehydration for identity transforms
When renderBeforeHydration is used and the active tab has an identity transform declaration (for example transform: translateX(0) or translate: 0 from a utility class), computed styles serialize as non-none even though the tab is not visually moved. This early return leaves the server-rendered indicator hidden until React hydrates, although the layout offset below would be correct, so the prehydration feature regresses for zero/identity transform styles.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The remark is valid, but it's an edge case. It requires renderBeforeHydration (opt-in), an identity transform declared on the active tab itself (ancestor transforms don't trigger the check), and SSR timing slow enough to notice. When it hits, the indicator simply stays hidden until hydration — the same experience as not opting into prehydration at all. Nothing is painted in the wrong place; there's no jump. That's the intended degradation path for the check, just triggered by a false positive.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1578ef9a5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // resolve against the tab's border box. | ||
| const { translate } = ownerWindow(element).getComputedStyle(element); | ||
| if (translate && translate !== 'none') { | ||
| const parts = translate.split(' '); |
There was a problem hiding this comment.
Preserve calc() translate animations
When the selected tab uses a valid translate longhand such as translate: calc(50% + 12px) 0, the computed value can retain the spaces inside calc(), so splitting on a plain space passes only calc(50% into resolveTranslateLength. That underestimates the tab-local translation, causing the comparison below to reject the rect-based offset and fall back to the un-translated layout slot, so the indicator no longer follows calc-based tab animations that the previous rect path tracked.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f92a03a2ac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The layout offset used to detect transform distortion comes from `offsetLeft`/`offsetTop`, which ignore scrolling. A scroll container between the tab and the list therefore moved the tab on screen without moving its layout slot, and the difference was read as transform distortion: the rect-based offset got rejected and the indicator was left behind by the full scroll amount. Subtract the scroll of every container between the two, in both the component and the pre-hydration script. The list's own scroll stays excluded because the indicator sits inside it and scrolls along with the tab. Also drop the now-redundant `hasNonZeroScale` guard, since a degenerate scale yields `NaN`/`Infinity` that the agreement check already rejects; resolve the active tab's computed style once instead of twice; and correct the comment on `getActiveTabTranslation` about how CSS composes the individual transform properties. Co-Authored-By: Claude Opus 5 <[email protected]>


Fixes
Tabs.Indicatordesynchronizing when the tab list is inside a 3D-transformed ancestor.The previous implementation derived indicator coordinates from
getBoundingClientRect()deltas and an inferred scale factor. That works for simple translations and axis-aligned scale transforms, but breaks with rotations, skew, perspective, or 3D transforms because bounding rects are projected viewport geometry and cannot always be mapped back to tab-list coordinates with a single scale.The component
The rect-based path is kept for transforms it can represent accurately, and the indicator falls back to layout offsets when the active tab or one of its ancestors has a distorting transform. Both offsets are computed and compared to decide which applies: the rect offset is only trusted when it agrees with the layout offset to within a couple of pixels of layout rounding, since agreement means no distortion is in effect. The layout offset walks the
offsetParentchain for both the tab and the tab list and subtracts their layout positions, so the indicator stays aligned because it lives in the same transformed subtree as the tab.Two things the comparison has to account for:
transform: translateX(12px)ortranslate: 50%on the selected tab — the indicator is a sibling and does not inherit the tab's transform. Both thetransformmatrix and thetranslatelonghand are read, with percentages resolved against the tab's border box.The pre-hydration script
The script deliberately does not mirror the component. It only ever uses the layout offset — no rect path, no scale inference — to keep the inlined bytes down, and it skips positioning entirely when the active tab carries its own
transform,translate,rotate, orscale. In that case the component may position the indicator relative to the tab's translated position, so painting the layout slot first would show a jump at hydration; leaving the indicator hidden until React takes over avoids that.Other changes
getElementTransformmoves out ofuseSwipeDismissinto its own module so the tabs bundle can use it without pulling in the swipe machinery. That is the only reasonToastRootandDrawerSwipeAreaappear in the diff — import updates, no behavior change.Browser regression tests cover rotated, flipped, and 3D-transformed ancestors, tab-local translations including percentage
translate, and a scrolled container between the list and the active tab.Shadow DOM is not specifically supported, to keep bundle size in check: the
offsetParentwalk and the pre-hydration script both stay within a single tree. (The component's scroll walk does use the shared shadow-safe traversal helper.) Transformed tabs alone are very rare. Transformed tabs using shadow DOM even more so.Fixes #4837
Demo: https://deploy-preview-4852--base-ui.netlify.app/experiments/tabs/tabs-3d-transform