@@ -449,10 +449,9 @@ describe('ReactDOMServerPartialHydration', () => {
449
449
expect ( deleted . length ) . toBe ( 0 ) ;
450
450
451
451
// Performing an update should force it to delete the boundary
452
- root . render ( < App value = { true } /> ) ;
453
-
454
- Scheduler . unstable_flushAll ( ) ;
455
- jest . runAllTimers ( ) ;
452
+ await act ( async ( ) => {
453
+ root . render ( < App value = { true } /> ) ;
454
+ } ) ;
456
455
457
456
expect ( hydrated . length ) . toBe ( 1 ) ;
458
457
expect ( deleted . length ) . toBe ( 1 ) ;
@@ -945,13 +944,12 @@ describe('ReactDOMServerPartialHydration', () => {
945
944
root . render ( < App text = "Hi" className = "hi" /> ) ;
946
945
947
946
// At the same time, resolving the promise so that rendering can complete.
948
- suspend = false ;
949
- resolve ( ) ;
950
- await promise ;
951
-
952
947
// This should first complete the hydration and then flush the update onto the hydrated state.
953
- Scheduler . unstable_flushAll ( ) ;
954
- jest . runAllTimers ( ) ;
948
+ await act ( async ( ) => {
949
+ suspend = false ;
950
+ resolve ( ) ;
951
+ await promise ;
952
+ } ) ;
955
953
956
954
// The new span should be the same since we should have successfully hydrated
957
955
// before changing it.
@@ -1093,9 +1091,9 @@ describe('ReactDOMServerPartialHydration', () => {
1093
1091
expect ( ref . current ) . toBe ( null ) ;
1094
1092
1095
1093
// Render an update, but leave it still suspended.
1096
- root . render ( < App text = "Hi" className = "hi" /> ) ;
1097
- Scheduler . unstable_flushAll ( ) ;
1098
- jest . runAllTimers ( ) ;
1094
+ await act ( async ( ) => {
1095
+ root . render ( < App text = "Hi" className = "hi" /> ) ;
1096
+ } ) ;
1099
1097
1100
1098
// Flushing now should delete the existing content and show the fallback.
1101
1099
@@ -1104,12 +1102,11 @@ describe('ReactDOMServerPartialHydration', () => {
1104
1102
expect ( container . textContent ) . toBe ( 'Loading...' ) ;
1105
1103
1106
1104
// Unsuspending shows the content.
1107
- suspend = false ;
1108
- resolve ( ) ;
1109
- await promise ;
1110
-
1111
- Scheduler . unstable_flushAll ( ) ;
1112
- jest . runAllTimers ( ) ;
1105
+ await act ( async ( ) => {
1106
+ suspend = false ;
1107
+ resolve ( ) ;
1108
+ await promise ;
1109
+ } ) ;
1113
1110
1114
1111
const span = container . getElementsByTagName ( 'span' ) [ 0 ] ;
1115
1112
expect ( span . textContent ) . toBe ( 'Hi' ) ;
@@ -1174,23 +1171,21 @@ describe('ReactDOMServerPartialHydration', () => {
1174
1171
expect ( ref . current ) . toBe ( span ) ;
1175
1172
1176
1173
// Render an update, but leave it still suspended.
1177
- root . render ( < App text = "Hi" className = "hi" /> ) ;
1178
-
1179
1174
// Flushing now should delete the existing content and show the fallback.
1180
- Scheduler . unstable_flushAll ( ) ;
1181
- jest . runAllTimers ( ) ;
1175
+ await act ( async ( ) => {
1176
+ root . render ( < App text = "Hi" className = "hi" /> ) ;
1177
+ } ) ;
1182
1178
1183
1179
expect ( container . getElementsByTagName ( 'span' ) . length ) . toBe ( 1 ) ;
1184
1180
expect ( ref . current ) . toBe ( span ) ;
1185
1181
expect ( container . textContent ) . toBe ( '' ) ;
1186
1182
1187
1183
// Unsuspending shows the content.
1188
- suspend = false ;
1189
- resolve ( ) ;
1190
- await promise ;
1191
-
1192
- Scheduler . unstable_flushAll ( ) ;
1193
- jest . runAllTimers ( ) ;
1184
+ await act ( async ( ) => {
1185
+ suspend = false ;
1186
+ resolve ( ) ;
1187
+ await promise ;
1188
+ } ) ;
1194
1189
1195
1190
expect ( span . textContent ) . toBe ( 'Hi' ) ;
1196
1191
expect ( span . className ) . toBe ( 'hi' ) ;
@@ -1252,20 +1247,21 @@ describe('ReactDOMServerPartialHydration', () => {
1252
1247
expect ( ref . current ) . toBe ( null ) ;
1253
1248
1254
1249
// Render an update, but leave it still suspended.
1255
- root . render ( < App text = "Hi" className = "hi" /> ) ;
1256
-
1257
1250
// Flushing now should delete the existing content and show the fallback.
1258
- Scheduler . unstable_flushAll ( ) ;
1259
- jest . runAllTimers ( ) ;
1251
+ await act ( async ( ) => {
1252
+ root . render ( < App text = "Hi" className = "hi" /> ) ;
1253
+ } ) ;
1260
1254
1261
1255
expect ( container . getElementsByTagName ( 'span' ) . length ) . toBe ( 0 ) ;
1262
1256
expect ( ref . current ) . toBe ( null ) ;
1263
1257
expect ( container . textContent ) . toBe ( 'Loading...' ) ;
1264
1258
1265
1259
// Unsuspending shows the content.
1266
- suspend = false ;
1267
- resolve ( ) ;
1268
- await promise ;
1260
+ await act ( async ( ) => {
1261
+ suspend = false ;
1262
+ resolve ( ) ;
1263
+ await promise ;
1264
+ } ) ;
1269
1265
1270
1266
Scheduler . unstable_flushAll ( ) ;
1271
1267
jest . runAllTimers ( ) ;
@@ -1490,13 +1486,12 @@ describe('ReactDOMServerPartialHydration', () => {
1490
1486
) ;
1491
1487
1492
1488
// At the same time, resolving the promise so that rendering can complete.
1493
- suspend = false ;
1494
- resolve ( ) ;
1495
- await promise ;
1496
-
1497
1489
// This should first complete the hydration and then flush the update onto the hydrated state.
1498
- Scheduler . unstable_flushAll ( ) ;
1499
- jest . runAllTimers ( ) ;
1490
+ await act ( async ( ) => {
1491
+ suspend = false ;
1492
+ resolve ( ) ;
1493
+ await promise ;
1494
+ } ) ;
1500
1495
1501
1496
// Since this should have been hydrated, this should still be the same span.
1502
1497
const newSpan = container . getElementsByTagName ( 'span' ) [ 0 ] ;
@@ -1569,27 +1564,25 @@ describe('ReactDOMServerPartialHydration', () => {
1569
1564
expect ( ref . current ) . toBe ( null ) ;
1570
1565
1571
1566
// Render an update, but leave it still suspended.
1572
- root . render (
1573
- < Context . Provider value = { { text : 'Hi' , className : 'hi' } } >
1574
- < App />
1575
- </ Context . Provider > ,
1576
- ) ;
1577
-
1578
1567
// Flushing now should delete the existing content and show the fallback.
1579
- Scheduler . unstable_flushAll ( ) ;
1580
- jest . runAllTimers ( ) ;
1568
+ await act ( async ( ) => {
1569
+ root . render (
1570
+ < Context . Provider value = { { text : 'Hi' , className : 'hi' } } >
1571
+ < App />
1572
+ </ Context . Provider > ,
1573
+ ) ;
1574
+ } ) ;
1581
1575
1582
1576
expect ( container . getElementsByTagName ( 'span' ) . length ) . toBe ( 0 ) ;
1583
1577
expect ( ref . current ) . toBe ( null ) ;
1584
1578
expect ( container . textContent ) . toBe ( 'Loading...' ) ;
1585
1579
1586
1580
// Unsuspending shows the content.
1587
- suspend = false ;
1588
- resolve ( ) ;
1589
- await promise ;
1590
-
1591
- Scheduler . unstable_flushAll ( ) ;
1592
- jest . runAllTimers ( ) ;
1581
+ await act ( async ( ) => {
1582
+ suspend = false ;
1583
+ resolve ( ) ;
1584
+ await promise ;
1585
+ } ) ;
1593
1586
1594
1587
const span = container . getElementsByTagName ( 'span' ) [ 0 ] ;
1595
1588
expect ( span . textContent ) . toBe ( 'Hi' ) ;
@@ -2320,16 +2313,15 @@ describe('ReactDOMServerPartialHydration', () => {
2320
2313
2321
2314
// Render an update, which will be higher or the same priority as pinging the hydration.
2322
2315
// The new update doesn't suspend.
2323
- root . render (
2324
- < ClassName . Provider value = { 'hi' } >
2325
- < App text = "Hi" />
2326
- </ ClassName . Provider > ,
2327
- ) ;
2328
-
2329
2316
// Since we're still suspended on the original data, we can't hydrate.
2330
2317
// This will force all expiration times to flush.
2331
- Scheduler . unstable_flushAll ( ) ;
2332
- jest . runAllTimers ( ) ;
2318
+ await act ( async ( ) => {
2319
+ root . render (
2320
+ < ClassName . Provider value = { 'hi' } >
2321
+ < App text = "Hi" />
2322
+ </ ClassName . Provider > ,
2323
+ ) ;
2324
+ } ) ;
2333
2325
2334
2326
// This will now be a new span because we weren't able to hydrate before
2335
2327
const newSpan = container . getElementsByTagName ( 'span' ) [ 0 ] ;
0 commit comments