Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fetcher.submit types #11631

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gorgeous-geese-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router-dom": patch
---

Fix `fetcher.submit` types - remove incorrect `navigate`/`fetcherKey`/`unstable_viewTransition` options because they are only relevant for `useSubmit`
36 changes: 19 additions & 17 deletions packages/react-router-dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function isFormDataSubmitterSupported() {
return _formDataSupportsSubmitter;
}

export interface SubmitOptions {
export interface FetcherSubmitOptions {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of directly definig these here, have a base private SharedSubmitOptions that can be extended. That way it's not easy to add something fetcher-only and accidentally leak it to non-fetcher cases. Do this for FetcherFormProps as well

/**
* The HTTP method used to submit the form. Overrides `<form method>`.
* Defaults to "GET".
Expand All @@ -170,15 +170,25 @@ export interface SubmitOptions {
encType?: FormEncType;

/**
* Indicate a specific fetcherKey to use when using navigate=false
* Determines whether the form action is relative to the route hierarchy or
* the pathname. Use this if you want to opt out of navigating the route
* hierarchy and want to instead route based on /-delimited URL segments
*/
fetcherKey?: string;
relative?: RelativeRoutingType;

/**
* navigate=false will use a fetcher instead of a navigation
* In browser-based environments, prevent resetting scroll after this
* navigation when using the <ScrollRestoration> component
*/
navigate?: boolean;
preventScrollReset?: boolean;

/**
* Enable flushSync for this submission's state updates
*/
unstable_flushSync?: boolean;
}

export interface SubmitOptions extends FetcherSubmitOptions {
/**
* Set `true` to replace the current entry in the browser's history stack
* instead of creating a new one (i.e. stay on "the same page"). Defaults
Expand All @@ -192,22 +202,14 @@ export interface SubmitOptions {
state?: any;

/**
* Determines whether the form action is relative to the route hierarchy or
* the pathname. Use this if you want to opt out of navigating the route
* hierarchy and want to instead route based on /-delimited URL segments
*/
relative?: RelativeRoutingType;

/**
* In browser-based environments, prevent resetting scroll after this
* navigation when using the <ScrollRestoration> component
* Indicate a specific fetcherKey to use when using navigate=false
*/
preventScrollReset?: boolean;
fetcherKey?: string;

/**
* Enable flushSync for this navigation's state updates
* navigate=false will use a fetcher instead of a navigation
*/
unstable_flushSync?: boolean;
navigate?: boolean;

/**
* Enable view transitions on this submission navigation
Expand Down
3 changes: 2 additions & 1 deletion packages/react-router-dom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import type {
ParamKeyValuePair,
URLSearchParamsInit,
SubmitTarget,
FetcherSubmitOptions,
} from "./dom";
import {
createSearchParams,
Expand Down Expand Up @@ -1523,7 +1524,7 @@ export interface FetcherSubmitFunction {
(
target: SubmitTarget,
// Fetchers cannot replace or set state because they are not navigation events
options?: Omit<SubmitOptions, "replace" | "state">
options?: FetcherSubmitOptions
): void;
}

Expand Down