Skip to content

Commit 709c02b

Browse files
2wheehryansolidClaude via Cursor
authored
fix(signals): release held writes after synchronous settlement (#3577)
* fix(signals): release held writes after synchronous settlement * chore(size): CSR cap 15.70 -> 15.75 KB for the sync-supersede wake (#3577) Measured 15,725 B against next's 15,686 (+39 B): one wakeParked() call on recompute's #3181 sync-settle branch; the rest is brotli layout. Co-authored-by: Claude via Cursor <[email protected]> --------- Co-authored-by: Ryan Carniato <[email protected]> Co-authored-by: Claude via Cursor <[email protected]>
1 parent d6b82d4 commit 709c02b

4 files changed

Lines changed: 91 additions & 3 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+
Fix effect writes remaining held when a pending memo is superseded by a synchronous result equal to its cached value. Recheck parked transactions after the source settles synchronously, since the superseded promise can no longer release them when it resolves.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,13 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
759759
// #3181: a synchronous settle supersedes the old landing callback, so
760760
// recompute owns its pending-source sweep. An uninitialized node without
761761
// a replacement source still has no truth to reveal and must stay parked.
762-
if (wasPendingSource && !(el._statusFlags & (STATUS_PENDING | STATUS_UNINITIALIZED)))
762+
if (wasPendingSource && !(el._statusFlags & (STATUS_PENDING | STATUS_UNINITIALIZED))) {
763763
settlePendingSource(el);
764+
// The superseded flight will not enter its waiting transactions at
765+
// landing. Recheck them now so an unchanged value cannot leave their
766+
// writes parked after the last pending source has settled.
767+
wakeParked();
768+
}
764769
}
765770
// A REPORTER whose pass stopped reading a source it reported on (a gate
766771
// closed) stops counting for the transaction waiting on it (A15 / #3426:

‎packages/signals/tests/late-pending-equality.test.ts‎

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,87 @@
11
import { expect, it } from "vitest";
22
import {
3+
createEffect,
34
createMemo,
45
createProjection,
56
createRenderEffect,
67
createRoot,
78
createSignal,
89
flush,
9-
isPending
10+
isPending,
11+
onCleanup,
12+
untrack
1013
} from "../src/index.js";
1114

15+
it("commits an effect write when a pending source is superseded with its cached value", async () => {
16+
const gate = Promise.withResolvers<number>();
17+
let flight: Promise<number> | undefined = gate.promise;
18+
let notify = () => {};
19+
let mount!: () => void;
20+
let readDerived!: () => number;
21+
let direct = -1;
22+
let displayedDerived = -1;
23+
const applied: number[] = [];
24+
const dispose = createRoot(dispose => {
25+
const [mounted, setMounted] = createSignal(false);
26+
mount = () => setMounted(true);
27+
createMemo(() => {
28+
if (!mounted()) {
29+
// Disposing the previous branch invalidates the new reader after
30+
// its first cached read, making it observe the pending flight.
31+
onCleanup(() => notify());
32+
return;
33+
}
34+
const [version, setVersion] = createSignal(0, { ownedWrite: true });
35+
notify = () => setVersion(value => value + 1);
36+
const data = createMemo(previous => {
37+
version();
38+
return flight && previous !== undefined ? flight : 1;
39+
});
40+
const [derived, setDerived] = createSignal(0);
41+
readDerived = () => untrack(derived);
42+
createEffect(data, value => {
43+
applied.push(value);
44+
setDerived(value);
45+
});
46+
createRenderEffect(data, value => {
47+
direct = value;
48+
});
49+
createRenderEffect(derived, value => {
50+
displayedDerived = value;
51+
});
52+
});
53+
return dispose;
54+
});
55+
try {
56+
flush();
57+
mount();
58+
flush();
59+
expect(applied).toEqual([1]);
60+
expect(readDerived()).toBe(0);
61+
expect(displayedDerived).toBe(0);
62+
flight = undefined;
63+
notify();
64+
flush();
65+
// Superseding the flight releases the write without waiting for its
66+
// abandoned promise to resolve.
67+
expect(applied).toEqual([1]);
68+
expect(direct).toBe(1);
69+
expect(readDerived()).toBe(1);
70+
expect(displayedDerived).toBe(1);
71+
gate.resolve(1);
72+
await Promise.resolve();
73+
await Promise.resolve();
74+
flush();
75+
expect(applied).toEqual([1]);
76+
expect(direct).toBe(1);
77+
expect(readDerived()).toBe(1);
78+
expect(displayedDerived).toBe(1);
79+
} finally {
80+
dispose();
81+
flush();
82+
}
83+
});
84+
1285
it("wakes a late reader when a conditional drops a pending source with an equal value", async () => {
1386
const gate = Promise.withResolvers<{ enabled: boolean }>();
1487
let start!: () => void;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,12 @@ module.exports = [
14901490
// source-settled predicate is `_settled` (shared with the DEV sweep,
14911491
// whose stub and flag are the only DEV bytes left in prod). Solid:
14921492
// `<Errored on>` is gone.
1493-
limit: "15.70 KB",
1493+
// Sync supersede wakes parked transactions (#3577, 2026-09-22): 15.70 ->
1494+
// 15.75 KB, measured at 15,725 B against `next`'s 15,686 (+39 B). One
1495+
// `wakeParked()` call on recompute's #3181 sync-settle branch (~15 B
1496+
// minified); the rest is brotli layout. The other scenarios stayed
1497+
// within their caps.
1498+
limit: "15.75 KB",
14941499
modifyEsbuildConfig
14951500
},
14961501
{

0 commit comments

Comments
 (0)