Skip to content

Commit f16aa73

Browse files
committed
fix(solid): a rejected fragment's clear gives an emptied region its text node back (#4372)
Moves the #4372 fix off `insertExpression`'s hot text path, which every app ships, to the cold path that breaks its assumption. A streamed Loading whose fallback an insert claimed as its sole text child: the fragment's swap takes that text node with the placeholder range, and the rejected fragment's fresh render clears what the swap put in, leaving the region empty. The next text value (an outer Errored's fallback, or text the content renders fresh) was then written to a missing first child. The clear now leaves an emptied region an empty text node, which that write fills. The insert fast path is back as it was on next; the hand-removal spec is pinned as a known failure. Adds the `text` shape: an empty rejected template under no Errored, the same crash on next. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent acb1955 commit f16aa73

8 files changed

Lines changed: 54 additions & 17 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"@solidjs/web": patch
2+
"solid-js": patch
33
---
44

5-
Hydration no longer crashes when a streamed `<Loading>` fragment rejects with an error that an `<Errored>` outside it catches, once the client has started hydrating before the fragment arrives. The swap took the claimed fallback's text, and a sole text child's update wrote to a node that was no longer there (`Cannot set properties of null (setting 'data')`, then `REACTIVITY_HALTED`). With no node left, the new text is inserted like a first one, so the page shows the server's error without asking again (#4372).
5+
Hydration no longer crashes when a streamed `<Loading>` fragment rejects after the client started hydrating and the region it stood in holds only text: an error an `<Errored>` outside it catches, or text content the client renders fresh. The swap took the claimed fallback's text node, and clearing the rejected fragment emptied the region, so the next text write found no node (`Cannot set properties of null (setting 'data')`, then `REACTIVITY_HALTED`). A region left empty by the clear now gets its text node back, so the page shows the outcome without asking again (#4372).

‎packages/solid/src/client/hydration.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3027,6 +3027,9 @@ function hydratedCreateLoadingBoundary<T, U>(
30273027
// the content is in the DOM, so render nothing until the resume
30283028
// adopts it.
30293029
const revealed = hy.v?.[id];
3030+
// The region the claimed fallback stands in, read before a swap takes
3031+
// the placeholder range.
3032+
const region = revealed ? null : document.getElementById("pl-" + id)?.parentNode;
30303033
waitAndResume(
30313034
fr,
30323035
shouldHydrate =>
@@ -3045,8 +3048,12 @@ function hydratedCreateLoadingBoundary<T, U>(
30453048
// claimed fallback left its nodes — the server's outcome for
30463049
// the failure, which `$dfr` lists in the reveal record
30473050
// (#4287) — beside the range the fresh render takes: clear
3048-
// them first.
3051+
// them first. The swap took the claimed fallback with its
3052+
// range, so a region left empty gets back an empty text node:
3053+
// an insert that claimed a text fallback as its sole child
3054+
// writes its next text there (#4372).
30493055
(revealed || hy.v?.[id]?.forEach?.((n: ChildNode) => n.remove()),
3056+
region && !region.firstChild && region.append(""),
30503057
IS_OBSERVE
30513058
? recover(id, registeredAt, () => resume(shouldHydrate))
30523059
: resume(shouldHydrate)),

‎packages/web/src/client.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,11 +3104,7 @@ function insertExpression(parent, value, current, marker) {
31043104

31053105
if (t === "string" || t === "number") {
31063106
const tc = typeof current;
3107-
// A sole text child is the raw primitive — unless the document moved it
3108-
// since: a streamed fragment's swap replaces a claimed fallback's text,
3109-
// and a rejected fragment's fresh render clears what the swap put in
3110-
// (#4372). With no node left, the value is inserted like a first one.
3111-
if ((tc === "string" || tc === "number") && parent.firstChild) {
3107+
if (tc === "string" || tc === "number") {
31123108
parent.firstChild.data = value;
31133109
} else {
31143110
if (ownsAllChildren(parent, current)) parent.textContent = value;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "errored-outside-loading-4372-text",
3+
"shell": "<main _hk=1><template id=\"pl-2\"></template>[LOAD]<!--pl-2--></main><script>(self.$R=self.$R||{})[\"\"]=[];_$HY.r[\"0\"]=$R[0]=($R[1]=($R[2]=() => {\n\tconst resolver = {\n\t\tp: 0,\n\t\ts: 0,\n\t\tf: 0\n\t};\n\tresolver.p = new Promise((resolve, reject) => {\n\t\tresolver.s = resolve;\n\t\tresolver.f = reject;\n\t});\n\treturn resolver;\n})()).p;_$HY.r[\"2_fr\"]=$R[3]=($R[4]=$R[2]()).p;</script>",
4+
"rest": "<template id=\"2\" e></template><script>$df(\"2\");function $df(e){return _$HY.f?_$HY.f(e):$dfr(e)}function $dfr(e,n,o,t){if(!(n=document.getElementById(e)))return 0;if(!(o=document.getElementById(\"pl-\"+e)))return(_$HY.dq=_$HY.dq||{})[e]=1,0;for(;o&&(8!==o.nodeType||o.nodeValue!==\"pl-\"+e);)t=o.nextSibling,o.remove(),o=t;t=o.parentNode,(_$HY.v=_$HY.v||{})[e]=n.hasAttribute(\"e\")?[...n.content.childNodes]:1,o.replaceWith(n.content),n.remove(),_$HY.fe(e,t),_$HY.hp&&_$HY.hp[e]&&($dh(_$HY.hp[e]),delete _$HY.hp[e]),$dfd();return 1}function $dfl(e,o,n){if(!(o=document.getElementById(\"pl-\"+e)))return(_$HY.dlq=_$HY.dlq||{})[e]=1,0;if(o._$fl)return 1;for(n=o.nextSibling;n;){if(8===n.nodeType&&n.nodeValue===\"pl-\"+e){o.parentNode&&o.parentNode.insertBefore(o.content.cloneNode(!0),n),o._$fl=1,$dfd();return 1}n=n.nextSibling}return 0}function $dflj(e,i){for(i=0;i<e.length;i++)$dfl(e[i])}function $dfd(e,i){if(e=_$HY.dq){_$HY.dq=0;for(i in e)$df(i)}if(e=_$HY.dlq){_$HY.dlq=0;for(i in e)$dfl(i)}}function $dfs(e,c,d){(_$HY.sc=_$HY.sc||{})[e]=c,d&&((_$HY.sd=_$HY.sd||{})[e]=1)}function $dfg(e,g,i,k){if(!(g=_$HY.sg&&_$HY.sg[e]))return;for(i=0;i<g.length;i++)if(_$HY.sc&&_$HY.sc[g[i]]>0)return;for(i=0;i<g.length;i++)k=g[i],delete _$HY.sg[k],$df(k)}function $dfc(e){if(--_$HY.sc[e]<=0){delete _$HY.sc[e],_$HY.sg&&_$HY.sg[e]?$dfg(e):!(_$HY.sd&&_$HY.sd[e])&&$df(e);_$HY.sd&&delete _$HY.sd[e]}}function $dfj(e,i,n){for(i=0;i<e.length;i++)if(_$HY.sc&&_$HY.sc[e[i]]>0){for(n=0;n<e.length;n++)(_$HY.sg=_$HY.sg||{})[e[n]]=e;return}for(i=0;i<e.length;i++)$df(e[i])}function $dfe(e,t,k){(t=e.target)&&t.getAttribute&&!t._$dc&&(k=t.getAttribute(\"data-dfc\"))&&(t._$dc=1,$dfc(k))}document.addEventListener(\"load\",$dfe,!0);document.addEventListener(\"error\",$dfe,!0);($R[5]=(resolver, data) => {\n\tresolver.s(data);\n\tresolver.p.s = 1;\n\tresolver.p.v = data;\n})($R[1],\"a\");</script><script>($R[7]=(resolver, data) => {\n\tresolver.f(data);\n\tresolver.p.s = 2;\n\tresolver.p.v = data;\n})($R[4],$R[6]=new Error(\"server render\"));</script>"
5+
}

‎packages/web/test/harness/scenarios.tsx‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,8 +3203,10 @@ export const setLazyErroredKey = (shape: LazyErroredShape, v: string) =>
32033203
// in the component around the boundaries (the issue's repro); `inner`: in a
32043204
// component under the Loading; `sibling`: the Errored beside other content;
32053205
// `element`: an element fallback. Hydrated from the shell, the client claims
3206-
// the streamed error and never asks again.
3207-
export const erroredOutsideLoadingShapes = ["app", "inner", "sibling", "element"] as const;
3206+
// the streamed error and never asks again. `text` (no Errored): the content
3207+
// is text whose server render throws after its async read, so the fragment
3208+
// rejects empty and the client renders the text fresh from the adopted value.
3209+
export const erroredOutsideLoadingShapes = ["app", "inner", "sibling", "element", "text"] as const;
32083210
export type ErroredOutsideLoadingShape = (typeof erroredOutsideLoadingShapes)[number];
32093211
let erroredOutsideLoadingAsks = 0;
32103212
export const erroredOutsideLoadingAskCount = () => erroredOutsideLoadingAsks;
@@ -3220,6 +3222,24 @@ export function erroredOutsideLoading(shape: ErroredOutsideLoadingShape) {
32203222
return <span>{m()}</span>;
32213223
};
32223224
return function ErroredOutsideLoading() {
3225+
if (shape === "text") {
3226+
const a = createMemo(async () => {
3227+
if (!isServer && Promise === RealPromise) erroredOutsideLoadingAsks++;
3228+
await sleep(10);
3229+
return "a";
3230+
});
3231+
return (
3232+
<main>
3233+
<Loading fallback="[LOAD]">
3234+
{(() => {
3235+
const v = a();
3236+
if (isServer) throw new Error("server render");
3237+
return "!" + v;
3238+
})()}
3239+
</Loading>
3240+
</main>
3241+
);
3242+
}
32233243
const m = shape === "inner" ? null : ask();
32243244
const content = () => (m ? <span>{m()}</span> : <Inner />);
32253245
if (shape === "element")

‎packages/web/test/hydration/errored-outside-loading-4372.spec.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ async function run(shape: ErroredOutsideLoadingShape, mode: "loaded" | "streamed
8181
}
8282
}
8383
expect(container.querySelector("main")).toBe(main);
84-
expect(main.textContent).toBe(shape === "sibling" ? "[ERR]tail" : "[ERR]");
84+
expect(main.textContent).toBe(
85+
shape === "sibling" ? "[ERR]tail" : shape === "text" ? "!a" : "[ERR]"
86+
);
87+
// One node for the outcome: nothing of the swap or the clear is left
88+
// beside it.
89+
if (shape !== "sibling") expect(main.childNodes.length).toBe(1);
8590
expect(sharedConfig.isHydrationInProgress!()).toBe(false);
8691
// The client claimed the server's error: it never asked again.
8792
expect(erroredOutsideLoadingAskCount()).toBe(asksBefore);

‎packages/web/test/insert-sole-text-removed-4372.spec.tsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import { expect, test } from "vitest";
66
import { createSignal, createRoot, flush } from "solid-js";
77

88
// #4372: a sole text child is updated with a `.data` write on the parent's
9-
// first child. When the document removed that node since (a streamed
10-
// fragment's swap took the claimed fallback's text, and a rejected
11-
// fragment's fresh render cleared what the swap put in), the next text value
12-
// is inserted like a first one instead of writing to a missing node.
13-
test("a sole text child removed from the document: the next text value is inserted", () => {
9+
// first child — the hot text path every app ships, which trusts that the node
10+
// is still there. Only a streamed fragment's swap removed it from under
11+
// Solid (the swap takes the claimed fallback's text, a rejected fragment's
12+
// fresh render clears what the swap put in); that cold path now leaves the
13+
// region its text node back (solid's hydration, #4372), and the fast path
14+
// stays as it is. Code outside Solid removing the node (here by hand) still
15+
// breaks the next write: pinned as a known failure, not a contract.
16+
test.fails("a sole text child removed by hand: the next text write has no node", () => {
1417
const [text, setText] = createSignal("a");
1518
let div!: HTMLDivElement;
1619
const dispose = createRoot(d => {

‎packages/web/test/server/hydration-harness.spec.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ describe("hydration parity harness — Errored outside a failing streamed Loadin
113113
// Shell: the Loading's fallback; the fragment: the Errored's fallback,
114114
// marked as a rejected fragment.
115115
expect(shell).toContain("[LOAD]");
116-
expect(rest).toMatch(/<template id="[^"]+" e>(<p[^>]*>)?\[ERR\]/);
116+
if (shape === "text") expect(rest).toMatch(/<template id="[^"]+" e><\/template>/);
117+
else expect(rest).toMatch(/<template id="[^"]+" e>(<p[^>]*>)?\[ERR\]/);
117118
});
118119
}
119120
});

0 commit comments

Comments
 (0)