Skip to content

Commit 85a582f

Browse files
committed
refactor: fix presence edge case
1 parent 2adc8a3 commit 85a582f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zag-js/presence": patch
3+
---
4+
5+
Fix race condition where dialog remains closed when `open` prop rapidly changes from `true` to `false` to `true`

packages/machines/presence/src/presence.machine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export const machine = createMachine<PresenceSchema>({
150150
},
151151

152152
effects: {
153-
trackAnimationEvents: ({ context, refs, send }) => {
153+
trackAnimationEvents: ({ context, refs, send, prop }) => {
154154
const node = refs.get("node")
155155
if (!node) return
156156

@@ -164,7 +164,7 @@ export const machine = createMachine<PresenceSchema>({
164164
const onEnd = (event: AnimationEvent) => {
165165
const animationName = getAnimationName(refs.get("styles"))
166166
const target = getEventTarget(event)
167-
if (target === node && animationName === context.get("unmountAnimationName")) {
167+
if (target === node && animationName === context.get("unmountAnimationName") && !prop("present")) {
168168
send({ type: "UNMOUNT", src: "animationend" })
169169
}
170170
}

0 commit comments

Comments
 (0)