Skip to content

Commit

Permalink
fix(core): check for swiper.el in destroy queue
Browse files Browse the repository at this point in the history
fixes #7530
  • Loading branch information
nolimits4web committed May 30, 2024
1 parent 5737f03 commit 39a3e53
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/core/classes/removeClasses.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default function removeClasses() {
const swiper = this;
const { el, classNames } = swiper;
if (!el || typeof el === 'string') return;

el.classList.remove(...classNames);
swiper.emitContainerClasses();
Expand Down
12 changes: 9 additions & 3 deletions src/core/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,12 @@ class Swiper {
// Cleanup styles
if (cleanStyles) {
swiper.removeClasses();
el.removeAttribute('style');
wrapperEl.removeAttribute('style');
if (el && typeof el !== 'string') {
el.removeAttribute('style');
}
if (wrapperEl) {
wrapperEl.removeAttribute('style');
}
if (slides && slides.length) {
slides.forEach((slideEl) => {
slideEl.classList.remove(
Expand All @@ -680,7 +684,9 @@ class Swiper {
});

if (deleteInstance !== false) {
swiper.el.swiper = null;
if (swiper.el && typeof swiper.el !== 'string') {
swiper.el.swiper = null;
}
deleteProps(swiper);
}
swiper.destroyed = true;
Expand Down
1 change: 1 addition & 0 deletions src/core/events/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const events = (swiper, method) => {
const capture = !!params.nested;
const domMethod = method === 'on' ? 'addEventListener' : 'removeEventListener';
const swiperMethod = method;
if (!el || typeof el === 'string') return;

// Touch Events
document[domMethod]('touchstart', swiper.onDocumentTouchStart, { passive: false, capture });
Expand Down
8 changes: 5 additions & 3 deletions src/modules/a11y/a11y.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,11 @@ export default function A11y({ swiper, extendParams, on }) {
const document = getDocument();
document.removeEventListener('visibilitychange', onVisibilityChange);
// Tab focus
swiper.el.removeEventListener('focus', handleFocus, true);
swiper.el.removeEventListener('pointerdown', handlePointerDown, true);
swiper.el.removeEventListener('pointerup', handlePointerUp, true);
if (swiper.el && typeof swiper.el !== 'string') {
swiper.el.removeEventListener('focus', handleFocus, true);
swiper.el.removeEventListener('pointerdown', handlePointerDown, true);
swiper.el.removeEventListener('pointerup', handlePointerUp, true);
}
}

on('beforeInit', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/modules/autoplay/autoplay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ export default function Autoplay({ swiper, extendParams, on, emit, params }) {
};

const detachMouseEvents = () => {
swiper.el.removeEventListener('pointerenter', onPointerEnter);
swiper.el.removeEventListener('pointerleave', onPointerLeave);
if (swiper.el && typeof swiper.el !== 'string') {
swiper.el.removeEventListener('pointerenter', onPointerEnter);
swiper.el.removeEventListener('pointerleave', onPointerLeave);
}
};

const attachDocumentEvents = () => {
Expand Down

0 comments on commit 39a3e53

Please sign in to comment.