Skip to content

Commit b81707c

Browse files
ryansolidClaude via Cursorcursoragent
committed
fix: useSubmissions keeps the same list while its submissions are unchanged
The filter memo returned a new array on every run, so any change to the router's submissions — another action's submission settling — re-ran every reader of this action's list, and the dev build warned UNSTABLE_MEMO_OUTPUT. Submissions are immutable records, so the memo now compares element identity. Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 7c24cf1 commit b81707c

3 files changed

Lines changed: 51 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
`useSubmissions` keeps the same list while its submissions are unchanged. The filter used to return a new array on every run, so another action's submission settling re-ran every reader of this action's list (and tripped the dev `UNSTABLE_MEMO_OUTPUT` warning).

‎src/data/action.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,15 @@ export function useSubmissions<T extends Array<any>, U, V>(
309309
filter?: (input: V) => boolean
310310
): Submission<V, NarrowResponse<U>>[] {
311311
const router = useRouter();
312-
const subs = createMemo(() =>
313-
router.submissions[0]().filter(s => s.url === (fn as any).base && (!filter || filter(s.input)))
312+
// Submissions are immutable records, so the same records in the same order
313+
// are the same list: another action's submissions changing re-runs the
314+
// filter but must not re-run this list's readers.
315+
const subs = createMemo(
316+
() =>
317+
router.submissions[0]().filter(
318+
s => s.url === (fn as any).base && (!filter || filter(s.input))
319+
),
320+
{ equals: (a, b) => a.length === b.length && a.every((s, i) => s === b[i]) }
314321
);
315322
return new Proxy<Submission<any, any>[]>([] as any, {
316323
get(_, property) {

‎test/data/action.spec.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createRoot } from "solid-js";
1+
import { createEffect, createRoot, flush } from "solid-js";
22
import { vi } from "vitest";
33
import {
44
action,
@@ -539,6 +539,42 @@ describe("useSubmissions", () => {
539539
expect(submission?.result).toBe("result2");
540540
});
541541
});
542+
543+
test("should not notify readers when another action's submissions change", () => {
544+
const record = (url: string) => ({
545+
input: [],
546+
url,
547+
result: "result",
548+
error: undefined,
549+
clear: vi.fn(),
550+
retry: vi.fn()
551+
});
552+
const a = action(async () => "a", "identity-a");
553+
const b = action(async () => "b", "identity-b");
554+
let runs = 0;
555+
const dispose = createRoot(dispose => {
556+
const submissions = useSubmissions(a);
557+
createEffect(
558+
() => {
559+
runs++;
560+
return submissions.length;
561+
},
562+
() => {}
563+
);
564+
return dispose;
565+
});
566+
flush();
567+
expect(runs).toBe(1);
568+
569+
mockRouterContext.submissions[1](entries => [...entries, record(b.url)]);
570+
flush();
571+
expect(runs).toBe(1);
572+
573+
mockRouterContext.submissions[1](entries => [...entries, record(a.url)]);
574+
flush();
575+
expect(runs).toBe(2);
576+
dispose();
577+
});
542578
});
543579

544580
describe("useAction", () => {

0 commit comments

Comments
 (0)