Skip to content

Commit e48b2fd

Browse files
committed
fix(signals): never re-queue a lane member disposed before the lane dissolves (#4613)
dissolveLane re-queued lane members (a correction re-asking a pending member, a stale reader's error re-deriving) without checking whether the member had been disposed since it joined the lane. An action's commit that disposed a keyed region whose inner list memo was still the action's lane work thus put the dead memo back in the heap; recompute's head wipe drops REACTIVE_DISPOSED, so the node came back to life in the torn-down region, mapped rows there and stayed subscribed (dev: RUN_WITH_DISPOSED_OWNER). A disposed reader is no reader (F-3, D-11): dissolution skips it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
1 parent 3ace826 commit e48b2fd

4 files changed

Lines changed: 243 additions & 1 deletion

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 lane member disposed before its lane dissolves no longer runs again (#4613). When an action's commit disposed a region whose list was still the action's lane work (e.g. a keyed `<For each={[filter()]}>` region swapped by a filter change held with the action), dissolving the lane re-queued the dead list memo; its pass dropped the disposed flag, so it mapped rows in the torn-down region, stayed subscribed, and dev logged `RUN_WITH_DISPOSED_OWNER`. A disposed reader is no reader (F-3, D-11): dissolution now skips it.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,12 @@ function dissolveLane(l: Transaction, into: Transaction | null, except?: Signal<
564564
for (let i = 0; i < l._nodes.length; i++) {
565565
const n = l._nodes[i];
566566
const x = n._x!;
567-
if (n === except || x._transaction !== l) continue;
567+
// A member disposed since it joined the lane is no reader any more
568+
// (F-3, D-11): dead, it stays at its last committed value (#3024). Nothing
569+
// here may queue it: recompute's head wipe would drop REACTIVE_DISPOSED
570+
// and run it again in a torn-down tree (#4613).
571+
if (n === except || x._transaction !== l || (n as Computed<any>)._flags & REACTIVE_DISPOSED)
572+
continue;
568573
const effect = (n as any)._type;
569574
const guess = n._config & CONFIG_GUESS;
570575
const slot = x._lane;
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* #4613: a lane member disposed before the lane dissolves never runs again.
3+
*
4+
* A filter keys a region (a keyed map over `[filter()]`); in it a list is
5+
* mapped from an optimistic store under Loading > Errored. An action removes
6+
* a row (a guess) and `refresh`es the store; the filter changes while the
7+
* action is out, so that frame is held with it (D-34 ¶3). The action's
8+
* commit disposes the "open" region, inner list memo included — but that
9+
* memo was still a member of the action's lane. Dissolving the lane re-queued
10+
* it, and its pass dropped REACTIVE_DISPOSED at the head wipe: a dead node
11+
* came back to life in the torn-down region, mapped rows there and stayed
12+
* subscribed (dev: `RUN_WITH_DISPOSED_OWNER`).
13+
*
14+
* Ruled (F-3, D-11): a disposed reader is no reader; it holds nothing, and
15+
* nothing re-derives it (a dead node freezes, #3024).
16+
*/
17+
import { afterEach, expect, it, vi } from "vitest";
18+
import {
19+
action,
20+
createErrorBoundary,
21+
createLoadingBoundary,
22+
createOptimisticStore,
23+
createRenderEffect,
24+
createRoot,
25+
createSignal,
26+
flush,
27+
mapArray,
28+
refresh
29+
} from "../src/index.js";
30+
31+
const tick = async () => {
32+
for (let i = 0; i < 4; i++) {
33+
await new Promise(r => setTimeout(r, 0));
34+
flush();
35+
}
36+
};
37+
38+
afterEach(() => vi.restoreAllMocks());
39+
40+
it("#4613: a region disposed while its list is lane work does not run again (F-3, D-11)", async () => {
41+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
42+
const asks: { key: string; res: (v: any) => void }[] = [];
43+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
44+
const settle = async (key: string, v: any) => {
45+
const i = asks.findIndex(a => a.key === key);
46+
expect(i).not.toBe(-1);
47+
asks.splice(i, 1)[0].res(v);
48+
await tick();
49+
};
50+
let shown = "";
51+
const rows: string[] = [];
52+
let setFilter!: (f: string) => void;
53+
let close!: (id: number) => any;
54+
const dispose = createRoot(d => {
55+
const [filter, sf] = createSignal("open");
56+
setFilter = sf;
57+
const [store, setStore] = createOptimisticStore(
58+
() => ask(`issues:${filter()}`),
59+
[] as { id: number }[],
60+
{ key: "id" }
61+
);
62+
close = action(function* (id: number) {
63+
setStore(list => {
64+
const i = list.findIndex(t => t.id === id);
65+
if (i >= 0) list.splice(i, 1);
66+
});
67+
yield ask(`close:${id}`);
68+
refresh(store);
69+
});
70+
const regions = mapArray(
71+
() => [filter()],
72+
(f: string) =>
73+
createLoadingBoundary(
74+
() =>
75+
createErrorBoundary(
76+
() => {
77+
const list = mapArray(
78+
() => store,
79+
(it: { id: number }) => {
80+
rows.push(`${f}:${it.id}`);
81+
return `[#${it.id}]`;
82+
}
83+
);
84+
return () => list().join("");
85+
},
86+
e => () => `error ${(e() as Error).message}`
87+
),
88+
() => () => "loading"
89+
)
90+
);
91+
createRenderEffect(
92+
() =>
93+
regions()
94+
.map(r => {
95+
// Boundaries resolve function children; unwrap whatever is left.
96+
let v: any = r();
97+
while (typeof v === "function") v = v();
98+
return v;
99+
})
100+
.join(""),
101+
v => void (shown = v)
102+
);
103+
return d;
104+
});
105+
await tick();
106+
await settle("issues:open", [{ id: 1 }, { id: 3 }, { id: 4 }]);
107+
expect(shown).toBe("[#1][#3][#4]");
108+
close(3);
109+
await tick();
110+
expect(shown).toBe("[#1][#4]");
111+
setFilter("closed");
112+
await tick();
113+
expect(shown).toBe("[#1][#4]");
114+
await settle("issues:closed", [{ id: 2 }]);
115+
await settle("close:3", {});
116+
rows.length = 0;
117+
await settle("issues:closed", [{ id: 2 }, { id: 3 }]);
118+
expect(shown).toBe("[#2][#3]");
119+
setFilter("open");
120+
await tick();
121+
await settle("issues:open", [{ id: 1 }, { id: 4 }]);
122+
expect(shown).toBe("[#1][#4]");
123+
// Only live regions mapped rows: none for the disposed "open" region.
124+
expect(rows).toEqual(["closed:2", "closed:3", "open:1", "open:4"]);
125+
expect(warn.mock.calls.map(c => String(c[0])).filter(m => m.includes("DISPOSED"))).toEqual([]);
126+
dispose();
127+
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*
5+
* #4613: a filter keys a region (`<For each={[filter()]}>`) and an action
6+
* removes a row from the list store, then `refresh`es it. The filter change
7+
* made while the action is out is held with it (D-34 ¶3). When the action
8+
* commits, the "open" region is disposed — and its inner `<For>`'s list
9+
* memo with it — but that memo was still a member of the action's lane. The
10+
* lane's dissolution re-queued it, and the re-run brought a disposed node
11+
* back to life in the torn-down region (`RUN_WITH_DISPOSED_OWNER`, twice).
12+
* A disposed reader is no reader (F-3, D-11): it never runs again.
13+
*/
14+
import { render } from "@solidjs/web";
15+
import {
16+
action,
17+
createOptimisticStore,
18+
createSignal,
19+
Errored,
20+
flush,
21+
For,
22+
Loading,
23+
refresh
24+
} from "solid-js";
25+
import { afterEach, expect, it, vi } from "vitest";
26+
27+
const tick = async () => {
28+
for (let i = 0; i < 4; i++) {
29+
await new Promise(r => setTimeout(r, 0));
30+
flush();
31+
}
32+
};
33+
34+
afterEach(() => vi.restoreAllMocks());
35+
36+
it("a region disposed under an action's lane does not run again (#4613)", async () => {
37+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
38+
const asks: { key: string; res: (v: any) => void }[] = [];
39+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
40+
const settle = async (key: string, v: any) => {
41+
const i = asks.findIndex(a => a.key === key);
42+
expect(i).not.toBe(-1);
43+
asks.splice(i, 1)[0].res(v);
44+
await tick();
45+
};
46+
const container = document.createElement("div");
47+
let setFilter!: (f: string) => void;
48+
let closeOne!: (id: number) => any;
49+
const rows: string[] = [];
50+
const dispose = render(() => {
51+
const [filter, sf] = createSignal("open");
52+
setFilter = sf;
53+
const [issues, set] = createOptimisticStore<any[]>(() => ask(`issues:${filter()}`), [], {
54+
key: "id"
55+
});
56+
closeOne = action(function* (id: number) {
57+
set(list => {
58+
const i = list.findIndex(t => t.id === id);
59+
if (i >= 0) list.splice(i, 1);
60+
});
61+
yield ask(`close:${id}`);
62+
refresh(issues);
63+
});
64+
return (
65+
<For each={[filter()]}>
66+
{(f: string) => (
67+
<Loading fallback={<p>loading {f}</p>}>
68+
<Errored fallback={e => <p>error {e().message}</p>}>
69+
<For each={issues}>
70+
{(it: any) => {
71+
rows.push(`${f}:${it.id}`);
72+
return <i>[#{it.id}]</i>;
73+
}}
74+
</For>
75+
</Errored>
76+
</Loading>
77+
)}
78+
</For>
79+
);
80+
}, container);
81+
await tick();
82+
await settle("issues:open", [{ id: 1 }, { id: 3 }, { id: 4 }]);
83+
expect(container.textContent).toBe("[#1][#3][#4]");
84+
closeOne(3);
85+
await tick();
86+
expect(container.textContent).toBe("[#1][#4]");
87+
setFilter("closed");
88+
await tick();
89+
// Held with the action (D-34 ¶3).
90+
expect(container.textContent).toBe("[#1][#4]");
91+
await settle("issues:closed", [{ id: 2 }]);
92+
expect(container.textContent).toBe("[#1][#4]");
93+
await settle("close:3", {});
94+
rows.length = 0;
95+
await settle("issues:closed", [{ id: 2 }, { id: 3 }]);
96+
expect(container.textContent).toBe("[#2][#3]");
97+
setFilter("open");
98+
await tick();
99+
await settle("issues:open", [{ id: 1 }, { id: 4 }]);
100+
expect(container.textContent).toBe("[#1][#4]");
101+
// No row was built for a disposed "open" region: only the live regions'.
102+
expect(rows).toEqual(["closed:2", "closed:3", "open:1", "open:4"]);
103+
expect(warn.mock.calls.map(c => String(c[0])).filter(m => m.includes("DISPOSED"))).toEqual([]);
104+
dispose();
105+
});

0 commit comments

Comments
 (0)