Skip to content

Commit 9ffe9fa

Browse files
committed
fix(hydration): guard speculative save() rollback against detached arm bounds
The speculative save() undo closure called restoreRootRange unconditionally. If removeHydrationRange detached the arm's end marker before rollback, the restore walk would never find the detached end, stripping all later siblings, and restoreRootNodes would throw NotFoundError from insertBefore. Add the same parentNode guard that journalRootRange already uses: skip the restore when before or after is no longer a child of parent.
1 parent 85f67f3 commit 9ffe9fa

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18729,7 +18729,14 @@ class HydrationCapability {
1872918729
const before = ranged ? arm.startMarker : null;
1873018730
const after = ranged ? arm.endMarker : null;
1873118731
const nodes = collectRootRange(parent, before, after);
18732-
(this.undo ??= []).push(() => restoreRootRange(parent, before, after, nodes));
18732+
(this.undo ??= []).push(() => {
18733+
if (
18734+
(before !== null && (STAGED_DOM?.view(before) ?? before).parentNode !== parent) ||
18735+
(after !== null && (STAGED_DOM?.view(after) ?? after).parentNode !== parent)
18736+
)
18737+
return;
18738+
restoreRootRange(parent, before, after, nodes);
18739+
});
1873318740
}
1873418741

1873518742
/**

0 commit comments

Comments
 (0)