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

next: Re-focussing popover trigger in dialog causes infinite loop #913

Open
Jels02 opened this issue Nov 13, 2024 · 7 comments
Open

next: Re-focussing popover trigger in dialog causes infinite loop #913

Jels02 opened this issue Nov 13, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@Jels02
Copy link

Jels02 commented Nov 13, 2024

Describe the bug

If you click on the popover trigger inside of a dialog too quickly (repeatedly) it will cause an infinite loop of focussing/refocussing and there will be an error in console. Best case, the browser stops it, worst case, you crash your tab and have to restart your browser

Reproduction

https://stackblitz.com/edit/stackblitz-starters-zuwmee?file=src%2Froutes%2F%2Bpage.svelte

Logs

bits-ui.js?v=77ba180e:3613 Uncaught RangeError: Maximum call stack size exceeded.
    at focus (bits-ui.js?v=77ba180e:3613:12)
    at HTMLDocument.handleFocusOut (bits-ui.js?v=77ba180e:3691:47)
    at focus (bits-ui.js?v=77ba180e:3613:12)
    at HTMLDocument.handleFocusIn (bits-ui.js?v=77ba180e:3683:9)
    at focus (bits-ui.js?v=77ba180e:3613:12)
    at HTMLDocument.handleFocusOut (bits-ui.js?v=77ba180e:3691:47)
    at focus (bits-ui.js?v=77ba180e:3613:12)
    at HTMLDocument.handleFocusIn (bits-ui.js?v=77ba180e:3683:9)
    at focus (bits-ui.js?v=77ba180e:3613:12)
    at HTMLDocument.handleFocusOut (bits-ui.js?v=77ba180e:3691:47)
Show 94 more frames

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/kit: ^2.0.0 => 2.8.0 
    bits-ui: ^1.0.0-next.52 => 1.0.0-next.52 
    svelte: ^5.0.0 => 5.1.16

Severity

blocking all usage of bits-ui

@Jels02
Copy link
Author

Jels02 commented Nov 13, 2024

Could be related to #755

@huntabyte
Copy link
Owner

Can you put a video in the issue so I can see what is happening?

@huntabyte huntabyte added the waiting for author The issue is pending a response from the issue author before further action can be taken. label Nov 13, 2024
@Jels02
Copy link
Author

Jels02 commented Nov 14, 2024

Can you put a video in the issue so I can see what is happening?

Screen.Recording.2024-11-14.at.10.39.27.AM.mov

@Jels02 Jels02 changed the title Re-focussing popover trigger in dialog causes infinite loop next: Re-focussing popover trigger in dialog causes infinite loop Nov 15, 2024
@huntabyte
Copy link
Owner

huntabyte commented Nov 16, 2024

Thanks, I see it now. Appears to be running into a race condition where the focus event for the next is triggering before the previous has cleaned up causing it to basically go into a very brief loop of focusin/out calls. I'll need to investigate this one a bit to determine how to best approach it.

To be clear and as a reminder to myself, this only happens when rapidly opening and then closing the popover.

@huntabyte huntabyte added bug Something isn't working and removed waiting for author The issue is pending a response from the issue author before further action can be taken. labels Nov 16, 2024
@Crazytieguy
Copy link

On my app when this happens the loop doesn't stop, so the browser tab freezes and has to be killed. Is there something I can do to bypass this issue until it's fixed?

@overiit
Copy link

overiit commented Jan 24, 2025

Same here. It freezes the application and renders some parts unusable.
For now the easiest solution likely is to just don't use two overlay/dialog/dropdownmenu/select/etc. components on top of each other, or at least from bits-ui, but would love to hear if there is an update regarding this.

@huntabyte
Copy link
Owner

I'm working on it 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants