Skip to content

Commit a298e26

Browse files
committed
fix: presence regression
1 parent 6b1d735 commit a298e26

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.changeset/few-clouds-press.md

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 regression in presence where UNMOUNT transition might not be called in consistently

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,28 @@ export const machine = createMachine<PresenceSchema>({
170170
}
171171

172172
const onEnd = (event: AnimationEvent) => {
173+
const animationName = getAnimationName(refs.get("styles"))
173174
const target = getEventTarget(event)
174-
if (target === node && event.animationName === context.get("unmountAnimationName") && !prop("present")) {
175+
if (target === node && animationName === context.get("unmountAnimationName") && !prop("present")) {
175176
send({ type: "UNMOUNT", src: "animationend" })
176177
}
177178
}
178179

180+
const onCancel = (event: AnimationEvent) => {
181+
const target = getEventTarget(event)
182+
if (target === node && !prop("present")) {
183+
send({ type: "UNMOUNT", src: "animationcancel" })
184+
}
185+
}
186+
179187
node.addEventListener("animationstart", onStart)
180-
node.addEventListener("animationcancel", onEnd)
188+
node.addEventListener("animationcancel", onCancel)
181189
node.addEventListener("animationend", onEnd)
182190
const cleanupStyles = setStyle(node, { animationFillMode: "forwards" })
183191

184192
return () => {
185193
node.removeEventListener("animationstart", onStart)
186-
node.removeEventListener("animationcancel", onEnd)
194+
node.removeEventListener("animationcancel", onCancel)
187195
node.removeEventListener("animationend", onEnd)
188196
nextTick(() => cleanupStyles())
189197
}

0 commit comments

Comments
 (0)