Skip to content

Commit 7819e04

Browse files
authored
chore: re-enable development warnings (remix-run#12269)
* chore: re-enable development warnings * remove warning as we are testing against production build. It is covered in unit tests * Create four-needles-search.md * chore: add ssr conditions / external conditions
1 parent 37a55e3 commit 7819e04

File tree

8 files changed

+84
-62
lines changed

8 files changed

+84
-62
lines changed

.changeset/four-needles-search.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"integration": patch
3+
"@react-router/dev": patch
4+
"react-router": patch
5+
---
6+
7+
chore: re-enable development warnings through a `development` exports condition.

integration/vite-spa-mode-test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,16 +566,6 @@ test.describe("SPA Mode", () => {
566566
await page.waitForSelector("[data-root]");
567567
expect(await page.locator("[data-root]").textContent()).toBe("Root");
568568
expect(await page.locator("[data-index]").textContent()).toBe("Index");
569-
570-
// Hydrates without issues - this message is expected due to the nested <Routes>
571-
expect(logs).toEqual([
572-
'You rendered descendant <Routes> (or called `useRoutes()`) at "/" ' +
573-
'(under <Route path="">) but the parent route path has no trailing "*". ' +
574-
"This means if you navigate deeper, the parent won't match anymore and " +
575-
"therefore the child routes will never render." +
576-
"\n\n" +
577-
'Please change the parent <Route path=""> to <Route path="/*">.',
578-
]);
579569
});
580570

581571
test("wraps default root HydrateFallback in user-provided Layout", async ({

jest/jest.config.shared.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ module.exports = {
2424
"\\.[jt]sx?$": require.resolve("./transform"),
2525
},
2626
watchPathIgnorePatterns: [...ignorePatterns, "\\/node_modules\\/"],
27+
globals: {
28+
__DEV__: true,
29+
},
2730
};

packages/react-router-dev/vite/plugin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
821821

822822
ssr: {
823823
external: ssrExternals,
824+
resolve: {
825+
conditions: viteCommand === "build" ? [] : ["development"],
826+
externalConditions:
827+
viteCommand === "build" ? [] : ["development"],
828+
},
824829
},
825830
optimizeDeps: {
826831
include: [
@@ -858,6 +863,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
858863
"react-router/dom",
859864
"react-router-dom",
860865
],
866+
conditions: viteCommand === "build" ? [] : ["development"],
861867
},
862868
base: viteUserConfig.base,
863869

packages/react-router/lib/components.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ import {
6262
import type { ViewTransition } from "./dom/global";
6363
import { warnOnce } from "./server-runtime/warnings";
6464

65-
// TODO: Let's get this back to using an import map and development/production
66-
// condition once we get the rollup build replaced
67-
const ENABLE_DEV_WARNINGS = true;
65+
// Provided by the build system
66+
declare const __DEV__: boolean;
67+
const ENABLE_DEV_WARNINGS = __DEV__;
6868

6969
/**
7070
* @private

packages/react-router/lib/hooks.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ import {
5050
} from "./router/utils";
5151
import type { SerializeFrom } from "./types";
5252

53-
// TODO: Let's get this back to using an import map and development/production
54-
// condition once we get the rollup build replaced
55-
const ENABLE_DEV_WARNINGS = true;
53+
// Provided by the build system
54+
declare const __DEV__: boolean;
55+
const ENABLE_DEV_WARNINGS = __DEV__;
5656

5757
/**
5858
Resolves a URL against the current location.

packages/react-router/package.json

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,53 @@
1818
"license": "MIT",
1919
"author": "Remix Software <[email protected]>",
2020
"sideEffects": false,
21-
"types": "./dist/index.d.ts",
22-
"main": "./dist/index.js",
23-
"unpkg": "./dist/umd/react-router.production.min.js",
24-
"module": "./dist/index.mjs",
21+
"types": "./dist/production/index.d.ts",
22+
"main": "./dist/production/index.js",
23+
"module": "./dist/production/index.mjs",
2524
"exports": {
2625
".": {
2726
"node": {
28-
"types": "./dist/index.d.ts",
29-
"module-sync": "./dist/index.mjs",
30-
"default": "./dist/index.js"
27+
"types": "./dist/production/index.d.ts",
28+
"development": {
29+
"module-sync": "./dist/development/index.mjs",
30+
"default": "./dist/development/index.js"
31+
},
32+
"module-sync": "./dist/production/index.mjs",
33+
"default": "./dist/production/index.js"
3134
},
3235
"import": {
33-
"types": "./dist/index.d.mts",
34-
"default": "./dist/index.mjs"
36+
"types": "./dist/production/index.d.mts",
37+
"development": "./dist/development/index.mjs",
38+
"default": "./dist/production/index.mjs"
3539
},
3640
"default": {
37-
"types": "./dist/index.d.ts",
38-
"default": "./dist/index.js"
41+
"types": "./dist/production/index.d.ts",
42+
"development": "./dist/development/index.js",
43+
"default": "./dist/production/index.js"
3944
}
4045
},
4146
"./types": {
42-
"types": "./dist/lib/types.d.ts"
47+
"types": "./dist/production/lib/types.d.ts"
4348
},
4449
"./dom": {
4550
"node": {
46-
"types": "./dist/dom-export.d.ts",
47-
"module-sync": "./dist/dom-export.mjs",
48-
"default": "./dist/dom-export.js"
51+
"types": "./dist/production/dom-export.d.ts",
52+
"development": {
53+
"module-sync": "./dist/development/dom-export.mjs",
54+
"default": "./dist/development/dom-export.js"
55+
},
56+
"module-sync": "./dist/production/dom-export.mjs",
57+
"default": "./dist/production/dom-export.js"
4958
},
5059
"import": {
51-
"types": "./dist/dom-export.d.mts",
52-
"default": "./dist/dom-export.mjs"
60+
"types": "./dist/production/dom-export.d.mts",
61+
"development": "./dist/development/dom-export.mjs",
62+
"default": "./dist/production/dom-export.mjs"
5363
},
5464
"default": {
55-
"types": "./dist/dom-export.d.ts",
56-
"default": "./dist/dom-export.js"
65+
"types": "./dist/production/dom-export.d.ts",
66+
"development": "./dist/development/dom-export.js",
67+
"default": "./dist/production/dom-export.js"
5768
}
5869
},
5970
"./package.json": "./package.json"

packages/react-router/tsup.config.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,37 @@ import pkg from "./package.json";
77

88
const entry = ["index.ts", "dom-export.ts", "lib/types.ts"];
99

10-
export default defineConfig([
11-
{
12-
clean: false,
13-
entry,
14-
format: ["cjs"],
15-
outDir: "dist",
16-
dts: true,
17-
banner: {
18-
js: createBanner(pkg.name, pkg.version),
10+
const config = (enableDevWarnings: boolean) =>
11+
defineConfig([
12+
{
13+
clean: false,
14+
entry,
15+
format: ["cjs"],
16+
outDir: enableDevWarnings ? "dist/development" : "dist/production",
17+
dts: true,
18+
banner: {
19+
js: createBanner(pkg.name, pkg.version),
20+
},
21+
define: {
22+
"import.meta.hot": "undefined",
23+
REACT_ROUTER_VERSION: JSON.stringify(pkg.version),
24+
__DEV__: JSON.stringify(enableDevWarnings),
25+
},
1926
},
20-
define: {
21-
"import.meta.hot": "undefined",
22-
REACT_ROUTER_VERSION: JSON.stringify(pkg.version),
27+
{
28+
clean: false,
29+
entry,
30+
format: ["esm"],
31+
outDir: enableDevWarnings ? "dist/development" : "dist/production",
32+
dts: true,
33+
banner: {
34+
js: createBanner(pkg.name, pkg.version),
35+
},
36+
define: {
37+
REACT_ROUTER_VERSION: JSON.stringify(pkg.version),
38+
__DEV__: JSON.stringify(enableDevWarnings),
39+
},
2340
},
24-
},
25-
{
26-
clean: false,
27-
entry,
28-
format: ["esm"],
29-
outDir: "dist",
30-
dts: true,
31-
banner: {
32-
js: createBanner(pkg.name, pkg.version),
33-
},
34-
define: {
35-
REACT_ROUTER_VERSION: JSON.stringify(pkg.version),
36-
},
37-
},
38-
]);
41+
]);
42+
43+
export default defineConfig([...config(false), ...config(true)]);

0 commit comments

Comments
 (0)