question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: Uncaught RangeError: Maximum call stack size exceeded. focusElement of Modal

See original GitHub issue

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

1.4.1

What browser are you using?

chrome

Reproduction repository

Not now.

Describe your issue

while we create Modal multiple (2+) it will throw me

focus-management.esm.js?d1e3:99 Uncaught RangeError: Maximum call stack size exceeded.
    at focusElement (focus-management.esm.js?d1e3:99)
    at eval (use-focus-trap.esm.js?25af:110)
    at handler (use-window-event.esm.js?b5e3:8)
    at focusElement (focus-management.esm.js?d1e3:99)
    at eval (use-focus-trap.esm.js?25af:110)
    at handler (use-window-event.esm.js?b5e3:8)
    at focusElement (focus-management.esm.js?d1e3:99)
    at eval (use-focus-trap.esm.js?25af:110)
    at handler (use-window-event.esm.js?b5e3:8)
    at focusElement (focus-management.esm.js?d1e3:99)
    at eval (use-focus-trap.esm.js?25af:110)
    at handler (use-window-event.esm.js?b5e3:8)
    at focusElement (focus-management.esm.js?d1e3:99)
    at eval (use-focus-trap.esm.js?25af:110)
    at handler (use-window-event.esm.js?b5e3:8)
    at focusElement (focus-management.esm.js?d1e3:99)
    at eval (use-focus-trap.esm.js?25af:110)
    at handler (use-window-event.esm.js?b5e3:8)
    at focusElement (focus-management.esm.js?d1e3:99)
    at eval (use-focus-trap.esm.js?25af:110)

Screenshot here

BTW, can Modal need to provider flag props to disabled focusElement feature, in most case we don’t need this, i think.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:16
  • Comments:33

github_iconTop GitHub Comments

22reactions
RobinMalfaitcommented, Mar 4, 2022

Hey! Thank you for your bug report! Much appreciated! 🙏

For everyone finding this issue.

The problem: You want 2 Dialogs, but it won’t work Solution: Dialogs must be nested if you want multiple Dialogs. Dialogs can’t be siblings because if you happen to open them at the same time each Dialog will try to steal focus again because a Dialog should be considered a separate page where you can’t interact with the content behind it.

17reactions
iandoecommented, Oct 22, 2021

We’re having this issue too, it’s a pretty common use case to have sibling modals, other libs like Baseweb handle this fine or at least provide a way to turn off autofocus

Upon opening, focus will be transferred to the first interactive element (unless autofocus is set to false) https://baseweb.design/components/modal/#accessibility

is there a way to do that with HeadlessUI, and if not would you be open to a PR allowing for autofocus to be turned off ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught RangeError: Maximum call stack size exceeded
You've got two infinite loops between two "modals" both demanding focus. The Dialog and the Select popover components are fighting for focus.
Read more >
Dialog (Modal) - Headless UI
A fully-managed, renderless dialog component jam-packed with accessibility and keyboard features, perfect for building completely custom modal and dialog ...
Read more >
JR63247: AN INFINITE LOOP OCCURS IN THE JAVASCRIPT ...
Under certain circumstances, using Modal Section controls in a coach can lead to ... Uncaught RangeError: Maximum call stack size exceeded. at subclass....
Read more >
JavaScript RangeError: Maximum Call Stack Size Exceeded
The JavaScript RangeError: Maximum call stack size exceeded is an error that occurs when there are too many function calls, or if a...
Read more >
InternalError: too much recursion - JavaScript - MDN Web Docs
RangeError : Maximum call stack size exceeded (Chrome) InternalError: too much ... or a function is missing a base case, JavaScript will throw...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found