bug: Conditionally rendering ionModal in react - Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
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
Conditionally rendering an IonModal, breaks when dismissing when using ionic v6.
Observed behavior: white/blank screen.
Error in console: react-dom.development.js:10301 Uncaught DOMException: Failed to execute ‘removeChild’ on ‘Node’: The node to be removed is not a child of this node.
Expected Behavior
In an ideal scenario - the ionic modal could be conditionally rendered (without using the isOpen prop) this is a common pattern in react applications.
Steps to Reproduce
- Conditionally render an IonModal
...
const [showIonModal, setShowIonModal] = useState(false);
...
return (
<div>
<IonButton onClick={() => setShowIonModal(true)}>
Show Modal
</IonButton>
{showIonModal && (
<IonModal isOpen={true} onDidDismiss={() => setShowIonModal(false)}>
<IonHeader>
<IonToolbar>
<IonTitle>Content</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent fullscreen>
Ionic Modal Content here!
<IonButton color="danger" onClick={() => setShowIonModal(false)}>
Hide Modal (will break)
</IonButton>
</IonContent>
</IonModal>
)}
</div>
)
...
- Dismiss the modal (so that IonModal is pulled from the dom)
- Observe the error.
Code Reproduction URL
https://github.com/corysmc/react-overlay-bug
Ionic Info
Ionic:
Ionic CLI : 6.15.0 Ionic Framework : @ionic/react 6.1.13
Utility:
cordova-res : not installed native-run : 1.6.0
System:
NodeJS : v14.16.0 npm : 6.14.11 OS : macOS Big Sur
Additional Information
Related: https://github.com/ionic-team/ionic-framework/issues/24887
Issue Analytics
- State:
- Created a year ago
- Comments:50 (27 by maintainers)
Top Results From Across the Web
React DOMException: Failed to execute 'removeChild' on 'Node'
This explains the error Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this...
Read more >Breaking React - a common pattern to avoid
Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
Read more >Gantt for React - The "Failed to execute 'removeChild' on ...
Gantt for React - The "Failed to execute 'removeChild' on 'Node'" error is thrown when double-clicking on a task after upgrading to v21.1.5....
Read more >React DOMException: Failed to execute 'removeChild' on 'Node'
Coding example for the question React DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of...
Read more >failed to execute 'removechild' on 'node': the nod 相關資訊:: 哇哇3C ...
Uncaught NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is no longer a child of this node. bug: Conditionally...
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
Once I try to use
@ionic/react@6.2.3-dev.11660337759.18ea0f7e
navigation is broken. Downgrading to 6.2.2 router works fine - but the issue outlined above is still present.Tapping on a navigation link, changes the URL, then refreshes the app back to the root url
The same thing happened when I downloaded the react conference app - and upgraded to this version of ionic/react.
Hello! Just wondering when an update will be made to correct this. Thanks!