Skip to content

Commit 6654bb6

Browse files
committed
Remove future.v7_normalizeFormMethod
1 parent bc69187 commit 6654bb6

File tree

9 files changed

+30
-46
lines changed

9 files changed

+30
-46
lines changed

.changeset/fair-cheetahs-hope.md

+6
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

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

+1-2
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

+3-3
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

+2-2
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

-1
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

-1
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

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export type {
3535
TrackedPromise,
3636
UIMatch,
3737
UpperCaseFormMethod,
38-
V7_FormMethod,
3938
} from "./utils";
4039

4140
export {

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

+11-22
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
AgnosticPatchRoutesOnMissFunction,
3937
} from "./utils";
4038
import {
@@ -367,7 +365,6 @@ export type HydrationState = Partial<
367365
*/
368366
export interface FutureConfig {
369367
v7_fetcherPersist: boolean;
370-
v7_normalizeFormMethod: boolean;
371368
v7_partialHydration: boolean;
372369
v7_prependBasename: boolean;
373370
unstable_skipActionErrorRevalidation: boolean;
@@ -735,17 +732,17 @@ interface RevalidatingFetcher extends FetchLoadMatch {
735732
}
736733

737734
const validMutationMethodsArr: MutationFormMethod[] = [
738-
"post",
739-
"put",
740-
"patch",
741-
"delete",
735+
"POST",
736+
"PUT",
737+
"PATCH",
738+
"DELETE",
742739
];
743740
const validMutationMethods = new Set<MutationFormMethod>(
744741
validMutationMethodsArr
745742
);
746743

747744
const validRequestMethodsArr: FormMethod[] = [
748-
"get",
745+
"GET",
749746
...validMutationMethodsArr,
750747
];
751748
const validRequestMethods = new Set<FormMethod>(validRequestMethodsArr);
@@ -845,7 +842,6 @@ export function createRouter(init: RouterInit): Router {
845842
// Config driven behavior flags
846843
let future: FutureConfig = {
847844
v7_fetcherPersist: false,
848-
v7_normalizeFormMethod: false,
849845
v7_partialHydration: false,
850846
v7_prependBasename: false,
851847
unstable_skipActionErrorRevalidation: false,
@@ -1373,7 +1369,6 @@ export function createRouter(init: RouterInit): Router {
13731369
opts?.relative
13741370
);
13751371
let { path, submission, error } = normalizeNavigateOptions(
1376-
future.v7_normalizeFormMethod,
13771372
false,
13781373
normalizedPath,
13791374
opts
@@ -2180,7 +2175,6 @@ export function createRouter(init: RouterInit): Router {
21802175
}
21812176

21822177
let { path, submission, error } = normalizeNavigateOptions(
2183-
future.v7_normalizeFormMethod,
21842178
true,
21852179
normalizedPath,
21862180
opts
@@ -3668,7 +3662,7 @@ export function createStaticHandler(
36683662
);
36693663

36703664
try {
3671-
if (isMutationMethod(request.method.toLowerCase())) {
3665+
if (isMutationMethod(request.method)) {
36723666
let result = await submit(
36733667
request,
36743668
matches,
@@ -4140,7 +4134,6 @@ function normalizeTo(
41404134
// Normalize navigation options by converting formMethod=GET formData objects to
41414135
// URLSearchParams so they behave identically to links with query params
41424136
function normalizeNavigateOptions(
4143-
normalizeFormMethod: boolean,
41444137
isFetcher: boolean,
41454138
path: string,
41464139
opts?: BaseNavigateOrFetchOptions
@@ -4168,9 +4161,7 @@ function normalizeNavigateOptions(
41684161

41694162
// Create a Submission on non-GET navigations
41704163
let rawFormMethod = opts.formMethod || "get";
4171-
let formMethod = normalizeFormMethod
4172-
? (rawFormMethod.toUpperCase() as V7_FormMethod)
4173-
: (rawFormMethod.toLowerCase() as FormMethod);
4164+
let formMethod = rawFormMethod.toUpperCase() as FormMethod;
41744165
let formAction = stripHashFromPath(path);
41754166

41764167
if (opts.body !== undefined) {
@@ -5501,14 +5492,12 @@ function isRedirectResponse(result: any): result is Response {
55015492
return status >= 300 && status <= 399 && location != null;
55025493
}
55035494

5504-
function isValidMethod(method: string): method is FormMethod | V7_FormMethod {
5505-
return validRequestMethods.has(method.toLowerCase() as FormMethod);
5495+
function isValidMethod(method: string): method is FormMethod {
5496+
return validRequestMethods.has(method.toUpperCase() as FormMethod);
55065497
}
55075498

5508-
function isMutationMethod(
5509-
method: string
5510-
): method is MutationFormMethod | V7_MutationFormMethod {
5511-
return validMutationMethods.has(method.toLowerCase() as MutationFormMethod);
5499+
function isMutationMethod(method: string): method is MutationFormMethod {
5500+
return validMutationMethods.has(method.toUpperCase() as MutationFormMethod);
55125501
}
55135502

55145503
async function resolveDeferredResults(

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

+7-14
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)