Skip to content

Commit a3d1828

Browse files
ryansolidClaude via Cursor
andcommitted
fix(signals): store backing paths record the stale reader's replay (Rule 1, backing-level form)
Step 3 of DESIGN-CONSOLIDATION move 3b. The stale-of-foreign clause has two halves — serve committed, and record the reader for replay at the hold's commit (A15 / A26, _gatedSubs). Core heldFromStale does both; the store's backing-level twins (heldFromReader for a key with no node, readSource's adoption-hold view for a reconcile inside an action) did only the first. A render effect whose untracked read hit either stayed on the pre-action value after the action settled. The registration is now one exported helper, recordStaleReplay(txn, c), called by heldFromStale and by the store's two backing sites (staleReplay: reader in context, not children-forbidden — the same gate core applies before it reaches heldFromStale). Pins: posture-store-parity S4 grows to the four store shapes (fold hold × adoption hold × with/without a node) beside the signal; all four fail on next, the it.fails from step 2 flips to a pass. Gate: suite green; oracles and the 621-cell posture matrix byte-identical to next; +31 B minified core (the helper), +123 B minified store (the fix); three brotli caps ratcheted with notes. Co-authored-by: Claude via Cursor <[email protected]>
1 parent cfd4dc0 commit a3d1828

6 files changed

Lines changed: 96 additions & 14 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 render effect's untracked read of a store key held by a foreign action — a key with no node, or a `reconcile` adoption held by the action — is now recorded for replay at the action's commit, as the signal path always was. Previously the store's backing-level selection served the committed value but skipped the registration, so the effect stayed on the pre-action value after the action settled. One registration (`recordStaleReplay`) is shared by the node path and the store's backing paths.

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

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

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,12 +1557,22 @@ export function installAuthoritativeRead(): void {
15571557
* also pending on an upstream re-ask blocks through that flight until it
15581558
* lands, and its landing re-runs the reader into the normal path.
15591559
*/
1560+
/** The replay half of the stale-of-foreign clause (A15 / A26): a stale reader
1561+
* served the committed value because `txn` holds what it read re-runs at
1562+
* txn's commit, when the value it was denied becomes the frame — unless its
1563+
* own last value already came from that transaction. One registration for
1564+
* the node path (heldFromStale) and the store's backing paths, which have
1565+
* no node to carry the hold (heldFromReader, the adoption hold view). */
1566+
export function recordStaleReplay(txn: Transition, c: Computed<any>): void {
1567+
const vt: Transition | null | undefined = (c as any)._valueTransition;
1568+
if (vt == null || currentTransition(vt) !== txn) txn._gatedSubs.add(c);
1569+
}
1570+
15601571
function heldFromStale(el: Signal<any> | Computed<any>, c: Computed<any>): boolean {
15611572
const t = el._transition;
15621573
if (t === null || t === activeTransition) return false;
15631574
const txn = currentTransition(t);
1564-
const vt: Transition | null | undefined = (c as any)._valueTransition;
1565-
if (vt == null || currentTransition(vt) !== txn) txn._gatedSubs.add(c);
1575+
recordStaleReplay(txn, c);
15661576
const reporters = txn._asyncReporters.get(el as Computed<any>);
15671577
if (reporters) reporters.add(c);
15681578
else if ((el as Computed<any>)._statusFlags & STATUS_PENDING)

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
hasActiveOverride,
4040
visibleOverride,
4141
readerSeesCommitted,
42+
recordStaleReplay,
4243
prepareComputed,
4344
read as readNode,
4445
READ_SLOW,
@@ -408,7 +409,19 @@ function heldFoldTransition(target: StoreNextTarget): Transition | null {
408409
function heldFromReader(target: StoreNextTarget): boolean {
409410
if (!stale && inOwnerContext()) return false;
410411
const txn = liveFoldTransition(target);
411-
return txn !== null && foreignHold(txn);
412+
return txn !== null && foreignHold(txn) && (staleReplay(txn), true);
413+
}
414+
415+
/** The replay half of the clause (core recordStaleReplay): the stale reader
416+
* just denied the held value re-runs at the hold's commit. Without it the
417+
* node path replayed (heldFromStale) and the backing paths did not — an
418+
* effect's untracked read of a key with no node stayed on the pre-action
419+
* value after the action settled (posture-store-parity S4). Only a reader in
420+
* context has a pass to replay; a children-forbidden reader sees the frame
421+
* and never the graph (A32). */
422+
function staleReplay(txn: Transition): void {
423+
const c = readerContext();
424+
if (c !== null && !(c._config & CONFIG_CHILDREN_FORBIDDEN)) recordStaleReplay(txn, c);
412425
}
413426

414427
/** Core read()'s `activeTransition !== el._transition`: a hold belongs to a
@@ -1668,7 +1681,13 @@ function readSource(target: StoreNextTarget): Record<PropertyKey, any> {
16681681
(stale && target.ht !== PLAIN_HOLD && foreignHold(currentTransition(target.ht))))
16691682
) {
16701683
const hv = heldMaskView(target);
1671-
if (hv !== null) return hv;
1684+
if (hv !== null) {
1685+
// The reader denied the adopted view replays at the adoption's commit
1686+
// (the replay half of the clause; a latest()-pull PLAIN_HOLD is not a
1687+
// transaction and has no commit).
1688+
if (target.ht !== PLAIN_HOLD) staleReplay(currentTransition(target.ht as Transition));
1689+
return hv;
1690+
}
16721691
}
16731692
return pendingBackingVisible(target, false) ? target.pb! : target.v;
16741693
}

‎packages/signals/tests/posture-store-parity.test.ts‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
flush,
3939
isPending,
4040
latest,
41+
reconcile,
4142
untrack
4243
} from "../src/index.js";
4344

@@ -208,10 +209,9 @@ describe("S4 — a stale reader's untracked read of a foreign hold replays at th
208209
expect(r.log).toEqual([0, 0, 1]);
209210
});
210211
// The backing twin (pendingBackingVisible / heldFromReader) serves the key
211-
// with no node the same committed value but has no node to record the
212-
// reader on — the effect never replays. Rule 1's backing-level form is an
213-
// open item of DESIGN-CONSOLIDATION move 3b (step 3).
214-
it.fails("store leaf WITHOUT a node: the same replay (backing twin gap)", async () => {
212+
// with no node the same committed value; it records the reader on the
213+
// holding transaction directly (staleReplay → core recordStaleReplay).
214+
it("store leaf WITHOUT a node: the same replay (backing twin)", async () => {
215215
const [s, setS] = createStore({ n: 0 });
216216
let release!: () => void;
217217
const r = untrackedStaleReplay(
@@ -229,4 +229,34 @@ describe("S4 — a stale reader's untracked read of a foreign hold replays at th
229229
await settle();
230230
expect(r.log).toEqual([0, 0, 1]);
231231
});
232+
// The other hold kind: an adoption (reconcile inside an action) holds at
233+
// the backing (`ht`, #3074) — the held view is served to the stale reader
234+
// by readSource, and the same replay is recorded there.
235+
for (const withNode of [false, true]) {
236+
it(`store reconcile held by a live action, ${withNode ? "with" : "without"} a node: the same replay`, async () => {
237+
const [s, setS] = createStore({ n: 0 });
238+
if (withNode) {
239+
createRoot(() =>
240+
createRenderEffect(
241+
() => s.n,
242+
() => {}
243+
)
244+
);
245+
flush();
246+
}
247+
let release!: () => void;
248+
const r = untrackedStaleReplay(
249+
() => s.n,
250+
() =>
251+
action(function* () {
252+
setS(reconcile({ n: 1 }));
253+
yield new Promise<void>(res => (release = res));
254+
})(),
255+
() => release()
256+
);
257+
expect(r.held).toEqual([0, 0]);
258+
await settle();
259+
expect(r.log).toEqual([0, 0, 1]);
260+
});
261+
}
232262
});

‎scripts/size/.size-limit.js‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,13 @@ module.exports = [
542542
// pure-signals fixtures -4 / -29 / -5 B. This scenario's esbuild bundle
543543
// measured at 16,509 B against `next`'s 16,495 — compressor layout, the
544544
// deltas across the ten scenarios run -19…+45 B in both directions.
545-
limit: "16.55 KB",
545+
// Stale-reader replay at the backing (move 3b step 3, 2026-09-17): a
546+
// render effect's untracked read of a store key held by a foreign action
547+
// — no node, or an adoption hold — is recorded for replay at the commit
548+
// as the signal path always was (core recordStaleReplay, shared with
549+
// heldFromStale). +31 B minified core, +123 B minified store (the fix,
550+
// posture-store-parity S4); measured at 16,580 B.
551+
limit: "16.60 KB",
546552
modifyEsbuildConfig
547553
},
548554
{
@@ -925,7 +931,13 @@ module.exports = [
925931
// pure-signals fixtures -4 / -29 / -5 B. This scenario's esbuild bundle
926932
// measured at 19,894 B against `next`'s 19,849 — compressor layout, the
927933
// deltas across the ten scenarios run -19…+45 B in both directions.
928-
limit: "19.90 KB",
934+
// Stale-reader replay at the backing (move 3b step 3, 2026-09-17): a
935+
// render effect's untracked read of a store key held by a foreign action
936+
// — no node, or an adoption hold — is recorded for replay at the commit
937+
// as the signal path always was (core recordStaleReplay, shared with
938+
// heldFromStale). +31 B minified core, +123 B minified store (the fix,
939+
// posture-store-parity S4); measured at 19,902 B.
940+
limit: "19.95 KB",
929941
modifyEsbuildConfig
930942
},
931943
{
@@ -1112,7 +1124,13 @@ module.exports = [
11121124
// A projection's leaf companions die with it; latest() of a dead leaf creates
11131125
// none (spec O5, 2026-09-16): 29,953 B (+43 over the cap); +104 B minified in
11141126
// owner.ts (core floor), the shadow retirement lives in verdict.ts.
1115-
limit: "30.00 KB",
1127+
// Stale-reader replay at the backing (move 3b step 3, 2026-09-17): a
1128+
// render effect's untracked read of a store key held by a foreign action
1129+
// — no node, or an adoption hold — is recorded for replay at the commit
1130+
// as the signal path always was (core recordStaleReplay, shared with
1131+
// heldFromStale). +31 B minified core, +123 B minified store (the fix,
1132+
// posture-store-parity S4); measured at 30,034 B.
1133+
limit: "30.05 KB",
11161134
modifyEsbuildConfig
11171135
},
11181136
{

0 commit comments

Comments
 (0)