Skip to content

Commit

Permalink
fix(remix-react): don't warn about runtime deprecation warnings in pr…
Browse files Browse the repository at this point in the history
…oduction (#5874)
  • Loading branch information
mcansh committed Mar 22, 2023
1 parent 58779de commit 10187ee
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changeset/mean-deers-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"remix": patch
"@remix-run/react": patch
---

don't warn about runtime deprecation warnings in production
8 changes: 3 additions & 5 deletions packages/remix-react/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { deserializeErrors } from "./errors";
import type { RouteModules } from "./routeModules";
import { createClientRoutes } from "./routes";
import { warnOnce } from "./warnings";
import { logDeprecationOnce } from "./warnings";

/* eslint-disable prefer-let/prefer-let */
declare global {
Expand Down Expand Up @@ -140,8 +140,7 @@ if (import.meta && import.meta.hot) {
export function RemixBrowser(_props: RemixBrowserProps): ReactElement {
if (!router) {
if (!window.__remixContext.future.v2_errorBoundary) {
warnOnce(
false,
logDeprecationOnce(
"⚠️ DEPRECATED: The separation of `CatchBoundary` and `ErrorBoundary` has " +
"been deprecated and Remix v2 will use a singular `ErrorBoundary` for " +
"all thrown values (`Response` and `Error`). Please migrate to the new " +
Expand All @@ -152,8 +151,7 @@ export function RemixBrowser(_props: RemixBrowserProps): ReactElement {
}

if (!window.__remixContext.future.v2_normalizeFormMethod) {
warnOnce(
false,
logDeprecationOnce(
"⚠️ 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()` " +
Expand Down
26 changes: 12 additions & 14 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import type {
TransitionStates,
} from "./transition";
import { IDLE_TRANSITION, IDLE_FETCHER } from "./transition";
import { warnOnce } from "./warnings";
import { logDeprecationOnce } from "./warnings";

function useDataRouterContext() {
let context = React.useContext(DataRouterContext);
Expand Down Expand Up @@ -368,13 +368,14 @@ export function Links() {
);

React.useEffect(() => {
warnOnce(
links.some((link) => "imagesizes" in link || "imagesrcset" in link),
"⚠️ DEPRECATED: The `imagesizes` & `imagesrcset` properties in " +
"your links have been deprecated in favor of `imageSizes` & " +
"`imageSrcSet` and support will be removed in Remix v2. Please update " +
"your code to use the new property names instead."
);
if (links.some((link) => "imagesizes" in link || "imagesrcset" in link)) {
logDeprecationOnce(
"⚠️ DEPRECATED: The `imagesizes` & `imagesrcset` properties in " +
"your links have been deprecated in favor of `imageSizes` & " +
"`imageSrcSet` and support will be removed in Remix v2. Please update " +
"your code to use the new property names instead."
);
}
}, [links]);

return (
Expand Down Expand Up @@ -1234,8 +1235,7 @@ export function useTransition(): Transition {
let navigation = useNavigation();

React.useEffect(() => {
warnOnce(
false,
logDeprecationOnce(
"⚠️ DEPRECATED: The `useTransition` hook has been deprecated in favor of " +
"`useNavigation` and will be removed in Remix v2. Please update your " +
"code to leverage `useNavigation`.\n\nSee https://remix.run/docs/hooks/use-transition " +
Expand Down Expand Up @@ -1472,8 +1472,7 @@ function addFetcherDeprecationWarnings(fetcher: Fetcher) {
let type: Fetcher["type"] = fetcher.type;
Object.defineProperty(fetcher, "type", {
get() {
warnOnce(
false,
logDeprecationOnce(
"⚠️ DEPRECATED: The `useFetcher().type` field has been deprecated and " +
"will be removed in Remix v2. Please update your code to rely on " +
"`fetcher.state`.\n\nSee https://remix.run/docs/hooks/use-fetcher for " +
Expand All @@ -1494,8 +1493,7 @@ function addFetcherDeprecationWarnings(fetcher: Fetcher) {
let submission: Fetcher["submission"] = fetcher.submission;
Object.defineProperty(fetcher, "submission", {
get() {
warnOnce(
false,
logDeprecationOnce(
"⚠️ DEPRECATED: The `useFetcher().submission` field has been deprecated and " +
"will be removed in Remix v2. The submission fields now live directly " +
"on the fetcher (`fetcher.formData`).\n\n" +
Expand Down
10 changes: 10 additions & 0 deletions packages/remix-react/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ export function warnOnce(condition: boolean, message: string): void {
console.warn(message);
}
}

export function logDeprecationOnce(
message: string,
key: string = message
): void {
if (process.env.NODE_ENV !== "production" && !alreadyWarned[key]) {
alreadyWarned[key] = true;
console.warn(message);
}
}

0 comments on commit 10187ee

Please sign in to comment.