Skip to content

Commit 3b67d54

Browse files
fix(Carousel): resolve plugins with page transitions (#4380)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
1 parent df8f202 commit 3b67d54

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

‎src/runtime/components/Carousel.vue

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export interface CarouselEmits {
118118
import { computed, ref, watch, onMounted } from 'vue'
119119
import useEmblaCarousel from 'embla-carousel-vue'
120120
import { Primitive, useForwardProps } from 'reka-ui'
121-
import { reactivePick, computedAsync } from '@vueuse/core'
121+
import { reactivePick } from '@vueuse/core'
122122
import { useAppConfig } from '#imports'
123123
import { useLocale } from '../composables/useLocale'
124124
import { tv } from '../utils/tv'
@@ -175,41 +175,45 @@ const options = computed<EmblaOptionsType>(() => ({
175175
direction: dir.value === 'rtl' ? 'rtl' : 'ltr'
176176
}))
177177
178-
const plugins = computedAsync<EmblaPluginType[]>(async () => {
179-
const plugins = []
178+
const plugins = ref<EmblaPluginType[]>([])
179+
180+
async function loadPlugins() {
181+
const emblaPlugins: EmblaPluginType[] = []
180182
181183
if (props.autoplay) {
182184
const AutoplayPlugin = await import('embla-carousel-autoplay').then(r => r.default)
183-
plugins.push(AutoplayPlugin(typeof props.autoplay === 'boolean' ? {} : props.autoplay))
185+
emblaPlugins.push(AutoplayPlugin(typeof props.autoplay === 'boolean' ? {} : props.autoplay))
184186
}
185187
186188
if (props.autoScroll) {
187189
const AutoScrollPlugin = await import('embla-carousel-auto-scroll').then(r => r.default)
188-
plugins.push(AutoScrollPlugin(typeof props.autoScroll === 'boolean' ? {} : props.autoScroll))
190+
emblaPlugins.push(AutoScrollPlugin(typeof props.autoScroll === 'boolean' ? {} : props.autoScroll))
189191
}
190192
191193
if (props.autoHeight) {
192194
const AutoHeightPlugin = await import('embla-carousel-auto-height').then(r => r.default)
193-
plugins.push(AutoHeightPlugin(typeof props.autoHeight === 'boolean' ? {} : props.autoHeight))
195+
emblaPlugins.push(AutoHeightPlugin(typeof props.autoHeight === 'boolean' ? {} : props.autoHeight))
194196
}
195197
196198
if (props.classNames) {
197199
const ClassNamesPlugin = await import('embla-carousel-class-names').then(r => r.default)
198-
plugins.push(ClassNamesPlugin(typeof props.classNames === 'boolean' ? {} : props.classNames))
200+
emblaPlugins.push(ClassNamesPlugin(typeof props.classNames === 'boolean' ? {} : props.classNames))
199201
}
200202
201203
if (props.fade) {
202204
const FadePlugin = await import('embla-carousel-fade').then(r => r.default)
203-
plugins.push(FadePlugin(typeof props.fade === 'boolean' ? {} : props.fade))
205+
emblaPlugins.push(FadePlugin(typeof props.fade === 'boolean' ? {} : props.fade))
204206
}
205207
206208
if (props.wheelGestures) {
207209
const { WheelGesturesPlugin } = await import('embla-carousel-wheel-gestures')
208-
plugins.push(WheelGesturesPlugin(typeof props.wheelGestures === 'boolean' ? {} : props.wheelGestures))
210+
emblaPlugins.push(WheelGesturesPlugin(typeof props.wheelGestures === 'boolean' ? {} : props.wheelGestures))
209211
}
210212
211-
return plugins
212-
})
213+
plugins.value = emblaPlugins
214+
}
215+
216+
watch(() => [props.autoplay, props.autoScroll, props.autoHeight, props.classNames, props.fade, props.wheelGestures], loadPlugins, { immediate: true })
213217
214218
const [emblaRef, emblaApi] = useEmblaCarousel(options.value, plugins.value)
215219

0 commit comments

Comments
 (0)