Skip to content

Commit bb7f9b5

Browse files
ryansolidclaude
andauthored
fix(signals): a derived store's write in a lane pass is the lane's derivation (#4478)
* fix(signals): a derived store's write in a lane pass is the lane's derivation `createStore(d => { d.v = m() })` with `m = createMemo(() => 1 + latest(s))`. An action writes `s` and stays open: `m` is a verdict reader, so its pass runs in the action's verdict lane and shows the new value now (F-6, D-25). The derive reads `m`, so its pass is that lane's work too, but its leaf writes are plain signal writes: they were staged in the flush, which joined the action, and the store showed the old value until the action ended. A memo derived the same way publishes into the lane. The derive's write in a lane pass now becomes the lane's derivation on the leaf (its value the lane's, the committed value untouched beneath; the lane's end commits it). Found by the async-gen rerun on rc.20 (pair E3, rows #2 and #7). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): record the derived-store lane-write fix's sizes over next @ 7135a77 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): record the derived-store lane-write fix's sizes over next @ e49b0c7 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): the lane-write fix's sizes hold over next @ ab3d2ad Re-measured after merging next @ ab3d2ad: the same bytes; the ledger lines name the new base. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): gate the derived store's lane-pass write on the lane engine Store bundles without lanes pay 0 B: createStore and compiled CSR and hydrating drop their cap raises. The lane bundles re-record. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent edd3c44 commit bb7f9b5

4 files changed

Lines changed: 102 additions & 0 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+
`createStore(fn)` over a `latest()`-reading memo shows an action's value as the memo does: a derive pass that is a lane's work writes its leaves as that lane's derivation instead of staging them with the action.

‎packages/signals/src/store/store.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ import {
9393
insertSubs,
9494
joinFuture,
9595
joinPassTx,
96+
list,
97+
laneStageHook,
9698
passLane,
9799
queuePendingNode,
98100
schedule,
@@ -1880,6 +1882,21 @@ function pullFamily(target: StoreTarget): void {
18801882
* classification, as core reads it — `heldNotFinal`). */
18811883
function holdWithDerive(target: StoreTarget, node: Signal<any>): void {
18821884
const fw = target.fam?.node;
1885+
// A pass that is a lane's work (a display-ahead read, F-6): its write is
1886+
// the lane's derivation, as a memo's value would be (D-25).
1887+
if (
1888+
laneStageHook &&
1889+
passLane !== null &&
1890+
!userWrite &&
1891+
node._pendingValue !== NOT_PENDING &&
1892+
!(node._config & CONFIG_OVERRIDE)
1893+
) {
1894+
list(node, passLane);
1895+
node._x!._lane = node._pendingValue;
1896+
node._pendingValue = NOT_PENDING;
1897+
node._config |= CONFIG_OVERRIDE;
1898+
return;
1899+
}
18831900
if (
18841901
fw !== undefined &&
18851902
fw !== null &&
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { expect, it } from "vitest";
2+
import {
3+
action,
4+
createMemo,
5+
createRenderEffect,
6+
createRoot,
7+
createSignal,
8+
createStore,
9+
flush,
10+
latest
11+
} from "../src/index.js";
12+
13+
// A derived store over a display-ahead memo (`m = memo(1 + latest(s))`,
14+
// `d.v = m()`) reads like the memo (async-gen E3, D-25 / F-6). An action
15+
// writes `s` and stays open: `m` shows the action's value now (its verdict
16+
// lane), and so must `store.v` — the derive's pass is that lane's work, so
17+
// its write is the lane's derivation, not a staging held with the action.
18+
for (const kind of ["memo", "store"] as const)
19+
it(`${kind}: a derive over latest() shows the action's value now`, () => {
20+
const [s, setS] = createSignal(1);
21+
let shown: unknown;
22+
createRoot(() => {
23+
const m = createMemo(() => 1 + latest(s));
24+
let view: () => unknown = m;
25+
if (kind === "store") {
26+
const [st] = createStore<{ v?: number }>(d => {
27+
d.v = m();
28+
}, {});
29+
view = () => st.v;
30+
}
31+
createRenderEffect(view, v => {
32+
shown = v;
33+
});
34+
});
35+
flush();
36+
expect(shown).toBe(2);
37+
const act = action(function* (n: number) {
38+
setS(n);
39+
yield new Promise(() => {});
40+
});
41+
act(0);
42+
flush();
43+
expect(shown).toBe(1);
44+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
// async-gen rerun on rc.20, E3 (a derived store `createStore(d => { d.v = m() })`
5+
// reads like `m`): over a display-ahead memo (`m0 = memo(latest(s0))`), an
6+
// action's write shows through `m0` at once (its verdict lane, D-25 / F-6),
7+
// but the store's leaf was staged with the action and showed the old value
8+
// until the action ended. The derive's pass is the lane's work; its write is
9+
// now the lane's derivation.
10+
import { expect, test } from "vitest";
11+
import { runScenario } from "./run.js";
12+
13+
const cases: Record<string, any> = {
14+
// [s0=1 m0=memo(latest(s0))] <span split[m0()]></span> :: A(s0=0) t
15+
"an action's write shows through the store now": {
16+
signals: [1],
17+
memos: [{ async: false, deps: [{ src: { k: "s", i: 0 }, how: "latest" }], poison: null }],
18+
tree: { t: "leaf", text: [], attrs: [{ how: "plain", src: { k: "m", i: 0 } }], grouped: false },
19+
steps: [{ t: "action", s: 0, v: 0 }, { t: "task" }]
20+
},
21+
// [s0=3 m0=memo(latest(s0) !%4=1)] <span>m0()</span> :: A(s0=3) s0=2 t
22+
"a plain write beside an action shows through the store now": {
23+
signals: [3],
24+
memos: [{ async: false, deps: [{ src: { k: "s", i: 0 }, how: "latest" }], poison: 1 }],
25+
tree: { t: "leaf", text: [{ how: "plain", src: { k: "m", i: 0 } }], attrs: [], grouped: true },
26+
steps: [{ t: "action", s: 0, v: 3 }, { t: "write", s: 0, v: 2 }, { t: "task" }]
27+
}
28+
};
29+
30+
for (const [name, sc] of Object.entries(cases))
31+
test(`E3: ${name}`, async () => {
32+
const memo = await runScenario(sc, {});
33+
const store = await runScenario(sc, { store: true });
34+
expect(store.screens).toEqual(memo.screens);
35+
expect(store.final).toBe(memo.final);
36+
});

0 commit comments

Comments
 (0)