Skip to content

Commit c25e809

Browse files
committed
test: pin Loading on after an action-held input change (#4605)
A keyed optimistic list asked by `filter()`; an action guesses, yields, then refreshes; a `filter` write while the action is out is held with it (D-34, #4336). After everything rests, a second `filter` write with nothing in flight arms `<Loading on={filter()}>` and shows the fallback with that change's frame (F-5, D-15). Without `on` the shown boundary forwards and the change holds the old list until the answer (F-5). Current `next` already behaves this way, in dev and prod conditions and with both compilers: the issue's reported frames have the two cases swapped. These pins (the issue's web spec with asserted frames, plus a signals-only twin) keep it so. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE
1 parent 5ddac94 commit c25e809

2 files changed

Lines changed: 279 additions & 0 deletions

File tree

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/**
2+
* #4605 (ReactiveScript timing fuzzer): a keyed `createOptimisticStore` list
3+
* asked by `filter()`, under `<Loading on={filter()}>`. An action guesses
4+
* (removes a row), yields, then `refresh()`es the list. A `filter` write
5+
* while the action is out is held with it (D-34, #4336); the action ends,
6+
* the refresh lands, everything rests. A second `filter` write with nothing
7+
* in flight is an `on` change like any other: it arms the boundary, which
8+
* shows its fallback with that change's frame (F-5, D-15) — as it does
9+
* without `on`, and as it does without the earlier held change.
10+
*/
11+
import { describe, expect, it } from "vitest";
12+
import {
13+
action,
14+
createLoadingBoundary,
15+
createOptimisticStore,
16+
createRenderEffect,
17+
createRoot,
18+
createErrorBoundary,
19+
createSignal,
20+
flush,
21+
mapArray,
22+
refresh,
23+
untrack
24+
} from "../src/index.js";
25+
26+
const tick = async () => {
27+
for (let i = 0; i < 4; i++) {
28+
await new Promise(r => setTimeout(r, 0));
29+
flush();
30+
}
31+
};
32+
33+
function page(on: boolean) {
34+
const asks: { key: string; res: (v: any) => void }[] = [];
35+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
36+
const land = async (key: string, v: any) => {
37+
const i = asks.findIndex(a => a.key === key);
38+
if (i < 0) throw new Error(`not asked: ${key}; asked: ${asks.map(a => a.key)}`);
39+
asks.splice(i, 1)[0].res(structuredClone(v));
40+
await tick();
41+
};
42+
const frames: string[] = [];
43+
let setFilter!: (f: string) => void;
44+
let closeOne!: (id: number) => void;
45+
createRoot(() => {
46+
const [filter, sf] = createSignal("open");
47+
setFilter = sf;
48+
const [issues, set] = createOptimisticStore<any[]>(() => ask(`issues:${filter()}`), [], {
49+
key: "id"
50+
} as any);
51+
closeOne = action(function* (id: number) {
52+
set((list: any[]) => {
53+
const i = list.findIndex(t => t.id === id);
54+
if (i >= 0) list.splice(i, 1);
55+
});
56+
yield ask(`close:${id}`);
57+
refresh(issues);
58+
}) as any;
59+
const view = untrack(() =>
60+
createLoadingBoundary(
61+
() =>
62+
createErrorBoundary(
63+
() => {
64+
const m = mapArray(
65+
() => issues,
66+
(it: any) => {
67+
createRenderEffect(
68+
() => it.id,
69+
() => {}
70+
);
71+
return () => `#${it.id}`;
72+
}
73+
);
74+
return () =>
75+
`${filter()}: ` +
76+
m()
77+
.map(f => f())
78+
.join(" ");
79+
},
80+
() => "error"
81+
),
82+
() => "loading",
83+
on ? { on: () => filter() } : undefined
84+
)
85+
);
86+
createRenderEffect(
87+
() => {
88+
let v: any = view();
89+
while (typeof v === "function") v = v();
90+
return v;
91+
},
92+
v => {
93+
if (frames.at(-1) !== v) frames.push(v);
94+
}
95+
);
96+
});
97+
return {
98+
land,
99+
asks,
100+
frames,
101+
screen: () => frames.at(-1),
102+
setFilter: async (f: string) => {
103+
setFilter(f);
104+
flush();
105+
await tick();
106+
},
107+
closeOne: async (id: number) => {
108+
closeOne(id);
109+
flush();
110+
await tick();
111+
}
112+
};
113+
}
114+
115+
describe("#4605 an `on` change after an earlier change was held by an action", () => {
116+
for (const on of [true, false]) {
117+
it(`the later change, with nothing in flight (on=${on})`, async () => {
118+
const p = page(on);
119+
await tick();
120+
await p.land("issues:open", [{ id: 1 }, { id: 3 }, { id: 4 }]);
121+
expect(p.screen()).toBe("open: #1 #3 #4");
122+
await p.closeOne(3);
123+
expect(p.screen()).toBe("open: #1 #4");
124+
await p.setFilter("closed");
125+
expect(p.screen()).toBe("open: #1 #4");
126+
await p.land("issues:closed", [{ id: 2 }]);
127+
expect(p.screen()).toBe("open: #1 #4");
128+
await p.land("close:3", {});
129+
expect(p.screen()).toBe("open: #1 #4");
130+
await p.land("issues:closed", [{ id: 2 }, { id: 3 }]);
131+
expect(p.screen()).toBe("closed: #2 #3");
132+
expect(p.asks).toEqual([]);
133+
await p.setFilter("open");
134+
// F-5/D-15: `on` arms and the fallback lands with the change; without
135+
// `on` the shown boundary forwards and the change holds.
136+
expect(p.screen()).toBe(on ? "loading" : "closed: #2 #3");
137+
await p.land("issues:open", [{ id: 1 }, { id: 4 }]);
138+
expect(p.screen()).toBe("open: #1 #4");
139+
expect(p.asks).toEqual([]);
140+
expect(p.frames).toEqual([
141+
"loading",
142+
"open: #1 #3 #4",
143+
"open: #1 #4",
144+
"closed: #2 #3",
145+
...(on ? ["loading"] : []),
146+
"open: #1 #4"
147+
]);
148+
});
149+
}
150+
});
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*
5+
* #4605 (F-5, D-15; D-34/#4336): a keyed list store asked by `filter()`,
6+
* under `<Loading on={filter()}>`. An action guesses (removes a row), yields,
7+
* then `refresh()`es the list. A `filter` write while the action is out is
8+
* held with it (D-34); the action ends, the refresh lands, everything rests.
9+
* A second `filter` write with nothing in flight is an `on` change like any
10+
* other: it arms the boundary, which shows its fallback with that change's
11+
* frame (F-5, D-15), as it does without the earlier held change. Without
12+
* `on` the boundary has shown content and forwards (F-5): the change holds,
13+
* the old list stays, and the new one reveals with its answer.
14+
* The signals-only twin: `packages/signals/tests/loading-on-held-change-4605.test.ts`.
15+
*/
16+
import { expect, test } from "vitest";
17+
import {
18+
For,
19+
Loading,
20+
Errored,
21+
action,
22+
createOptimisticStore,
23+
createSignal,
24+
flush,
25+
refresh
26+
} from "solid-js";
27+
import { render } from "../src/index.js";
28+
29+
const tick = async () => {
30+
for (let i = 0; i < 4; i++) {
31+
await new Promise(r => setTimeout(r, 0));
32+
flush();
33+
}
34+
};
35+
36+
function run(useOn: boolean) {
37+
return async () => {
38+
const asks: { key: string; res: (v: any) => void; rej: (e: any) => void }[] = [];
39+
const ask = (key: string) => new Promise<any>((res, rej) => asks.push({ key, res, rej }));
40+
const settle = async (key: string, f: (a: any) => void) => {
41+
const i = asks.findIndex(a => a.key === key);
42+
f(asks.splice(i, 1)[0]);
43+
await tick();
44+
};
45+
const container = document.body.appendChild(document.createElement("div"));
46+
const frames: string[] = [];
47+
const snap = (l: string) =>
48+
frames.push(`${l}: ${container.textContent} air ${asks.map(a => a.key)}`.trimEnd());
49+
let setFilter!: (f: string) => void;
50+
let closeOne!: (id: number) => any;
51+
const dispose = render(() => {
52+
const [filter, sf] = createSignal("open");
53+
setFilter = sf;
54+
const [issues, set] = createOptimisticStore<any[]>(() => ask(`issues:${filter()}`), [], {
55+
key: "id"
56+
});
57+
closeOne = action(function* (id: number) {
58+
set(list => {
59+
const i = list.findIndex(t => t.id === id);
60+
if (i >= 0) list.splice(i, 1);
61+
});
62+
yield ask(`close:${id}`);
63+
refresh(issues);
64+
});
65+
const body = () => (
66+
<Errored fallback={e => <p>error {(e() as Error).message}</p>}>
67+
<p>
68+
{filter()}: <For each={issues}>{(it: any) => <i>[#{it.id}]</i>}</For>
69+
</p>
70+
</Errored>
71+
);
72+
return useOn ? (
73+
<Loading on={filter()} fallback={<p>loading</p>}>
74+
{body()}
75+
</Loading>
76+
) : (
77+
<Loading fallback={<p>loading</p>}>{body()}</Loading>
78+
);
79+
}, container);
80+
await tick();
81+
await settle("issues:open", a => a.res([{ id: 1 }, { id: 3 }, { id: 4 }]));
82+
snap("loaded");
83+
closeOne(3);
84+
await tick();
85+
snap("close #3");
86+
setFilter("closed");
87+
await tick();
88+
snap("filter closed");
89+
await settle("issues:closed", a => a.res([{ id: 2 }]));
90+
snap("closed answered");
91+
await settle("close:3", a => a.res({}));
92+
snap("close accepted");
93+
await settle("issues:closed", a => a.res([{ id: 2 }, { id: 3 }]));
94+
snap("refresh answered");
95+
setFilter("open");
96+
await tick();
97+
snap("filter open");
98+
await settle("issues:open", a => a.res([{ id: 1 }, { id: 4 }]));
99+
snap("open answered");
100+
dispose();
101+
container.remove();
102+
return frames;
103+
};
104+
}
105+
106+
const before = [
107+
"loaded: open: [#1][#3][#4] air",
108+
"close #3: open: [#1][#4] air close:3",
109+
"filter closed: open: [#1][#4] air close:3,issues:closed",
110+
"closed answered: open: [#1][#4] air close:3",
111+
"close accepted: open: [#1][#4] air issues:closed",
112+
"refresh answered: closed: [#2][#3] air"
113+
];
114+
115+
test("#4605 with `on`: the change after the held one shows the fallback", async () => {
116+
expect(await run(true)()).toEqual([
117+
...before,
118+
"filter open: loading air issues:open",
119+
"open answered: open: [#1][#4] air"
120+
]);
121+
});
122+
123+
test("#4605 without `on`: the shown boundary forwards, the change holds", async () => {
124+
expect(await run(false)()).toEqual([
125+
...before,
126+
"filter open: closed: [#2][#3] air issues:open",
127+
"open answered: open: [#1][#4] air"
128+
]);
129+
});

0 commit comments

Comments
 (0)