Skip to content

Commit c376083

Browse files
committed
fix(solid): a rejected fragment's fresh render claims what the server sent
Hydration never asks again for an answer the server sent. When a streamed <Loading> fragment rejects with no outcome (no <Errored> on the server could draw the failure: the one above it was already on the wire, or there is none), the client still renders the fragment fresh, so the graph under the boundary is created. Now every read in that render claims its serialized record instead of asking again: - a read the server resolved takes its value; - a read whose record is an error throws that error (as the server serialized it: redacted unless markSafeError) to the nearest client boundary through the normal path, or is an uncaught error when there is none; - only a read with no record at all computes (a truncated stream's refs are dropped from the registry). How: a rejection (the server's, or the stream cut short) now resumes the boundary with 0 rather than false, and resumeBoundaryHydration runs every fresh render as a served pass (`servedPass(set, adopt)`), adopting (`_hydratingValue`) only after a rejection. A superseded render and an asset failure do not adopt. servedPass resets its state in a `finally`, because an uncaught error leaves the flush by throwing. Recovery is a real input change or a client boundary's reset(), as for any hydrated failure (#4273). Changed expectations: async-memo-element-4242.spec.tsx, uncontained variants and their `-reference` twins (the generic "server render error at this position" path, so both change together; they still compare equal): - runs: [] for the jsx shape. `outer` adopts the server's error and never runs. (The loaded-mode check used to expect the client to compute the element: "jsx-41Count: 1".) The issue shape keeps ["inner"]. That run is the fixture's own: the dry run's continuation escapes the mock Promise through a real timer and builds the inner slot, whose memo has no owner id to adopt by. - halted: true, done: false (were false/true in loaded mode). The adopted error has no client boundary to reach (a <Loading> does not catch), so it is uncaught, as on any client render. The reactive system halts, and the halted resume never completes hydration. - text "", afterClick undefined (were "jsx-41Count: 1"/"Count: 1", and "nested-41"). The element came from the errored memo, so it never renders and there is no counter to click. - shown ["outer", ""] streamed, [""] loaded: the fallback, then nothing. client-hydration.spec.ts, "rejected _fr resumes without hydrating serialized children" -> "rejected _fr resumes fresh, adopting serialized children": memo() 0 -> 7. The fresh DOM stays, but the serialized 7 is the server's answer, so the client uses it rather than computing 0. client-recovery-record.spec.ts (three tests): b.memo() 0 -> 7, for the same reason. The recovery records are unchanged. New: served-error-no-reask.spec.tsx with two parity-harness scenarios. - nested-rejection-no-outcome: a shell <Errored> over a streamed outer <Loading> (a resolved read, a counter) and an inner <Loading> whose read fails on the server beside a read the server resolved. The inner fragment rejects with no outcome. The fresh render shows the server's error in the shell Errored, with 0 asks for either read. reset() asks once, and the recreated graph is live (the counter clicks). - served-error-reread: a served error mid-hydration (a slow boundary still pending) stands with no ask. reset() is a real retry: one ask, and it recovers while hydration still runs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 24cfaa3 commit c376083

9 files changed

Lines changed: 387 additions & 37 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"solid-js": patch
3+
---
4+
5+
Hydration never asks again for what the server sent, even when a streamed boundary's fragment rejects with no outcome (no `<Errored>` on the server could draw the failure). The client still renders that fragment fresh, so its graph is created, but every read in it now claims its serialized record: reads the server resolved take their values, and a read whose record is an error throws that error to the nearest client boundary, or is an uncaught error when there is none. Only reads with no record, such as those cut off by a truncated stream, compute. Recovery comes from a real input change or a boundary's `reset()`, as for any hydrated failure.

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

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,9 @@ export function syncThenable(value: any) {
588588
/**
589589
* A served pass: `write(x)` lands a served answer — the server's answer for a
590590
* node arriving (the async runtime writes it and flushes, synchronously),
591-
* or a rejected fragment's fresh render over the outcome the server drew
592-
* (the boundary's trigger) — and the flush round that carries it is
591+
* or a boundary's fresh render (its trigger; `adopt`: hydrating, so what it
592+
* creates adopts its server answer by id, claiming nothing) — and the
593+
* flush round that carries it is
593594
* hydration's own pass over served answers (`_claimOwner`, that round). A
594595
* node that adopted its own server answer re-runs there because the
595596
* server's answer for something it reads arrived, not because a client
@@ -599,12 +600,18 @@ export function syncThenable(value: any) {
599600
* the flush, where a node it reaches computes. Runs from a settled promise,
600601
* outside any claim window.
601602
*/
602-
const servedPass = (write: (x?: any) => void) => (x?: any) => {
603+
const servedPass = (write: (x?: any) => void, adopt?: boolean) => (x?: any) => {
603604
flush();
605+
_hydratingValue = adopt!;
604606
_claimOwner = ~clock;
605-
write(x);
606-
flush();
607-
_claimOwner = null;
607+
// An uncaught error (no client boundary for a served error) leaves the
608+
// flush by throwing: the pass still ends.
609+
try {
610+
write(x);
611+
flush();
612+
} finally {
613+
_claimOwner = _hydratingValue = null as any;
614+
}
608615
};
609616

610617
/**
@@ -2288,7 +2295,7 @@ function resumeBoundaryHydration(
22882295
id: string,
22892296
set: () => void,
22902297
release: () => boolean,
2291-
shouldHydrate = true
2298+
shouldHydrate: boolean | 0 = true
22922299
) {
22932300
// Read before release(): releasing removes the boundaryScopes entry.
22942301
const scope = sharedConfig.boundaryScopes?.get(id);
@@ -2316,11 +2323,15 @@ function resumeBoundaryHydration(
23162323
scope,
23172324
o
23182325
)
2319-
: // The client renders the boundary fresh (recover): no claim. Over the
2320-
// outcome the server drew for the failure (an `<Errored>` fallback the
2321-
// swap brought, listed in the reveal record, #4287) it is that
2322-
// failure's content run, as a hydrated `<Errored>`'s is: a served pass.
2323-
((globalThis as any)._$HY?.v?.[id]?.[0] ? servedPass(set) : set)();
2326+
: // The client renders the boundary fresh (recover): no claim, a served
2327+
// pass. After a rejection (0: the server's, or the stream cut short)
2328+
// the render adopts what the server sent by id, as a hydrated
2329+
// `<Errored>`'s content run does: the failing read's error included,
2330+
// thrown to the nearest client boundary — the outcome the server drew
2331+
// for it, if any (#4287), or an uncaught error — instead of asking
2332+
// again. What the server never sent (a truncated ref is dropped from
2333+
// the registry) computes.
2334+
servedPass(set, shouldHydrate === 0)();
23242335
flush();
23252336
checkHydrationComplete();
23262337
}
@@ -2336,7 +2347,7 @@ function resumeBoundaryHydration(
23362347
function recover(
23372348
id: string,
23382349
registeredAt: number,
2339-
resume: (shouldHydrate?: boolean) => void
2350+
resume: (shouldHydrate?: boolean | 0) => void
23402351
): void {
23412352
if (registeredAt < 0 || !OBSERVE!.records.observed("recovery")) {
23422353
resume(false);
@@ -2354,7 +2365,7 @@ function recover(
23542365
function initBoundaryResume(
23552366
o: Owner,
23562367
id: string
2357-
): [trigger: () => void, resume: (shouldHydrate?: boolean) => void, release: () => boolean] {
2368+
): [trigger: () => void, resume: (shouldHydrate?: boolean | 0) => void, release: () => boolean] {
23582369
_pendingBoundaries++;
23592370
(o as any)._hp = 1;
23602371
// Capture the current root's registry/gather pair for this boundary's
@@ -2714,17 +2725,17 @@ function fragmentAbort(id: string): Promise<never> {
27142725

27152726
function waitAndResume(
27162727
p: any,
2717-
resume: (shouldHydrate?: boolean) => void,
2728+
resume: (shouldHydrate?: boolean | 0) => void,
27182729
assetPromise?: Promise<void>,
2719-
hydrateRejected = true,
2730+
hydrateRejected: boolean | 0 = true,
27202731
abort?: Promise<never>
27212732
) {
27222733
// Settle data and assets independently: an asset error must not be written
27232734
// into the data ref's rejected state, and a data rejection must still keep
27242735
// its own hydrate semantics. (`p` may be an exotic thenable — coerce first.)
27252736
// An abort promise (fragment truncation) races the data: its rejection
27262737
// flows through the same rejected-state write as a server-sent rejection.
2727-
const data: Promise<boolean> = (
2738+
const data: Promise<boolean | 0> = (
27282739
abort ? Promise.race([Promise.resolve(p), abort]) : Promise.resolve(p)
27292740
).then(
27302741
() => {
@@ -2767,7 +2778,7 @@ function reportAssetFailure(err: any) {
27672778

27682779
function scheduleResumeAfterAssets(
27692780
id: string,
2770-
resume: (shouldHydrate?: boolean) => void,
2781+
resume: (shouldHydrate?: boolean | 0) => void,
27712782
assetPromise?: Promise<void>
27722783
): boolean {
27732784
sharedConfig.gather?.(id);
@@ -2954,7 +2965,7 @@ function hydratedCreateLoadingBoundary<T, U>(
29542965
// branch and `recover` with it.
29552966
waitAndResume(
29562967
1,
2957-
IS_OBSERVE ? () => recover(id, registeredAt, resume) : () => resume(false),
2968+
IS_OBSERVE ? () => recover(id, registeredAt, () => resume(0)) : () => resume(0),
29582969
assetPromise
29592970
);
29602971
return undefined;
@@ -2997,9 +3008,13 @@ function hydratedCreateLoadingBoundary<T, U>(
29973008
// (#4287) — beside the range the fresh render takes: clear
29983009
// them first.
29993010
(revealed || hy.v?.[id]?.forEach?.((n: ChildNode) => n.remove()),
3000-
IS_OBSERVE ? recover(id, registeredAt, resume) : resume(false)),
3011+
IS_OBSERVE
3012+
? recover(id, registeredAt, () => resume(shouldHydrate))
3013+
: resume(shouldHydrate)),
30013014
assetPromise,
3002-
false,
3015+
// A rejection (the server's, or the stream cut short) resumes with 0:
3016+
// the fresh render adopts what the server sent (resumeBoundaryHydration).
3017+
0,
30033018
fragmentAbort(id)
30043019
);
30053020
return revealed ? undefined : fallback();

‎packages/solid/test/client-hydration.spec.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4697,7 +4697,7 @@ describe("Loading boundary: fragment registration channel (_fr)", () => {
46974697
expect(memo()).toBe(99);
46984698
});
46994699

4700-
test("rejected _fr resumes without hydrating serialized children", async () => {
4700+
test("rejected _fr resumes fresh, adopting serialized children", async () => {
47014701
let rejectFr!: (e: any) => void;
47024702
const frPromise: any = new Promise<boolean>((_, rej) => (rejectFr = rej));
47034703
frPromise.s = 0;
@@ -4739,7 +4739,8 @@ describe("Loading boundary: fragment registration channel (_fr)", () => {
47394739
await new Promise<void>(r => setTimeout(r, 50));
47404740
flush();
47414741

4742-
expect(memo()).toBe(0);
4742+
// Fresh DOM, but the server's answer is used: hydration never refetches.
4743+
expect(memo()).toBe(7);
47434744
});
47444745

47454746
test("_fr with assets waits for both fragment and assets", async () => {

‎packages/solid/test/client-recovery-record.spec.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ describe.skipIf(OBSERVE === undefined)("recovery record", () => {
119119
rejectFr(new Error("stream error"));
120120
await new Promise<void>(r => setTimeout(r, 20));
121121
flush();
122-
// Fresh client DOM: the serialized 7 was never adopted.
123-
expect(b.memo()).toBe(0);
122+
// Fresh client DOM, the serialized 7 adopted: hydration never refetches.
123+
expect(b.memo()).toBe(7);
124124
expect(records).toEqual([{ id: "t0", at: T0, waitedMs: 30, renderMs: RENDER_MS }]);
125125
});
126126

@@ -133,7 +133,7 @@ describe.skipIf(OBSERVE === undefined)("recovery record", () => {
133133
const b = boundary();
134134
await new Promise<void>(r => setTimeout(r, 10));
135135
flush();
136-
expect(b.memo()).toBe(0);
136+
expect(b.memo()).toBe(7);
137137
// The rejection had already arrived when the boundary registered: the
138138
// clock did not move between registration and the recovery, so the
139139
// person saw no fallback — `waitedMs` is exactly 0.
@@ -163,7 +163,7 @@ describe.skipIf(OBSERVE === undefined)("recovery record", () => {
163163
const b = boundary();
164164
await new Promise<void>(r => setTimeout(r, 10));
165165
flush();
166-
expect(b.memo()).toBe(0);
166+
expect(b.memo()).toBe(7);
167167
// The runtime never read the clock: `registeredAt` is -1 with no listener.
168168
expect(performance.now).not.toHaveBeenCalled();
169169
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "nested-rejection-no-outcome",
3+
"shell": "<div _hk=1><!--$--><template id=\"pl-200\"></template><i _hk=2000>outer loading</i><!--pl-200--><!--/--><span>tail</span></div><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[\"200003_fr\"]=$R[3]=($R[4]=$R[2]()).p;_$HY.r[\"200_fr\"]=$R[5]=($R[6]=$R[2]()).p;_$HY.r[\"200003000\"]=$R[7]=($R[8]=$R[2]()).p;_$HY.r[\"200003001\"]=$R[9]=($R[10]=$R[2]()).p;</script>",
4+
"rest": "<template id=\"200\"><span _hk=200000>a</span><button _hk=200002 id=\"nested-rejection-count\">c0</button><template id=\"pl-200003\"></template><i _hk=2000030>inner loading</i><!--pl-200003--></template><script>($R[11]=(resolver, data) => {\n\tresolver.s(data);\n\tresolver.p.s = 1;\n\tresolver.p.v = data;\n})($R[1],\"a\");$df(\"200\");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);</script><script>$R[11]($R[6],!0);</script><script>$R[11]($R[8],\"b\");</script><template id=\"200003\" e></template><script>$df(\"200003\");($R[13]=(resolver, data) => {\n\tresolver.f(data);\n\tresolver.p.s = 2;\n\tresolver.p.v = data;\n})($R[10],$R[12]=new Error(\"no user 7\"));</script><script>$R[13]($R[4],$R[12]);</script>"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "served-error-reread",
3+
"shell": "<div _hk=2><!--$--><template id=\"pl-300\"></template><i _hk=3000>loading</i><!--pl-300--><!--/--><!--$--><template id=\"pl-5\"></template><i _hk=50>slow loading</i><!--pl-5--><!--/--></div><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[\"1\"]=$R[3]=($R[4]=$R[2]()).p;_$HY.r[\"5_fr\"]=$R[5]=($R[6]=$R[2]()).p;_$HY.r[\"300_fr\"]=$R[7]=($R[8]=$R[2]()).p;</script>",
4+
"rest": "<template id=\"300\" e><p _hk=40>failed: <!--$-->no user 7<!--/--></p></template><script>($R[10]=(resolver, data) => {\n\tresolver.f(data);\n\tresolver.p.s = 2;\n\tresolver.p.v = data;\n})($R[1],$R[9]=new Error(\"no user 7\"));_$HY.r[\"3\"]=$R[9];$df(\"300\");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);</script><script>$R[10]($R[8],$R[9]);</script><template id=\"5\"><b _hk=5000>slow</b></template><script>($R[11]=(resolver, data) => {\n\tresolver.s(data);\n\tresolver.p.s = 1;\n\tresolver.p.v = data;\n})($R[4],\"slow\");$df(\"5\");</script><script>$R[11]($R[6],!0);</script>"
5+
}

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

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,110 @@ function ServedSourceLanding() {
17341734
);
17351735
}
17361736

1737+
// ---------------------------------------------------------------------------
1738+
// Never refetch: a served error is the server's answer while hydration runs.
1739+
// A shell memo `user` fails on the server after the shell flushed; an
1740+
// <Errored> over a <Loading> reads it beside an unrelated signal `n`, and a
1741+
// slow second <Loading> keeps hydration open after the failure shows. On
1742+
// the client `user` resolves, so only a real ask recovers: the Errored's
1743+
// reset() is one, mid-hydration too. A write to `n` re-runs the reader.
1744+
let servedErrorAsks = 0;
1745+
export const servedErrorAskCount = () => servedErrorAsks;
1746+
export const servedErrorControl: { setN?: (v: number) => void; reset?: () => void } = {};
1747+
function ServedErrorReread() {
1748+
const [n, setN] = createSignal(0);
1749+
servedErrorControl.setN = setN;
1750+
const user = createMemo(async (): Promise<string> => {
1751+
if (!isServer && Promise === RealPromise) servedErrorAsks++;
1752+
await sleep(5);
1753+
if (isServer) throw new Error("no user 7");
1754+
return "u7";
1755+
});
1756+
const slow = createMemo(async () => {
1757+
await sleep(isServer ? 60 : 1);
1758+
return "slow";
1759+
});
1760+
return (
1761+
<div>
1762+
<Errored
1763+
fallback={(e: any, reset: () => void) => (
1764+
(servedErrorControl.reset = reset),
1765+
(<p>failed: {e().message}</p>)
1766+
)}
1767+
>
1768+
<Loading fallback={<i>loading</i>}>
1769+
<span>{n() + ":" + user()}</span>
1770+
</Loading>
1771+
</Errored>
1772+
<Loading fallback={<i>slow loading</i>}>
1773+
<b>{slow()}</b>
1774+
</Loading>
1775+
</div>
1776+
);
1777+
}
1778+
1779+
// An uncontained failure the server cannot draw: an <Errored> in the shell
1780+
// over a <Loading> that streamed its content (a resolved read `a`, a
1781+
// counter), with a nested <Loading> whose read `user` fails after that,
1782+
// beside a read `b` the server resolved. The Errored and the outer fragment
1783+
// are already on the wire, so the inner fragment rejects with no outcome.
1784+
// The client renders that fragment fresh, so its graph is created, but
1785+
// every read claims what the server sent: `b` its value, `user` its error,
1786+
// thrown to the nearest client boundary, the shell's Errored. No ask.
1787+
// reset() asks, and the recreated graph is live.
1788+
let nestedRejectionAsks = 0;
1789+
let nestedRejectionSiblingAsks = 0;
1790+
export const nestedRejectionAskCount = () => nestedRejectionAsks;
1791+
export const nestedRejectionSiblingAskCount = () => nestedRejectionSiblingAsks;
1792+
export const nestedRejectionControl: { reset?: () => void } = {};
1793+
function NestedRejectionUser() {
1794+
const b = createMemo(async (): Promise<string> => {
1795+
if (!isServer && Promise === RealPromise) nestedRejectionSiblingAsks++;
1796+
await sleep(10);
1797+
return "b";
1798+
});
1799+
const user = createMemo(async (): Promise<string> => {
1800+
if (!isServer && Promise === RealPromise) nestedRejectionAsks++;
1801+
await sleep(20);
1802+
if (isServer) throw new Error("no user 7");
1803+
return "u7";
1804+
});
1805+
return (
1806+
<b>
1807+
{b()}
1808+
{user()}
1809+
</b>
1810+
);
1811+
}
1812+
function NestedRejection() {
1813+
const a = createMemo(async () => {
1814+
await sleep(5);
1815+
return "a";
1816+
});
1817+
const [count, setCount] = createSignal(0);
1818+
return (
1819+
<div>
1820+
<Errored
1821+
fallback={(e: any, reset: () => void) => (
1822+
(nestedRejectionControl.reset = reset),
1823+
(<p>failed: {e().message}</p>)
1824+
)}
1825+
>
1826+
<Loading fallback={<i>outer loading</i>}>
1827+
<span>{a()}</span>
1828+
<button id="nested-rejection-count" onClick={() => setCount(c => c + 1)}>
1829+
{"c" + count()}
1830+
</button>
1831+
<Loading fallback={<i>inner loading</i>}>
1832+
<NestedRejectionUser />
1833+
</Loading>
1834+
</Loading>
1835+
</Errored>
1836+
<span>tail</span>
1837+
</div>
1838+
);
1839+
}
1840+
17371841
// ---------------------------------------------------------------------------
17381842
// #3414: a sync throw the SERVER catches, with a zero-arg fallback thunk
17391843
// (`fallback={() => <Fallback />}`), inside an enclosing boundary. Errored
@@ -3110,6 +3214,20 @@ export const scenarios: Scenario[] = [
31103214
expectedTextAfterUpdate: "user:u8tail",
31113215
stableSelector: "div"
31123216
},
3217+
{
3218+
name: "served-error-reread",
3219+
App: ServedErrorReread,
3220+
async: true,
3221+
expectedText: "failed: no user 7slow",
3222+
serverText: "loading slow loading failed: no user 7 slow"
3223+
},
3224+
{
3225+
name: "nested-rejection-no-outcome",
3226+
App: NestedRejection,
3227+
async: true,
3228+
expectedText: "failed: no user 7tail",
3229+
serverText: "outer loading tail a c0 inner loading"
3230+
},
31133231
{
31143232
name: "served-source-landing",
31153233
App: ServedSourceLanding,

0 commit comments

Comments
 (0)