11
11
12
12
let React ;
13
13
let ReactDOM ;
14
+ let ReactDOMClient ;
14
15
let Suspense ;
15
16
let Scheduler ;
16
17
let act ;
@@ -23,6 +24,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
23
24
jest . resetModules ( ) ;
24
25
React = require ( 'react' ) ;
25
26
ReactDOM = require ( 'react-dom' ) ;
27
+ ReactDOMClient = require ( 'react-dom/client' ) ;
26
28
Scheduler = require ( 'scheduler' ) ;
27
29
act = require ( 'internal-test-utils' ) . act ;
28
30
Suspense = React . Suspense ;
@@ -98,7 +100,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
98
100
return text ;
99
101
}
100
102
101
- it ( 'hides and unhides timed out DOM elements' , async ( ) => {
103
+ it ( 'hides and unhides timed out DOM elements in legacy roots ' , async ( ) => {
102
104
const divs = [
103
105
React . createRef ( null ) ,
104
106
React . createRef ( null ) ,
@@ -144,18 +146,22 @@ describe('ReactDOMSuspensePlaceholder', () => {
144
146
</ Suspense >
145
147
) ;
146
148
}
147
- ReactDOM . render ( < App /> , container ) ;
149
+ const root = ReactDOMClient . createRoot ( container ) ;
150
+ await act ( ( ) => {
151
+ root . render ( < App /> ) ;
152
+ } ) ;
153
+
148
154
expect ( container . textContent ) . toEqual ( 'Loading...' ) ;
149
155
150
- await act ( async ( ) => {
151
- await resolveText ( 'B' ) ;
156
+ await act ( ( ) => {
157
+ resolveText ( 'B' ) ;
152
158
} ) ;
153
159
154
160
expect ( container . textContent ) . toEqual ( 'ABC' ) ;
155
161
} ) ;
156
162
157
163
it (
158
- 'outside concurrent mode , re-hides children if their display is updated ' +
164
+ 'in legacy roots , re-hides children if their display is updated ' +
159
165
'but the boundary is still showing the fallback' ,
160
166
async ( ) => {
161
167
const { useState} = React ;
@@ -207,7 +213,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
207
213
) ;
208
214
209
215
// Regression test for https://github.com/facebook/react/issues/14188
210
- it ( 'can call findDOMNode() in a suspended component commit phase' , async ( ) => {
216
+ it ( 'can call findDOMNode() in a suspended component commit phase in legacy roots ' , async ( ) => {
211
217
const log = [ ] ;
212
218
const Lazy = React . lazy (
213
219
( ) =>
@@ -267,7 +273,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
267
273
} ) ;
268
274
269
275
// Regression test for https://github.com/facebook/react/issues/14188
270
- it ( 'can call findDOMNode() in a suspended component commit phase (#2)' , ( ) => {
276
+ it ( 'can call legacy findDOMNode() in a suspended component commit phase (#2)' , async ( ) => {
271
277
let suspendOnce = Promise . resolve ( ) ;
272
278
function Suspend ( ) {
273
279
if ( suspendOnce ) {
@@ -304,9 +310,16 @@ describe('ReactDOMSuspensePlaceholder', () => {
304
310
) ;
305
311
}
306
312
307
- ReactDOM . render ( < App /> , container ) ;
313
+ const root = ReactDOMClient . createRoot ( container ) ;
314
+ await act ( ( ) => {
315
+ root . render ( < App /> ) ;
316
+ } ) ;
317
+
308
318
expect ( log ) . toEqual ( [ 'cDM' ] ) ;
309
- ReactDOM . render ( < App /> , container ) ;
319
+ await act ( ( ) => {
320
+ root . render ( < App /> ) ;
321
+ } ) ;
322
+
310
323
expect ( log ) . toEqual ( [ 'cDM' , 'cDU' ] ) ;
311
324
} ) ;
312
325
} ) ;
0 commit comments