Skip to content

Commit c631bac

Browse files
committed
Remove future.v7_normalizeFormMethod
1 parent 972a1fb commit c631bac

File tree

10 files changed

+36
-55
lines changed

10 files changed

+36
-55
lines changed

.changeset/fair-cheetahs-hope.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"react-router-dom": major
3+
"react-router": major
4+
---
5+
6+
Remove `future.v7_normalizeFormMethod` future flag

docs/community/api-development-strategy.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,15 @@ These flags are only applicable when using a [Data Router][picking-a-router] and
5656

5757
```js
5858
const router = createBrowserRouter(routes, {
59-
future: {
60-
v7_normalizeFormMethod: true,
61-
},
59+
future: {},
6260
});
6361
```
6462

65-
| Flag | Description |
66-
| ----------------------------------------- | --------------------------------------------------------------------- |
67-
| `v7_fetcherPersist` | Delay active fetcher cleanup until they return to an `idle` state |
68-
| `v7_normalizeFormMethod` | Normalize `useNavigation().formMethod` to be an uppercase HTTP Method |
69-
| [`v7_partialHydration`][partialhydration] | Support partial hydration for Server-rendered apps |
70-
| `v7_prependBasename` | Prepend the router basename to navigate/fetch paths |
63+
| Flag | Description |
64+
| ----------------------------------------- | ----------------------------------------------------------------- |
65+
| `v7_fetcherPersist` | Delay active fetcher cleanup until they return to an `idle` state |
66+
| [`v7_partialHydration`][partialhydration] | Support partial hydration for Server-rendered apps |
67+
| `v7_prependBasename` | Prepend the router basename to navigate/fetch paths |
7168

7269
#### `createStaticHandler` Future Flags
7370

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ describe("submissions", () => {
536536
expect(t.router.state.fetchers.get("key")?.formMethod).toBeUndefined();
537537
});
538538

539-
it("normalizes to uppercase in v7 via v7_normalizeFormMethod", async () => {
539+
it("normalizes to uppercase", async () => {
540540
let t = setup({
541541
routes: [
542542
{
@@ -553,7 +553,6 @@ describe("submissions", () => {
553553
},
554554
],
555555
future: {
556-
v7_normalizeFormMethod: true,
557556
v7_prependBasename: false,
558557
},
559558
});

packages/react-router/__tests__/router/utils/data-router-setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ export function setup({
507507
// Otherwise we should only need a loader for the leaf match
508508
let activeLoaderMatches = [match];
509509
// @ts-expect-error
510-
if (opts?.formMethod != null && opts.formMethod.toLowerCase() !== "get") {
510+
if (opts?.formMethod != null && opts.formMethod.toUpperCase() !== "GET") {
511511
if (currentRouter.state.navigation?.location) {
512512
let matches = matchRoutes(
513513
inFlightRoutes || currentRouter.routes,
@@ -572,7 +572,7 @@ export function setup({
572572
invariant(currentRouter, "No currentRouter available");
573573

574574
// @ts-expect-error
575-
if (opts?.formMethod != null && opts.formMethod.toLowerCase() !== "get") {
575+
if (opts?.formMethod != null && opts.formMethod.toUpperCase() !== "GET") {
576576
activeActionType = "navigation";
577577
activeActionNavigationId = navigationId;
578578
// Assume happy path and mark this navigations loaders as active. Even if
@@ -662,7 +662,7 @@ export function setup({
662662
invariant(currentRouter, "No currentRouter available");
663663

664664
// @ts-expect-error
665-
if (opts?.formMethod != null && opts.formMethod.toLowerCase() !== "get") {
665+
if (opts?.formMethod != null && opts.formMethod.toUpperCase() !== "GET") {
666666
activeActionType = "fetch";
667667
activeActionFetchId = navigationId;
668668
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export type URLSearchParamsInit =
5959
supports arrays as values in the object form of the initializer
6060
instead of just strings. This is convenient when you need multiple
6161
values for a given key, but don't want to use an array initializer.
62-
62+
6363
For example, instead of:
64-
64+
6565
```tsx
6666
let searchParams = new URLSearchParams([
6767
['sort', 'name'],

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ export function createStaticRouter(
304304
get future() {
305305
return {
306306
v7_fetcherPersist: false,
307-
v7_normalizeFormMethod: false,
308307
v7_partialHydration: opts.future?.v7_partialHydration === true,
309308
v7_prependBasename: false,
310309
unstable_skipActionErrorRevalidation: false,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ function createHydratedRouter(): RemixRouter {
162162
history: createBrowserHistory(),
163163
basename: ssrInfo.context.basename,
164164
future: {
165-
v7_normalizeFormMethod: true,
166165
v7_fetcherPersist: ssrInfo.context.future.v3_fetcherPersist,
167166
v7_partialHydration: true,
168167
v7_prependBasename: true,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export type {
3434
TrackedPromise,
3535
UIMatch,
3636
UpperCaseFormMethod,
37-
V7_FormMethod,
3837
} from "./utils";
3938

4039
export {

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import type {
3333
Submission,
3434
SuccessResult,
3535
UIMatch,
36-
V7_FormMethod,
37-
V7_MutationFormMethod,
3836
} from "./utils";
3937
import {
4038
ErrorResponseImpl,
@@ -355,7 +353,6 @@ export type HydrationState = Partial<
355353
*/
356354
export interface FutureConfig {
357355
v7_fetcherPersist: boolean;
358-
v7_normalizeFormMethod: boolean;
359356
v7_partialHydration: boolean;
360357
v7_prependBasename: boolean;
361358
unstable_skipActionErrorRevalidation: boolean;
@@ -714,17 +711,17 @@ interface RevalidatingFetcher extends FetchLoadMatch {
714711
}
715712

716713
const validMutationMethodsArr: MutationFormMethod[] = [
717-
"post",
718-
"put",
719-
"patch",
720-
"delete",
714+
"POST",
715+
"PUT",
716+
"PATCH",
717+
"DELETE",
721718
];
722719
const validMutationMethods = new Set<MutationFormMethod>(
723720
validMutationMethodsArr
724721
);
725722

726723
const validRequestMethodsArr: FormMethod[] = [
727-
"get",
724+
"GET",
728725
...validMutationMethodsArr,
729726
];
730727
const validRequestMethods = new Set<FormMethod>(validRequestMethodsArr);
@@ -822,7 +819,6 @@ export function createRouter(init: RouterInit): Router {
822819
// Config driven behavior flags
823820
let future: FutureConfig = {
824821
v7_fetcherPersist: false,
825-
v7_normalizeFormMethod: false,
826822
v7_partialHydration: false,
827823
v7_prependBasename: false,
828824
unstable_skipActionErrorRevalidation: false,
@@ -1341,7 +1337,6 @@ export function createRouter(init: RouterInit): Router {
13411337
opts?.relative
13421338
);
13431339
let { path, submission, error } = normalizeNavigateOptions(
1344-
future.v7_normalizeFormMethod,
13451340
false,
13461341
normalizedPath,
13471342
opts
@@ -1995,7 +1990,6 @@ export function createRouter(init: RouterInit): Router {
19951990
}
19961991

19971992
let { path, submission, error } = normalizeNavigateOptions(
1998-
future.v7_normalizeFormMethod,
19991993
true,
20001994
normalizedPath,
20011995
opts
@@ -3243,7 +3237,7 @@ export function createStaticHandler(
32433237
);
32443238

32453239
try {
3246-
if (isMutationMethod(request.method.toLowerCase())) {
3240+
if (isMutationMethod(request.method)) {
32473241
let result = await submit(
32483242
request,
32493243
matches,
@@ -3715,7 +3709,6 @@ function normalizeTo(
37153709
// Normalize navigation options by converting formMethod=GET formData objects to
37163710
// URLSearchParams so they behave identically to links with query params
37173711
function normalizeNavigateOptions(
3718-
normalizeFormMethod: boolean,
37193712
isFetcher: boolean,
37203713
path: string,
37213714
opts?: BaseNavigateOrFetchOptions
@@ -3743,9 +3736,7 @@ function normalizeNavigateOptions(
37433736

37443737
// Create a Submission on non-GET navigations
37453738
let rawFormMethod = opts.formMethod || "get";
3746-
let formMethod = normalizeFormMethod
3747-
? (rawFormMethod.toUpperCase() as V7_FormMethod)
3748-
: (rawFormMethod.toLowerCase() as FormMethod);
3739+
let formMethod = rawFormMethod.toUpperCase() as FormMethod;
37493740
let formAction = stripHashFromPath(path);
37503741

37513742
if (opts.body !== undefined) {
@@ -4987,14 +4978,12 @@ function isRedirectResponse(result: any): result is Response {
49874978
return status >= 300 && status <= 399 && location != null;
49884979
}
49894980

4990-
function isValidMethod(method: string): method is FormMethod | V7_FormMethod {
4991-
return validRequestMethods.has(method.toLowerCase() as FormMethod);
4981+
function isValidMethod(method: string): method is FormMethod {
4982+
return validRequestMethods.has(method.toUpperCase() as FormMethod);
49924983
}
49934984

4994-
function isMutationMethod(
4995-
method: string
4996-
): method is MutationFormMethod | V7_MutationFormMethod {
4997-
return validMutationMethods.has(method.toLowerCase() as MutationFormMethod);
4985+
function isMutationMethod(method: string): method is MutationFormMethod {
4986+
return validMutationMethods.has(method.toUpperCase() as MutationFormMethod);
49984987
}
49994988

50004989
async function resolveDeferredResults(

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,11 @@ export type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
8282
export type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
8383

8484
/**
85-
* Active navigation/fetcher form methods are exposed in lowercase on the
86-
* RouterState
85+
* Active navigation/fetcher form methods are exposed in uppercase on the
86+
* RouterState. This is to align with the normalization done via fetch().
8787
*/
88-
export type FormMethod = LowerCaseFormMethod;
89-
export type MutationFormMethod = Exclude<FormMethod, "get">;
90-
91-
/**
92-
* In v7, active navigation/fetcher form methods are exposed in uppercase on the
93-
* RouterState. This is to align with the normalization done via fetch().
94-
*/
95-
export type V7_FormMethod = UpperCaseFormMethod;
96-
export type V7_MutationFormMethod = Exclude<V7_FormMethod, "GET">;
88+
export type FormMethod = UpperCaseFormMethod;
89+
export type MutationFormMethod = Exclude<FormMethod, "GET">;
9790

9891
export type FormEncType =
9992
| "application/x-www-form-urlencoded"
@@ -116,23 +109,23 @@ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
116109
*/
117110
export type Submission =
118111
| {
119-
formMethod: FormMethod | V7_FormMethod;
112+
formMethod: FormMethod;
120113
formAction: string;
121114
formEncType: FormEncType;
122115
formData: FormData;
123116
json: undefined;
124117
text: undefined;
125118
}
126119
| {
127-
formMethod: FormMethod | V7_FormMethod;
120+
formMethod: FormMethod;
128121
formAction: string;
129122
formEncType: FormEncType;
130123
formData: undefined;
131124
json: JsonValue;
132125
text: undefined;
133126
}
134127
| {
135-
formMethod: FormMethod | V7_FormMethod;
128+
formMethod: FormMethod;
136129
formAction: string;
137130
formEncType: FormEncType;
138131
formData: undefined;

0 commit comments

Comments
 (0)