Skip to content

Commit

Permalink
chore: destroy zoom on route leave (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
abocsan-plenty authored Dec 9, 2024
1 parent 61fd214 commit 241ab39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions apps/web/components/Drift/Drift.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ onMounted(() => {
let demoTrigger = document.querySelector(`.demo-trigger-${index}`) as HTMLElement;
let paneContainer = document.querySelector('.drift-zoom-image') as HTMLElement;
if (!demoTrigger || !paneContainer) {
return;
}
drift = new Drift(demoTrigger, {
paneContainer: paneContainer,
containInline: true,
Expand All @@ -25,6 +29,20 @@ onMounted(() => {
});
});
onBeforeRouteUpdate(() => {
if (drift) {
drift.destroy();
drift = null;
}
});
onBeforeRouteLeave(() => {
if (drift) {
drift.destroy();
drift = null;
}
});
onUnmounted(() => {
if (drift) {
drift.destroy();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/ZoomableImage/ZoomableImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{ $t('double-tap-zoom') }}
</div>

<Drift v-if="!isMobile" :index="index">
<Drift v-if="!isMobile && imagesLoaded[`gallery-img-${index}`]" :index="index">
<NuxtImg
v-bind="nuxtImgProps"
@touchstart="onTouchStart"
Expand Down

0 comments on commit 241ab39

Please sign in to comment.