bug: [React] IonModal is not removed from DOM when parent component unmounts
See original GitHub issuePrerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Ionic Framework Version
- v4.x
- v5.x
- v6.x
- Nightly
Current Behavior
When a component rendering an IonModal is unmounted by React, the ion modal DOM node is not removed.
Expected Behavior
Expected similar/same behavior as Ionic v5, where when a React component unmounts, the corresponding components being rendered by that component are also cleaned up. Even if there is no animation, I believe the DOM should be cleaned up
Steps to Reproduce
- Have a component (Call it
MyComponent
) that renders an IonModal - Conditionally mount that component somewhere.
- Toggle the modal to present by changing
isOpen
to true. - Now, without toggling the modal’s
isOpen
prop, simply toggle the mounting condition so React unmountsMyComponent
. - The Modal is not removed from the DOM
Code Reproduction URL
https://codesandbox.io/s/ionic-6-3-3-modal-unmount-bug-0etb2k?file=/src/pages/Home.tsx No response
Ionic Info
Ionic React: 6.3.3
Additional Information
Link to codesandox example: https://codesandbox.io/s/ionic-6-3-3-modal-unmount-bug-0etb2k?file=/src/pages/Home.tsx
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top Results From Across the Web
bug: Conditionally rendering ionModal in react - Failed to ...
The IonModal implementation in React does not have a framework delegate configured. This results in us manually removing the element from the DOM, ......
Read more >React-Bootstrap Modal - Error when unmounting from DOM
I am using react-bootstrap modal component. I wish to unmount from the page but experience an error that I am unable to pinpoint...
Read more >ion-modal: Ionic Mobile App Custom Modal ... - Ionic Framework
ion-modal is a dialog that appears on top of mobile app content, and must be dismissed before interaction resumes. Learn more about custom...
Read more >Avoid unnecessary remounting of DOM elements in React
Log to the console when it's mounted and unmounted from the DOM. class Child extends React.Component { componentDidMount ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @puopg can you test with this dev-build and let me know if you run into any issues?
I’ve additionally forked your reproduction here: https://codesandbox.io/s/ionic-6-3-3-modal-unmount-bug-forked-dflgj8
@filip-dot-cube The PR is still open, so its not available on an official release to my understanding yet.
https://github.com/ionic-team/ionic-framework/pull/26245