Skip to content

fix: position overlays in their own window - #10967

Closed
Hanan88 wants to merge 2 commits into
adobe:mainfrom
Hanan88:codex/position-overlays-in-owner-window
Closed

Hanan88 wants to merge 2 commits into
adobe:mainfrom
Hanan88:codex/position-overlays-in-owner-window

Conversation

@Hanan88

@Hanan88 Hanan88 commented Nov 15, 2026 •

Copy link
Copy Markdown

Closes #10951.

Summary

Popovers in a secondary window can use the opener’s viewport for placement, stay in place when their own window resizes, or close when an unrelated element scrolls.

Use the overlay and trigger’s owning document and window for geometry, resize events, and scroll handling. Keep explicitly configured boundaries and continue dismissing when an ancestor of the trigger scrolls. Add browser regression tests for placement, resize, and scroll dismissal in a secondary document.

The proposed containing-element helper in #10558 could shorten the containing-block lookup once available. The viewport, scroll, and observer fixes use the DOM helpers already available on main. The existing positioning callback now clears the recorded viewport scale when the popover closes.

📝 Test Instructions

  1. Run yarn start-parcel3 and open React Aria Components → Popover → Secondary Window in Storybook.
  2. Keep the Storybook window tall, click Open secondary window, then click Open popover inside the smaller window. At about 340 px of inner height, the popover should fit above the button.
  3. With the popover still open, use the mouse wheel over Scroll here with the popover open in the upper-right of the popup. The popover should stay open.
  4. Grow the popup to about 560 px of inner height. The popover should move below the button while remaining open.

I ran the story in a real Chrome popup with both versions of the positioning code. With the original code, the popover opened below the button and was clipped, and scrolling the separate area dismissed it. With the fix, all four steps behaved as described. I ran the story component directly because the local Storybook build failed in Parcel on Windows. The broader local Jest and SSR runs hit failures in the Table and NumberField suites.

Release impact

  • Only changes docs, tests, CI, or development tools. Nothing shipped to users changes.
  • Fixes a bug or improves existing code without changing how apps use it.
  • Adds a feature or API while keeping existing usage working.
  • May break existing usage or require changes in apps that use this code.

✅ PR Checklist

  • I followed the contributing guide.
  • I tested this change locally and included the results in Test Instructions, or explained why testing does not apply.
  • I understand and can explain every change in this PR. If I used AI assistance, I followed the AI contribution guidance.

🧢 Your Project

Independent open-source contribution, prepared with Codex assistance.

@snowystinger snowystinger 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.

I took a brief look, this is way more changes than I was expecting, though most of it looks pretty straightforward. Can you check if building based on https://github.com/adobe/react-spectrum/pull/10558/changes would simplify things.

Test instructions in the PR description is so that a human can verify what going on. Saying that test pass doesn't really help us much, we can see that all the tests pass or fail in CI. If there isn't a way to do that, then please add some more tests and stories. Sidenote, it doesn't look like the tests open new windows? just iframes, which wasn't mentioned in the issue. I'm fine that this fixes those as well, but please add a story which shows the original bug.

}
// Freeze positioning if the viewport is zoomed after opening the overlay.
let initialViewport = useRef<{viewport: VisualViewport; scale: number} | null>(null);
useLayoutEffect(() => {

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.

why'd this change from a useEffect to a useLayoutEffect


let visualViewport = getVisualViewport();
let ownerWindow = getOwnerWindow(overlayNode);
let documentElement = overlayNode.ownerDocument.documentElement;

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.

we have a getOwnerDocument helper as well that we should try to use

@Hanan88 Hanan88 closed this Nov 16, 2026
@snowystinger

Copy link
Copy Markdown
Member

What happened? Why was this PR closed? did something not work? or did you not have time for further changes?

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.

Overlays rendered into a second window (window.open, Document Picture-in-Picture) are positioned against the opener window

2 participants