@@ -3,7 +3,7 @@ import type {
33 SelectContentImplEmits ,
44 SelectContentImplProps ,
55} from ' ./SelectContentImpl.vue'
6- import { computed , onMounted , ref , watch } from ' vue'
6+ import { computed , onMounted , onUnmounted , ref , watch } from ' vue'
77
88export type SelectContentEmits = SelectContentImplEmits
99
@@ -44,15 +44,31 @@ const presenceRef = ref<InstanceType<typeof Presence>>()
4444const present = computed (() => props .forceMount || rootContext .open .value )
4545const renderPresence = ref (present .value )
4646
47- watch (present , () => {
47+ let renderPresenceTimeout: ReturnType <typeof setTimeout > | undefined
48+
49+ function clearRenderPresenceTimeout() {
50+ if (renderPresenceTimeout ) {
51+ clearTimeout (renderPresenceTimeout )
52+ renderPresenceTimeout = undefined
53+ }
54+ }
55+
56+ watch (present , (_value , _oldValue , onCleanup ) => {
4857 // Toggle render presence after a delay (nextTick is not enough)
4958 // to allow children to re-render with the latest state.
5059 // Otherwise, they would remain in the old state during the transition,
5160 // which would prevent the animation that depend on state (e.g., data-[state=closed])
5261 // from being applied accurately.
5362 // @see https://github.com/unovue/reka-ui/issues/1865
54- setTimeout (() => renderPresence .value = present .value )
63+ clearRenderPresenceTimeout ()
64+ renderPresenceTimeout = setTimeout (() => {
65+ renderPresence .value = present .value
66+ renderPresenceTimeout = undefined
67+ })
68+ onCleanup (clearRenderPresenceTimeout )
5569})
70+
71+ onUnmounted (clearRenderPresenceTimeout )
5672 </script >
5773
5874<template >
0 commit comments