Skip to content

fix(core): position popovers manually under a transformed ancestor - #9762

Merged
sampotts merged 2 commits into
videojs:mainfrom
vladosskins178:fix/popover-transformed-ancestor
Nov 18, 2026
Merged

sampotts merged 2 commits into
videojs:mainfrom
vladosskins178:fix/popover-transformed-ancestor

Conversation

@vladosskins178

@vladosskins178 vladosskins178 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9752

What

Under a transformed ancestor, PopupPositioner now uses the rect-based manual path even where CSS anchor positioning is supported (option 1 from the issue). Everything in the style then comes from getBoundingClientRect(), so both parts agree.

  • positioning.ts: new hasTransformedAncestor(element). It walks the flat tree (walkAncestors with composed: true, so it crosses the skin's shadow root) and checks transform, translate, scale, rotate and perspective. The trigger's own transform is skipped, so a pressed or animated button doesn't switch modes.
  • getAnchorPositionStyle() takes an optional useAnchorPositioning argument (default: supportsAnchorPositioning()). When the manual path runs in a browser that supports anchor positioning, it also resets translate, justify-self, align-self, margin-inline-start and margin-block-start. applyStyles() never removes properties, so values from an earlier anchor position would otherwise stay on the popup. Browsers without anchor support get exactly the same styles as before.
  • positioner.ts: anchorSupported = supportsAnchorPositioning() && !hasTransformedAncestor(trigger). This same flag also picks the containing-block origin and the popup rect, as it already did for the fallback.

Without a transformed ancestor, nothing changes in any browser.

Testing

Reproduced first with the CDN build (pnpm build:packages && pnpm build:cdn) and the default video skin inside <div style="position:absolute; left:50%; top:50%; width:640px; transform:translate(-50%,-50%)"> at 1440×900. Playwright drove headed Firefox 148.0.2 (under Xvfb, because headless Firefox reports hover: none) and Chromium. Positions are the left/top of the trigger and the popup:

trigger popup before popup after
Firefox, volume popover 449, 582 771, 654 (overlaps the controls, +320/+180 = the transform) 451, 474 (12px above, centered)
Chromium, volume popover 449, 582 451, 474 451, 474
Firefox, settings menu 956, 582 — 852, 530 (12px above, clamped inside the player)

Without the transform, Firefox and Chromium give the same positions before and after the change.

Unit tests:

  • positioning.test.ts: hasTransformedAncestor (ancestor transform, the element's own transform ignored, across a shadow root), plus the manual path with anchor support turned off (no anchor() values, anchor-only properties reset).
  • positioner.test.ts: with anchor support, a trigger gets anchor() styles. After its wrapper gets a transform, the next sync gives manual coordinates and translate: none. CSS.supports is stubbed, so there is no module mock.
  • The 5 new tests fail without the change.

Ran: vp test run in core (1709 passed), html (526) and react (695), plus pnpm typecheck and pnpm lint. I ran all of it again from a fresh clone of the branch, along with the Firefox/Chromium measurements above.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Firefox resolves CSS anchor() against the anchor's untransformed box, while
the cross-axis clamp is built from getBoundingClientRect(), which includes
transforms. Under a transformed ancestor the popup lands away from its
trigger. Use the rect-based manual path there, and clear the properties
only the anchor path sets when switching to it.

Fixes videojs#9752
@netlify

netlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

👷 Deploy request for vjs10-site pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 0d7c3e6

@netlify

netlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

👷 Deploy request for vjs-registry pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 0d7c3e6

@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown

@vladosskins178 is attempting to deploy a commit to the Mux Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Claude review: no high-confidence bugs found.

@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
videojs-sandbox Ready Ready Preview Nov 18, 2026 1:43am UTC

Request Review

@spuppo-mux spuppo-mux left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Tested on Safari, Chrome and Firefox

@sampotts

Copy link
Copy Markdown
Collaborator

Thanks for the thorough write-up and the before-and-after measurements, @vladosskins178. This looks good to merge. Falling back to the rect-based path keeps every value in one coordinate system, and the property resets cover switching back from an earlier anchor position.

Two non-blocking notes for follow-up, not this PR:

  • Moving transforms. On the manual path, the popup only repositions on scroll, window resize or a ResizeObserver callback, and a transform changing doesn't fire any of those. If the ancestor's transform animates while a popover is open (a dialog scaling in, a carousel slide moving), the popup can stay where it was until the next event. Browsers without anchor support already behave this way, but this PR extends it to Chromium and Firefox under transforms.
  • Popups outside the top layer. A popup without a popover attribute positions itself relative to the transformed ancestor, and getFixedContainingBlockOrigin only corrects for an offset, so its manual coordinates would be off under scale or rotate. That overlaps with Bug: A Media-Dialog That Is Placed Inside an Element with a transform (or filter, contain, will-change: transform, perspective, ...) Can Not Be Shown as a Full-Viewport Modal #9569.

@github-actions

Copy link
Copy Markdown
Contributor

Claude review: no high-confidence bugs found.

@sampotts
sampotts merged commit e9da7b8 into videojs:main Nov 18, 2026
28 checks passed
@videojs-release videojs-release Bot mentioned this pull request Nov 17, 2026

This branch was successfully deployed

1 active deployment
Preview — 0d7c3e69 Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Anchor-Positioned Popovers Land in the Wrong Place Under a Transformed Ancestor in Firefox

3 participants