From 490132bec927d1d59d3aefe3a6cb8158322598cf Mon Sep 17 00:00:00 2001 From: ocavue Date: Fri, 12 Dec 2025 11:45:42 +1100 Subject: [PATCH] fix: use a simple counter for act --- src/pure.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/pure.tsx b/src/pure.tsx index 48a47aa..79fb5d1 100644 --- a/src/pure.tsx +++ b/src/pure.tsx @@ -6,12 +6,16 @@ import ReactDOMClient from 'react-dom/client' const { debug, getElementLocatorSelectors } = utils -const activeActs = new Set() +let activeActs = 0 function setActEnvironment(env: boolean | undefined): void { (globalThis as any).IS_REACT_ACT_ENVIRONMENT = env } +function updateActEnvironment(): void { + setActEnvironment(activeActs > 0) +} + // @ts-expect-error unstable_act is not typed, but exported const _act = React.act || React.unstable_act @@ -21,17 +25,14 @@ const _act = React.act || React.unstable_act const act = typeof _act !== 'function' ? async (cb: () => unknown) => { await cb() } : async (cb: () => unknown) => { - setActEnvironment(true) - const actId = crypto.randomUUID() - activeActs.add(actId) + activeActs++ + updateActEnvironment() try { await _act(cb) } finally { - activeActs.delete(actId) - if (!activeActs.size) { - setActEnvironment(false) - } + activeActs-- + updateActEnvironment() } }