buildHydrationDiffNode() — react Function Reference
Architecture documentation for the buildHydrationDiffNode() function in ReactFiberHydrationContext.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 0a0d4387_d230_00e3_0763_8da5f624b610["buildHydrationDiffNode()"] 4bc7109f_638d_d9f7_bf47_6ec55b2fa128["ReactFiberHydrationContext.js"] 0a0d4387_d230_00e3_0763_8da5f624b610 -->|defined in| 4bc7109f_638d_d9f7_bf47_6ec55b2fa128 4f7485e1_382f_1ae7_7a01_1c81a3bbbdd1["warnNonHydratedInstance()"] 4f7485e1_382f_1ae7_7a01_1c81a3bbbdd1 -->|calls| 0a0d4387_d230_00e3_0763_8da5f624b610 21487635_299a_7954_90ab_2c469023f80b["tryHydrateInstance()"] 21487635_299a_7954_90ab_2c469023f80b -->|calls| 0a0d4387_d230_00e3_0763_8da5f624b610 73a9e7ed_1281_819e_047c_f2d46a8df791["claimHydratableSingleton()"] 73a9e7ed_1281_819e_047c_f2d46a8df791 -->|calls| 0a0d4387_d230_00e3_0763_8da5f624b610 0c745329_8d79_5006_cb91_2a5765029a9b["prepareToHydrateHostTextInstance()"] 0c745329_8d79_5006_cb91_2a5765029a9b -->|calls| 0a0d4387_d230_00e3_0763_8da5f624b610 7c2189dd_f0c5_03ea_484b_2da399ad0e70["warnIfUnhydratedTailNodes()"] 7c2189dd_f0c5_03ea_484b_2da399ad0e70 -->|calls| 0a0d4387_d230_00e3_0763_8da5f624b610 style 0a0d4387_d230_00e3_0763_8da5f624b610 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-reconciler/src/ReactFiberHydrationContext.js lines 97–144
function buildHydrationDiffNode(
fiber: Fiber,
distanceFromLeaf: number,
): HydrationDiffNode {
if (fiber.return === null) {
// We're at the root.
if (hydrationDiffRootDEV === null) {
hydrationDiffRootDEV = {
fiber: fiber,
children: [],
serverProps: undefined,
serverTail: [],
distanceFromLeaf: distanceFromLeaf,
};
} else if (hydrationDiffRootDEV.fiber !== fiber) {
throw new Error(
'Saw multiple hydration diff roots in a pass. This is a bug in React.',
);
} else if (hydrationDiffRootDEV.distanceFromLeaf > distanceFromLeaf) {
hydrationDiffRootDEV.distanceFromLeaf = distanceFromLeaf;
}
return hydrationDiffRootDEV;
}
const siblings = buildHydrationDiffNode(
fiber.return,
distanceFromLeaf + 1,
).children;
// The same node may already exist in the parent. Since we currently always render depth first
// and rerender if we suspend or terminate early, if a shared ancestor was added we should still
// be inside of that shared ancestor which means it was the last one to be added. If this changes
// we may have to scan the whole set.
if (siblings.length > 0 && siblings[siblings.length - 1].fiber === fiber) {
const existing = siblings[siblings.length - 1];
if (existing.distanceFromLeaf > distanceFromLeaf) {
existing.distanceFromLeaf = distanceFromLeaf;
}
return existing;
}
const newNode: HydrationDiffNode = {
fiber: fiber,
children: [],
serverProps: undefined,
serverTail: [],
distanceFromLeaf: distanceFromLeaf,
};
siblings.push(newNode);
return newNode;
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does buildHydrationDiffNode() do?
buildHydrationDiffNode() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberHydrationContext.js.
Where is buildHydrationDiffNode() defined?
buildHydrationDiffNode() is defined in packages/react-reconciler/src/ReactFiberHydrationContext.js at line 97.
What calls buildHydrationDiffNode()?
buildHydrationDiffNode() is called by 5 function(s): claimHydratableSingleton, prepareToHydrateHostTextInstance, tryHydrateInstance, warnIfUnhydratedTailNodes, warnNonHydratedInstance.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free