Skip to content

Commit 9597442

Browse files
committed
fix(core): prevent observer trigger because of grab cursor
fixes #6423
1 parent cf8cdf5 commit 9597442

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/core/grab-cursor/setGrabCursor.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ export default function setGrabCursor(moving) {
77
)
88
return;
99
const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl;
10+
if (swiper.isElement) {
11+
swiper.__preventObserver__ = true;
12+
}
1013
el.style.cursor = 'move';
1114
el.style.cursor = moving ? 'grabbing' : 'grab';
15+
if (swiper.isElement) {
16+
requestAnimationFrame(() => {
17+
swiper.__preventObserver__ = false;
18+
});
19+
}
1220
}

src/core/grab-cursor/unsetGrabCursor.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@ export default function unsetGrabCursor() {
33
if ((swiper.params.watchOverflow && swiper.isLocked) || swiper.params.cssMode) {
44
return;
55
}
6+
if (swiper.isElement) {
7+
swiper.__preventObserver__ = true;
8+
}
69
swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = '';
10+
if (swiper.isElement) {
11+
requestAnimationFrame(() => {
12+
swiper.__preventObserver__ = false;
13+
});
14+
}
715
}

src/core/modules/observer/observer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ export default function Observer({ swiper, extendParams, on, emit }) {
1010
// The observerUpdate event should only be triggered
1111
// once despite the number of mutations. Additional
1212
// triggers are redundant and are very costly
13+
if (swiper.__preventObserver__) return;
1314
if (mutations.length === 1) {
1415
emit('observerUpdate', mutations[0]);
1516
return;
1617
}
18+
1719
const observerUpdate = function observerUpdate() {
1820
emit('observerUpdate', mutations[0]);
1921
};

0 commit comments

Comments
 (0)