@@ -358,7 +358,11 @@ describe('ReactDOMFizzServer', () => {
358
358
window . __INIT__ = function ( ) {
359
359
bootstrapped = true ;
360
360
// Attempt to hydrate the content.
361
- ReactDOM . hydrateRoot ( container , < App isClient = { true } /> ) ;
361
+ ReactDOM . hydrateRoot ( container , < App isClient = { true } /> , {
362
+ onRecoverableError ( error ) {
363
+ Scheduler . unstable_yieldValue ( error . message ) ;
364
+ } ,
365
+ } ) ;
362
366
} ;
363
367
364
368
await act ( async ( ) => {
@@ -394,7 +398,10 @@ describe('ReactDOMFizzServer', () => {
394
398
expect ( getVisibleChildren ( container ) ) . toEqual ( < div > Loading...</ div > ) ;
395
399
396
400
// Now we can client render it instead.
397
- Scheduler . unstable_flushAll ( ) ;
401
+ expect ( Scheduler ) . toFlushAndYield ( [
402
+ 'The server could not finish this Suspense boundary, likely due to ' +
403
+ 'an error during server rendering. Switched to client rendering.' ,
404
+ ] ) ;
398
405
399
406
// The client rendered HTML is now in place.
400
407
expect ( getVisibleChildren ( container ) ) . toEqual ( < div > Hello</ div > ) ;
@@ -465,7 +472,11 @@ describe('ReactDOMFizzServer', () => {
465
472
expect ( loggedErrors ) . toEqual ( [ ] ) ;
466
473
467
474
// Attempt to hydrate the content.
468
- ReactDOM . hydrateRoot ( container , < App isClient = { true } /> ) ;
475
+ ReactDOM . hydrateRoot ( container , < App isClient = { true } /> , {
476
+ onRecoverableError ( error ) {
477
+ Scheduler . unstable_yieldValue ( error . message ) ;
478
+ } ,
479
+ } ) ;
469
480
Scheduler . unstable_flushAll ( ) ;
470
481
471
482
// We're still loading because we're waiting for the server to stream more content.
@@ -484,7 +495,10 @@ describe('ReactDOMFizzServer', () => {
484
495
expect ( getVisibleChildren ( container ) ) . toEqual ( < div > Loading...</ div > ) ;
485
496
486
497
// Now we can client render it instead.
487
- Scheduler . unstable_flushAll ( ) ;
498
+ expect ( Scheduler ) . toFlushAndYield ( [
499
+ 'The server could not finish this Suspense boundary, likely due to ' +
500
+ 'an error during server rendering. Switched to client rendering.' ,
501
+ ] ) ;
488
502
489
503
// The client rendered HTML is now in place.
490
504
expect ( getVisibleChildren ( container ) ) . toEqual ( < div > Hello</ div > ) ;
@@ -766,7 +780,11 @@ describe('ReactDOMFizzServer', () => {
766
780
// We're still showing a fallback.
767
781
768
782
// Attempt to hydrate the content.
769
- ReactDOM . hydrateRoot ( container , < App /> ) ;
783
+ ReactDOM . hydrateRoot ( container , < App /> , {
784
+ onRecoverableError ( error ) {
785
+ Scheduler . unstable_yieldValue ( error . message ) ;
786
+ } ,
787
+ } ) ;
770
788
Scheduler . unstable_flushAll ( ) ;
771
789
772
790
// We're still loading because we're waiting for the server to stream more content.
@@ -778,7 +796,10 @@ describe('ReactDOMFizzServer', () => {
778
796
} ) ;
779
797
780
798
// We still can't render it on the client.
781
- Scheduler . unstable_flushAll ( ) ;
799
+ expect ( Scheduler ) . toFlushAndYield ( [
800
+ 'The server could not finish this Suspense boundary, likely due to an ' +
801
+ 'error during server rendering. Switched to client rendering.' ,
802
+ ] ) ;
782
803
expect ( getVisibleChildren ( container ) ) . toEqual ( < div > Loading...</ div > ) ;
783
804
784
805
// We now resolve it on the client.
@@ -1455,7 +1476,11 @@ describe('ReactDOMFizzServer', () => {
1455
1476
// We're still showing a fallback.
1456
1477
1457
1478
// Attempt to hydrate the content.
1458
- ReactDOM . hydrateRoot ( container , < App isClient = { true } /> ) ;
1479
+ ReactDOM . hydrateRoot ( container , < App isClient = { true } /> , {
1480
+ onRecoverableError ( error ) {
1481
+ Scheduler . unstable_yieldValue ( error . message ) ;
1482
+ } ,
1483
+ } ) ;
1459
1484
Scheduler . unstable_flushAll ( ) ;
1460
1485
1461
1486
// We're still loading because we're waiting for the server to stream more content.
@@ -1484,7 +1509,10 @@ describe('ReactDOMFizzServer', () => {
1484
1509
expect ( getVisibleChildren ( container ) ) . toEqual ( < div > Loading...</ div > ) ;
1485
1510
1486
1511
// That will let us client render it instead.
1487
- Scheduler . unstable_flushAll ( ) ;
1512
+ expect ( Scheduler ) . toFlushAndYield ( [
1513
+ 'The server could not finish this Suspense boundary, likely due to ' +
1514
+ 'an error during server rendering. Switched to client rendering.' ,
1515
+ ] ) ;
1488
1516
1489
1517
// The client rendered HTML is now in place.
1490
1518
expect ( getVisibleChildren ( container ) ) . toEqual (
@@ -1736,8 +1764,11 @@ describe('ReactDOMFizzServer', () => {
1736
1764
// The first paint switches to client rendering due to mismatch
1737
1765
expect ( Scheduler ) . toFlushUntilNextPaint ( [
1738
1766
'client' ,
1739
- 'Log recoverable error: An error occurred during hydration. ' +
1740
- 'The server HTML was replaced with client content' ,
1767
+ 'Log recoverable error: Hydration failed because the initial ' +
1768
+ 'UI does not match what was rendered on the server.' ,
1769
+ 'Log recoverable error: There was an error while hydrating. ' +
1770
+ 'Because the error happened outside of a Suspense boundary, the ' +
1771
+ 'entire root will switch to client rendering.' ,
1741
1772
] ) ;
1742
1773
} ) . toErrorDev (
1743
1774
[
@@ -1834,8 +1865,11 @@ describe('ReactDOMFizzServer', () => {
1834
1865
// The first paint switches to client rendering due to mismatch
1835
1866
expect ( Scheduler ) . toFlushUntilNextPaint ( [
1836
1867
'client' ,
1837
- 'Log recoverable error: An error occurred during hydration. ' +
1838
- 'The server HTML was replaced with client content' ,
1868
+ 'Log recoverable error: Hydration failed because the initial ' +
1869
+ 'UI does not match what was rendered on the server.' ,
1870
+ 'Log recoverable error: There was an error while hydrating. ' +
1871
+ 'Because the error happened outside of a Suspense boundary, the ' +
1872
+ 'entire root will switch to client rendering.' ,
1839
1873
] ) ;
1840
1874
} ) . toErrorDev (
1841
1875
[
@@ -1928,7 +1962,13 @@ describe('ReactDOMFizzServer', () => {
1928
1962
// An error logged but instead of surfacing it to the UI, we switched
1929
1963
// to client rendering.
1930
1964
expect ( ( ) => {
1931
- expect ( Scheduler ) . toFlushAndYield ( [ 'Yay!' , 'Hydration error' ] ) ;
1965
+ expect ( Scheduler ) . toFlushAndYield ( [
1966
+ 'Yay!' ,
1967
+ 'Hydration error' ,
1968
+ 'There was an error while hydrating. Because the error happened ' +
1969
+ 'outside of a Suspense boundary, the entire root will switch ' +
1970
+ 'to client rendering.' ,
1971
+ ] ) ;
1932
1972
} ) . toErrorDev (
1933
1973
'An error occurred during hydration. The server HTML was replaced' ,
1934
1974
{ withoutStack : true } ,
@@ -2012,7 +2052,11 @@ describe('ReactDOMFizzServer', () => {
2012
2052
2013
2053
// An error logged but instead of surfacing it to the UI, we switched
2014
2054
// to client rendering.
2015
- expect ( Scheduler ) . toFlushAndYield ( [ 'Yay!' , 'Hydration error' ] ) ;
2055
+ expect ( Scheduler ) . toFlushAndYield ( [
2056
+ 'Yay!' ,
2057
+ 'Hydration error' ,
2058
+ 'There was an error while hydrating this Suspense boundary. Switched to client rendering.' ,
2059
+ ] ) ;
2016
2060
expect ( getVisibleChildren ( container ) ) . toEqual (
2017
2061
< div >
2018
2062
< span />
@@ -2178,7 +2222,11 @@ describe('ReactDOMFizzServer', () => {
2178
2222
2179
2223
// An error logged but instead of surfacing it to the UI, we switched
2180
2224
// to client rendering.
2181
- expect ( Scheduler ) . toFlushAndYield ( [ 'Hydration error' ] ) ;
2225
+ expect ( Scheduler ) . toFlushAndYield ( [
2226
+ 'Hydration error' ,
2227
+ 'There was an error while hydrating this Suspense boundary. Switched ' +
2228
+ 'to client rendering.' ,
2229
+ ] ) ;
2182
2230
expect ( getVisibleChildren ( container ) ) . toEqual (
2183
2231
< div >
2184
2232
< span />
@@ -2328,8 +2376,14 @@ describe('ReactDOMFizzServer', () => {
2328
2376
expect ( Scheduler ) . toFlushAndYield ( [
2329
2377
'A' ,
2330
2378
'B' ,
2379
+
2331
2380
'Logged recoverable error: Hydration error' ,
2381
+ 'Logged recoverable error: There was an error while hydrating this ' +
2382
+ 'Suspense boundary. Switched to client rendering.' ,
2383
+
2332
2384
'Logged recoverable error: Hydration error' ,
2385
+ 'Logged recoverable error: There was an error while hydrating this ' +
2386
+ 'Suspense boundary. Switched to client rendering.' ,
2333
2387
] ) ;
2334
2388
} ) ;
2335
2389
} ) ;
0 commit comments