GeezerVison is showing github.com — Add ReactDOMClient to ServerIntegration(Hooks|NewContext) (#28135) · react/react@fa6674b
File treeExpand file treeCollapse file tree Open diff view settings packages/react-dom/src/__tests__
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMServerIntegrationHooks-test.js +31-9Lines changed: 31 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); | 16 | 16 |
| 17 | 17 | let React; | 18 | | -let ReactDOM; | | 18 | +let ReactDOMClient; | 19 | 19 | let ReactDOMServer; | 20 | 20 | let ReactTestUtils; | 21 | 21 | let useState; | @@ -39,7 +39,7 @@ function initModules() { | 39 | 39 | jest.resetModules(); | 40 | 40 |
| 41 | 41 | React = require('react'); | 42 | | - ReactDOM = require('react-dom'); | | 42 | + ReactDOMClient = require('react-dom/client'); | 43 | 43 | ReactDOMServer = require('react-dom/server'); | 44 | 44 | ReactTestUtils = require('react-dom/test-utils'); | 45 | 45 | useState = React.useState; | @@ -67,14 +67,19 @@ function initModules() { | 67 | 67 |
| 68 | 68 | // Make them available to the helpers. | 69 | 69 | return { | 70 | | - ReactDOM, | | 70 | + ReactDOMClient, | 71 | 71 | ReactDOMServer, | 72 | 72 | ReactTestUtils, | 73 | 73 | }; | 74 | 74 | } | 75 | 75 |
| 76 | | -const {resetModules, itRenders, itThrowsWhenRendering, serverRender} = | 77 | | - ReactDOMServerIntegrationUtils(initModules); | | 76 | +const { | | 77 | + resetModules, | | 78 | + itRenders, | | 79 | + itThrowsWhenRendering, | | 80 | + clientRenderOnBadMarkup, | | 81 | + serverRender, | | 82 | +} = ReactDOMServerIntegrationUtils(initModules); | 78 | 83 |
| 79 | 84 | describe('ReactDOMServerHooks', () => { | 80 | 85 | beforeEach(() => { | @@ -422,8 +427,13 @@ describe('ReactDOMServerHooks', () => { | 422 | 427 | }); | 423 | 428 | return 'hi'; | 424 | 429 | } | 425 | | - | 426 | | - const domNode = await render(<App />, 1); | | 430 | + const domNode = await render( | | 431 | + <App />, | | 432 | + render === clientRenderOnBadMarkup | | 433 | + ? // On hydration mismatch we retry and therefore log the warning again. | | 434 | + 2 | | 435 | + : 1, | | 436 | + ); | 427 | 437 | expect(domNode.textContent).toEqual('hi'); | 428 | 438 | }); | 429 | 439 |
| @@ -436,7 +446,13 @@ describe('ReactDOMServerHooks', () => { | 436 | 446 | return value; | 437 | 447 | } | 438 | 448 |
| 439 | | - const domNode = await render(<App />, 1); | | 449 | + const domNode = await render( | | 450 | + <App />, | | 451 | + render === clientRenderOnBadMarkup | | 452 | + ? // On hydration mismatch we retry and therefore log the warning again. | | 453 | + 2 | | 454 | + : 1, | | 455 | + ); | 440 | 456 | expect(domNode.textContent).toEqual('0'); | 441 | 457 | }); | 442 | 458 | }); | @@ -859,7 +875,13 @@ describe('ReactDOMServerHooks', () => { | 859 | 875 | return <Text text={count} />; | 860 | 876 | } | 861 | 877 |
| 862 | | - const domNode1 = await render(<ReadInMemo />, 1); | | 878 | + const domNode1 = await render( | | 879 | + <ReadInMemo />, | | 880 | + render === clientRenderOnBadMarkup | | 881 | + ? // On hydration mismatch we retry and therefore log the warning again. | | 882 | + 2 | | 883 | + : 1, | | 884 | + ); | 863 | 885 | expect(domNode1.textContent).toEqual('42'); | 864 | 886 |
| 865 | 887 | const domNode2 = await render(<ReadInReducer />, 1); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMServerIntegrationNewContext-test.js +20-8Lines changed: 20 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | const ReactDOMServerIntegrationUtils = require('./utils/ReactDOMServerIntegrationTestUtils'); | 14 | 14 |
| 15 | 15 | let React; | 16 | | -let ReactDOM; | | 16 | +let ReactDOMClient; | 17 | 17 | let ReactDOMServer; | 18 | 18 | let ReactTestUtils; | 19 | 19 |
| 20 | 20 | function initModules() { | 21 | 21 | // Reset warning cache. | 22 | 22 | jest.resetModules(); | 23 | 23 | React = require('react'); | 24 | | - ReactDOM = require('react-dom'); | | 24 | + ReactDOMClient = require('react-dom/client'); | 25 | 25 | ReactDOMServer = require('react-dom/server'); | 26 | 26 | ReactTestUtils = require('react-dom/test-utils'); | 27 | 27 |
| 28 | 28 | // Make them available to the helpers. | 29 | 29 | return { | 30 | | - ReactDOM, | | 30 | + ReactDOMClient, | 31 | 31 | ReactDOMServer, | 32 | 32 | ReactTestUtils, | 33 | 33 | }; | 34 | 34 | } | 35 | 35 |
| 36 | | -const {resetModules, itRenders} = ReactDOMServerIntegrationUtils(initModules); | | 36 | +const {resetModules, itRenders, clientRenderOnBadMarkup} = | | 37 | + ReactDOMServerIntegrationUtils(initModules); | 37 | 38 |
| 38 | 39 | describe('ReactDOMServerIntegration', () => { | 39 | 40 | beforeEach(() => { | @@ -365,8 +366,13 @@ describe('ReactDOMServerIntegration', () => { | 365 | 366 | </div> | 366 | 367 | ); | 367 | 368 | }; | 368 | | - // We expect 1 error. | 369 | | - await render(<App />, 1); | | 369 | + await render( | | 370 | + <App />, | | 371 | + render === clientRenderOnBadMarkup | | 372 | + ? // On hydration mismatch we retry and therefore log the warning again. | | 373 | + 2 | | 374 | + : 1, | | 375 | + ); | 370 | 376 | }, | 371 | 377 | ); | 372 | 378 |
| @@ -391,8 +397,14 @@ describe('ReactDOMServerIntegration', () => { | 391 | 397 | </div> | 392 | 398 | ); | 393 | 399 | }; | 394 | | - // We expect 1 error. | 395 | | - await render(<App />, 1); | | 400 | + | | 401 | + await render( | | 402 | + <App />, | | 403 | + render === clientRenderOnBadMarkup | | 404 | + ? // On hydration mismatch we retry and therefore log the warning again. | | 405 | + 2 | | 406 | + : 1, | | 407 | + ); | 396 | 408 | }, | 397 | 409 | ); | 398 | 410 |
| |
|