Skip to content

Commit b4880fc

Browse files
ryansolidClaude via Cursorcursoragent
committed
fix(web/frames): the address is an async source — one landing per bound address, one response per store (S-flush)
A0 (SCs are rendered data): a frame is one async value outward. The mount's covering <Loading> now pends on the bound address's FIRST FLUSH — content or error — through `FrameHost.landing(address)`, read per bound address through a fresh node (frames-rulings 1.5, 1.6 (i)): a switch is a new question on the source, the superseded address's late writes release nothing, an unrevealed boundary stays on its fallback and a revealed one holds. The two hand-rolled shell gates (`boundaryComponent`'s arm/release/settle/setGate and `adoptBoundary`'s twin), `followAddress`'s re-arm and frameless waiter, and `onApply`-as-release go. An unstaged response announces itself to the host at its header (`start`), so the address reads "in flight" from the header to the landing. The store is one response's (1.4 full; 2.1/2.2): a version bump or rebind replaces the store wholesale — root, segments, slot records, the error — so a byte-identical root under a new version still applies as the new version's (C7 c), a held record leaves with the response that carried it (C6 a1, b2), and `argsEquivalent`/`clearStreamRecords` delete; the mount's `#slotArgs` value compare is what preserves occurrence state. The host keeps the latest landed version as `shown` so a mount opened mid-flight seeds the committed value (holds-latest) and the landing fans out as the version's whole set. The occurrence's name decides its class: a called occurrence (`prop#n`) found without its record waits for it — never evaluated argless (C18 ×3 flip; the #2968 poll stays as the document face's re-sync trigger, scoped to called occurrences) — and a bare occurrence is direct-insert. A reveal is an apply (2.3, interim): the document face's reveal cascade syncs the adopting frame, so a direct-insert range the fragment carried mounts (C2 b) and a record drained before its range was shown takes effect at the reveal (C4 d). Pins flipped to `test`: C2 (b), C4 (d), C6 (a1, b2), C7 (c), C17 (a — re-pinned: B's first flush, not its `start`, releases), C17 (c), harness C2 ×1, C18 ×3. Re-pinned: frames-binding-slots "orphan record … waits" (was "still mounts"), frames-hn-client zero-data occurrence is the bare prop. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 49a8dca commit b4880fc

12 files changed

Lines changed: 653 additions & 745 deletions
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: the address is an async source (S-flush) — a mount's covering `<Loading>` pends on the bound address's first flush through `FrameHost.landing(address)` (content or error), per bound address, so a switch is a new question and the superseded address's late writes release nothing (contract C17 a, c); the store is one response's — a version bump or rebind replaces it wholesale, root included (C6 a1, b2; C7 c); a called occurrence (`prop#n`) found without its record waits for it instead of being evaluated argless (C18); the document face's reveal cascade syncs the adopting frame — a reveal is an apply (C2 b, C4 d).

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

Lines changed: 107 additions & 185 deletions
Large diffs are not rendered by default.

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

Lines changed: 170 additions & 151 deletions
Large diffs are not rendered by default.

‎packages/web/frames/src/frame-transport.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,19 @@ export function createServerComponentHandler({
796796
if (connections.get(address) === connection) connections.delete(address);
797797
});
798798
};
799+
/**
800+
* An unstaged response has begun for an address — at its header, before
801+
* its body is read. The integration rotates its response-scoped state,
802+
* and the address's store moves to the response's version NOW: the
803+
* address is a source (`host.landing`), and from here until the body's
804+
* first flush it reads "in flight" — a mount opened in between pends on
805+
* that landing instead of materializing the superseded one. The body's
806+
* own `start` chunk then writes the same version and nothing.
807+
*/
808+
const begin = (address, version, response) => {
809+
if (onStream) onStream(address, version, response);
810+
host.apply({ type: "start", id: address, version });
811+
};
799812
return {
800813
intercept:
801814
intercept &&
@@ -867,7 +880,7 @@ export function createServerComponentHandler({
867880
return binding;
868881
}
869882
const version = bump(address);
870-
if (onStream) onStream(address, version, response);
883+
begin(address, version, response);
871884
// The end is judged by the loop from `connection.ended` (set
872885
// synchronously by applyFrames); a rejected read is a death it
873886
// already sees, not an error record — the loop decides what the
@@ -895,7 +908,7 @@ export function createServerComponentHandler({
895908
// behind a completed body.
896909
const entry = host.get(address) ? stage(address, binding, version, response) : undefined;
897910
if (entry) entry.stream(address, version);
898-
else if (onStream) onStream(address, version, response);
911+
else begin(address, version, response);
899912
const target = entry || host;
900913
const applied = applyFrameResponse(response, target, { as: address, version }).catch(err =>
901914
target.apply({

‎packages/web/test/consistency/c02-revealed-occurrence-mounts.spec.tsx‎

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -231,54 +231,54 @@ describe("C2 — no inert server content", () => {
231231
);
232232

233233
// Arm (b): a direct-insert occurrence (`children`) is recordless by design.
234-
// Revealed into the adopted region, it must mount all the same.
235-
test.fails(
236-
"(b) direct-insert `children` occurrence revealed after adoption: mounted and live",
237-
async () => {
238-
const fid = freshFid("c2b");
239-
const frag = "c2b";
240-
page = bootPage(pendingShell(fid, frag));
241-
page.declareFragment(frag);
242-
const Comp = (globalThis as any)._$SC.r(fid);
243-
const [tick, setTick] = createSignal(0);
244-
const dispose = hydrate(
245-
() => (
246-
<Comp>
247-
<b>{tick()}</b>
248-
</Comp>
249-
),
250-
page.container
251-
);
252-
await quiesce();
253-
expect(page.container.textContent).toBe("loading");
234+
// Revealed into the adopted region, it must mount all the same. Was red
235+
// on `next` (the reveal applied nothing, so no sync ran over the revealed
236+
// range); green under frames-rulings 2.3 — a reveal is an apply: the
237+
// document face's reveal cascade syncs the adopting frame.
238+
test("(b) direct-insert `children` occurrence revealed after adoption: mounted and live", async () => {
239+
const fid = freshFid("c2b");
240+
const frag = "c2b";
241+
page = bootPage(pendingShell(fid, frag));
242+
page.declareFragment(frag);
243+
const Comp = (globalThis as any)._$SC.r(fid);
244+
const [tick, setTick] = createSignal(0);
245+
const dispose = hydrate(
246+
() => (
247+
<Comp>
248+
<b>{tick()}</b>
249+
</Comp>
250+
),
251+
page.container
252+
);
253+
await quiesce();
254+
expect(page.container.textContent).toBe("loading");
254255

255-
page.revealFragment(frag, slotRange("children", liveChildrenHtml(fid)));
256-
await quiesce();
257-
await quiesce();
258-
const b = page.container.querySelector("b")!;
259-
expect(b).not.toBeNull();
260-
expect(page.container.textContent).toBe("0");
256+
page.revealFragment(frag, slotRange("children", liveChildrenHtml(fid)));
257+
await quiesce();
258+
await quiesce();
259+
const b = page.container.querySelector("b")!;
260+
expect(b).not.toBeNull();
261+
expect(page.container.textContent).toBe("0");
261262

262-
setTick(1);
263-
flush();
264-
// Observed on next: the revealed <b> shows "0" after the bump (the
265-
// client `children` JSX was never evaluated); no warning, no error.
266-
// Expected: "1" — the occurrence mounted and its hole is live. Where
267-
// it goes wrong: client.ts adoptBoundary's `fr.subscribe` callback is
268-
// the only reaction to a reveal, and it does two things — claim nested
269-
// `pl-*` placeholders and `drainRecords()`. `drainRecords` applies only
270-
// NEW `sc:slot:`/`sc:region:` keys; a direct-insert occurrence has no
271-
// record by design, so nothing reaches `host.apply`, no `#flush` runs,
272-
// and frame-client.ts `#syncSlots` — the only place a marker pair is
273-
// discovered and mounted — never walks the revealed content. The
274-
// reveal itself (`$dfr` → `_$HY.fe`) carries no re-sync.
275-
expect(page.container.textContent).toBe("1");
276-
expect(page.container.querySelector("b")).toBe(b);
277-
expect(page.warnings).toEqual([]);
278-
expect(page.errors).toEqual([]);
279-
dispose();
280-
}
281-
);
263+
setTick(1);
264+
flush();
265+
// Observed on next: the revealed <b> shows "0" after the bump (the
266+
// client `children` JSX was never evaluated); no warning, no error.
267+
// Expected: "1" — the occurrence mounted and its hole is live. Where
268+
// it goes wrong: client.ts adoptBoundary's `fr.subscribe` callback is
269+
// the only reaction to a reveal, and it does two things — claim nested
270+
// `pl-*` placeholders and `drainRecords()`. `drainRecords` applies only
271+
// NEW `sc:slot:`/`sc:region:` keys; a direct-insert occurrence has no
272+
// record by design, so nothing reaches `host.apply`, no `#flush` runs,
273+
// and frame-client.ts `#syncSlots` — the only place a marker pair is
274+
// discovered and mounted — never walks the revealed content. The
275+
// reveal itself (`$dfr` → `_$HY.fe`) carries no re-sync.
276+
expect(page.container.textContent).toBe("1");
277+
expect(page.container.querySelector("b")).toBe(b);
278+
expect(page.warnings).toEqual([]);
279+
expect(page.errors).toEqual([]);
280+
dispose();
281+
});
282282

283283
// Arm (c2): reveal BEFORE hydrate, post-done. Global hydration has already
284284
// completed in this worker (forced here with a throwaway pass, so the arm

‎packages/web/test/consistency/c04-record-applies-once.spec.tsx‎

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -204,47 +204,42 @@ describe("C4 — a record applies exactly once, in any drain order", () => {
204204
// and record are in the document (and the `_fr` settled) when the boundary
205205
// adopts, but its `$df` is deferred to the group's reveal. The adopt-time
206206
// drain applies the record while the range is still inside the template;
207-
// the reveal then brings the range into the shown content.
208-
test.fails(
209-
"(d) drain-before-reveal: a record drained before its range is shown takes effect once the range is revealed",
210-
async () => {
211-
const fid = freshFid("c4d");
212-
const frag = "c4d-frag";
213-
page = bootPage(frameHtml(fid, `<ul>${placeholderHtml(frag, "<i>loading</i>")}</ul>`));
214-
page.slotRecord(fid, "item#0", { text: "one" });
215-
const reveal = parkFragment(page, frag, slotRange("item#0", fillHtml(fid, "item#0", "one")));
216-
const Comp = (globalThis as any)._$SC.r(fid);
217-
const invocations: number[] = [];
218-
const pushes: string[] = [];
219-
const dispose = hydrate(() => <Comp item={makeFill(invocations, pushes)} />, page.container);
220-
await quiesce();
221-
// Pending at adopt: the fallback shows, the record is in the store.
222-
expect(page.container.textContent).toBe("loading");
223-
expect(invocations.length).toBe(0);
207+
// the reveal then brings the range into the shown content. Was red on
208+
// `next`; green under frames-rulings 2.3/2.4 — a reveal is an apply (the
209+
// reveal cascade syncs the adopting frame, which finds the range and the
210+
// record it holds), and `appliedRecords` is a delivery dedupe, not an
211+
// application: "applied" means shown.
212+
test("(d) drain-before-reveal: a record drained before its range is shown takes effect once the range is revealed", async () => {
213+
const fid = freshFid("c4d");
214+
const frag = "c4d-frag";
215+
page = bootPage(frameHtml(fid, `<ul>${placeholderHtml(frag, "<i>loading</i>")}</ul>`));
216+
page.slotRecord(fid, "item#0", { text: "one" });
217+
const reveal = parkFragment(page, frag, slotRange("item#0", fillHtml(fid, "item#0", "one")));
218+
const Comp = (globalThis as any)._$SC.r(fid);
219+
const invocations: number[] = [];
220+
const pushes: string[] = [];
221+
const dispose = hydrate(() => <Comp item={makeFill(invocations, pushes)} />, page.container);
222+
await quiesce();
223+
// Pending at adopt: the fallback shows, the record is in the store.
224+
expect(page.container.textContent).toBe("loading");
225+
expect(invocations.length).toBe(0);
224226

225-
// The group's reveal.
226-
expect(reveal()).toBe(1);
227-
await quiesce();
228-
await quiesce();
229-
expect(page.container.textContent).toBe("one");
230-
// Observed on next: the range is shown (text "one") but the record
231-
// took effect ZERO times — invocations 0, no push; nothing logged.
232-
// Expected: exactly one invocation with { text: "one" }. Where it goes
233-
// wrong: client.ts adoptBoundary's adopt-time `drainRecords` applies
234-
// `sc:slot:<fid>:item#0` to the store (`host.apply` → `FrameImpl.apply`
235-
// → `#flush` → `#syncSlots`), but the sync finds no `item#0` marker
236-
// pair — the range is still inside `<template id=frag>` — so the
237-
// record is consumed (`appliedRecords`) with no mount. The reveal's
238-
// `fr.subscribe` drain then sees the key as already applied, applies
239-
// nothing, and no `#flush`/`#syncSlots` follows; the record in the
240-
// store and the range in the DOM never meet.
241-
expect(invocations.length).toBe(1);
242-
expect(pushes).toEqual(["one"]);
243-
expect(page.warnings).toEqual([]);
244-
expect(page.errors).toEqual([]);
245-
dispose();
246-
}
247-
);
227+
// The group's reveal.
228+
expect(reveal()).toBe(1);
229+
await quiesce();
230+
await quiesce();
231+
expect(page.container.textContent).toBe("one");
232+
// Was observed on next: the range shown (text "one") but the record
233+
// took effect ZERO times — the adopt-time drain's sync found no
234+
// `item#0` marker pair (the range was still inside `<template>`), the
235+
// reveal's drain saw the key as already applied, and no sync followed
236+
// the reveal. Now the reveal syncs: one invocation, one push.
237+
expect(invocations.length).toBe(1);
238+
expect(pushes).toEqual(["one"]);
239+
expect(page.warnings).toEqual([]);
240+
expect(page.errors).toEqual([]);
241+
dispose();
242+
});
248243

249244
// Arm (e2): a live hole op arriving AFTER adoption applies once; the same
250245
// op re-sent (a fresh record of identical html) must not produce a second

‎packages/web/test/consistency/c06-stale-wait-never-lands.spec.tsx‎

Lines changed: 66 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -105,57 +105,48 @@ describe("C6 — a held record never lands on content it no longer belongs to",
105105
// and before the html). A's held record, kept across the rebind, must
106106
// never mount the fill with B's data.
107107
//
108-
// Observed on `next`: when B's html flushes (before B's slot record), the
109-
// fill MOUNTS with "jB/kB" — A's record `{k:$ref"1", j:$ref"2"}` resolved
110-
// against B's table — and the site shows `BjB/kB` (frames recorded:
111-
// `…` → `A` → `BjB/kB` → `BkB/jB`; `seen` = `["jB/kB", "kB/jB"]`) until
112-
// B's slot record arrives and live-updates it to "kB/jB". Expected: no
113-
// mount until B's own record; never the swapped pair. Where it goes wrong:
114-
// `FrameImpl.rebind` → `#resetStreamState(true)` → `clearStreamRecords`
115-
// deletes seg/hole/attr/:error and the root but KEEPS every `slot:*`
116-
// record (the dedupe that preserves occurrence state across a same-
117-
// address morph), so A's record is still the occurrence's record after
118-
// the frame moved to B; `#syncSlots` resolves it through `#resolveRef`,
119-
// which routes by the frame's NEW id → `tableFor(B)`. While B's data
120-
// is absent `#refsUnresolved` skips it, but B's data makes it resolvable
121-
// and B's html's flush applies it — a record from A's response read
122-
// through B's table, before B has said anything about the occurrence.
123-
test.fails(
124-
"(a1) switch during the wait, new stream orders data → html → slot: the stale record never mounts with the new data",
125-
async () => {
126-
const fid = freshFid("c6a1");
127-
const getX = createServerReference(fid);
128-
await sharedHost();
129-
const { held } = stubHeldFetch([WIRE, WIRE]);
130-
const [a, b] = held;
131-
const site = mountSite(getX);
132-
await pump();
133-
a.send(start);
134-
a.send(recordA);
135-
a.send(html("A"));
136-
await pump();
137-
expect(site.div.querySelector("h1")!.textContent).toBe("A");
138-
// A's data never arrives: the record waits.
139-
expect(site.seen).toEqual([]);
140-
site.setN(2);
141-
await pump();
142-
b.send(start);
143-
for (const c of createDataSource().chunks(WIRE, 1, { "2": "kB", "1": "jB" })) b.send(c);
144-
b.send(html("B"));
145-
await pump();
146-
expect(site.div.querySelector("h1")!.textContent).toBe("B");
147-
const mountedBeforeRecord = site.seen.slice();
148-
b.send(recordB);
149-
b.send(complete);
150-
b.close();
151-
await pump();
152-
expect(site.div.querySelector("li")!.textContent).toBe("kB/jB");
153-
expect(site.frames.some(f => f.includes("jB/kB"))).toBe(false);
154-
expect(site.seen).not.toContain("jB/kB");
155-
expect(mountedBeforeRecord).toEqual([]);
156-
expect(site.seen).toEqual(["kB/jB"]);
157-
}
158-
);
108+
// Was red on `next`: when B's html flushed (before B's slot record), the
109+
// fill MOUNTED with "jB/kB" — A's record `{k:$ref"1", j:$ref"2"}` resolved
110+
// against B's table — because `FrameImpl.rebind` kept every `slot:*`
111+
// record across the move and `#resolveRef` routed by the frame's NEW id.
112+
// Green under frames-rulings 1.4 (full): the store is one response's —
113+
// the rebind (like a version bump) replaces it wholesale, so A's held
114+
// record leaves with A, and the called occurrence found recordless
115+
// under B WAITS for B's own record rather than mounting (its name,
116+
// `comment#0`, says it has one).
117+
test("(a1) switch during the wait, new stream orders data → html → slot: the stale record never mounts with the new data", async () => {
118+
const fid = freshFid("c6a1");
119+
const getX = createServerReference(fid);
120+
await sharedHost();
121+
const { held } = stubHeldFetch([WIRE, WIRE]);
122+
const [a, b] = held;
123+
const site = mountSite(getX);
124+
await pump();
125+
a.send(start);
126+
a.send(recordA);
127+
a.send(html("A"));
128+
await pump();
129+
expect(site.div.querySelector("h1")!.textContent).toBe("A");
130+
// A's data never arrives: the record waits.
131+
expect(site.seen).toEqual([]);
132+
site.setN(2);
133+
await pump();
134+
b.send(start);
135+
for (const c of createDataSource().chunks(WIRE, 1, { "2": "kB", "1": "jB" })) b.send(c);
136+
b.send(html("B"));
137+
await pump();
138+
expect(site.div.querySelector("h1")!.textContent).toBe("B");
139+
const mountedBeforeRecord = site.seen.slice();
140+
b.send(recordB);
141+
b.send(complete);
142+
b.close();
143+
await pump();
144+
expect(site.div.querySelector("li")!.textContent).toBe("kB/jB");
145+
expect(site.frames.some(f => f.includes("jB/kB"))).toBe(false);
146+
expect(site.seen).not.toContain("jB/kB");
147+
expect(mountedBeforeRecord).toEqual([]);
148+
expect(site.seen).toEqual(["kB/jB"]);
149+
});
159150

160151
// Arm (a2): the same switch, B ordered html → data → slot. No flush
161152
// happens between B's data and B's record, so the stale record is never
@@ -252,41 +243,31 @@ describe("C6 — a held record never lands on content it no longer belongs to",
252243
expect(site.seen).toEqual(["k1/j1", "k2/j2"]);
253244
});
254245

255-
// Observed on `next`: at v2's commit the fill is INVOKED with "j2/k2" —
256-
// v1's held record `{k:$ref"1", j:$ref"2"}` resolved against v2's table —
257-
// and the `<li>` holds "j2/k2" between two synchronous applies of the
258-
// commit, before v2's own record live-updates it to "k2/j2" (`seen` is
259-
// `["j2/k2", "k2/j2"]`; a MutationObserver sees only the final text since
260-
// the whole commit is one task). Expected: the fill mounts once, with
261-
// "k2/j2". Where it goes wrong: frame-transport.ts `stage(...).commit`
262-
// installs the staged tables (`data.commit()` → `tables.set(A, v2's)`)
263-
// BEFORE replaying the buffered chunks, and the first replayed chunk —
264-
// `start` — bumps the frame's version and flushes; `FrameImpl.#syncSlots`
265-
// still finds v1's record under `slot:comment#0` (slot records survive
266-
// the version bump by design), `#refsUnresolved` now answers through v2's
267-
// table, and the held record mounts with v2's values. `preview` cannot
268-
// prevent it (it only pushes into MOUNTED occurrences, and a held one is
269-
// not mounted), and v2's own slot record is replayed only after `start`.
270-
test.fails(
271-
"(b2) refetch during the wait, v1's data never before the commit: the held v1 record never mounts with v2's data",
272-
async () => {
273-
const { site, sendLateV1, commitV2 } = await refetchDuringWait(freshFid("c6b2"));
274-
await commitV2();
275-
expect(site.div.querySelector("li")!.textContent).toBe("k2/j2");
276-
// v1's stragglers after the commit: nothing of v1 reaches the fill.
277-
sendLateV1();
278-
await pump();
279-
expect(site.div.querySelector("li")!.textContent).toBe("k2/j2");
280-
for (const swapped of ["j2/k2", "j1/k1"]) {
281-
expect(
282-
site.frames.some(f => f.includes(swapped)),
283-
swapped
284-
).toBe(false);
285-
expect(site.seen).not.toContain(swapped);
286-
}
287-
expect(site.seen).toEqual(["k2/j2"]);
246+
// Was red on `next`: at v2's commit the fill was INVOKED with "j2/k2" —
247+
// v1's held record resolved against v2's table — because the first
248+
// replayed chunk (`start`) bumped the version and flushed with v1's
249+
// record still in the store (slot records survived the bump by design)
250+
// and the staged tables already installed. Green under frames-rulings
251+
// 1.4 (full): the bump replaces the store wholesale, v1's held record
252+
// leaves with v1, and the occurrence waits for v2's own record (replayed
253+
// right after) — one mount, with v2's values.
254+
test("(b2) refetch during the wait, v1's data never before the commit: the held v1 record never mounts with v2's data", async () => {
255+
const { site, sendLateV1, commitV2 } = await refetchDuringWait(freshFid("c6b2"));
256+
await commitV2();
257+
expect(site.div.querySelector("li")!.textContent).toBe("k2/j2");
258+
// v1's stragglers after the commit: nothing of v1 reaches the fill.
259+
sendLateV1();
260+
await pump();
261+
expect(site.div.querySelector("li")!.textContent).toBe("k2/j2");
262+
for (const swapped of ["j2/k2", "j1/k1"]) {
263+
expect(
264+
site.frames.some(f => f.includes(swapped)),
265+
swapped
266+
).toBe(false);
267+
expect(site.seen).not.toContain(swapped);
288268
}
289-
);
269+
expect(site.seen).toEqual(["k2/j2"]);
270+
});
290271

291272
// Arm (c): disposal during the wait — later chunks never invoke the fill.
292273
test("(c) dispose during the wait: the record's data and the stream's end never invoke the fill", async () => {

0 commit comments

Comments
 (0)