Skip to content

Commit 8b122d2

Browse files
authored
fix: use a simple counter for act (#43)
1 parent 57c57b1 commit 8b122d2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/pure.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import ReactDOMClient from 'react-dom/client'
66

77
const { debug, getElementLocatorSelectors } = utils
88

9-
const activeActs = new Set<string>()
9+
let activeActs = 0
1010

1111
function setActEnvironment(env: boolean | undefined): void {
1212
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = env
1313
}
1414

15+
function updateActEnvironment(): void {
16+
setActEnvironment(activeActs > 0)
17+
}
18+
1519
// @ts-expect-error unstable_act is not typed, but exported
1620
const _act = React.act || React.unstable_act
1721

@@ -21,17 +25,14 @@ const _act = React.act || React.unstable_act
2125
const act = typeof _act !== 'function'
2226
? async (cb: () => unknown) => { await cb() }
2327
: async (cb: () => unknown) => {
24-
setActEnvironment(true)
25-
const actId = crypto.randomUUID()
26-
activeActs.add(actId)
28+
activeActs++
29+
updateActEnvironment()
2730
try {
2831
await _act(cb)
2932
}
3033
finally {
31-
activeActs.delete(actId)
32-
if (!activeActs.size) {
33-
setActEnvironment(false)
34-
}
34+
activeActs--
35+
updateActEnvironment()
3536
}
3637
}
3738

0 commit comments

Comments
 (0)