Skip to content

Commit 005f777

Browse files
committed
Update to optiona API
1 parent a53e253 commit 005f777

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

packages/react-router/__tests__/router/fetchers-test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,5 +3653,18 @@ describe("fetchers", () => {
36533653
});
36543654
expect(B.loaders.fetch.signal.aborted).toBe(true);
36553655
});
3656+
3657+
it("passes along the `reason` to the abort controller", async () => {
3658+
let t = setup({
3659+
routes: [
3660+
{ id: "root", path: "/" },
3661+
{ id: "fetch", path: "/fetch", loader: true },
3662+
],
3663+
});
3664+
3665+
let A = await t.fetch("/fetch", "a", "root");
3666+
t.router.resetFetcher("a", { reason: "BECAUSE I SAID SO" });
3667+
expect(A.loaders.fetch.signal.reason).toBe("BECAUSE I SAID SO");
3668+
});
36563669
});
36573670
});

packages/react-router/lib/dom/lib.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,7 +2668,7 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
26682668
* @param reason Optional `reason` to provide to [`AbortController.abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort)
26692669
* @returns void
26702670
*/
2671-
unstable_reset: (reason?: unknown) => void;
2671+
unstable_reset: (opts?: { reason?: unknown }) => void;
26722672

26732673
/**
26742674
* Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called.
@@ -2843,7 +2843,7 @@ export function useFetcher<T = any>({
28432843

28442844
let unstable_reset = React.useCallback<
28452845
FetcherWithComponents<T>["unstable_reset"]
2846-
>((reason) => router.resetFetcher(fetcherKey, reason), [router, fetcherKey]);
2846+
>((opts) => router.resetFetcher(fetcherKey, opts), [router, fetcherKey]);
28472847

28482848
let FetcherForm = React.useMemo(() => {
28492849
let FetcherForm = React.forwardRef<HTMLFormElement, FetcherFormProps>(

packages/react-router/lib/router/router.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export interface Router {
222222
* Reset the fetcher for a given key
223223
* @param key
224224
*/
225-
resetFetcher(key: string, reason?: unknown): void;
225+
resetFetcher(key: string, opts?: { reason?: unknown }): void;
226226

227227
/**
228228
* @private
@@ -3068,8 +3068,8 @@ export function createRouter(init: RouterInit): Router {
30683068
return state.fetchers.get(key) || IDLE_FETCHER;
30693069
}
30703070

3071-
function resetFetcher(key: string, reason?: unknown) {
3072-
abortFetcher(key, reason);
3071+
function resetFetcher(key: string, opts?: { reason?: unknown }) {
3072+
abortFetcher(key, opts?.reason);
30733073
updateFetcherState(key, getDoneFetcher(null));
30743074
}
30753075

0 commit comments

Comments
 (0)