react/scripts/jest
Josh Story 16d2bbbd1f
Client render dehydrated Suspense boundaries on document load (#31620)
When streaming SSR while hydrating React will wait for Suspense
boundaries to be revealed by the SSR stream before attempting to hydrate
them. The rationale here is that the Server render is likely further
ahead of whatever the client would produce so waiting to let the server
stream in the UI is preferable to retrying on the client and possibly
delaying how quickly the primary content becomes available. However If
the connection closes early (user hits stop for instance) or there is a
server error which prevents additional HTML from being delivered to the
client this can put React into a broken state where the boundary never
resolves nor errors and the hydration never retries that boundary
freezing it in it's fallback state.

Once the document has fully loaded we know there is not way any
additional Suspense boundaries can arrive. This update changes react-dom
on the client to schedule client renders for any unfinished Suspense
boundaries upon document loading.

The technique for client rendering a fallback is pretty straight
forward. When hydrating a Suspense boundary if the Document is in
'complete' readyState we interpret pending boundaries as fallback
boundaries. If the readyState is not 'complete' we register an event to
retry the boundary when the DOMContentLoaded event fires.

To test this I needed JSDOM to model readyState. We previously had a
temporary implementation of readyState for SSR streaming but I ended up
implementing this as a mock of JSDOM that implements a fake readyState
that is mutable. It starts off in 'loading' readyState and you can
advance it by mutating document.readyState. You can also reset it to
'loading'. It fires events when changing states.

This seems like the least invasive way to get closer-to-real-browser
behavior in a way that won't require remembering this subtle detail
every time you create a test that asserts Suspense resolution order.
2024-12-03 13:13:35 -08:00
..
devtools chore[react-devtools]: add global for native and use it to fork backend implementation (#30533) 2024-08-02 10:51:15 +01:00
matchers Remove Component Stack from React Logged Warnings and Error Reporting (#30308) 2024-07-12 13:02:22 -04:00
spec-equivalence-reporter Migrate testRunner from jasmine2 to jest-circus (#26144) 2023-02-10 13:39:14 -05:00
typescript Use declare const instead of declare var (#28599) 2024-03-22 11:20:18 -04:00
config.base.js Client render dehydrated Suspense boundaries on document load (#31620) 2024-12-03 13:13:35 -08:00
config.build-devtools.js [BE] upgrade prettier to 3.3.3 (#30420) 2024-07-22 16:09:01 -04:00
config.build.js [BE] upgrade prettier to 3.3.3 (#30420) 2024-07-22 16:09:01 -04:00
config.source-persistent.js DevTools: Show hook names based on variable usage (#21641) 2021-07-01 14:39:18 -04:00
config.source-www.js DevTools: Show hook names based on variable usage (#21641) 2021-07-01 14:39:18 -04:00
config.source-xplat.js Add xplat test variants (#29734) 2024-06-04 13:07:29 -04:00
config.source.js DevTools: Show hook names based on variable usage (#21641) 2021-07-01 14:39:18 -04:00
dont-run-jest-directly.js Add error when running jest directly (#12726) 2018-05-01 12:46:17 -07:00
jest-cli.js [ci] Cleanup --ci flag 2024-07-29 19:18:03 -04:00
jest.js [Codemod] Update copyright header to Meta (#25315) 2022-10-18 11:19:24 -04:00
patchMessageChannel.js [Flight][Fizz] schedule work async (#29551) 2024-06-06 10:07:24 -07:00
patchSetImmediate.js [Flight][Fizz] schedule work async (#29551) 2024-06-06 10:07:24 -07:00
preprocessor.js Transform JSX to Lazy Requires instead of Wrappers (#30433) 2024-07-23 15:51:23 -04:00
ReactDOMServerIntegrationEnvironment.js Client render dehydrated Suspense boundaries on document load (#31620) 2024-12-03 13:13:35 -08:00
ReactJSDOMEnvironment.js Client render dehydrated Suspense boundaries on document load (#31620) 2024-12-03 13:13:35 -08:00
setupEnvironment.js [Flight][Fizz] schedule work async (#29551) 2024-06-06 10:07:24 -07:00
setupGlobal.js Use toMatchInlineSnapshot for dehydrated values (#20618) 2021-04-26 12:30:34 -04:00
setupHostConfigs.js Export captureOwnerStacks() only in DEV "react" builds (#29923) 2024-06-19 14:19:48 -04:00
setupTests.build.js Enforce that the "react-server" build of "react" is used (#27436) 2023-09-29 18:24:05 -04:00
setupTests.js Client render dehydrated Suspense boundaries on document load (#31620) 2024-12-03 13:13:35 -08:00
setupTests.persistent.js Update jest to v26 (#21574) 2021-05-27 16:33:57 +01:00
setupTests.www.js Remove forceConcurrentByDefaultForTesting flag (#30436) 2024-07-24 10:17:33 -04:00
setupTests.xplat.js Add xplat test variants (#29734) 2024-06-04 13:07:29 -04:00
TestFlags.js Temporarily disable suspending during work loop (#30762) 2024-09-04 12:38:36 -04:00