Skip to content

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

Open

Description

@crhayes

🐛 Bug Report

When a React tree is portaled into another window's document, such as a popup from window.open() or a Document Picture-in-Picture window, overlay positioning uses the opener's window globals. Popovers and menus then show up in the wrong place, stay at 0,0 or close unexpectedly. This is a specific case of #4634.

🤔 Expected Behavior

Overlay positioning, resize handling and close-on-scroll use the window that owns the overlay and trigger elements (element.ownerDocument.defaultView).

😯 Current Behavior

Overlays in a second window read the opener's globals in four places:

  • overlays/calculatePosition.ts: viewport size and the instanceof HTMLElement containing-block check
  • overlays/useOverlayPosition.ts: resize listener on the opener window
  • overlays/useCloseOnScroll.ts: instanceof Node / HTMLInputElement checks, so any scroll in the second window closes the overlay
  • utils/useResizeObserver.ts: the opener's ResizeObserver, which doesn't fire for the second window while the opener tab is hidden (measured in Chrome Document PiP), so an overlay placed at 0,0 on first layout stays there

💁 Possible Solution

Resolve the window from the element (element.ownerDocument.defaultView), as getOwnerWindow already does. We're running this as a local patch.

🔦 Context

We portal part of our UI into a Document Picture-in-Picture window in Chrome, and into a second BrowserWindow in Electron. Menus and popovers inside it hit all four problems above.

💻 Code Sample

function App() {
  let [container, setContainer] = useState<HTMLElement | null>(null);
  let open = async () => {
    let win = await documentPictureInPicture.requestWindow({width: 400, height: 400});
    // or: let win = window.open('', '', 'width=400,height=400')!;
    setContainer(win.document.body);
  };
  return (
    <>
      <button onClick={open}>Open window</button>
      {container && createPortal(
        <UNSAFE_PortalProvider getContainer={() => container}>
          <MenuTrigger>
            <Button>Menu</Button>
            <Popover><Menu><MenuItem>One</MenuItem><MenuItem>Two</MenuItem></Menu></Popover>
          </MenuTrigger>
        </UNSAFE_PortalProvider>,
        container
      )}
    </>
  );
}

🧢 Your Environment

Software Version(s)
react-aria 3.52.1
React 18.3.1
Browser Chrome (Document Picture-in-Picture), Electron
Operating System macOS

Related: #4634, #10581

Activity

  1. added
    enhancement
    on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions