Skip to content

Commit 5c2174c

Browse files
committed
fix(signals): seat new nodes in their creator's lane from the start
A memo created by a lane pass ran its body outside the lane, so render effects it created read the transaction's staged value and were born held: the lane revealed the memo's element before they ran (#3835). A reader with no committed value yet keeps its previous reads of a pending flight, so a Loading mounted by the lane still shows its fallback (#3540) and a render effect stays a stale reader.
1 parent 59fb244 commit 5c2174c

5 files changed

Lines changed: 263 additions & 11 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
A node created by a lane pass is the lane's from the start of its first pass, not only at its end (#3835). A memo mounted by an optimistic write (a `<Show>` over an optimistic signal) used to run its body outside the lane, so the render effects it created read the transaction's staged value and were born held: the lane revealed the memo's element before those effects had run once. They now read the screen like the rest of the lane's frame and run at the reveal. A pending flight reads as it did before for a node with no committed value yet: a memo sees it pending, held or not, so a `Loading` the lane mounts shows its fallback (A29's boundary exemption, #3540), and a render effect is still a stale reader of a held flight (rule 3).

‎packages/signals/docs/RULES-INDEX.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
7373
| A26 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:107` | — | action-await-contract.test.ts×2 fuzz-findings-l2.test.ts×1 posture-store-parity.test.ts×2 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×1 visibility-oracle.test.ts×1 | [ruled 2026-07-17] An ambient transaction window is one flush; parking is flush-driven — (**ruled 2026-07-17**, #2913; **enforcement hardened 2026-08-31**, #3141 — parking is flush-driven, and a trans… |
7474
| A27 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:293` | — | loading-value.test.ts×2 visibility-oracle.states.ts×18 visibility-oracle.test.ts×1 | [ruled 2026-08-10] The commit-#0 loading window is loading-class and verdict-quiet — (**ruled 2026-08-10**) **The commit-#0 loading window is loading-class and verdict-quiet.** A node born committed v… |
7575
| A28 | ruled, mechanism landed | `docs/SPEC-ASYNC-SEMANTICS.md:91` | constants.ts×1 core.ts×12 lanes.ts×2 scheduler.ts×3 types.ts×1 verdict.ts×2 store.ts×4 | createOptimistic.test.ts×5 fuzz-findings-l2.test.ts×6 held-derivation-not-a-proposal-3612.test.ts×1 latest-held-till-flush.test.ts×1 posture-store-parity.test.ts×5 question-scoped-pending.test.ts×3 snapshot-derived-store-rows.test.ts×1 createOptimisticStore.test.ts×10 optimistic-draft-visibility-3665.test.ts×5 optimistic-list-mutation-matrix.harness.ts×1 optimistic-list-mutation-matrix.test.ts×2 shallow.test.ts×1 woken-transaction-adopts-staged-bump.test.ts×1 treeshake.test.ts×2 verdict-contract.test.ts×1 visibility-oracle-store.states.ts×8 visibility-oracle.states.ts×8 | [ruled, mechanism landed 2026-09-15] A write becomes visible at flush — to every channel — (**ruled 2026-09-08**; supersedes the #2922 mid-tick pull) **A write becomes visible at flush — to every chan… |
76-
| A29 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:115` | boundaries.ts×1 action.ts×1 constants.ts×1 core.ts×9 effect.ts×1 scheduler.ts×3 signals.ts×1 store.ts×1 | adoption-unchanged-key-read-3706.test.ts×9 body-end-supersession-visibility.test.ts×1 born-held.test.ts×3 boundary-not-born-held-3540.test.ts×4 createProjection.draft-lifetime-3585.test.ts×1 direct-commit-readers-posture.test.ts×1 fuzz-findings-l2.test.ts×6 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 held-truth-lane-only.test.ts×3 l2-contract.test.ts×1 latest-held-till-flush.test.ts×2 mount-over-foreign-hold-3761.test.ts×1 optimistic-read-lane-not-transaction-3698.test.ts×3 posture-born-held-and-observation.test.ts×1 posture-store-parity.test.ts×6 derived-presence-async-3726.test.ts×3 optimistic-untracked-reads-f3-f5.test.ts×1 store-unchanged-read-independent-write-3688.test.ts×1 tick-scoped-pass-transaction.test.ts×2 treeshake.test.ts×3 visibility-oracle-store.states.ts×5 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-09-13 (#3408)] A tracked read served a live transaction's staged value enters that transaction — A tracked computation served a node's staged `_pendingValue` — a value a … |
76+
| A29 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:115` | boundaries.ts×1 action.ts×1 constants.ts×1 core.ts×10 effect.ts×1 scheduler.ts×3 signals.ts×1 store.ts×1 | adoption-unchanged-key-read-3706.test.ts×9 body-end-supersession-visibility.test.ts×1 born-held.test.ts×3 boundary-not-born-held-3540.test.ts×4 createProjection.draft-lifetime-3585.test.ts×1 direct-commit-readers-posture.test.ts×1 fuzz-findings-l2.test.ts×6 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 held-truth-lane-only.test.ts×3 l2-contract.test.ts×1 latest-held-till-flush.test.ts×2 mount-over-foreign-hold-3761.test.ts×1 optimistic-mount-nested-memo-3835.test.ts×1 optimistic-read-lane-not-transaction-3698.test.ts×3 posture-born-held-and-observation.test.ts×1 posture-store-parity.test.ts×6 derived-presence-async-3726.test.ts×3 optimistic-untracked-reads-f3-f5.test.ts×1 store-unchanged-read-independent-write-3688.test.ts×1 tick-scoped-pass-transaction.test.ts×2 treeshake.test.ts×3 visibility-oracle-store.states.ts×5 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-09-13 (#3408)] A tracked read served a live transaction's staged value enters that transaction — A tracked computation served a node's staged `_pendingValue` — a value a … |
7777
| A30 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:249` | async.ts×3 attribution.ts×1 constants.ts×1 core.ts×1 effect.ts×1 lanes.ts×1 scheduler.ts×5 | async-landing-deps-3461.test.ts×3 fuzz-findings-l2.test.ts×3 held-conditional-effect.test.ts×1 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 ispending-in-boundary-on-3528.test.ts×1 lane-frame-deferred-run-3662.test.ts×1 lane-frame-held-lane-3662.test.ts×1 posture-born-held-and-observation.test.ts×1 treeshake.test.ts×2 write-proposals-3494.test.ts×2 zombie-rerun-after-commit-3546.test.ts×2 | [ruled 2026-09-13 (#3410)] A memo's dependencies are the committed frame's until the frame is replaced — A pass that _staged_ its value has not replaced the committed frame, so the committed value sti… |
7878
| A31 | live | `docs/SPEC-ASYNC-SEMANTICS.md:123` | boundaries.ts×1 core.ts×1 lanes.ts×1 verdict.ts×2 | fuzz-findings-l2.test.ts×6 ispending-combined-atomic-3442.test.ts×1 | [live 2026-09-14 (#3442)] A memo computes under its own lane posture, never its puller's — A memo's value is one shared slot every reader sees, so its pass runs under the lane posture the memo itself … |
7979
| A32 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:131` | core.ts×4 lanes.ts×1 store.ts×1 | visibility-oracle-store.states.ts×8 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 | [ruled 2026-09-14] Children-forbidden readers see the frame, not the graph — `createTrackedEffect` and `onSettled` callbacks are effect-phase code that runs after the frame is decided. They read the f… |

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,18 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
258258
// (REACTIVE_LANE_DIRTY, lanes.ts — a leaf the lane owns). A written guess's
259259
// own pass is its truth arriving (A18), the frame's. A tracked read of a
260260
// lane's value moves a derivation's pass into the lane (`read`); a leaf's
261-
// never moves. Restored at the end, after this pass's staging and runs
262-
// have been routed.
261+
// never moves. A first pass sits in its creator's lane from its start
262+
// (ruling A), so what its body creates and reads is the lane's too (#3835).
263+
// Restored at the end, after this pass's staging and runs have been routed.
263264
const prevLane = passLane;
264265
setPassLane(
265266
(el._flags & REACTIVE_LANE_DIRTY ||
266267
(el._config & (CONFIG_OVERRIDE | CONFIG_GUESS)) === CONFIG_OVERRIDE) &&
267268
el._x?._transaction?._lane
268269
? el._x._transaction
269-
: null
270+
: create && creatorPass(context)?._flags! & REACTIVE_RECOMPUTING_DEPS
271+
? prevLane
272+
: null
270273
);
271274
// Attribution hook: fired before this run touches the dep list — `_deps`
272275
// still holds the previous run's links (the subscriptions that could have
@@ -497,11 +500,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
497500
// that read none of the lane's world has left it: its result is the
498501
// frame's (a derivation whose branch no longer reaches the guess). A
499502
// guess is written, not derived — it never leaves this way.
500-
let lane =
501-
passLane ??
502-
(create && (creatorPass(oldcontext)?._flags ?? 0) & REACTIVE_RECOMPUTING_DEPS
503-
? prevLane
504-
: null);
503+
let lane = passLane;
505504
// Listed before its staging, a pending pass included (the lane's own
506505
// flight is the lane's); false: the pass left the lane (lanes.ts).
507506
const errored = !!el._x?._error;
@@ -982,9 +981,13 @@ function frameRead(c: Computed<any>, el: Signal<any> | Computed<any>): boolean {
982981
// leaf — the transaction's own later passes read it — so a mainline mount's
983982
// derivations carry the future (A29, born held); only its direct bindings
984983
// read the screen.
984+
// Lane work with no committed value yet reads a flight as a mount's memo
985+
// does: it enters, and the boundary it mounts catches the pending (#3540).
985986
const verdict = c._config & CONFIG_VERDICT;
986987
if (
987-
passLane === null &&
988+
(passLane === null ||
989+
(c._statusFlags & STATUS_UNINITIALIZED &&
990+
(el as Computed<any>)._statusFlags & STATUS_PENDING)) &&
988991
!verdict &&
989992
((c as any)._type !== EFFECT_RENDER || el._config & CONFIG_INPUTS_PUBLISHED)
990993
)
@@ -1684,7 +1687,10 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
16841687
!(el._config & CONFIG_OVERRIDE) &&
16851688
!(owner._statusFlags & STATUS_UNINITIALIZED)
16861689
) {
1687-
if (passLane !== null) committed = true;
1690+
// A reader with no committed value yet sees the flight pending: a boundary
1691+
// a lane mounts shows its fallback (A29's boundary exemption, #3540).
1692+
if (passLane !== null && !((c as Computed<any> | null)?._statusFlags! & STATUS_UNINITIALIZED))
1693+
committed = true;
16881694
else if (c !== null && c._config & CONFIG_VERDICT) {
16891695
committed = true;
16901696
GlobalQueue._observeFlight!(c as Computed<any>, owner);
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/**
2+
* #3835 — a subtree mounted by an optimistic write is the lane's frame
3+
* (ruling A), all the way down. A memo created by the lane pass used to sit
4+
* outside the lane while its own body ran, so the render effect it created
5+
* read the transaction's staged value and was born held: the lane revealed
6+
* the memo's element with the effect's first run still waiting on the
7+
* transaction.
8+
*/
9+
import { afterEach, describe, expect, it } from "vitest";
10+
import {
11+
action,
12+
createMemo,
13+
createOptimistic,
14+
createRenderEffect,
15+
createRoot,
16+
createSignal,
17+
flush,
18+
createLoadingBoundary,
19+
untrack
20+
} from "../src/index.js";
21+
22+
afterEach(() => flush());
23+
24+
const tick = () => new Promise<void>(r => setTimeout(r, 0));
25+
26+
function setup(nested: boolean) {
27+
type El = { color?: string };
28+
let shown: El | undefined;
29+
let run!: () => Promise<void>;
30+
let finish!: () => void;
31+
let dispose!: () => void;
32+
createRoot(d => {
33+
dispose = d;
34+
const [enabled, setEnabled] = createSignal(false);
35+
const [visible, setVisible] = createOptimistic(enabled);
36+
const content = () => {
37+
const el: El = {};
38+
createRenderEffect(
39+
() => (enabled() ? "blue" : "red"),
40+
v => {
41+
el.color = v;
42+
}
43+
);
44+
return el;
45+
};
46+
const view = createMemo(() => {
47+
if (!visible()) return undefined;
48+
return nested ? createMemo(content) : () => content();
49+
});
50+
createRenderEffect(
51+
() => view()?.(),
52+
el => {
53+
shown = el;
54+
}
55+
);
56+
const act = action(function* () {
57+
setEnabled(true);
58+
setVisible(true);
59+
yield new Promise<void>(r => (finish = r));
60+
});
61+
run = () => act();
62+
});
63+
flush();
64+
return {
65+
shown: () => (shown ? { ...shown } : undefined),
66+
run: () => run(),
67+
finish: () => finish(),
68+
dispose: () => dispose()
69+
};
70+
}
71+
72+
describe("#3835 optimistic mount of a nested memo", () => {
73+
for (const nested of [true, false])
74+
it(`${nested ? "memo-wrapped" : "direct"} content reveals with the screen value`, async () => {
75+
const s = setup(nested);
76+
expect(s.shown()).toBeUndefined();
77+
const p = s.run();
78+
flush();
79+
await tick();
80+
flush();
81+
expect(s.shown()).toEqual({ color: "red" });
82+
s.finish();
83+
await p;
84+
await tick();
85+
flush();
86+
expect(s.shown()).toEqual({ color: "blue" });
87+
s.dispose();
88+
});
89+
});
90+
91+
describe("#3835 a Loading mounted by an optimistic write over a parent flight", () => {
92+
// A29's boundary exemption holds for lane work too: the boundary's first
93+
// pass sees the flight pending, held or not, and shows its fallback; it is
94+
// not handed the flight's committed value.
95+
for (const order of ["same tick", "after the park"])
96+
it(`shows its fallback (${order})`, async () => {
97+
const log: unknown[] = [];
98+
let run!: () => Promise<void>;
99+
let finish!: () => void;
100+
let dispose!: () => void;
101+
const lands: ((v: number) => void)[] = [];
102+
createRoot(d => {
103+
dispose = d;
104+
const [count, setCount] = createSignal(1);
105+
const [show, setShow] = createSignal(false);
106+
const data = createMemo(() => {
107+
const v = count();
108+
return v === 1 ? v : new Promise<number>(r => lands.push(r));
109+
});
110+
const [visible, setVisible] = createOptimistic(show);
111+
const view = createMemo(() =>
112+
visible()
113+
? untrack(() =>
114+
createLoadingBoundary(
115+
() => `data ${data()}`,
116+
() => "fallback"
117+
)
118+
)
119+
: () => "hidden"
120+
);
121+
createRenderEffect(
122+
() => view()(),
123+
v => {
124+
log.push(v);
125+
}
126+
);
127+
const act = action(function* () {
128+
setCount(2);
129+
if (order === "after the park") yield tick();
130+
setShow(true);
131+
setVisible(true);
132+
yield new Promise<void>(r => (finish = r));
133+
});
134+
run = () => act();
135+
});
136+
flush();
137+
const p = run();
138+
for (let i = 0; i < 2; i++) {
139+
flush();
140+
await tick();
141+
}
142+
flush();
143+
expect(log).toEqual(["hidden", "fallback"]);
144+
lands.forEach(land => land(2));
145+
await tick();
146+
flush();
147+
expect(log).not.toContain("data 1");
148+
finish();
149+
await p;
150+
await tick();
151+
flush();
152+
expect(log.at(-1)).toBe("data 2");
153+
expect(log).not.toContain("data 1");
154+
dispose();
155+
});
156+
});
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*
5+
* #3835: a component mounted by an optimistic write reveals with the lane's
6+
* screen values. Its memo's render effects used to be born held by the
7+
* transaction, so the element showed before its style was ever applied.
8+
*/
9+
import { describe, expect, test } from "vitest";
10+
import { action, createMemo, createOptimistic, createSignal, flush, Show } from "solid-js";
11+
import { render } from "@solidjs/web";
12+
13+
const tick = () => new Promise<void>(r => setTimeout(r, 0));
14+
15+
function setup(opts: { memo: boolean; dynamicText: boolean }) {
16+
const container = document.createElement("div");
17+
document.body.appendChild(container);
18+
let run!: () => Promise<void>;
19+
let finish!: () => void;
20+
21+
function Content(props: { enabled: () => boolean }) {
22+
const view = () => (
23+
<div style={{ color: props.enabled() ? "blue" : "red" }}>
24+
Hello{opts.dynamicText ? (props.enabled() ? " world" : "") : ""}
25+
</div>
26+
);
27+
return opts.memo ? createMemo(view) : view();
28+
}
29+
30+
function App() {
31+
const [enabled, setEnabled] = createSignal(false);
32+
const [visible, setVisible] = createOptimistic(enabled);
33+
const act = action(function* () {
34+
setEnabled(true);
35+
setVisible(true);
36+
yield new Promise<void>(r => (finish = r));
37+
});
38+
run = () => act();
39+
return (
40+
<>
41+
<Show when={visible()}>
42+
<Content enabled={enabled} />
43+
</Show>
44+
</>
45+
);
46+
}
47+
48+
const dispose = render(() => <App />, container);
49+
return {
50+
container,
51+
run: () => run(),
52+
finish: () => finish(),
53+
dispose: () => {
54+
dispose();
55+
container.remove();
56+
}
57+
};
58+
}
59+
60+
describe("#3835 optimistic mount applies its bindings at the reveal", () => {
61+
for (const memo of [true, false])
62+
for (const dynamicText of [true, false])
63+
test(`memo=${memo} dynamicText=${dynamicText}`, async () => {
64+
const s = setup({ memo, dynamicText });
65+
flush();
66+
expect(s.container.innerHTML).toBe("");
67+
const p = s.run();
68+
flush();
69+
await tick();
70+
flush();
71+
const during = s.container.innerHTML;
72+
s.finish();
73+
await p;
74+
await tick();
75+
flush();
76+
const after = s.container.innerHTML;
77+
s.dispose();
78+
expect({ during, after }).toEqual({
79+
during: '<div style="color: red;">Hello</div>',
80+
after: dynamicText
81+
? '<div style="color: blue;">Hello world</div>'
82+
: '<div style="color: blue;">Hello</div>'
83+
});
84+
});
85+
});

0 commit comments

Comments
 (0)