Skip to content

Commit 1c14992

Browse files
fix(signals): an external source echo satisfies until after await (#3898) (#3937)
* fix(signals): an external source echo satisfies until after await (#3898) Co-authored-by: Cursor <[email protected]> * size: record the measured caps for the live echo (#3898) CI measured the content compare at 9,680 B, 29,238 B, 25,245 B, and 41,019 B brotli. Those caps match the measurement, rounded up to 0.01 KB. Co-authored-by: Cursor <[email protected]> * size: record stacked caps for the live echo (#3898) Measured on next after the loading-wake landing. Caps match that brotli size, rounded up to 0.01 KB. Hello world stays under 10KB. Co-authored-by: Cursor <[email protected]> * size: record stacked caps for the live echo (#3898) Measured on next after the superseded-verdict landing. Caps match that brotli size, rounded up to 0.01 KB. Hello world stays under 10KB. Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Cursor <[email protected]>
1 parent f6905dc commit 1c14992

6 files changed

Lines changed: 109 additions & 7 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+
An async-generator action's `until` resolves when an external source echoes the optimistic row after `await`, instead of timing out on an acknowledgement the source already contains.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,33 @@ export function laneStage(
378378
* covered (no landing beneath it) — `optimisticReverted`'s "reverted". */
379379
let reverting = false;
380380

381+
/** Plain data with the same contents: an optimistic row and the source
382+
* object that echoes it. Not reference equality. A throw (a cycle, a
383+
* throwing accessor) is not a match, so that landing stays a correction. */
384+
function sameContents(a: unknown, b: unknown): boolean {
385+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) return false;
386+
try {
387+
return JSON.stringify(a) === JSON.stringify(b);
388+
} catch {
389+
return false;
390+
}
391+
}
392+
381393
export function supersede(n: Signal<any> | Computed<any>, value: unknown, changed: boolean): void {
382394
const l = txOf(n);
383395
// Resolved: the parent may have merged into another transaction since the
384396
// lane opened (two actions guessing one slot entangle, A34 (1)) — the
385397
// truth is held by the transaction that lands, not the merged-away one.
386398
const parent = resolveTx(l._parent ?? l);
399+
// A different object with the same plain contents is the guess's echo, not
400+
// a correction (#3898). Reference inequality dissolved the lane and held
401+
// the echo under the open action, so a mainline `until` (after `await`)
402+
// dropped a source that already contained the acknowledgement. Confirming
403+
// stages the truth beneath the guess: the screen keeps the guess, and an
404+
// authoritative reader sees the echo without the pass joining the hold.
405+
// A real content change still corrects. A held broadcast of a different row
406+
// (#3482) is not this landing.
407+
if (changed && sameContents(n._x!._lane, value)) changed = false;
387408
if (changed) {
388409
// Observe: a displayed guess is being replaced by a differing truth — a
389410
// landing's (superseded), or the value it covered (reverted: the body

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ function rowSame(a: any, b: any, keyFn: ((item: any) => any) | null): boolean {
200200
if (keyFn === null || !isWrappable(a) || !isWrappable(b)) return false;
201201
const ka = keyFn(unwrapValue(a));
202202
const kb = keyFn(unwrapValue(b));
203+
// Keyless rows are identified by position — reconcile's fallback when the
204+
// key is missing. The caller already paired these by index, so two keyless
205+
// rows are the same row and the landing confirms the arrangement instead of
206+
// dissolving it. Dissolving held an external echo under the action, and a
207+
// mainline `until` then timed out on a source that already contained it
208+
// (#3898). Keyed rows still match only on the key.
209+
if (ka === undefined && kb === undefined) return true;
203210
return ka !== undefined && sameKey(ka, kb);
204211
}
205212

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* #3898 — an async-generator action times out waiting for a live
3+
* acknowledgement even after the authoritative source, updated from outside
4+
* the action, already contains that acknowledgement.
5+
*
6+
* Distinct from #3482 (`direct-commit-readers-posture.test.ts`). There the
7+
* confirming frame is broadcast only under the action's own hold, and a
8+
* mainline `until()` (no bare `yield` after `await`) is born held and must
9+
* time out. Here the source signal is written from outside the action to the
10+
* same client id the optimistic draft already pushed. That echo is
11+
* authoritative truth, and `until()` must resolve. A bare `yield` after
12+
* `await` is not required for this echo.
13+
*/
14+
import { expect, test } from "vitest";
15+
import {
16+
action,
17+
createOptimisticStore,
18+
createRoot,
19+
createSignal,
20+
flush,
21+
until
22+
} from "../src/index.js";
23+
24+
test("external source echo satisfies until after await in an async-generator action (#3898)", async () => {
25+
const [source, setSource] = createSignal<{ clientId: string }[]>([]);
26+
let rows!: { clientId: string }[];
27+
let setRows!: (fn: (draft: { clientId: string }[]) => void) => void;
28+
let dispose!: () => void;
29+
30+
createRoot(d => {
31+
dispose = d;
32+
const [r, setR] = createOptimisticStore<{ clientId: string }[]>(() => source(), []);
33+
rows = r;
34+
setRows = setR;
35+
});
36+
37+
const save = action(async function* () {
38+
setRows(draft => {
39+
draft.push({ clientId: "c1" });
40+
});
41+
await 0; // continuation resumes outside the action context
42+
yield until(() => rows.some(row => row.clientId === "c1"), { timeout: 100 });
43+
});
44+
45+
const done = save().then(
46+
() => "confirmed" as const,
47+
(error: unknown) => error
48+
);
49+
50+
// The await-0 continuation installs until() before the outside echo lands.
51+
await new Promise(r => setTimeout(r, 20));
52+
setSource([{ clientId: "c1" }]);
53+
flush();
54+
55+
await expect(done).resolves.toBe("confirmed");
56+
flush();
57+
expect(rows.some(row => row.clientId === "c1")).toBe(true);
58+
dispose();
59+
});

‎scripts/size/floor-caps.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"minified": 106107
1717
},
1818
"page: live server components (base + live/GET + action + isPending/latest)": {
19-
"cap": "37.94 KB",
20-
"minified": 118150
19+
"cap": "37.98 KB",
20+
"minified": 118409
2121
},
2222
"server: floor (getRequestEvent + isServer)": {
2323
"cap": "1.34 KB",

‎scripts/size/scenarios.js‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,8 +1284,11 @@ module.exports = [
12841284
// world stays under 10 KB.
12851285
// #3892 (2026-10-08): measured at 9,672 B brotli / 27,234 B minified by CI
12861286
// (Size run 37873440136). Cap set to that brotli size, rounded up to 0.01 KB.
1287-
limit: "9.68 KB",
1288-
capMinified: 27234,
1287+
// #3898 stacks on this; its combined size is remeasured before merge.
1288+
// #3898 stacked on next (2026-10-08): measured at 9,727 B brotli / 27,398 B minified
1289+
// by CI (Size run 37877131816). Cap set to that brotli size, rounded up to 0.01 KB.
1290+
limit: "9.73 KB",
1291+
capMinified: 27398,
12891292
alias
12901293
},
12911294
{
@@ -2333,9 +2336,10 @@ module.exports = [
23332336
// condition hello world stays under 10 KB.
23342337
// #3892 (2026-10-08): measured at 29,252 B brotli / 92,410 B minified by CI
23352338
// (Size run 37873440136). Cap set to that brotli size, rounded up to 0.01 KB.
2336-
// #3884 stacks on this; its combined size is remeasured before merge.
2337-
limit: "29.26 KB",
2338-
capMinified: 92410,
2339+
// #3898 stacked on #3884 (2026-10-08): measured at 29,281 B brotli / 92,619 B minified
2340+
// by CI (Size run 37878629674). Cap set to that brotli size, rounded up to 0.01 KB.
2341+
limit: "29.29 KB",
2342+
capMinified: 92619,
23392343
alias
23402344
},
23412345
{
@@ -3408,6 +3412,7 @@ module.exports = [
34083412
// (Size run 37873440136). Cap set to that brotli size, rounded up to 0.01 KB.
34093413
// #3884 stacked on next (2026-10-08): measured at 25,293 B brotli / 79,170 B minified
34103414
// by CI (Size run 37877131031). Cap set to that brotli size, rounded up to 0.01 KB.
3415+
// #3898 stacked on this cap (Size run 37878629674) and stayed under it.
34113416
limit: "25.30 KB",
34123417
capMinified: 79170,
34133418
alias
@@ -4437,6 +4442,10 @@ module.exports = [
44374442
// eager note. Cap set at measured + 10 B rounded up to 0.01 KB. Accepted
44384443
// by the maintainer (2026-10-08, "perf is important enough — it's the
44394444
// point here"). The cap is frozen again at 37.94 KB.
4445+
// Size-Exception (#3898 stacked on #3884, 2026-10-08): 37.94 -> 37.98 KB
4446+
// (floor-caps.json), measured at 37,975 B brotli / 118,409 B minified by CI
4447+
// (Size run 37878629674). Cap set to that brotli size, rounded up to 0.01 KB.
4448+
// Hello world stays under 10 KB.
44404449
limit: floorCaps["page: live server components (base + live/GET + action + isPending/latest)"],
44414450
capMinified:
44424451
floorMinified["page: live server components (base + live/GET + action + isPending/latest)"],
@@ -4611,6 +4620,7 @@ module.exports = [
46114620
// (2026-10-08, "perf is important enough — it's the point here").
46124621
// #3884 stacked on next (2026-10-08): measured at 41,057 B brotli / 123,713 B minified
46134622
// by CI (Size run 37877131031). Cap set to that brotli size, rounded up to 0.01 KB.
4623+
// #3898 stacked on this cap (Size run 37878629674) and stayed under it.
46144624
limit: "41.06 KB",
46154625
capMinified: 123713,
46164626
alias: pageAlias

0 commit comments

Comments
 (0)