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: @ionic/react: ion-slides: Failed to execute 'removeChild' on 'Node'

See original GitHub issue

Bug 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:

  1. Start a new React blank project:
    ionic start slides blank --type=react

  2. 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;
  1. Run ionic serve
  2. 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:closed
  • Created 4 years ago
  • Reactions:18
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

56reactions
Finessecommented, Nov 25, 2019

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:

// When the `item` slides ids don't change
<IonSlides key={item.id}>
  {item.slides.map(slide => (<IonSlide key={slide.id}><h1>{slide.text}</h1></IonSlide>))}
</IonSlides>

// When the `item` slides ids change
<IonSlides key={item.slides.map(slide => slide.id).join('_')}>
  {item.slides.map(slide => (<IonSlide key={slide.id}><h1>{slide.text}</h1></IonSlide>))}
</IonSlides>

It makes the ion-slides be destroyed and created (instead of crashing) on every slides change.

5reactions
TylerBurnettcommented, Jun 13, 2020

Any chance this ticket can get an update? This issue is actually quite crippling to ionic display functionality.

Read more comments on GitHub >

github_iconTop 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 >

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