Skip to content

Commit eede0ad

Browse files
committed
fix(hydration): update block markers after rebuiltAt removes the stamped boundary
When an unframed singleRoot component rebuilds during hydration and then suspends before commitBag, the finally block stamps the mismatched server node as the block boundary (startMarker/endMarker). When the retry later commits, rebuiltAt removes that server node, leaving the block markers detached. A subsequent identity change or unmount then fails to remove the committed rebuilt root from the DOM. Fix by checking in commitBag whether rebuiltAt just detached the block's markers, and if so, updating them to point to the root that replaced the removed server node. This mirrors the singleRoot self-mark pattern where startMarker === endMarker === the root element.
1 parent 9ba872a commit eede0ad

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20892,10 +20892,20 @@ function commitBag<T>(scope: Scope, root: Node | null, bag: T): T {
2089220892
// which stays until now.
2089320893
if (hydration === null || (STAGED_DOM?.view(root) ?? root).parentNode !== block.parentNode) {
2089420894
const parent = block.parentNode;
20895-
(STAGED_DOM?.view(parent) ?? parent).insertBefore(
20896-
root,
20897-
hydration?.rebuiltAt(root, parent) ?? block.endMarker,
20898-
);
20895+
const at = hydration?.rebuiltAt(root, parent);
20896+
(STAGED_DOM?.view(parent) ?? parent).insertBefore(root, at ?? block.endMarker);
20897+
// rebuiltAt removed the server node the block stamped as its boundary
20898+
// (an unframed singleRoot that suspended before this commit). Update
20899+
// the markers to the root that replaced it so a later unmount or swap
20900+
// finds the live node.
20901+
if (
20902+
at !== undefined &&
20903+
block.startMarker != null &&
20904+
(STAGED_DOM?.view(block.startMarker) ?? block.startMarker).parentNode === null
20905+
) {
20906+
block.startMarker = root;
20907+
block.endMarker = root;
20908+
}
2089920909
}
2090020910
}
2090120911
scope.slots[0] = bag;

0 commit comments

Comments
 (0)