Skip to content

Commit

Permalink
fix(react): flush effect sync
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Mar 8, 2025
1 parent 9e3d225 commit f8ac71e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-snakes-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zag-js/react": patch
---

Flush effects synchronously rather than within a microtask
6 changes: 3 additions & 3 deletions packages/frameworks/react/src/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ export function useMachine<T extends MachineSchema>(
const fns = effects.current
return () => {
hydratedStateRef.current = state.ref.current
fns.forEach((fn) => fn?.())
effects.current = new Map()
transitionRef.current = null
queueMicrotask(() => {
fns.forEach((fn) => fn?.())
effects.current = new Map()
transitionRef.current = null
action(machine.exit)
})
}
Expand Down

0 comments on commit f8ac71e

Please sign in to comment.