-
Notifications
You must be signed in to change notification settings - Fork 47.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fiber] support hydration when rendering Suspense anywhere #32224
base: main
Are you sure you want to change the base?
Conversation
ec6a539
to
5b6d0a9
Compare
5b6d0a9
to
e0dff86
Compare
e0dff86
to
7ca25bf
Compare
7ca25bf
to
f49516e
Compare
f49516e
to
29269cc
Compare
29269cc
to
cb8aee0
Compare
cb8aee0
to
d103fac
Compare
d103fac
to
4a89f74
Compare
4a89f74
to
186fd8b
Compare
186fd8b
to
0c469b3
Compare
0c469b3
to
75a8cbf
Compare
75a8cbf
to
d64a73c
Compare
@@ -948,6 +993,37 @@ export function clearSuspenseBoundary( | |||
data === SUSPENSE_FALLBACK_START_DATA | |||
) { | |||
depth++; | |||
} else if (data.length === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a bit bold but rendering comments in React components it's super common and this is only run on dehydrated suspense boundaries so we're generally only susceptible to colliding with user of innerHTML. We can't eliminate every collision so while prefixing with $
and this style of comment is not going to be written by a user so the most likely consequence is that there is a collision with an extension.
If we want to be significantly more defensive we can add a check that the nextSibling
is also a comment matching the Suspense end marker. But I don't think it's actually worth the code size to include
d64a73c
to
507f04c
Compare
507f04c
to
5832fe9
Compare
stacked on facebook#32163 This continues the work of making Suspense workable anywhere in a react-dom tree. See the prior PRs for how we handle server rendering and client rendering. In this change we update the hydration implementation to be able to locate expected nodes. In particular this means hydration understands now that the default hydration context is the document body when the container is above the body. One case that is unique to hydration is clearing Suspense boundaries. When hydration fails or when the server instructs the client to recover an errored boundary it's possible that the html, head, and body tags in the initial document were written from a fallback or a different primary content on the server and need to be replaced by the client render. However these tags (and in the case of head, their content) won't be inside the comment nodes that identify the bounds of the Suspense boundary. And when client rendering you may not even render the same singletons that were server rendered. So when server rendering a boudnary which contributes to the preamble (the html, head, and body tag openings plus the head contents) we emit a special marker comment just before closing the boundary out. This marker encodes which parts of the preamble this boundary owned. If we need to clear the suspense boundary on the client we read this marker and use it to reset the appropriate singleton state.
b7ed994
to
a85088e
Compare
follow up to #32163
This continues the work of making Suspense workable anywhere in a react-dom tree. See the prior PRs for how we handle server rendering and client rendering. In this change we update the hydration implementation to be able to locate expected nodes. In particular this means hydration understands now that the default hydration context is the document body when the container is above the body.
One case that is unique to hydration is clearing Suspense boundaries. When hydration fails or when the server instructs the client to recover an errored boundary it's possible that the html, head, and body tags in the initial document were written from a fallback or a different primary content on the server and need to be replaced by the client render. However these tags (and in the case of head, their content) won't be inside the comment nodes that identify the bounds of the Suspense boundary. And when client rendering you may not even render the same singletons that were server rendered. So when server rendering a boudnary which contributes to the preamble (the html, head, and body tag openings plus the head contents) we emit a special marker comment just before closing the boundary out. This marker encodes which parts of the preamble this boundary owned. If we need to clear the suspense boundary on the client we read this marker and use it to reset the appropriate singleton state.