ionic-framework: Swiper breaking if accessed quickly enough and multiple times
Ionic version: [x ] 2.x
I’m submitting a … [x ] bug report
Current behavior: If we navigate quickly between pages that have a swiper in some cases the ngOnDestroy of the swiper breaks
Expected behavior: The swiper need to initialize every time it’s called
Steps to reproduce: Create 2 pages in a tabbed interface and add to the first a swiper. Try to navigate between those pages a lot of times stressing as much the swiper component
Related code:
When trying to destroy the component here:
https://github.com/driftyco/ionic/blob/master/src/components/slides/slides.ts#L1092
this
is not defined.
This might be occuring cause of this:
https://github.com/driftyco/ionic/blob/master/src/components/slides/slides.ts#L939
ngAfterContentInit() {
this._plt.timeout(() => {
this._initSlides();
}, 300);
}
timing out or this: https://github.com/driftyco/ionic/blob/master/src/components/slides/slides.ts#L903
if (viewCtrl) {
var subscription = viewCtrl.readReady.subscribe(() => {
subscription.unsubscribe();
this._initSlides();
});
}
not managing to resolve the subscription before the destroy of the component.
As all above are asynchronous the ngOnDestroy might be called before the initialization of the component and as a consequence breaking it.
Potential fix would be to add a check for the this
if it’s present before trying to access it.
ngOnDestroy() {
if(!this) {
return;
}
this._init = false;
this._unregs.forEach(unReg => {
unReg();
});
this._unregs.length = 0;
destroySwiper(this);
this.enableKeyboardControl(false);
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 17 (4 by maintainers)
This issue still exists
Hello from 2018. This issue is still exist and setTimeout is bad solution. For devices with powerful hardware 50ms is quite enough, but for old devices sometimes even 500ms is not enough and error appears.
This is not cordova or some third party module issue, this is bug in your framework core. Please fix it or add status
won't fix
and add in docs marknot production ready
to slides feature.Update: dirty solution that work in all cases is to wrap logic in try/catch
and call
this._recursiveSlideTo(1)
that return promise on finish and can be chain with other logic.Why is closed this? I’m still getting error calling SlideTo:
This issue still exists global packages:
local packages:
System:
Is this issue fixed? Is there any workaround for now to solve this?
why its closed??? As everyone says. This problem is still existing.