Skip to content

Commit 6658563

Browse files
committed
Merge origin/next into claude/project-thread-x1ore2-4426
Ledger conflicts resolved to next's entries, then re-measured over next @ 9c4e4a8: frozen floors base SC 33.77 KB (101,638) and live SC 38.83 KB (117,331); compiled base SC 35.72 KB (108,007). Size-Exception in the PR body. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
2 parents 97278f0 + 9c4e4a8 commit 6658563

17 files changed

Lines changed: 403 additions & 33 deletions
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 pass that reads `latest(m)` and then `isPending(m)` of an unheld refetch outside any `Loading` no longer loops ("Potential Infinite Loop Detected"): the `latest` read opened the flush's transaction for nothing held, the probe asked to re-run at that transaction's landing, and every re-run opened another. The probe now joins the verdict lane without asking for that re-run; the reader shows the committed value beside `true`, then the refetch's answer.
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+
The transaction a `latest()` read of an unheld refetch opens is no longer kept alive after it lands: the mark that it was opened by `latest` lives on the transaction itself instead of in a module-level reference.
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+
`createOptimisticStore`: a row removed by an accepted action no longer comes back when its refresh lands while another removal is pending; each re-base of an arrangement guess composes from the rows the setter wrote.
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+
Writes that net to a signal's committed value in one tick no longer hold an errored memo's re-run with an action, so `isPending` of it stays `false` (D-8).

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,9 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
20272027
if (__TEST__) shadowActual(SLOT_C);
20282028
return el._value as T;
20292029
}
2030-
stagedRead(c as Computed<any>);
2030+
// A staging equal to the committed value is writes that netted (D-8): no
2031+
// proposal, so not a read of the frame's future.
2032+
if (el._pendingValue !== el._value) stagedRead(c as Computed<any>);
20312033
if (__TEST__) shadowActual(SLOT_P);
20322034
return el._pendingValue as T;
20332035
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ export interface Transaction {
288288
* (scripts/mangle-props.mjs), which costs the floors bytes for a path
289289
* only optimistic stores reach. */
290290
folded?: (c: Computed<any> | null, el: Signal<any> | Computed<any>) => unknown;
291+
/** Opened by a `latest()` read of an unheld flight (verdict.ts
292+
* `pendingVerdict`): it holds nothing of that flight, and a probe in it is
293+
* its verdict lane's with no re-run at its landing (F-6, D-23). Unset
294+
* until then; not `_`-prefixed, as `folded`. */
295+
latest?: 1;
291296
/** `affects()` marks declared in it (affects.ts): released at the landing.
292297
* Not nodes — a mark holds nothing (`blocked` never sees one). */
293298
_marks: Signal<any>[] | null;

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,16 @@ function pendingVerdict(c: Computed<any> | null, el: Computed<any>): void {
247247
// verdict lane's now, as a plain read of a flight makes it
248248
// (`observeFlight`). Its frame pass re-derived in the lane (R5) asked
249249
// its question again (F-9, #4397). A staging's is the seam's (#4365).
250-
if (!probing) joinFuture(null);
250+
// A probe in a transaction only that opened is the lane's too, with no
251+
// re-run at its landing: nothing it holds flips the verdict — the
252+
// flight's own landing re-derives the reader — and it lands at this
253+
// seam, where a re-run would open it again, every flush (F-6, D-23).
254+
// (The mark is the transaction's own — `Transaction.latest` — so
255+
// nothing outlives its landing.)
256+
if (!probing)
257+
flushTransaction ||
258+
(joinFuture(null), ((flushTransaction as Transaction | null)!.latest = 1));
259+
else if (flushTransaction?.latest) return route(c, flushTransaction);
251260
provisionalVerdict(c, false); // decided above
252261
}
253262
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ GlobalQueue._laneRebase = (el: Signal<any>, truth: unknown, older: boolean) => {
382382
}
383383
const used = new Set<unknown>();
384384
const rows: any[] = [];
385-
const guessed = view.rows as any[];
385+
// From the guess as written, not an earlier re-base's composition: a
386+
// derive's landing writes key by key, and a truth row one partial write
387+
// showed must not stay appended once the landing drops it (#4441).
388+
const guessed = (view.g ??= view.rows as any[]);
386389
for (let i = 0; i < guessed.length; i++) {
387390
const g = guessed[i];
388391
const k = isWrappable(g) ? keyFn(g) : undefined;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ export function sameKey(a: any, b: any): boolean {
283283
* revert against it by row identity — by key when the family has one
284284
* (the server's object for a guessed row is the same row). */
285285
export class LaneView {
286+
/** The rows the setter wrote, kept across re-bases: each composes from
287+
* them over the latest truth (optimistic.ts `_laneRebase`, #4441). */
288+
declare g?: any[];
286289
constructor(
287290
public rows: Record<PropertyKey, any>,
288291
/** The backing the guess is shown over: the committed one at the

‎packages/signals/tests/gc.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
latest,
1414
mapArray
1515
} from "../src/index.js";
16+
import { flushTransaction, type Transaction } from "../src/core/scheduler.js";
1617

1718
function gc() {
1819
return new Promise(resolve =>
@@ -90,6 +91,48 @@ it("releases an unobserved reader queued by an idle cross-root rejection", async
9091
}
9192
});
9293

94+
it("releases the transaction a latest() read of an unheld refetch opened once it lands", async () => {
95+
// F-6, D-23 (#4453): `pendingVerdict` marks the flush's transaction a
96+
// `latest` read of an unheld flight opened. It holds nothing of the
97+
// flight and lands at that flush's seam — after which nothing may keep it.
98+
const asks: ((v: number) => void)[] = [];
99+
const [s, setS] = createSignal(1);
100+
let armed = false,
101+
opened: Transaction | null = null;
102+
const dispose = createRoot(dispose => {
103+
const m = createMemo(() => {
104+
s();
105+
return new Promise<number>(resolve => asks.push(resolve));
106+
});
107+
createRenderEffect(
108+
() => {
109+
const v = `${latest(m)} ${isPending(m)}`;
110+
if (armed) opened ??= flushTransaction;
111+
return v;
112+
},
113+
() => {}
114+
);
115+
return dispose;
116+
});
117+
flush();
118+
await new Promise<void>(r => setTimeout(r, 0));
119+
asks.shift()!(1);
120+
await new Promise<void>(r => setTimeout(r, 0));
121+
flush();
122+
armed = true;
123+
setS(2);
124+
flush();
125+
expect(opened).not.toBeNull();
126+
const ref = new WeakRef(opened!);
127+
opened = null;
128+
asks.shift()!(2);
129+
await new Promise<void>(r => setTimeout(r, 0));
130+
flush();
131+
dispose();
132+
await collectGarbage();
133+
expect(ref.deref()).toBeUndefined();
134+
});
135+
93136
if (global.gc) {
94137
it("should gc computed if there are no observers", async () => {
95138
const [$x] = createSignal(0),

0 commit comments

Comments
 (0)