bug: @ionic/react: ion-slides: Failed to execute 'removeChild' on 'Node'
See original GitHub issueBug Report
Ionic version: [cli] 5.2.2 [@ionic/react] 0.0.6
Current behavior: When trying to remove a slide to dynamically generated slides, the following uncaught exception occurs:
react-dom.development.js:9279 Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
Expected behavior: The slides should be updated to reflect the correct number of slides, without causing any errors.
Steps to reproduce:
-
Start a new React blank project:
ionic start slides blank --type=react
-
Use the following
Home.tsx
template:
import {IonContent, IonHeader, IonTitle, IonToolbar, IonSlides, IonSlide, IonButton} from '@ionic/react';
import React, {useState} from 'react';
const slideOpts = {
initialSlide: 0,
speed: 400
};
const Home: React.FunctionComponent = () => {
const [slides, setSlides] = useState([
{id: '1', text: 'Slide 1'},
{id: '2', text: 'Slide 2'},
{id: '3', text: 'Slide 3'},
{id: '4', text: 'Slide 4'},
{id: '5', text: 'Slide 5'}
]);
return (
<>
<IonHeader>
<IonToolbar>
<IonTitle>Ionic Blank</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonButton onClick={() => setSlides(slides.slice(1))}>
Remove first slide
</IonButton>
<IonSlides pager={true} options={slideOpts}>
{slides.map(slide => (<IonSlide key={slide.id}><h1>{slide.text}</h1></IonSlide>))}
</IonSlides>
</IonContent>
</>
);
};
export default Home;
- Run
ionic serve
- Click on the “Remove first slide” button.
Related code:
https://github.com/m-spyratos/-ionic-react-slides-remove
Ionic info:
Ionic:
Ionic CLI: 5.2.2 (/usr/local/lib/node_modules/ionic)
Ionic Framework: @ionic/react 0.0.6
Utility:
cordova-res: not installed
native-run: not installed
System:
NodeJS: v10.16.0 (/usr/local/bin/node)
npm: 6.10.0
OS: macOS Mojave
Issue Analytics
- State:
- Created 4 years ago
- Reactions:18
- Comments:20 (2 by maintainers)
Top Results From Across the Web
bug: @ionic/react: ion-slides: Failed to execute 'removeChild ...
Current behavior: When trying to remove a slide to dynamically generated slides, the following uncaught exception occurs: react-dom.development.
Read more >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 >IonSlides with useState - Ionic Forum
I want that when i click on the slide, the slider disappear. but im getting this error. Uncaught DOMException: Node.removeChild: The node to ......
Read more >Tried to edit a page: Error: Failed to execute 'removeChild' on ...
I am pretty new to all this so very confused. Error: Failed to execute 'removeChild' on 'Node': The node to be removed is...
Read more >failed to execute 'insertbefore' on 'node' react - You.com
It turns out that it was a child component throwing the error. Even though the exception was being thrown at the setState line,...
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 Free
Top 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
Here is a workaround. Change the
IonSlides
key
when your slides list changes. It’s not a universal workaround but it’s suitable for some cases:It makes the
ion-slides
be destroyed and created (instead of crashing) on every slides change.Any chance this ticket can get an update? This issue is actually quite crippling to ionic display functionality.