Skip to content

Commit f354324

Browse files
ryansolidClaude via Cursorcursoragent
committed
fix(web/frames): report a rejected server <Loading> fragment inside an adopted frame in dev; the client shows the server's outcome (C12 c, client half)
Frames-rulings 3.3 under A0's corollary 4 (inward): a server `<Loading>` inside a server component is the SERVER's boundary; its outcome arrives as markup and the client shows whatever the server rendered for it — never a blank it invents, never a client error fallback for a server state. A rejected one has no client twin to surface its `<key>_fr` rejection (`hydratedCreateLoadingBoundary`'s `s === 2` arm runs only for a boundary registered against it), so the adoption that claims its placeholder observes the rejection and names it in dev (0 B prod). The blank the position shows today is the server half's gap: `server.ts`'s error path hands `sink.fragment` a `" "` template (the client twin, when there is one, renders over it; a server component's boundary has none). Pins: C12 (c) re-pinned per 3.3 — (c1) the rejection is reported in dev, the client invents no error state (test); (c2) the position shows the server's rendered outcome, never a blank (test.fails, the server half). Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent b4880fc commit f354324

3 files changed

Lines changed: 77 additions & 20 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
frames (dev): a server `<Loading>` fragment inside an adopted server component that rejects on the server is reported — the client shows what the server rendered for that outcome and invents no error state of its own (contract C12 c, client half).

‎packages/web/frames/src/client.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,35 @@ function adoptBoundary(
12791279
// be held, not landed in a range nobody owns.
12801280
const claimedFragments = new Set<string>();
12811281
const claimRegionFragments = (root: ParentNode) => {
1282-
const fr = (globalThis as any)._$HY?.fr;
1282+
const hy = (globalThis as any)._$HY;
1283+
const fr = hy?.fr;
12831284
if (!fr || !fr.claim) return;
12841285
root.querySelectorAll('template[id^="pl-"]').forEach(tpl => {
12851286
const fragId = tpl.id.slice(3);
12861287
if (claimedFragments.has(fragId)) return;
12871288
claimedFragments.add(fragId);
12881289
fr.claim(fragId);
1290+
// A server `<Loading>` inside a server component is the SERVER's
1291+
// boundary (A0, corollary 4 — inward): its outcome arrives as markup,
1292+
// and the client shows whatever the server rendered for it — never a
1293+
// client-invented error state. A rejected one has no client twin to
1294+
// surface its `<key>_fr` rejection (hydratedCreateLoadingBoundary's
1295+
// `s === 2` arm runs only for a boundary registered against it), so
1296+
// dev names it here; the server's error path writes a BLANK template
1297+
// for it today (web/src/server.ts, the `done` closure's `" "`), which
1298+
// is the server half's gap, not a client state to invent.
1299+
if (IS_DEV) {
1300+
const ref = hy.r && hy.r[fragId + "_fr"];
1301+
ref &&
1302+
typeof ref.then === "function" &&
1303+
ref.then(undefined, (error: unknown) =>
1304+
console.error(
1305+
`Server <Loading> fragment "${fragId}" inside server component "${id}" rejected on ` +
1306+
`the server; the frame shows what the server rendered for that outcome.`,
1307+
error
1308+
)
1309+
);
1310+
}
12891311
});
12901312
};
12911313
const drainRecords = () => {

‎packages/web/test/consistency/c12-boundary-parity.spec.tsx‎

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,46 @@ describe("C12 — boundary parity at claim", () => {
139139
// writes a blank content template (`sink.fragment(key, " ")`), activates
140140
// it (`$df`), and rejects `<key>_fr` (web/src/server.ts, the `done`
141141
// closure). The shell at that position is the fallback; the delivery is
142-
// an error. The invariant: the position shows the error fallback — fresh
143-
// client DOM — and never silently empties.
142+
// an error. Re-read under A0 (frames-rulings 3.3, corollary 4 inward):
143+
// the server `<Loading>` inside the frame is the SERVER's boundary, and
144+
// the client shows whatever the server rendered for its outcome — never
145+
// a blank, never a client-invented error fallback. Two halves: the
146+
// client reports the rejection in dev (c1, green); the position shows
147+
// the server's rendered outcome (c2) — red until the server half renders
148+
// the error outcome into the fragment instead of a blank (the fix is
149+
// `server.ts`'s, not a client state).
150+
test("(c1) rejected after adopt: the rejection is reported in dev; the client invents no error state", async () => {
151+
const fid = freshFid("c12c1");
152+
const frag = "c12c1-frag";
153+
page = bootPage(shell(fid, frag));
154+
const fetches = countFetches();
155+
const fr = page.declareFragment(frag);
156+
const Comp = (globalThis as any)._$SC.r(fid);
157+
const dispose = hydrate(
158+
() => <Comp item={(p: { text: string }) => <li>{p.text}</li>} />,
159+
page.container
160+
);
161+
await quiesce();
162+
const swapped = page.revealFragment(frag, " ", false);
163+
fr.reject(new Error("boom"));
164+
await quiesce();
165+
await quiesce();
166+
expect(swapped).toBe(1);
167+
expect(fr.promise.s).toBe(2);
168+
expect(page.hy.fr.pending()).toBe(false);
169+
expect(fetches).toEqual([]);
170+
// Reported, once, naming the fragment and the frame.
171+
expect(page.errors.length).toBe(1);
172+
expect(page.errors[0]).toContain(`fragment "${frag}"`);
173+
expect(page.errors[0]).toContain(fid);
174+
expect(page.warnings).toEqual([]);
175+
// No client error state at the position: what the server wrote stands.
176+
expect(page.container.querySelector("li")).toBeNull();
177+
dispose();
178+
});
179+
144180
test.fails(
145-
"(c) rejected after adopt: the position shows an error fallback, not a silent blank; the rejection is surfaced",
181+
"(c2) rejected after adopt: the position shows the server's rendered outcome, never a blank (server half)",
146182
async () => {
147183
const fid = freshFid("c12c");
148184
const frag = "c12c-frag";
@@ -169,23 +205,17 @@ describe("C12 — boundary parity at claim", () => {
169205
expect(fr.promise.s).toBe(2);
170206
expect(page.hy.fr.pending()).toBe(false);
171207
expect(fetches).toEqual([]);
172-
// Observed on next: the swap lands the blank template — the frame's
173-
// text goes "loading" → " " (the fallback is gone, the position is
174-
// empty), `fr.pending()` reads false, and NOTHING is logged: no
175-
// console.error, no warning, no diagnostics. Expected: an error
176-
// fallback at the position (fresh client DOM) and the rejection
177-
// surfaced. Where it goes wrong: the server `<Loading>` has no client
178-
// twin — solid/hydration.ts `hydratedCreateLoadingBoundary`'s `s === 2`
179-
// branch (resume fresh, error to the nearest <Errored>) only runs for
180-
// a boundary that registered against `<key>_fr`, and the adoption's
181-
// `claimRegionFragments` (client.ts adoptBoundary) only claims the
182-
// placeholder so the swap may proceed. The ledger's `fragmentPolicy`
183-
// then swaps whatever template the document wrote — here the blank —
184-
// and the `_fr` rejection has no consumer: `serovalPromise` (and the
185-
// real serializer's thenable) swallow it. The page converges on an
186-
// empty range with no record of the failure anywhere.
208+
// Observed: the swap lands the blank template the server wrote — the
209+
// frame's text goes "loading" → " " (the fallback is gone, the
210+
// position is empty). Expected: the server's rendered outcome for the
211+
// failure at the position — the nearest server `<Errored>`'s
212+
// fallback; with none, the error escapes the server component and
213+
// the whole response is the frame's `:error`. The gap is the server
214+
// half's: `server.ts`'s error path hands `sink.fragment` a `" "`
215+
// template (the client twin, when there is one, renders over it; a
216+
// server component's boundary has none). The client correctly
217+
// invents nothing here (see c1).
187218
expect(page.container.textContent.trim()).not.toBe("");
188-
expect(page.errors.length + page.warnings.length).toBeGreaterThan(0);
189219
frames.stop();
190220
dispose();
191221
}

0 commit comments

Comments
 (0)