From dee287d16d0c2d95606980011c64101d24a39519 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 1 Apr 2022 20:51:09 +0100 Subject: [PATCH 1/5] [WIP] Diffs for hydration errors --- .../__tests__/ReactDOMHydrationDiff-test.js | 659 +++++++++++------- .../react-dom/src/client/ReactDOMComponent.js | 117 +++- 2 files changed, 499 insertions(+), 277 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js index 9237493c6dcec..09edd2caf3234 100644 --- a/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js @@ -83,28 +83,17 @@ describe('ReactDOMServerHydration', () => { ); } - if (gate(flags => flags.enableClientRenderFallbackOnTextMismatch)) { - expect(testMismatch(Mismatch)).toMatchInlineSnapshot(` - Array [ - "Warning: Text content did not match. Server: \\"server\\" Client: \\"client\\" - in main (at **) - in div (at **) - in Mismatch (at **)", - "Warning: An error occurred during hydration. The server HTML was replaced with client content in
.", - "Caught [Text content does not match server-rendered HTML.]", - "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", - ] - `); - } else { - expect(testMismatch(Mismatch)).toMatchInlineSnapshot(` - Array [ - "Warning: Text content did not match. Server: \\"server\\" Client: \\"client\\" - in main (at **) - in div (at **) - in Mismatch (at **)", - ] - `); - } + expect(testMismatch(Mismatch)).toMatchInlineSnapshot(` + Array [ + "Warning: Text content did not match. Server: \\"server\\" Client: \\"client\\" + in main (at **) + in div (at **) + in Mismatch (at **)", + "Warning: An error occurred during hydration. The server HTML was replaced with client content in
.", + "Caught [Text content does not match server-rendered HTML.]", + "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", + ] + `); }); // @gate __DEV__ @@ -263,16 +252,16 @@ describe('ReactDOMServerHydration', () => { ); } expect(testMismatch(Mismatch)).toMatchInlineSnapshot(` - Array [ - "Warning: Expected server HTML to contain a matching
in
. - in main (at **) - in div (at **) - in Mismatch (at **)", - "Warning: An error occurred during hydration. The server HTML was replaced with client content in
.", - "Caught [Hydration failed because the initial UI does not match what was rendered on the server.]", - "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", - ] - `); + Array [ + "Warning: Expected server HTML to contain a matching
in
. + in main (at **) + in div (at **) + in Mismatch (at **)", + "Warning: An error occurred during hydration. The server HTML was replaced with client content in
.", + "Caught [Hydration failed because the initial UI does not match what was rendered on the server.]", + "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", + ] + `); }); // @gate __DEV__ @@ -287,16 +276,16 @@ describe('ReactDOMServerHydration', () => { ); } expect(testMismatch(Mismatch)).toMatchInlineSnapshot(` - Array [ - "Warning: Expected server HTML to contain a matching
in
. - in header (at **) - in div (at **) - in Mismatch (at **)", - "Warning: An error occurred during hydration. The server HTML was replaced with client content in
.", - "Caught [Hydration failed because the initial UI does not match what was rendered on the server.]", - "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", - ] - `); + Array [ + "Warning: Expected server HTML to contain a matching
in
. + in header (at **) + in div (at **) + in Mismatch (at **)", + "Warning: An error occurred during hydration. The server HTML was replaced with client content in
.", + "Caught [Hydration failed because the initial UI does not match what was rendered on the server.]", + "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", + ] + `); }); // @gate __DEV__ @@ -311,16 +300,16 @@ describe('ReactDOMServerHydration', () => { ); } expect(testMismatch(Mismatch)).toMatchInlineSnapshot(` - Array [ - "Warning: Expected server HTML to contain a matching
in
. - in main (at **) - in div (at **) - in Mismatch (at **)", - "Warning: An error occurred during hydration. The server HTML was replaced with client content in
.", - "Caught [Hydration failed because the initial UI does not match what was rendered on the server.]", - "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", - ] - `); + Array [ + "Warning: Expected server HTML to contain a matching
in
. + in main (at **) + in div (at **) + in Mismatch (at **)", + "Warning: An error occurred during hydration. The server HTML was replaced with client content in
.", + "Caught [Hydration failed because the initial UI does not match what was rendered on the server.]", + "Caught [There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.]", + ] + `); }); // @gate __DEV__ @@ -335,16 +324,39 @@ describe('ReactDOMServerHydration', () => { ); } expect(testMismatch(Mismatch)).toMatchInlineSnapshot(` - Array [ - "Warning: Expected server HTML to contain a matching