Skip to content

Commit e8dcf6c

Browse files
committed
fix: address review findings
The comment above the pass's previous value in `recompute` now says a lane node's lane value is used only when the slot holds one, matching the guarded expression beneath it. The #3955 test now covers `createMemo(fn)` beside `createSignal(fn)`, asserts that the landing after the equal lane passes flushes without throwing and records only arrays, and resets a halted system after each case so each case fails on its own pre-fix. The changeset describes the thrown `prev is not iterable` instead of the internal marker.
1 parent fe83b04 commit e8dcf6c

3 files changed

Lines changed: 55 additions & 44 deletions

File tree

‎.changeset/fix-lane-derivation-prev-3955.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@solidjs/signals": patch
33
---
44

5-
A derivation re-running under a lane whose first pass was equal receives its committed value as `prev` instead of the empty `NOT_PENDING` marker.
5+
A `createSignal(fn)` or `createMemo(fn)` derivation that reads `latest()` or `isPending()` of a signal an in-flight async memo is holding receives its previous value as `prev` on every re-run under the hold. When its first pass under the hold was equal to the previous value, the next pass received an empty internal marker instead, so `(prev = []) => [...prev]` threw `prev is not iterable` and halted the reactive system.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
374374
// — here, the finally below, updateIfNecessary — carries it (#3543).
375375
el._flags = REACTIVE_RECOMPUTING_DEPS | (el._flags & REACTIVE_ZOMBIE);
376376
el._time = clock;
377-
// The pass's previous value: its staging, else the lane's value for a
378-
// lane's node (lanes.ts), else the committed one.
377+
// The pass's previous value: its staging, else a lane node's lane value
378+
// when it has one (lanes.ts), else the committed one.
379379
let value =
380380
el._pendingValue !== NOT_PENDING
381381
? el._pendingValue
Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { describe, expect, it } from "vitest";
1+
import { afterEach, describe, expect, it } from "vitest";
22
import {
33
createMemo,
44
createRenderEffect,
55
createRoot,
66
createSignal,
77
flush,
88
isPending,
9-
latest
9+
latest,
10+
resetErrorHalt
1011
} from "../src/index.js";
1112

1213
function deferred<T = void>() {
@@ -21,49 +22,59 @@ async function tick(n = 4) {
2122
}
2223

2324
describe("a derivation reading a held signal through latest()/isPending() keeps its prev", () => {
24-
for (const read of ["latest", "isPending"] as const) {
25-
it(`${read}(): an equal pass under the hold does not turn the next pass's prev into NOT_PENDING`, async () => {
26-
const prevs: unknown[] = [];
27-
const gates = { current: deferred() };
28-
let setFilter!: (v: string) => void;
29-
let dispose!: () => void;
30-
createRoot(d => {
31-
dispose = d;
32-
const [filter, set] = createSignal("a");
33-
setFilter = set;
34-
const data = createMemo(async () => {
35-
const f = filter();
36-
await gates.current.promise;
37-
return f;
38-
});
39-
createRenderEffect(data, () => {});
40-
const [names] = createSignal<string[]>(
41-
(prev = []) => {
25+
afterEach(() => {
26+
resetErrorHalt();
27+
});
28+
29+
for (const kind of ["createSignal", "createMemo"] as const) {
30+
for (const read of ["latest", "isPending"] as const) {
31+
it(`${kind} + ${read}(): an equal pass under the hold does not turn the next pass's prev into NOT_PENDING`, async () => {
32+
const prevs: unknown[] = [];
33+
const gates = { current: deferred() };
34+
let setFilter!: (v: string) => void;
35+
let dispose!: () => void;
36+
createRoot(d => {
37+
dispose = d;
38+
const [filter, set] = createSignal("a");
39+
setFilter = set;
40+
const data = createMemo(async () => {
41+
const f = filter();
42+
await gates.current.promise;
43+
return f;
44+
});
45+
createRenderEffect(data, () => {});
46+
const compute = (prev: string[] = []) => {
4247
read === "latest" ? latest(filter) : isPending(filter);
4348
prevs.push(prev);
4449
return [...prev];
45-
},
46-
{ equals: (a, b) => a.length === b.length }
47-
);
48-
createRenderEffect(names, () => {});
49-
});
50-
flush();
51-
const mountGate = gates.current;
52-
gates.current = deferred();
53-
mountGate.resolve();
54-
await tick();
55-
expect(prevs).toEqual([[]]);
50+
};
51+
const equals = (a: string[], b: string[]) => a.length === b.length;
52+
const names =
53+
kind === "createSignal"
54+
? createSignal<string[]>(compute, { equals })[0]
55+
: createMemo<string[]>(compute, { equals });
56+
createRenderEffect(names, () => {});
57+
});
58+
flush();
59+
const mountGate = gates.current;
60+
gates.current = deferred();
61+
mountGate.resolve();
62+
await tick();
63+
expect(prevs).toEqual([[]]);
5664

57-
setFilter("b");
58-
flush();
59-
setFilter("c");
60-
expect(() => flush()).not.toThrow();
61-
await tick();
62-
expect(prevs).toEqual([[], [], []]);
65+
setFilter("b");
66+
flush();
67+
setFilter("c");
68+
expect(() => flush()).not.toThrow();
69+
await tick();
70+
expect(prevs).toEqual([[], [], []]);
6371

64-
gates.current.resolve();
65-
await tick();
66-
dispose();
67-
});
72+
gates.current.resolve();
73+
for (let i = 0; i < 4; i++) await Promise.resolve();
74+
expect(() => flush()).not.toThrow();
75+
expect(prevs).toEqual(read === "isPending" ? [[], [], [], []] : [[], [], []]);
76+
dispose();
77+
});
78+
}
6879
}
6980
});

0 commit comments

Comments
 (0)