Skip to content

Commit

Permalink
Add deprecation warnings for v2_normalizeFormMethod (#5863)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Mar 21, 2023
1 parent e82db90 commit d9fd875
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/normalize-form-method-deprecation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@remix-run/dev": minor
"@remix-run/react": minor
---

Add deprecation warnings for `v2_normalizeFormMethod`
13 changes: 8 additions & 5 deletions docs/hooks/use-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import { useNavigation } from "@remix-run/react";

function SomeComponent() {
const navigation = useNavigation();
navigation.state;
navigation.location;
navigation.formData;
navigation.formAction;
navigation.formMethod;
navigation.state; // "idle" | "submitting" | "loading"
navigation.location; // Location being navigated to
navigation.formData; // formData being submitted
navigation.formAction; // url being submitted to
navigation.formMethod; // "GET" | "POST" | "PATCH" | "PUT" | "DELETE"
}
```

<docs-warning>The `useNavigation().formMethod` field is lowercase without the `future.v2_normalizeFormMethod` [Future Flag][api-development-strategy]. This is being normalized to uppercase to align with the `fetch()` behavior in v2, so please upgrade your Remix v1 applications to adopt the uppercase HTTP methods.</docs-warning>

<docs-info>For more information and usage, please refer to the [React Router `useNavigation` docs][rr-usenavigation].</docs-info>

[rr-usenavigation]: https://reactrouter.com/hooks/use-navigation
[api-development-strategy]: ../pages/api-development-strategy
1 change: 1 addition & 0 deletions integration/action-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test.describe("actions", () => {
future: {
v2_routeConvention: true,
v2_errorBoundary: true,
v2_normalizeFormMethod: true,
},
files: {
"app/routes/urlencoded.jsx": js`
Expand Down
1 change: 1 addition & 0 deletions integration/defer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test.describe("non-aborted", () => {
future: {
v2_routeConvention: true,
v2_errorBoundary: true,
v2_normalizeFormMethod: true,
},
files: {
"app/components/counter.tsx": js`
Expand Down
1 change: 1 addition & 0 deletions integration/hmr-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let fixture = (options: { port: number; appServerPort: number }) => ({
unstable_tailwind: true,
v2_routeConvention: true,
v2_errorBoundary: true,
v2_normalizeFormMethod: true,
},
files: {
"package.json": json({
Expand Down
8 changes: 7 additions & 1 deletion packages/remix-dev/__tests__/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import stripAnsi from "strip-ansi";

import { run } from "../cli/run";
import { server } from "./msw";
import { errorBoundaryWarning, flatRoutesWarning } from "../config";
import {
errorBoundaryWarning,
flatRoutesWarning,
formMethodWarning,
} from "../config";

beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
afterAll(() => server.close());
Expand Down Expand Up @@ -349,6 +353,8 @@ describe("the create command", () => {
]);
expect(output.trim()).toBe(
errorBoundaryWarning +
"\n" +
formMethodWarning +
"\n" +
flatRoutesWarning +
"\n\n" +
Expand Down
10 changes: 10 additions & 0 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ export async function readConfig(
warnOnce(errorBoundaryWarning, "v2_errorBoundary");
}

if (!appConfig.future?.v2_normalizeFormMethod) {
warnOnce(formMethodWarning, "v2_normalizeFormMethod");
}

let isCloudflareRuntime = ["cloudflare-pages", "cloudflare-workers"].includes(
appConfig.serverBuildTarget ?? ""
);
Expand Down Expand Up @@ -775,3 +779,9 @@ export const errorBoundaryWarning =
"behavior in Remix v1 via the `future.v2_errorBoundary` flag in your " +
"`remix.config.js` file. For more information, see " +
"https://remix.run/docs/route/error-boundary-v2";

export const formMethodWarning =
"⚠️ DEPRECATED: Please enable the `future.v2_normalizeFormMethod` flag to " +
"prepare for the Remix v2 release. Lowercase `useNavigation().formMethod`" +
"values are being normalized to uppercase in v2 to align with the `fetch()` " +
"behavior. For more information, see https://remix.run/docs/hooks/use-navigation";
10 changes: 10 additions & 0 deletions packages/remix-react/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ export function RemixBrowser(_props: RemixBrowserProps): ReactElement {
);
}

if (!window.__remixContext.future.v2_normalizeFormMethod) {
warnOnce(
false,
"⚠️ DEPRECATED: Please enable the `future.v2_normalizeFormMethod` flag to " +
"prepare for the Remix v2 release. Lowercase `useNavigation().formMethod`" +
"values are being normalized to uppercase in v2 to align with the `fetch()` " +
"behavior. For more information, see https://remix.run/docs/hooks/use-navigation"
);
}

let routes = createClientRoutes(
window.__remixManifest.routes,
window.__remixRouteModules,
Expand Down

0 comments on commit d9fd875

Please sign in to comment.