Cannot register modal instance that's already open

See original GitHub issue

When a modal is open, double-clicking on the background overlay results in the modal disappearing then quickly reappearing again with the following warning in the console:

react_devtools_backend.js:6 React-Modal: Cannot register modal instance that's already open 
    at ModalPortal (http://localhost:4500/static/js/0.chunk.js:60569:5)
    at Modal (http://localhost:4500/static/js/0.chunk.js:60212:5)

Additionally, the ReactModal__Body--open class remains on the body after closing the re-opened modal.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:24

github_iconTop GitHub Comments

8reactions
timothymalchamcommented, Apr 25, 2022

I am now getting this error after upgrading to React 18. Prior to doing the upgrade, I did not see this error: React-Modal: Cannot register modal instance that's already open. Does anybody have any idea of what might have changed?

6reactions
Phanabanicommented, Oct 25, 2022

I was having this error (react-modal@3.15.1, React@18.2.0), and after a lot of frustration found out that my problem was caused by using React.StrictMode in my root element, which apparently double-invokes some lifecycle methods in development mode (not production, though). As of now, this behavior is documented in the StrictMode docs – search for “double-invoking the following functions”.

I found this solution by accident, because I was investigating an effect being called twice and found this answer, which also referenced this answer which has more info about the double rendering of StrictMode.

It seems like this is harmless in my case because the only visible issue is the warning in console (modals are still displaying fine), but if anyone has a suggestion for suppressing the warning, I’d appreciate it! Removing the StrictMode tag stops this issue from happening, but I want to keep the benefits of using strict mode.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-modal: How to close one modal and open a new one at ...
This answer seems to assume that you need to register any new modal in both openModal and closeModal methods. That's not a good...
Read more >
react-modal documentation
The following is an example of using react-modal specifying all the possible props and options: ... Function that will be run after the...
Read more >
Build a simple Modal Component with React - Bits and Pieces
This will render whatever is passed to this component, which is just perfect for a dynamic modal. Close the modal. After opening a...
Read more >
Modal · Bootstrap v5.2
For example, you could toggle a password reset modal from within an already open sign in modal. Please note multiple modals cannot be...
Read more >
react-sliding-pane - npm
Start using react-sliding-pane in your project by running `npm i ... pane content is not rendered when pane is closed; Based on react-modal...
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