dillon1000/react
Commit
Browse files [Fizz] Finalize postponed nextSegmentId after the prelude flush (#36779)
`getPostponedState` snapshots `request.nextSegmentId` at `onAllReady`,
before the Fizz stream is flowing. At this point we have visited all
Suspense boundaries and know which ones suspended by user code or not.
However, only when the stream is flowing are we counting the size of
each boundary. When we detect large boundaries, we suspend them i.e. we
outline them instead of keeping them inline. This results in more
segments being written while the postponed state holds a stale count.
We now keep a reference to the returned postponed state and mutate the
segment IDs when we outline. That way serializing `postponed` after the
`prelude` has flushed writes the latest postponed state.
The current API design means that you can potentially serialize stale
postponed state. We're considering a redesign to make these issues
impossible (e.g. https://github.com/react/react/pull/36815).
For now, the postponed state should only be serialized or passed onto a
`resume` once the `prelude` has flushed e.g.:
```js
const { createWriteStream, writeFileSync } = require('node:fs');
const { createWriteStream } = require('node:stream');
const { prelude, postponed } = prenderToNodeStream(...)
// serializing `postponed` now would write a stale state.
// serialize prelude
const destination = createWriteStream('prelude.html')
prelude.pipe(destination)
await finished(prelude)
// now we can serialize postponed
writeFileSync('postponed.json', JSON.stringify(postponed))
```
---------
Co-authored-by: Sebastian Sebbie Silbermann <[email protected]>Changed paths2 files
First-parent comparisonpackages/react-dom/src/__tests__/ReactDOMFizzStaticBrowser-test.js ModifiedM packages/react-server/src/ReactFizzServer.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…