File tree 1 file changed +31
-0
lines changed
packages/react-reconciler/src/__tests__ 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1366,4 +1366,35 @@ describe('ReactHooks', () => {
1366
1366
) ,
1367
1367
) . toThrow ( 'Hello' ) ;
1368
1368
} ) ;
1369
+
1370
+ // Regression test for https://github.com/facebook/react/issues/14790
1371
+ it ( 'does not fire a false positive warning when suspending' , async ( ) => {
1372
+ const { Suspense, useState, useRef} = React ;
1373
+
1374
+ let wasSuspended = false ;
1375
+ function trySuspend ( ) {
1376
+ if ( ! wasSuspended ) {
1377
+ throw new Promise ( resolve => {
1378
+ wasSuspended = true ;
1379
+ resolve ( ) ;
1380
+ } ) ;
1381
+ }
1382
+ }
1383
+
1384
+ function Child ( ) {
1385
+ React . useState ( ) ;
1386
+ trySuspend ( ) ;
1387
+ return 'hello' ;
1388
+ }
1389
+
1390
+ const Wrapper = React . memo ( Child ) ;
1391
+ const root = ReactTestRenderer . create (
1392
+ < Suspense fallback = "loading" >
1393
+ < Wrapper />
1394
+ </ Suspense > ,
1395
+ ) ;
1396
+ expect ( root ) . toMatchRenderedOutput ( 'loading' ) ;
1397
+ await Promise . resolve ( ) ;
1398
+ expect ( root ) . toMatchRenderedOutput ( 'hello' ) ;
1399
+ } ) ;
1369
1400
} ) ;
You can’t perform that action at this time.
0 commit comments