Skip to content

[tabs] Consider 3D transforms when positioning the indicator - #4852

Merged
michaldudak merged 24 commits into
mui:masterfrom
michaldudak:tabs-indicator-3d
Aug 13, 2026
Merged

michaldudak merged 24 commits into
mui:masterfrom
michaldudak:tabs-indicator-3d

Conversation

@michaldudak

@michaldudak michaldudak commented May 19, 2026 •

Copy link
Copy Markdown
Member

Fixes Tabs.Indicator desynchronizing 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 offsetParent chain 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:

  • The active tab's own translation moves its rect but not its layout slot, so it is subtracted before comparing. This is what lets the indicator follow tab-local animations such as transform: translateX(12px) or translate: 50% on the selected tab — the indicator is a sibling and does not inherit the tab's transform. Both the transform matrix and the translate longhand are read, with percentages resolved against the tab's border box.
  • Scroll containers between the tab and the list move the tab on screen without moving its layout slot, so their scroll is subtracted from the layout offset. Otherwise the difference reads as transform distortion, the rect offset is rejected, and the indicator is left behind by the full scroll amount. The list's own scroll is excluded, because the indicator sits inside it and scrolls along with the tab.

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, or scale. 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

getElementTransform moves out of useSwipeDismiss into its own module so the tabs bundle can use it without pulling in the swipe machinery. That is the only reason ToastRoot and DrawerSwipeArea appear 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 offsetParent walk 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

@pkg-pr-new

pkg-pr-new Bot commented May 19, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4852
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4852
    

commit: 9194d36

@code-infra-dashboard

code-infra-dashboard Bot commented May 19, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+699B(+0.15%) 🔺+291B(+0.20%)

Details of bundle changes

Performance

Total duration: 1,324.26 ms +45.20 ms(+3.5%) | Renders: 76 (+0) | Paint: 2,054.93 ms +33.40 ms(+1.7%)

Test Duration Renders
Dialog mount (300 instances) 63.56 ms 🔺+10.96 ms(+20.8%) 1 (+0)

14 tests within noise — details

Metric alarms

Test Metric Change
Dialog mount (300 instances) bench:paint 🔺 +17.78 ms

Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented May 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9194d36
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a7d7c8f82b9a60008476619
😎 Deploy Preview https://deploy-preview-4852--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@michaldudak michaldudak changed the title [Tabs] Consider 3d transforms when positioning the indicator [Tabs] Consider 3D transforms when positioning the indicator May 19, 2026
@michaldudak michaldudak added component: tabs Changes related to the tabs component. type: bug It doesn't behave as expected. labels May 19, 2026
@michaldudak
michaldudak marked this pull request as ready for review May 19, 2026 08:23

@flaviendelangle flaviendelangle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / getRelativeLayoutOffset byte-for-byte identical to the production code at TabsIndicator.tsx:23-45. A formula regression would pass. Worse: the previous helper used getBoundingClientRect + scale division, which was an independent oracle — that independence is now lost for every existing case routed through assertBubblePositionVariables (lines 94, 116, 144, 175, 222, 271).

Important Issues (3)

  • silent-failure-hunter: offsetParent === null is handled silently — TabsIndicator.tsx:23-34. For position: fixed tab 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 deleted hasNonZeroScale else-branch and the old getBoundingClientRect()-returns-zero path used to absorb this. Consider returning null and 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.ts can drift from TabsIndicator.tsx undetected.
  • silent-failure-hunter: Prehydration loop has no type guard — prehydrationScript.template.js:47-56. A non-HTMLElement offsetParent (e.g., SVG root) yields undefined arithmetic → NaN CSS variables. The TSX-side as HTMLElement | null cast 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 proves getBoundingClientRect() 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 intermediate position: relative wrapper 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 deleted hasNonZeroScale branch was reachable. The new offset-walk handles it correctly, but only the rotateY case is exercised.
  • comment-analyzer: One-line comment justified on - ancestor.clientLeft / - ancestor.clientTop at TabsIndicator.tsx:42-44 (and mirrors in template + test). The loop adds the ancestor's own clientLeft once, 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-offsetParent root. Common-ancestor contributions cancel exactly in the subtraction.
  • code-reviewer: Dropping tabList.scrollLeft/scrollTop is correct — offsetLeft is unaffected by ancestor scrolling (unlike getBoundingClientRect), so the old compensation is no longer needed.
  • code-reviewer: Removing the hasNonZeroScale fallback is a net improvement — the old fallback to raw activeTab.offsetLeft was 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

  1. 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.
  2. Decide on the offsetParent === null policy — either an early-bail (preferred) or a dev-mode assertion. Quick, low-risk.
  3. Add a scaleX(0) test alongside the 3D one to close the gap left by removing hasNonZeroScale.
  4. Optional: one-line comment on the ancestor-clientLeft subtraction and an instanceof HTMLElement guard 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.

@atomiks

atomiks commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Sizing is less ideal:

Before:
Screenshot 2026-05-19 at 10 08 25 pm

After:
Screenshot 2026-05-19 at 10 08 38 pm

https://master--base-ui.netlify.app/experiments/tabs/tabs-overflow

@michaldudak
michaldudak requested a review from aarongarciah as a code owner May 20, 2026 10:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +106 to +109
return hasTransform(element) ||
(Math.abs(rectOffset[0] - layoutOffset[0]) <= 1 &&
Math.abs(rectOffset[1] - layoutOffset[1]) <= 1)
? rectOffset

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@michaldudak
michaldudak marked this pull request as draft May 20, 2026 11:47
@michaldudak
michaldudak marked this pull request as ready for review May 21, 2026 07:02

Copy link
Copy Markdown
Member Author

Codex Review (GPT-5.5)

Reviewed the full PR 4852 branch against freshly fetched upstream/master. Dominant type: bug-fix; the offset-path approach looks sound for the reported 3D transform bug, with one remaining browser-facing transform gap.

1. Bugs / Issues

1. 🟡 CSS scale longhand flips still use the rect path (non-blocking)

packages/react/src/tabs/indicator/hasDistortingTransform.ts

function hasDistortingTransformLonghand(css: CSSStyleDeclaration): boolean {
  const rotate = css.getPropertyValue('rotate').trim();
  // ...
  return (
    // rotate / perspective only
  );
}

The helper handles rotate longhand, but not scale. In Chromium, scale: -1 1 leaves computedStyle.transform as none, so the matrix check is bypassed; the rect formula then loses the flip direction because rect.width / cssWidth is positive.

Fix: Parse css.getPropertyValue('scale') and treat negative X/Y scale values as distorting. Add a browser regression for style={{ scale: '-1 1' }} and mirror the logic in the prehydration script.

Test Coverage Assessment

I ran pnpm test:chromium TabsIndicator --no-watch and pnpm test:jsdom TabsIndicator --no-watch; both passed. The added browser tests cover the reported 3D transform case plus rotation and shorthand flip cases.

Recommendation

Approve after nits are addressed 🟡

The main fix addresses the reported desync and is covered by targeted browser tests. I’d address the longhand scale gap before merging so the transform classifier covers the same flip semantics regardless of whether authors use shorthand or individual transform properties.

@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 10, 2026
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]>
@michaldudak

Copy link
Copy Markdown
Member Author

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.

atomiks commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The tests are correctly inside the Chromium-only describe.skipIf(isJSDOM)('rendering') block, and I have the full picture of the old vs. new code paths now. Here's the review.

Review: mui/base-ui#4852 — [Tabs] Consider 3D transforms when positioning the indicator

Overview

The fix is sound. The component now computes transform-immune layout offsets (cumulative offsetLeft/offsetTop walk) as the baseline, and only upgrades to the sub-pixel rect-based value when both agree within 2px — i.e. when no distorting transform is in effect. The prehydration script drops the rect path entirely and uses only layout offsets. A nice side benefit nobody mentions in the PR description: during an animated transform transition, rects are mid-flight garbage while layout offsets stay stable, so switching tabs during the flip now bakes in correct values — the "Switch during flip" demo case.

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:

  • Before this PR, the prehydration script's else { offsetLeft } branch was nearly unreachable (hasNonZeroScale is true for any visible list), so prehydration values were sub-pixel exact from the rect path. After, prehydration left/top are always integer-rounded.
  • offsetLeft rounds to nearest, so when the active tab's true position has a fractional part ≥ 0.5, the rounded left overshoots by up to 0.5px (and width can add ~0.5px more when getCssDimensions hits its offsetWidth fallback, e.g. box-sizing: content-box). If the active tab is the one defining the content's right/bottom edge (typically the last tab), the indicator — absolutely positioned inside the list — extends past scrollWidth by that sub-pixel amount. Browsers compute scrollable overflow at fractional precision, so an overflow: auto list that previously fit exactly gains a scrollbar until hydration replaces the values. On classic-scrollbar platforms (Windows, macOS "Always show") that's a visible flash plus a ~15px layout shift, and the whole point of renderBeforeHydration is that hydration may be seconds away.
  • Why your overflow demo doesn't show it: it's layout-dependent (needs a ≥.5 fractional position that rounds up, on the edge-defining tab), and in that demo the list already scrolls — an extra 0.5px of overflow is invisible when the scrollbar is already present. The risky case is a list that exactly fits. macOS overlay scrollbars also hide it. So "looks fine in the demo" is not proof of safety here.

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 hidden when scrollWidth is read, so it reflects only real content. It also degrades nicely: when the true edge rounds up into scrollWidth, the clamp is inactive and nothing changes; when it rounds down, the clamp recovers a near-exact sub-pixel value for the last tab. It additionally guarantees --active-tab-right/--active-tab-bottom never go negative, which the current code allows (consumers styling via right would otherwise get a sub-pixel left-shift). Trailing list padding makes the clamp inactive, never wrong.

Correctness of the new paths

  • The 2px agreement gate (MAX_LAYOUT_ROUNDING_ERROR): the trade-offs are reasonable. False-accept: a very slight distortion (rotate < ~1°, weak perspective) shifts the rect by < 2px, so the rect path wins while marginally wrong — but error is bounded by the gate itself. False-reject needs 5+ fractional offset hops compounding in the same direction — contrived, and the fallback is still correct to ±rounding. Gating both axes together (rather than per-axis) is right, since real distortions affect both.
  • Pure-scale transforms (the case the old code explicitly supported): rect/scale agrees with the layout offset within rounding, so the precise path is still taken. No regression there.
  • getCumulativeOffset: the offsetLeft + offsetParent.clientLeft walk is the standard correct algorithm (offsets are relative to the offset parent's padding edge, so each hop must re-add its border). Scroll-independence is what you want here, since the CSS vars are consumed in the list's content box. Known unhandled quirks — position: sticky mid-stick, table cells, scrolled ancestors between tab and list — are pre-existing or pathological; fine to ignore. The shadow DOM exclusion is explicitly justified in the description.

Tests

Good coverage and thoughtful design: activating tab 3 so the buggy math couldn't vacuously pass at (0,0), covering transform, the rotate/scale longhands, scaleX(-1) (size-preserving, so the old scale heuristic couldn't detect it), and perspective(...) rotateY(...) for the original issue. The "list is not the offset parent" test pins down the getLayoutOffset subtraction specifically. All correctly Chromium-restricted. One gap worth considering: no prehydration-script test for the transformed case — the script was rewritten but only the component path is exercised (and an RTL case for the fallback path would be nice-to-have).

Minor notes

  • prehydrationScript.min.ts semantics match the template (rect/scale code fully gone, list dimensions no longer computed — dead code removed). The if (activeTab != null && tabsList != null) check in the template is redundant after the early returns, but it's pre-existing.
  • Bundle impact looks roughly neutral: the minified script is about the same length; the component keeps both paths plus the gate, a small add.
  • The experiment follows the repo utilities (useTimeout, useStableCallback) correctly.

Verdict

Approve with one suggestion: the prehydration overshoot is real, newly introduced, and fixable with the two-line Math.min clamp above — worth adding given renderBeforeHydration exists precisely for the long-hydration scenario where the flash would be most visible.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +159 to +162
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Split retried overlap checks

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 👍 / 👎.

Comment on lines +250 to +253
function getActiveTabTranslation(element: HTMLElement) {
const cs = getComputedStyle(element);
let x = 0;
let y = 0;

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.

I think Toast/Drawer use something similar?

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@oliviertassinari
oliviertassinari requested a review from jjenzz as a code owner June 27, 2026 20:50
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 3, 2026
@michaldudak michaldudak changed the title [Tabs] Consider 3D transforms when positioning the indicator [tabs] Consider 3D transforms when positioning the indicator Jul 6, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +26 to +31
if (
activeTabStyle.transform !== 'none' ||
activeTabStyle.translate !== 'none' ||
activeTabStyle.rotate !== 'none' ||
activeTabStyle.scale !== 'none'
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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(' ');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 16, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 13, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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]>
@michaldudak
michaldudak merged commit 6078aad into mui:master Aug 13, 2026
6 checks passed
@michaldudak
michaldudak deleted the tabs-indicator-3d branch August 13, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: tabs Changes related to the tabs component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tabs] Tabs.Indicator position gets stuck / desynchronized inside a 3D rotated parent

4 participants