Skip to content

Commit

Permalink
fix(core): prevent observer trigger because of grab cursor
Browse files Browse the repository at this point in the history
fixes #6423
  • Loading branch information
nolimits4web committed Feb 27, 2023
1 parent cf8cdf5 commit 9597442
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/grab-cursor/setGrabCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ export default function setGrabCursor(moving) {
)
return;
const el = swiper.params.touchEventsTarget === 'container' ? swiper.el : swiper.wrapperEl;
if (swiper.isElement) {
swiper.__preventObserver__ = true;
}
el.style.cursor = 'move';
el.style.cursor = moving ? 'grabbing' : 'grab';
if (swiper.isElement) {
requestAnimationFrame(() => {
swiper.__preventObserver__ = false;
});
}
}
8 changes: 8 additions & 0 deletions src/core/grab-cursor/unsetGrabCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ export default function unsetGrabCursor() {
if ((swiper.params.watchOverflow && swiper.isLocked) || swiper.params.cssMode) {
return;
}
if (swiper.isElement) {
swiper.__preventObserver__ = true;
}
swiper[swiper.params.touchEventsTarget === 'container' ? 'el' : 'wrapperEl'].style.cursor = '';
if (swiper.isElement) {
requestAnimationFrame(() => {
swiper.__preventObserver__ = false;
});
}
}
2 changes: 2 additions & 0 deletions src/core/modules/observer/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export default function Observer({ swiper, extendParams, on, emit }) {
// The observerUpdate event should only be triggered
// once despite the number of mutations. Additional
// triggers are redundant and are very costly
if (swiper.__preventObserver__) return;
if (mutations.length === 1) {
emit('observerUpdate', mutations[0]);
return;
}

const observerUpdate = function observerUpdate() {
emit('observerUpdate', mutations[0]);
};
Expand Down

0 comments on commit 9597442

Please sign in to comment.