Skip to content

feat(react-router): only render dev warnings in dev #13461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-bugs-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": patch
---

Only render dev warnings in DEV mode
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
- thethmuu
- thisiskartik
- thomasgauvin
- ThomasTheTitan
- thomasverleye
- ThornWu
- tiborbarsi
Expand Down
5 changes: 1 addition & 4 deletions packages/react-router/lib/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
AwaitContext,
DataRouterContext,
DataRouterStateContext,
ENABLE_DEV_WARNINGS,
FetchersContext,
LocationContext,
NavigationContext,
Expand All @@ -63,10 +64,6 @@ import {
import type { ViewTransition } from "./dom/global";
import { warnOnce } from "./server-runtime/warnings";

// Provided by the build system
declare const __DEV__: boolean;
const ENABLE_DEV_WARNINGS = __DEV__;

/**
* @private
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/react-router/lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,7 @@ RouteContext.displayName = "Route";

export const RouteErrorContext = React.createContext<any>(null);
RouteErrorContext.displayName = "RouteError";

// Provided by the build system
declare const __DEV__: boolean;
export const ENABLE_DEV_WARNINGS = __DEV__;
5 changes: 3 additions & 2 deletions packages/react-router/lib/dom/ssr/errorBoundaries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from "react";
import { Scripts, useFrameworkContext } from "./components";
import type { Location } from "../../router/history";
import { isRouteErrorResponse } from "../../router/utils";
import { ENABLE_DEV_WARNINGS } from "../../context";

type RemixErrorBoundaryProps = React.PropsWithChildren<{
location: Location;
Expand Down Expand Up @@ -83,7 +84,7 @@ export function RemixRootDefaultErrorBoundary({
dangerouslySetInnerHTML={{
__html: `
console.log(
"💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://remix.run/guides/errors for more information."
"💿 Hey developer 👋. You can provide a way better UX than this when your app throws errors. Check out https://reactrouter.com/how-to/error-boundary for more information."
);
`,
}}
Expand All @@ -96,7 +97,7 @@ export function RemixRootDefaultErrorBoundary({
<h1 style={{ fontSize: "24px" }}>
{error.status} {error.statusText}
</h1>
{heyDeveloper}
{ENABLE_DEV_WARNINGS ? heyDeveloper : null}
</BoundaryShell>
);
}
Expand Down
15 changes: 9 additions & 6 deletions packages/react-router/lib/dom/ssr/fallback.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from "react";

import { BoundaryShell } from "./errorBoundaries";
import { ENABLE_DEV_WARNINGS } from "../../context";

// If the user sets `clientLoader.hydrate=true` somewhere but does not
// provide a `HydrateFallback` at any level of the tree, then we need to at
Expand All @@ -9,18 +10,20 @@ import { BoundaryShell } from "./errorBoundaries";
export function RemixRootDefaultHydrateFallback() {
return (
<BoundaryShell title="Loading..." renderScripts>
<script
dangerouslySetInnerHTML={{
__html: `
{ENABLE_DEV_WARNINGS ? (
<script
dangerouslySetInnerHTML={{
__html: `
console.log(
"💿 Hey developer 👋. You can provide a way better UX than this " +
"when your app is loading JS modules and/or running \`clientLoader\` " +
"functions. Check out https://remix.run/route/hydrate-fallback " +
"functions. Check out https://reactrouter.com/start/framework/route-module#hydratefallback " +
"for more information."
);
`,
}}
/>
}}
/>
) : null}
</BoundaryShell>
);
}
5 changes: 1 addition & 4 deletions packages/react-router/lib/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
AwaitContext,
DataRouterContext,
DataRouterStateContext,
ENABLE_DEV_WARNINGS,
LocationContext,
NavigationContext,
RouteContext,
Expand Down Expand Up @@ -51,10 +52,6 @@ import {
} from "./router/utils";
import type { SerializeFrom } from "./types/route-data";

// Provided by the build system
declare const __DEV__: boolean;
const ENABLE_DEV_WARNINGS = __DEV__;

/**
Resolves a URL against the current location.

Expand Down