You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.)
The text was updated successfully, but these errors were encountered:
This API wouldn't support a create-during-render pattern. You'd need to create the source at the module level. Otherwise a mutation might happen between the time when root hydration starts and when a particular component that reads from the source is hydrated.
I don't see an alternative to this though, without e.g. tightening constraints on "version" to be serializable.
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 bycreateRoot
) 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.)
The text was updated successfully, but these errors were encountered: