Skip to content

useMutableSource and hydration #18183

Closed
@bvaughn

Description

@bvaughn

Follow up to PR #18000 and RFC reactjs/rfcs#147

The new useMutableSource hook will need at least one additional API to be able to support server rendering and hydration. This API would likely be on the React root (the object returned by createRoot) and would enable mutable sources to have their versions eagerly captured before hydration begins.

How is the version used?

Currently a work-in-progress version of each mutable source is stored on the source itself. This version enables us to avoid tearing before a source has been subscribed to. This version number is lazily populated (the first time a source is read during a given render).

How will the version be used during hydration?

In the case of server rendering, this version will need to be eagerly populated for every source so that we can detect tearing between the version of the source used for the server respond, and the version we will eventually read from while hydrating on the client.

How will this work?

One way to do this would be to store an array on each React root of mutable source and version number pairs. Each time we start (or resume) hydration, we can iterate through this array and use it to initialize the work-in-progress version for each source.

Once all outstanding hydration work is finished, we can clear the array. (Although this will require an additional change as we do not currently have a way to detect that we've finished all pending hydration work.)

Metadata

Metadata

Labels

React Core TeamOpened by a member of the React Core Team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions