Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[popover]: crash on Chrome when using portalElement #3229

Open
marg51 opened this issue Dec 19, 2023 · 1 comment
Open

[popover]: crash on Chrome when using portalElement #3229

marg51 opened this issue Dec 19, 2023 · 1 comment

Comments

@marg51
Copy link

marg51 commented Dec 19, 2023

Current behavior

Hello :)

On some Chrome browsers, when using portalElement, the tab crashes when opening the popover.

The popover does open for a few seconds before the tab crashes, as if there was some kind of infinite loop.

There is nothing in the console before the crash.

It's still unclear which browsers are impacted: for the same version, some people can replicate the crash, but not everyone -› there is an unknown external factor.

One of the Chrome versions impacted: Version 120.0.6099.109 (Official Build) (arm64)

We were initially on version 0.2.16 but we can also replicate it with the latest version.

On a team of 4 ( on mac )

  • 2 can replicate
  • 2 can't.
  • One can replicate on Arc Browser.

Minimal reproduction step:

https://stackblitz.com/edit/vitejs-vite-dmafri?file=package.json,src%2FApp.tsx&terminal=dev

image

And thank you for the hard-work, we truly love using ariakit ❤️

Steps to reproduce the bug

  1. preview
  2. Click on "trigger"
  3. you may have your tab crashing

This should be enough to reproduce it:

 <Ariakit.Popover
    store={popover}
    portalElement={document.body}
    portal
  >

Expected behavior

no crashes

Workaround

We've used react's createPortal instead

Possible solutions

No response

@georgekaran
Copy link
Contributor

georgekaran commented Dec 19, 2023

Hey @marg51

That's probably related to the following line which we should address properly in a near future. Both getRootElement and portalElement are returning the document.body which is probably the cause for the loop in this case.

useSafeLayoutEffect(() => {
const element = ref.current;
if (!element || !portal) {
setPortalNode(null);
return;
}
const portalEl = getPortalElement(element, portalElement);
// TODO: Warn about portals as the document.body element.
if (!portalEl) {
setPortalNode(null);
return;
}
const isPortalInDocument = portalEl.isConnected;
if (!isPortalInDocument) {
const rootElement = context || getRootElement(element);
rootElement.appendChild(portalEl);
}

Using any other element instead of the document.body and you should be good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants