Skip to content

Commit 91aa3f5

Browse files
committed
fix(hydration): record stale innerHTML on undo list and use keepsServerValue in htextSwap structural arm
- setHTML: call hydration.save(el) before the stale-capture path falls through to the general innerHTML write, so a speculative attempt that rolls back restores the original server content instead of leaving the client HTML in place. - htextSwap: replace isHydrationSuppressed(host) with this.keepsServerValue(host) in the structural (no-text-node) arm, so a suppressed host under stale captures installs the client text instead of an empty tracking node that a same-value update would never patch.
1 parent af7724c commit 91aa3f5

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21504,13 +21504,13 @@ class HydrationCapability {
2150421504
return posNode as Text;
2150521505
}
2150621506
const host = (STAGED_DOM?.view(posNode) ?? posNode)?.parentNode ?? null;
21507-
const suppressed = isHydrationSuppressed(host);
21507+
const keeps = this.keepsServerValue(host);
2150821508
// A non-empty client text binding where the server has no text node is a
2150921509
// structural mismatch, just like an extra client element. Build the client
2151021510
// text so recovery succeeds, but publish the normal dev diagnostic. A
2151121511
// suppressed host keeps the absent server value by installing only an empty
2151221512
// tracking node; later real commits can update that node normally.
21513-
if (text !== '' && !suppressed) {
21513+
if (text !== '' && !keeps) {
2151421514
if (host !== null) this.save(host);
2151521515
noteRecoverableHydrationError(() => new Error(formatClientError(54)));
2151621516
if (process.env.NODE_ENV !== 'production') {
@@ -21521,7 +21521,7 @@ class HydrationCapability {
2152121521
);
2152221522
}
2152321523
}
21524-
const created = (STAGED_DOM?.view(document) ?? document).createTextNode(suppressed ? '' : text);
21524+
const created = (STAGED_DOM?.view(document) ?? document).createTextNode(keeps ? '' : text);
2152521525
if (posNode !== null && (STAGED_DOM?.view(posNode) ?? posNode).parentNode !== null) {
2152621526
domNode((STAGED_DOM?.view(posNode) ?? posNode).parentNode!).insertBefore(created, posNode);
2152721527
}
@@ -24117,7 +24117,7 @@ export function setHTML(el: Element, value: any): void {
2411724117
}
2411824118
// React keeps the server's HTML on a mismatch. Server HTML that predates
2411924119
// the client's state (staleServerValues) is not worth keeping: write the
24120-
// client's below.
24120+
// client's below, after recording the parent so rollback can restore it.
2412124121
if (!hydration.staleServerValues) {
2412224122
if (process.env.NODE_ENV !== 'production' && !hydration.keepsServerValue(el))
2412324123
warnHydrationKeptServerValue(
@@ -24128,6 +24128,7 @@ export function setHTML(el: Element, value: any): void {
2412824128
);
2412924129
return;
2413024130
}
24131+
hydration.save(el);
2413124132
}
2413224133
if (el.localName === 'script') {
2413324134
setScriptText(el, next);

0 commit comments

Comments
 (0)