-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Clear extra nodes if there's a hydration mismatch within a suspense boundary #22592
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,6 +261,8 @@ function tryHydrate(fiber, nextInstance) { | |
const instance = canHydrateInstance(nextInstance, type, props); | ||
if (instance !== null) { | ||
fiber.stateNode = (instance: Instance); | ||
hydrationParentFiber = fiber; | ||
nextHydratableInstance = getFirstHydratableChild(instance); | ||
return true; | ||
} | ||
return false; | ||
|
@@ -270,6 +272,9 @@ function tryHydrate(fiber, nextInstance) { | |
const textInstance = canHydrateTextInstance(nextInstance, text); | ||
if (textInstance !== null) { | ||
fiber.stateNode = (textInstance: TextInstance); | ||
hydrationParentFiber = fiber; | ||
// Text Instances don't have children so there's nothing to hydrate. | ||
nextHydratableInstance = null; | ||
return true; | ||
} | ||
return false; | ||
|
@@ -294,6 +299,10 @@ function tryHydrate(fiber, nextInstance) { | |
); | ||
dehydratedFragment.return = fiber; | ||
fiber.child = dehydratedFragment; | ||
hydrationParentFiber = fiber; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could avoid updating this and instead leave it. I.e. not step into it and then not call pop in the complete phase instead. That might be better than "entering" it twice in two different ways. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also instead of trying to hydrate automatically entering these, we could make an explicit call in each begin phase ot enter. |
||
// While a Suspense Instance does have children, we won't step into | ||
// it during the first pass. Instead, we'll reenter it later. | ||
nextHydratableInstance = null; | ||
return true; | ||
} | ||
} | ||
|
@@ -322,6 +331,7 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void { | |
// We use this as a heuristic. It's based on intuition and not data so it | ||
// might be flawed or unnecessary. | ||
nextInstance = getNextHydratableSibling(firstAttemptedInstance); | ||
const prevHydrationParentFiber: Fiber = (hydrationParentFiber: any); | ||
if (!nextInstance || !tryHydrate(fiber, nextInstance)) { | ||
// Nothing to hydrate. Make it an insertion. | ||
insertNonHydratedInstance((hydrationParentFiber: any), fiber); | ||
|
@@ -333,13 +343,8 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void { | |
// superfluous and we'll delete it. Since we can't eagerly delete it | ||
// we'll have to schedule a deletion. To do that, this node needs a dummy | ||
// fiber associated with it. | ||
deleteHydratableInstance( | ||
(hydrationParentFiber: any), | ||
firstAttemptedInstance, | ||
); | ||
deleteHydratableInstance(prevHydrationParentFiber, firstAttemptedInstance); | ||
} | ||
hydrationParentFiber = fiber; | ||
nextHydratableInstance = getFirstHydratableChild((nextInstance: any)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This happens to return |
||
} | ||
|
||
function prepareToHydrateHostInstance( | ||
|
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 is how I noticed this issue in the first place.
getFirstHydratableChildWithinSuspenseInstance
calls nextSibling to get the first child but if there are no children in the Suspense boundary it'll pop out of the boundary. Because in<!--$--><!--/$-->
nextSibling will give you the SUSPENSE_END_DATA comment. Which is then ignored by getNextHydratable. We can assume that in all calls of getNextHydratable, reaching one of these is like reaching the end of siblings.