File tree Expand file tree Collapse file tree 3 files changed +15
-9
lines changed Expand file tree Collapse file tree 3 files changed +15
-9
lines changed Original file line number Diff line number Diff line change 2
2
// https://github.com/testing-library/react-testing-library/blob/3dcd8a9649e25054c0e650d95fca2317b7008576/src/act-compat.js
3
3
import * as React from 'react' ;
4
4
5
- import * as DeprecatedReactTestUtils from 'react-dom/test-utils' ;
6
-
7
5
declare const globalThis : {
8
6
IS_REACT_ACT_ENVIRONMENT : boolean ;
9
7
} ;
@@ -13,9 +11,6 @@ declare const globalThis: {
13
11
// We do check if act exists, but webpack will still throw an error on compile time
14
12
const clonedReact = { ...React } ;
15
13
16
- const reactAct =
17
- typeof clonedReact . act === 'function' ? clonedReact . act : DeprecatedReactTestUtils . act ;
18
-
19
14
export function setReactActEnvironment ( isReactActEnvironment : boolean ) {
20
15
globalThis . IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment ;
21
16
}
@@ -67,7 +62,15 @@ function withGlobalActEnvironment(actImplementation: (callback: () => void) => P
67
62
} ;
68
63
}
69
64
70
- export const act =
71
- process . env . NODE_ENV === 'production'
65
+ export const getAct = async ( ) => {
66
+ // Lazy loading this makes sure that @storybook /react can be loaded in SSR contexts
67
+ // For example when SSR'ing portable stories
68
+ const reactAct =
69
+ typeof clonedReact . act === 'function'
70
+ ? clonedReact . act
71
+ : ( await import ( 'react-dom/test-utils' ) ) . act ;
72
+
73
+ return process . env . NODE_ENV === 'production'
72
74
? ( cb : ( ...args : any [ ] ) => any ) => cb ( )
73
75
: withGlobalActEnvironment ( reactAct ) ;
76
+ } ;
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as React from 'react';
2
2
3
3
import semver from 'semver' ;
4
4
5
- import { act , getReactActEnvironment , setReactActEnvironment } from './act-compat' ;
5
+ import { getAct , getReactActEnvironment , setReactActEnvironment } from './act-compat' ;
6
6
import type { Decorator } from './public-types' ;
7
7
8
8
export const parameters = { renderer : 'react' } ;
@@ -32,6 +32,8 @@ export const beforeAll = async () => {
32
32
// https://github.com/testing-library/react-testing-library/blob/3dcd8a9649e25054c0e650d95fca2317b7008576/src/pure.js
33
33
const { configure } = await import ( '@storybook/test' ) ;
34
34
35
+ const act = await getAct ( ) ;
36
+
35
37
configure ( {
36
38
unstable_advanceTimersWrapper : ( cb ) => {
37
39
return act ( cb ) ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import type { RenderContext } from 'storybook/internal/types';
5
5
6
6
import { global } from '@storybook/global' ;
7
7
8
- import { act } from './act-compat' ;
8
+ import { getAct } from './act-compat' ;
9
9
import type { ReactRenderer , StoryContext } from './types' ;
10
10
11
11
const { FRAMEWORK_OPTIONS } = global ;
@@ -98,6 +98,7 @@ export async function renderToCanvas(
98
98
unmountElement ( canvasElement ) ;
99
99
}
100
100
101
+ const act = await getAct ( ) ;
101
102
await new Promise < void > ( async ( resolve , reject ) => {
102
103
actQueue . push ( async ( ) => {
103
104
try {
You can’t perform that action at this time.
0 commit comments