Skip to content

Commit

Permalink
fix: fallback to unstable_act for React < 18.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 22, 2024
1 parent d264499 commit 4dd16ad
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/pure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ import ReactDOMClient from 'react-dom/client'
// usually the async nature of Vitest browser mode ensures consistency,
// but rendering is sync and controlled by React directly
function act(cb: () => unknown) {
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
React.act(cb)
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = false
// @ts-expect-error unstable_act is not typed, but exported
const act = React.act || React.unstable_act
if (!act) {
cb()
}
else {
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true
act(cb)
;(globalThis as any).IS_REACT_ACT_ENVIRONMENT = false
}
}

export interface RenderResult extends LocatorSelectors {
Expand Down

0 comments on commit 4dd16ad

Please sign in to comment.