Skip to content

Commit 9efb987

Browse files
committed
fix(signals): a pass with no value yet reads the screen in a latest()-only transaction; latestOpened clears on a real join
- stagedScreen's frame-read branch (D-22) skips a pass with no value yet: its first answer is nobody's hold (D-6) and would commit the staging whether or not the frame parks. It reads the screen and runs again at the landing, as before. Async-gen seed 3289 #1831: a grouped leaf ended on [ROOT-E] where the split one, and next, show [F] (F-1, F-12). The minimized case and the generated one (default, grouped, split, latest-through-a-memo) are pinned. - latestOpened clears when anything else joins the flush's transaction (joinFuture) and when the flush ends. - caught()'s walk to an error fallback above a Loading is one loop with no type test outside it (-20 B on the boundary bundles). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 5600428 commit 9efb987

6 files changed

Lines changed: 90 additions & 16 deletions

File tree

‎packages/signals/src/boundaries.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ function caught(b: Boundary, node: Computed<any>, error: unknown, source = node)
202202
// A loading fallback behind an error fallback is hidden: the error stays
203203
// the display until what the fallback waits on answers (D-39) — the
204204
// error boundary waits on it too.
205-
if (b._type === STATUS_PENDING)
206-
for (let p = b._parent; p; p = p._parent)
207-
if (p._type === STATUS_ERROR && p._fallback) record(p, node);
205+
// (`_type`: STATUS_PENDING 1 < STATUS_ERROR 2 — an error boundary above a
206+
// loading one.)
207+
for (let p: Boundary | null = b; (p = p._parent); )
208+
if (p._fallback && p._type > b._type) record(p, node);
208209
if (b._armed) flip(b);
209210
// Already showing the fallback: one more reader to wait on changes
210211
// nothing on screen. The fallback is instantiated once per show — a later

‎packages/signals/src/core/core.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,12 +2193,16 @@ export function stagedScreen(c: Computed<any>): boolean {
21932193
// A transaction only a `latest()` read opened holds nothing: the staging
21942194
// is the frame's read for a pass in the frame's seat, as it is before the
21952195
// frame has one, and the seam re-derives the pass once only if the flush
2196-
// parks (D-22, F-10). Lane work sees the screen (D-37).
2196+
// parks (D-22, F-10). Lane work sees the screen (D-37). Not a pass with no
2197+
// value yet: its first answer is nobody's hold (D-6) and would commit the
2198+
// staging whether or not the frame parks — it reads the screen, and runs
2199+
// again at the landing.
21972200
if (
21982201
observeFlightHook &&
21992202
flushTransaction === latestOpened &&
22002203
passLane === null &&
2201-
c._config & CONFIG_VERDICT
2204+
c._config & CONFIG_VERDICT &&
2205+
!(c._statusFlags & STATUS_UNINITIALIZED)
22022206
)
22032207
return !stagedReaders.push(c);
22042208
staleReader(c, flushTransaction);

‎packages/signals/src/core/scheduler.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ export function resolveTx(t: Transaction): Transaction {
371371
* went pending with nothing held). Joining a second one merges it into the
372372
* flush's: the work that touched both entangles them (A15). */
373373
export function joinFuture(t: Transaction | null): void {
374+
// Something real joins: the transaction is no longer `latest()`'s alone.
375+
latestOpened = null;
374376
const f = flushTransaction;
375377
if (f === null) {
376378
flushTransaction = t === null ? newTransaction(false) : resolveTx(t);
@@ -924,7 +926,7 @@ export class GlobalQueue implements IQueue {
924926
// pure round — the parent's flights before the parent is judged below.
925927
if (laneCorrectionsHook?.()) runHeap(dirtyQueue, GlobalQueue._update);
926928
const joined = flushTransaction;
927-
flushTransaction = null;
929+
flushTransaction = latestOpened = null;
928930
// The frame's verdict is in: the guesses written since the last seam
929931
// open their lane under the frame's transaction (a lane's own flush
930932
// parents a nested lane to it), or are dropped — the frame commits, and
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
// async-gen seed 3289 #1831 (E1, E9): a grouped and a split leaf, and a
5+
// leaf reading `latest()` through a memo, show the same screen (F-1, F-12).
6+
// `m2 = memo(latest(m0) + m1)` has no value yet when `m0`'s first load
7+
// lands in a flush whose transaction only `latest()` reads opened; its
8+
// first answer is nobody's hold (D-6), so it reads `m1`'s screen, not the
9+
// staging (D-22's frame read is for a pass that has a value to re-derive
10+
// on). Reading the staging there committed an answer that threw later, and
11+
// the grouped leaf ended on `[ROOT-E]` where the split one shows `[F]`.
12+
import { expect, test } from "vitest";
13+
import fc from "fast-check";
14+
import { runScenario } from "./run.js";
15+
import { scenarioArb } from "./scenario.js";
16+
17+
const minimized = {
18+
signals: [0],
19+
memos: [
20+
{ async: true, deps: [{ src: { k: "s", i: 0 }, how: "plain" }], poison: null },
21+
{
22+
async: false,
23+
deps: [
24+
{ src: { k: "s", i: 0 }, how: "plain" },
25+
{ src: { k: "m", i: 0 }, how: "latest" }
26+
],
27+
poison: 0
28+
},
29+
{
30+
async: false,
31+
deps: [
32+
{ src: { k: "m", i: 0 }, how: "latest" },
33+
{ src: { k: "m", i: 1 }, how: "plain" }
34+
],
35+
poison: 1
36+
}
37+
],
38+
tree: {
39+
t: "show",
40+
when: { how: "pending", src: { k: "m", i: 0 } },
41+
child: {
42+
t: "leaf",
43+
text: [],
44+
attrs: [
45+
{ how: "latest", src: { k: "m", i: 2 } },
46+
{ how: "plain", src: { k: "m", i: 0 } }
47+
],
48+
grouped: true
49+
},
50+
fallback: true
51+
},
52+
steps: [{ t: "settle", pick: 5 }, { t: "task" }, { t: "write", s: 0, v: 1 }, { t: "task" }]
53+
} as any;
54+
55+
test("minimized: grouped and split attributes show the same screens, ending on [F]", async () => {
56+
const grouped = await runScenario(minimized, { grouped: true });
57+
const split = await runScenario(minimized, { split: true });
58+
expect(grouped.screens).toEqual(split.screens);
59+
expect(grouped.screens.at(-1)).toBe("[F]");
60+
});
61+
62+
test("the generated case: grouped, split, default and latest-through-a-memo agree", async () => {
63+
const sc = fc.sample(scenarioArb(), { seed: 3289, numRuns: 1832 })[1831];
64+
const base = await runScenario(sc, {});
65+
for (const v of [{ grouped: true }, { split: true }, { latestDerive: true }])
66+
expect((await runScenario(sc, v)).screens).toEqual(base.screens);
67+
});

‎scripts/size/floor-caps.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"page: live server components (base + live/GET + action + isPending/latest)": {
1919
"cap": "37.75 KB",
20-
"minified": 115708
20+
"minified": 115709
2121
},
2222
"server: floor (getRequestEvent + isServer)": {
2323
"cap": "1.34 KB",

0 commit comments

Comments
 (0)