Skip to content

Commit f311f4a

Browse files
committedJun 18, 2024
fix #452 useSubmission types/references
1 parent d81473a commit f311f4a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed
 

‎.changeset/mighty-goats-join.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
fix #452 useSubmission types/references

‎src/data/action.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { $TRACK, createMemo, createSignal, JSX, onCleanup, getOwner } from "solid-js";
22
import { isServer } from "solid-js/web";
33
import { useRouter } from "../routing.js";
4-
import { RouterContext, Submission, Navigator } from "../types.js";
4+
import type { RouterContext, Submission, SubmissionStub, Navigator } from "../types.js";
55
import { mockBase } from "../utils.js";
66
import { cacheKeyOp, hashKey, revalidate, cache } from "./cache.js";
77

@@ -38,12 +38,13 @@ export function useSubmissions<T extends Array<any>, U>(
3838
export function useSubmission<T extends Array<any>, U>(
3939
fn: Action<T, U>,
4040
filter?: (arg: T) => boolean
41-
): Submission<T, U> {
41+
): Submission<T, U> | SubmissionStub {
4242
const submissions = useSubmissions(fn, filter);
4343
return new Proxy(
4444
{},
4545
{
4646
get(_, property) {
47+
if (submissions.length === 0 && property === "clear" || property === "retry") return (() => {});
4748
return submissions[submissions.length - 1]?.[property as keyof Submission<T, U>];
4849
}
4950
}

‎src/types.ts

+10
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ export type Submission<T, U> = {
202202
retry: () => void;
203203
};
204204

205+
export type SubmissionStub = {
206+
readonly input: undefined;
207+
readonly result: undefined;
208+
readonly error: undefined;
209+
readonly pending: undefined;
210+
readonly url: undefined;
211+
clear: () => void;
212+
retry: () => void;
213+
};
214+
205215
export interface MaybePreloadableComponent extends Component {
206216
preload?: () => void;
207217
}

0 commit comments

Comments
 (0)