Skip to content

Commit 2234098

Browse files
committed
Merge remote-tracking branch 'origin/next' into claude/project-thread-x1ore2-4502
2 parents db0d9dd + 6af149e commit 2234098

9 files changed

Lines changed: 260 additions & 4 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)`: a derive that went pending on a source and was settled without re-running (a staged rejection, or a re-ask that returned to the committed question) settles its readers with it, as a memo's would: `isPending` ends and a refetch's rejection reaches them.

‎.changeset/equals-netting-4483.md‎

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 write that a custom `equals` calls equal to the committed value now nets to it (D-8) while another write to the signal is staged, so it pends nothing (#4483).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
5353
| A6 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:361` | boundaries.ts×2 | derived-write-then-derivation-3733.test.ts×1 enforceLoadingBoundary.test.ts×1 | [ruled] `ASYNC_OUTSIDE_LOADING_BOUNDARY` is warn-only — `ASYNC_OUTSIDE_LOADING_BOUNDARY` is a warn-only diagnostic; an `Errored` above must not swallow it and must not show its fallback for a pending. |
5454
| A7 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:167` | seat.ts×1 truth.ts×1 verdict.ts×1 | fuzz-findings-l2.test.ts×1 latest-uninitialized-over-latest-4362.test.ts×2 spec-async-semantics.test.ts×2 visibility-oracle-store.states.ts×1 visibility-oracle.states.ts×1 visibility-oracle.test.ts×1 | [ruled, amended in place] Resolved async never reads `[false, undefined]` — After an async memo resolves, `[isPending(x), latest(x)]` is `[false, resolvedValue]` — never `[false, undefined]`. **Amende… |
5555
| A8 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:175` | — | create-deferred-3710.test.ts×1 createMemo.test.ts×1 visibility-oracle-store.states.ts×1 visibility-oracle.states.ts×2 | [ruled, amended in place 2026-07-07] `isPending(() => latest(x))` follows `x`'s own async only — verdicts are per-channel — (**re-ruled 2026-07-07c** — was "tracks the transition the same as `isPendin… |
56-
| A9 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:183` | projection.ts×1 target.ts×1 | spec-async-semantics.test.ts×3 visibility-oracle-store.states.ts×4 visibility-oracle-store.test.ts×1 | [ruled, amended in place 2026-07-07] Store leaves behind a firewall report the firewall's new-question refetch — `isPending` on a store leaf behind a firewall reports the firewall's refetch like any a… |
56+
| A9 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:183` | async.ts×1 projection.ts×1 target.ts×1 | spec-async-semantics.test.ts×3 visibility-oracle-store.states.ts×4 visibility-oracle-store.test.ts×1 | [ruled, amended in place 2026-07-07] Store leaves behind a firewall report the firewall's new-question refetch — `isPending` on a store leaf behind a firewall reports the firewall's refetch like any a… |
5757
| A10 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:191` | async.ts×1 core.ts×3 lanes.ts×1 scheduler.ts×1 seat.ts×1 verdict.ts×3 | boundary-not-born-held-3540.test.ts×1 createMemo.test.ts×1 error-staged-recovery.test.ts×1 fuzz-findings-l2.test.ts×1 ispending-memo-unstamped-hold-3457.test.ts×2 latest-isPending-consistency.test.ts×3 latest-uninitialized-over-latest-4362.test.ts×1 verdict-contract.test.ts×2 verdict-memo-flight-no-reask.test.ts×1 | [ruled] `[isPending(x), x()]` is atomic within one scope — `[isPending(x), x()]` read in one scope is atomic: a reader that observed the fresh value must not see `pending === true` for it. |
5858
| A11 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:103` | — | latest-isPending-consistency.test.ts×1 loading-fallback-in-flush-3540.test.ts×2 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×1 | [ruled] Sync derivations of held sources are visible through `latest()`/`isPending()` — Sync derivations of transition-held sources are visible through `latest()`/`isPending()` (held sync recompute is… |
5959
| A12 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:199` | — | createOptimistic.test.ts×2 spec-async-semantics.test.ts×1 | [ruled, amended in place] Resting optimistic nodes report pending like a plain memo — A resting optimistic node reports pending via exactly the causes a plain async memo does (A19) — a reverting optim… |

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ import {
4949
freshHook,
5050
holdWorkHook,
5151
guessing,
52-
laneStageHook
52+
laneStageHook,
53+
storeParkHook
5354
} from "./scheduler.js";
5455
import type { Computed, Link, Owner } from "./types.js";
5556

@@ -377,6 +378,11 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
377378
enqueueSub(node);
378379
scheduled = true;
379380
}
381+
// A derived store's derive pending by propagation (its pass not re-run):
382+
// its readers wait on the derive itself, not on this source, so they
383+
// settle with it, as a memo's would through its dependents (F-9, A9).
384+
// Only a store build has one (`storeParkHook`).
385+
else if (storeParkHook) (node as any).fam?.st();
380386
if (node._x !== null) node._x._blocked = false;
381387
// Fully settled with nobody watching: release candidate (#2934). Checked
382388
// again at release time — deferred so unobserved() can't unlink subs

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,10 +2543,17 @@ export function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T
25432543
// user comparator must not run against `undefined` (matches recompute).
25442544
// D-41: a write over a shown error is a change whatever the last good
25452545
// value was — the error leaves at its commit (`commitPendingNode`).
2546+
// `custom`: with the verdict engine, whether `el` carries a comparator of
2547+
// its own — `isSame`'s fast-path test, taken once for this gate and D-8's
2548+
// netting below, so the default comparator's `===` runs inline and a
2549+
// rewrite loop pays nothing for the netting (CodSpeed `propagation:
2550+
// avoidable`). Without the engine it is `null`: the gate folds to the
2551+
// plain `isSame` call and the netting away, byte for byte as before.
2552+
const custom = observeFlightHook ? el._equals !== isEqual : null;
25462553
const valueChanged =
25472554
!!((el as Computed<T>)._statusFlags & STATUS_UNINITIALIZED) ||
25482555
!!el._x?._shownError ||
2549-
!isSame(el, currentValue, v);
2556+
(custom === false ? currentValue !== v : !isSame(el, currentValue, v));
25502557
if (!valueChanged) return v;
25512558

25522559
// Attribution hook: this committed write is where a re-run chain begins.
@@ -2568,7 +2575,22 @@ export function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T
25682575
// A28: a held node rewritten outside a flush keeps its flushed staging
25692576
// for every reader until the flush that carries the rewrite.
25702577
else if (el._config & CONFIG_HELD && !globalQueue._running) stashFlushed(el);
2571-
el._pendingValue = v;
2578+
// D-8 (#4483): a staged rewrite the comparator calls equal to the
2579+
// committed value nets to it; staging the committed value itself lets
2580+
// every netted test (`_pendingValue === _value`) see writes that made no
2581+
// proposal. (Unstaged, the gate above already compared it.)
2582+
// The netted test reads it only with the verdict engine (`isPending`,
2583+
// `latest`): a build without it stages `v` as written. Under the default
2584+
// comparator only the committed object itself is equal, and `v` is already
2585+
// it, so a rewrite loop pays one local test (`custom`, from the gate).
2586+
// (`custom` is truthy only with the engine installed.)
2587+
el._pendingValue =
2588+
custom &&
2589+
wasStaged &&
2590+
!((el as Computed<T>)._statusFlags & STATUS_UNINITIALIZED || el._x?._shownError) &&
2591+
isSame(el, el._value, v)
2592+
? el._value
2593+
: v;
25722594
// A28 arm, gated on the load the write already pays for (`context`); the
25732595
// arm itself is a cold helper so setSignal stays within every setter's
25742596
// inlining budget, ~300 B bytecode.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ function settleFamily(fam: StoreFamily): void {
214214
* pass's own throw. */
215215
function familyStatus(this: StoreFamily, status: number, error?: unknown): void {
216216
if (status & STATUS_PENDING) wakeFamily(this);
217+
// No status: the source's settle walk retired the derive's pending, its
218+
// pass not re-run (core `settlePendingSource`) — the readers waiting on the
219+
// derive settle with it (F-9). A re-run would ask again: an async derive's
220+
// new flight is a second wait, and would run ahead of a staged rejection's
221+
// publish, which reaches the derive at the commit (F-12, D-41).
222+
else if (!status) settleFamily(this);
217223
// The error rides along: a reader the derive's own pass already handed it
218224
// (a sync derive re-run in the same flush) is not handed it again.
219225
else if (status & STATUS_ERROR) errorFamily(this, error);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { expect, it } from "vitest";
2+
import {
3+
createErrorBoundary,
4+
createLoadingBoundary,
5+
createMemo,
6+
createRenderEffect,
7+
createRoot,
8+
createSignal,
9+
createStore,
10+
flush
11+
} from "../src/index.js";
12+
13+
// A derived store over an async memo (`d.v = m()`) reads like the memo
14+
// (async-gen E3). The derive went pending on the memo's flight, and the
15+
// flight settled without the derive re-running: the settle retired the memo
16+
// from the derive, and now settles the store's readers with it, as a memo's
17+
// readers settle through its dependents — not by re-running the derive,
18+
// whose new flight would be a second wait (F-9; #4463's error-once test)
19+
// (F-12: a rejection staged in the transaction lands; its isPending twin,
20+
// F-9, is pinned in web's async-gen store-derive-settle-e3.spec.ts).
21+
const micro = () => Promise.resolve();
22+
const drain = async () => {
23+
for (let i = 0; i < 4; i++) {
24+
for (let j = 0; j < 6; j++) await micro();
25+
flush();
26+
await new Promise(r => setTimeout(r, 0));
27+
}
28+
flush();
29+
};
30+
31+
function app(
32+
kind: "memo" | "store",
33+
init: number,
34+
poison: number | null,
35+
leaf: (v: () => any) => string
36+
) {
37+
const flights: (() => void)[] = [];
38+
const [s, setS] = createSignal(init);
39+
let screen = "";
40+
const dispose = createRoot(d => {
41+
const m = createMemo(() => {
42+
const v = s() + 1;
43+
return new Promise<number>((res, rej) =>
44+
flights.push(() => (v % 4 === poison ? rej(new Error(`m0:${v}`)) : res(v)))
45+
);
46+
});
47+
let view: () => any = m;
48+
if (kind === "store") {
49+
const [st] = createStore<{ v?: number }>(d => {
50+
d.v = m();
51+
}, {});
52+
view = () => st.v;
53+
}
54+
const b = createErrorBoundary(
55+
() =>
56+
createLoadingBoundary(
57+
() => createMemo(() => leaf(view)),
58+
() => "[L]"
59+
),
60+
() => "[E]"
61+
);
62+
createRenderEffect(
63+
() => {
64+
const r: any = b();
65+
return typeof r === "function" ? r() : r;
66+
},
67+
v => {
68+
screen = String(v);
69+
}
70+
);
71+
return d;
72+
});
73+
flush();
74+
const settleAll = async () => {
75+
await drain();
76+
while (flights.length) {
77+
flights.shift()!();
78+
await drain();
79+
}
80+
};
81+
return { flights, setS, settleAll, screen: () => screen, dispose };
82+
}
83+
84+
for (const kind of ["memo", "store"] as const) {
85+
it(`${kind}: a refetch's rejection, asked in the first answer's flush, shows the error`, async () => {
86+
const a = app(kind, 2, 1, v => `v${v()}`);
87+
a.flights.shift()!();
88+
await micro();
89+
a.setS(0);
90+
await a.settleAll();
91+
expect(a.screen()).toBe("[E]");
92+
a.dispose();
93+
});
94+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// #4483 (D-8: a tick whose writes net to the slot's committed value made no
2+
// proposal). An action rewrites a signal back to its committed value while a
3+
// mainline write to it is still staged. Under a custom `equals`, a new object
4+
// the comparator calls equal nets exactly like the committed object itself:
5+
// the slot pends nothing, so `isPending` of a memo over it stays `false`.
6+
// Without a custom `equals`, only identity nets; a new object is a proposal.
7+
import { afterEach, describe, expect, it } from "vitest";
8+
import {
9+
action,
10+
createMemo,
11+
createRenderEffect,
12+
createRoot,
13+
createSignal,
14+
flush,
15+
isPending,
16+
resetErrorHalt
17+
} from "../src/index.js";
18+
19+
afterEach(() => resetErrorHalt());
20+
const tick = async () => {
21+
await new Promise(r => setTimeout(r, 0));
22+
flush();
23+
};
24+
25+
const run = async (custom: boolean, write: "committed" | "copy") => {
26+
const one = { k: 1 };
27+
const [s, setS] = createSignal(one, custom ? { equals: (a, b) => a.k === b.k } : undefined);
28+
const seen: boolean[] = [];
29+
const dispose = createRoot(d => {
30+
const m0 = createMemo(() => {
31+
const v = s().k + 1;
32+
if (v % 4 === 2) throw new Error(`m0:${v}`);
33+
return v;
34+
});
35+
createRenderEffect(
36+
() => isPending(m0),
37+
v => void seen.push(v)
38+
);
39+
return d;
40+
});
41+
flush();
42+
const act = action(function* () {
43+
setS(write === "committed" ? one : { k: 1 });
44+
yield new Promise(() => {});
45+
});
46+
setS({ k: 2 });
47+
act();
48+
await tick();
49+
dispose();
50+
return seen;
51+
};
52+
53+
describe("#4483: writes that net under a custom equals pend nothing (D-8)", () => {
54+
it("nets the committed object itself (identity)", async () => {
55+
expect(await run(true, "committed")).toEqual([false]);
56+
});
57+
58+
it("nets a new object the comparator calls equal", async () => {
59+
expect(await run(true, "copy")).toEqual([false]);
60+
});
61+
62+
it("without a custom equals, nets only the committed object", async () => {
63+
expect(await run(false, "committed")).toEqual([false]);
64+
expect(await run(false, "copy")).toEqual([false, true]);
65+
});
66+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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`): two liveness failures with one cause. The derive went
6+
// pending on m0's flight; the flight then settled (a rejection staged in its
7+
// transaction, or a re-ask that returned to the committed question) without
8+
// the derive re-running. The settle retired m0 from the derive, but the
9+
// store's readers wait on the derive itself (projection.ts `wakeFamily`), and
10+
// nothing retired that: `isPending` stayed true forever (F-9), and the staged
11+
// rejection's transaction never landed, so the error never showed (F-12). The
12+
// settle walk now settles the family with the derive (core
13+
// `settlePendingSource` -> projection.ts `familyStatus`), as a memo's
14+
// readers settle through its dependents.
15+
import { expect, test } from "vitest";
16+
import { runScenario } from "./run.js";
17+
18+
const cases: Record<string, any> = {
19+
// [s0=2 m0=async(s0)] <span fx[m0()]>isPending(m0)</span> :: S5 m A(s0=0) s0=2
20+
"isPending settles when the re-ask nets to the committed question": {
21+
signals: [2],
22+
memos: [{ async: true, deps: [{ src: { k: "s", i: 0 }, how: "plain" }], poison: null }],
23+
tree: {
24+
t: "leaf",
25+
text: [{ how: "pending", src: { k: "m", i: 0 } }],
26+
attrs: [{ how: "plain", src: { k: "m", i: 0 } }],
27+
grouped: true
28+
},
29+
steps: [
30+
{ t: "settle", pick: 5 },
31+
{ t: "micro" },
32+
{ t: "action", s: 0, v: 0 },
33+
{ t: "write", s: 0, v: 2 }
34+
]
35+
},
36+
// [s0=2 s1=2 m0=async(s1 !%4=1)] <span>m0()</span> :: S4 m s1=0
37+
"a refetch's rejection reaches the store's readers": {
38+
signals: [2, 2],
39+
memos: [{ async: true, deps: [{ src: { k: "s", i: 1 }, how: "plain" }], poison: 1 }],
40+
tree: { t: "leaf", text: [{ how: "plain", src: { k: "m", i: 0 } }], attrs: [], grouped: true },
41+
steps: [{ t: "settle", pick: 4 }, { t: "micro" }, { t: "write", s: 1, v: 0 }]
42+
}
43+
};
44+
45+
for (const [name, sc] of Object.entries(cases))
46+
test(`E3: ${name}`, async () => {
47+
const memo = await runScenario(sc, {});
48+
const store = await runScenario(sc, { store: true });
49+
expect(store.screens).toEqual(memo.screens);
50+
expect(store.final).toBe(memo.final);
51+
expect(store.findings).toEqual([]);
52+
});

0 commit comments

Comments
 (0)