Skip to content

Commit

Permalink
Remove future.v7_normalizeFormMethod (#11697)
Browse files Browse the repository at this point in the history
* Remove future.v7_normalizeFormMethod

* fix build

* Fix tests
  • Loading branch information
brophdawg11 authored Jun 25, 2024
1 parent 714a2c5 commit 618a5be
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 74 deletions.
6 changes: 6 additions & 0 deletions .changeset/fair-cheetahs-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"react-router-dom": major
"react-router": major
---

Remove `future.v7_normalizeFormMethod` future flag
1 change: 0 additions & 1 deletion packages/react-router-dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export type {
FormMethod,
GetScrollRestorationKeyFunction,
StaticHandlerContext,
V7_FormMethod,
BrowserRouterProps,
HashRouterProps,
HistoryRouterProps,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/__tests__/router/fetchers-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe("fetchers", () => {
formData: createFormData({ key: "value" }),
});
expect(A.fetcher.state).toBe("loading");
expect(A.fetcher.formMethod).toBe("get");
expect(A.fetcher.formMethod).toBe("GET");
expect(A.fetcher.formAction).toBe("/foo");
expect(A.fetcher.formData).toEqual(createFormData({ key: "value" }));
expect(A.fetcher.formEncType).toBe("application/x-www-form-urlencoded");
Expand Down Expand Up @@ -2111,7 +2111,7 @@ describe("fetchers", () => {
"formAction": "/two/three",
"formData": FormData {},
"formEncType": "application/x-www-form-urlencoded",
"formMethod": "post",
"formMethod": "POST",
"json": undefined,
"nextParams": {
"a": "two",
Expand Down
10 changes: 5 additions & 5 deletions packages/react-router/__tests__/router/navigation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ describe("navigations", () => {
// @ts-expect-error
new URLSearchParams(navigation.formData).toString()
).toBe("gosh=dang");
expect(navigation.formMethod).toBe("post");
expect(navigation.formMethod).toBe("POST");
expect(navigation.formEncType).toBe("application/x-www-form-urlencoded");
expect(navigation.location).toMatchObject({
pathname: "/foo",
Expand All @@ -1169,7 +1169,7 @@ describe("navigations", () => {
// @ts-expect-error
new URLSearchParams(navigation.formData).toString()
).toBe("gosh=dang");
expect(navigation.formMethod).toBe("post");
expect(navigation.formMethod).toBe("POST");
expect(navigation.formEncType).toBe("application/x-www-form-urlencoded");
expect(navigation.location).toMatchObject({
pathname: "/foo",
Expand Down Expand Up @@ -1203,7 +1203,7 @@ describe("navigations", () => {
// @ts-expect-error
new URLSearchParams(navigation.formData).toString()
).toBe("gosh=dang");
expect(navigation.formMethod).toBe("post");
expect(navigation.formMethod).toBe("POST");
expect(navigation.location).toMatchObject({
pathname: "/bar",
search: "",
Expand All @@ -1229,7 +1229,7 @@ describe("navigations", () => {
let navigation = t.router.state.navigation;
expect(navigation.state).toBe("loading");
expect(navigation.formData).toEqual(createFormData({ gosh: "dang" }));
expect(navigation.formMethod).toBe("get");
expect(navigation.formMethod).toBe("GET");
expect(navigation.formEncType).toBe("application/x-www-form-urlencoded");
expect(navigation.location).toMatchObject({
pathname: "/foo",
Expand Down Expand Up @@ -1257,7 +1257,7 @@ describe("navigations", () => {
let navigation = t.router.state.navigation;
expect(navigation.state).toBe("loading");
expect(navigation.formData).toEqual(createFormData({ gosh: "dang" }));
expect(navigation.formMethod).toBe("get");
expect(navigation.formMethod).toBe("GET");
expect(navigation.formEncType).toBe("application/x-www-form-urlencoded");
expect(navigation.location?.pathname).toBe("/bar");

Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/__tests__/router/revalidate-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describe("router.revalidate", () => {
pathname: "/tasks",
search: "?key=value",
},
formMethod: "get",
formMethod: "GET",
formData: createFormData({ key: "value" }),
},
revalidation: "loading",
Expand Down
8 changes: 4 additions & 4 deletions packages/react-router/__tests__/router/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ describe("a router", () => {
pathname: "/tasks",
search: "?key=value",
});
expect(t.router.state.navigation.formMethod).toBe("get");
expect(t.router.state.navigation.formMethod).toBe("GET");
expect(t.router.state.navigation.formData).toEqual(
createFormData({ key: "value" })
);
Expand All @@ -710,7 +710,7 @@ describe("a router", () => {
pathname: "/tasks",
search: "?key=value",
});
expect(t.router.state.navigation.formMethod).toBe("get");
expect(t.router.state.navigation.formMethod).toBe("GET");
expect(t.router.state.navigation.formData).toEqual(
createFormData({ key: "value" })
);
Expand All @@ -730,7 +730,7 @@ describe("a router", () => {
pathname: "/tasks",
search: "?key=2",
});
expect(t.router.state.navigation.formMethod).toBe("get");
expect(t.router.state.navigation.formMethod).toBe("GET");
expect(t.router.state.navigation.formData).toEqual(
createFormData({ key: "2" })
);
Expand All @@ -750,7 +750,7 @@ describe("a router", () => {
pathname: "/tasks",
search: "?key=1",
});
expect(t.router.state.navigation.formMethod).toBe("post");
expect(t.router.state.navigation.formMethod).toBe("POST");
expect(t.router.state.navigation.formData).toEqual(
createFormData({ key: "2" })
);
Expand Down
16 changes: 8 additions & 8 deletions packages/react-router/__tests__/router/should-revalidate-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ describe("shouldRevalidate", () => {
nextParams: {},
nextUrl: expect.urlMatch("http://localhost/child"),
defaultShouldRevalidate: true,
formMethod: "post",
formMethod: "POST",
formAction: "/child",
formEncType: "application/x-www-form-urlencoded",
actionResult: "ACTION",
Expand Down Expand Up @@ -310,7 +310,7 @@ describe("shouldRevalidate", () => {
nextParams: {},
nextUrl: expect.urlMatch("http://localhost/"),
defaultShouldRevalidate: true,
formMethod: "post",
formMethod: "POST",
formAction: "/child",
formEncType: "application/x-www-form-urlencoded",
actionResult: undefined,
Expand Down Expand Up @@ -364,7 +364,7 @@ describe("shouldRevalidate", () => {
nextParams: {},
nextUrl: expect.urlMatch("http://localhost/child"),
defaultShouldRevalidate: true,
formMethod: "post",
formMethod: "POST",
formAction: "/child",
formEncType: "application/x-www-form-urlencoded",
actionResult: "ACTION",
Expand Down Expand Up @@ -406,7 +406,7 @@ describe("shouldRevalidate", () => {
// @ts-expect-error
let arg = shouldRevalidate.mock.calls[0][0];
let expectedArg: Partial<ShouldRevalidateFunctionArgs> = {
formMethod: "post",
formMethod: "POST",
formAction: "/",
formEncType: "application/json",
text: undefined,
Expand Down Expand Up @@ -448,7 +448,7 @@ describe("shouldRevalidate", () => {
// @ts-expect-error
let arg = shouldRevalidate.mock.calls[0][0];
let expectedArg: Partial<ShouldRevalidateFunctionArgs> = {
formMethod: "post",
formMethod: "POST",
formAction: "/",
formEncType: "text/plain",
text: "hello world",
Expand Down Expand Up @@ -657,7 +657,7 @@ describe("shouldRevalidate", () => {
formAction: "/child",
formData: createFormData({}),
formEncType: "application/x-www-form-urlencoded",
formMethod: "post",
formMethod: "POST",
defaultShouldRevalidate: true,
});

Expand Down Expand Up @@ -715,7 +715,7 @@ describe("shouldRevalidate", () => {
"formAction": "/fetch",
"formData": FormData {},
"formEncType": "application/x-www-form-urlencoded",
"formMethod": "post",
"formMethod": "POST",
"json": undefined,
"nextParams": {},
"nextUrl": "http://localhost/",
Expand Down Expand Up @@ -779,7 +779,7 @@ describe("shouldRevalidate", () => {
"formAction": "/fetch",
"formData": FormData {},
"formEncType": "application/x-www-form-urlencoded",
"formMethod": "post",
"formMethod": "POST",
"json": undefined,
"nextParams": {},
"nextUrl": "http://localhost/",
Expand Down
15 changes: 7 additions & 8 deletions packages/react-router/__tests__/router/submission-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,16 +504,16 @@ describe("submissions", () => {
formMethod: "get",
formData: createFormData({}),
});
expect(t.router.state.navigation.formMethod).toBe("get");
expect(t.router.state.navigation.formMethod).toBe("GET");
await A.loaders.child.resolve("LOADER");
expect(t.router.state.navigation.formMethod).toBeUndefined();
await t.router.navigate("/");

let B = await t.navigate("/child", {
formMethod: "POST",
formMethod: "post",
formData: createFormData({}),
});
expect(t.router.state.navigation.formMethod).toBe("post");
expect(t.router.state.navigation.formMethod).toBe("POST");
await B.actions.child.resolve("ACTION");
await B.loaders.child.resolve("LOADER");
expect(t.router.state.navigation.formMethod).toBeUndefined();
Expand All @@ -523,20 +523,20 @@ describe("submissions", () => {
formMethod: "GET",
formData: createFormData({}),
});
expect(t.router.state.fetchers.get("key")?.formMethod).toBe("get");
expect(t.router.state.fetchers.get("key")?.formMethod).toBe("GET");
await C.loaders.child.resolve("LOADER FETCH");
expect(t.router.state.fetchers.get("key")?.formMethod).toBeUndefined();

let D = await t.fetch("/child", "key", {
formMethod: "post",
formMethod: "POST",
formData: createFormData({}),
});
expect(t.router.state.fetchers.get("key")?.formMethod).toBe("post");
expect(t.router.state.fetchers.get("key")?.formMethod).toBe("POST");
await D.actions.child.resolve("ACTION FETCH");
expect(t.router.state.fetchers.get("key")?.formMethod).toBeUndefined();
});

it("normalizes to uppercase in v7 via v7_normalizeFormMethod", async () => {
it("normalizes to uppercase", async () => {
let t = setup({
routes: [
{
Expand All @@ -553,7 +553,6 @@ describe("submissions", () => {
},
],
future: {
v7_normalizeFormMethod: true,
v7_prependBasename: false,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export function setup({
// Otherwise we should only need a loader for the leaf match
let activeLoaderMatches = [match];
// @ts-expect-error
if (opts?.formMethod != null && opts.formMethod.toLowerCase() !== "get") {
if (opts?.formMethod != null && opts.formMethod.toUpperCase() !== "GET") {
if (currentRouter.state.navigation?.location) {
let matches = matchRoutes(
inFlightRoutes || currentRouter.routes,
Expand Down Expand Up @@ -572,7 +572,7 @@ export function setup({
invariant(currentRouter, "No currentRouter available");

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

// @ts-expect-error
if (opts?.formMethod != null && opts.formMethod.toLowerCase() !== "get") {
if (opts?.formMethod != null && opts.formMethod.toUpperCase() !== "GET") {
activeActionType = "fetch";
activeActionFetchId = navigationId;
} else {
Expand Down
1 change: 0 additions & 1 deletion packages/react-router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ export type {
GetScrollRestorationKeyFunction,
StaticHandlerContext,
Submission,
V7_FormMethod,
} from "./lib/router";

export type {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/lib/dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export type URLSearchParamsInit =
supports arrays as values in the object form of the initializer
instead of just strings. This is convenient when you need multiple
values for a given key, but don't want to use an array initializer.
For example, instead of:
```tsx
let searchParams = new URLSearchParams([
['sort', 'name'],
Expand Down
1 change: 0 additions & 1 deletion packages/react-router/lib/dom/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ export function createStaticRouter(
get future() {
return {
v7_fetcherPersist: false,
v7_normalizeFormMethod: false,
v7_partialHydration: opts.future?.v7_partialHydration === true,
v7_prependBasename: false,
unstable_skipActionErrorRevalidation: false,
Expand Down
1 change: 0 additions & 1 deletion packages/react-router/lib/dom/ssr/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ function createHydratedRouter(): RemixRouter {
history: createBrowserHistory(),
basename: ssrInfo.context.basename,
future: {
v7_normalizeFormMethod: true,
v7_fetcherPersist: ssrInfo.context.future.v3_fetcherPersist,
v7_partialHydration: true,
v7_prependBasename: true,
Expand Down
1 change: 0 additions & 1 deletion packages/react-router/lib/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export type {
TrackedPromise,
UIMatch,
UpperCaseFormMethod,
V7_FormMethod,
} from "./utils";

export {
Expand Down
Loading

0 comments on commit 618a5be

Please sign in to comment.