ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.09k stars 13.51k forks source link

[Ionic v4] Uncaught TypeError: Cannot read property 'split' of undefined #15122

Closed peterpeterparker closed 6 years ago

peterpeterparker commented 6 years ago

Ionic Info @ionic/angular: "4.0.0-beta.2"

Describe the Bug The following error poped up in my Chrome debug console a couple of times today. I don't know effectively when unfortunately

d6ubnyaf.js:5 Uncaught TypeError: Cannot read property 'split' of undefined at i.removeClass (d6ubnyaf.js:5) at t.destroy (d6ubnyaf.js:5) at t.destroy (d6ubnyaf.js:5) at d6ubnyaf.js:5 at Array.forEach () at d6ubnyaf.js:5 at Array.forEach () at t.push../node_modules/@ionic/core/dist/esm/es5/d6ubnyaf.js.h.emit (d6ubnyaf.js:5) at t.destroy (d6ubnyaf.js:5) at e.componentDidUnload (d6ubnyaf.js:5)

where d6ubnyaf.js:5 is

removeClass:function(e){for(var t=e.split(" "),i=0;i<t.length;i+=1)for(var s=0;s<this.length;s+=1)void 0!==this[s].classList&&this[s].classList.remove(t[i]);return this},hasClass:function(e){return!!this[0]&&this[0].classList.contains(e)},

which according the header is an Ionic file

/*!
 * (C) Ionic http://ionicframework.com - MIT License
 * Built with http://stenciljs.com
 */

Expected Behavior No such error ;)

manucorporat commented 6 years ago

it's actually Swiper (used in ion-slides), not our code :(

http://idangero.us/swiper/

cc @mhartington any idea?

mhartington commented 6 years ago

@peterpeterparker got a sample project or test case for this?

peterpeterparker commented 6 years ago

@mhartington I'll observe the situation during the next days and will see if I found a way of providing such info/samples

peterpeterparker commented 6 years ago

I just faced the error again and I ask my self if the error "just" happens in a particular state where the slider is added to the dom but not fully loaded

For example the following code might generate the problem time to time

isNotFirstSlide(): boolean {
    return this.slider && this.slider.nativeElement && this.slider.nativeElement.getActiveIndex() > 0;
}

As workaround I think I would be able to do something like

isNotFirstSlide(): boolean {
    try {
        return this.slider && this.slider.nativeElement && this.slider.nativeElement.getActiveIndex() > 0;
    } catch (err) {
        return false;
    }
}

will try this and will update the issue

peterpeterparker commented 6 years ago

I didn't face the error the last three days so I'm guessing that my above explanation and workaround aren't that wrong, therefore I close this issue

If you land on the error and you are not willing to use try/catch, @rapropos provided another possible option on the Ionic forum https://forum.ionicframework.com/t/ionic-4-slides/138717/3?u=reedrichards which might works too respectively

   slides: Slides;

  @ViewChild(Slides) set slidesvc(slides) {
    this.slides = slides;
  }
peterpeterparker commented 6 years ago

btw. 10 days later, didn't encounter the problem anymore, so definitely all good

mhartington commented 6 years ago

👍