Skip to content
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

chore: re-enable development warnings #12269

Merged
merged 4 commits into from
Nov 13, 2024
Merged
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
7 changes: 7 additions & 0 deletions .changeset/four-needles-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"integration": patch
"@react-router/dev": patch
"react-router": patch
---

chore: re-enable development warnings through a `development` exports condition.
10 changes: 0 additions & 10 deletions integration/vite-spa-mode-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,6 @@ test.describe("SPA Mode", () => {
await page.waitForSelector("[data-root]");
expect(await page.locator("[data-root]").textContent()).toBe("Root");
expect(await page.locator("[data-index]").textContent()).toBe("Index");

// Hydrates without issues - this message is expected due to the nested <Routes>
expect(logs).toEqual([
'You rendered descendant <Routes> (or called `useRoutes()`) at "/" ' +
'(under <Route path="">) but the parent route path has no trailing "*". ' +
"This means if you navigate deeper, the parent won't match anymore and " +
"therefore the child routes will never render." +
"\n\n" +
'Please change the parent <Route path=""> to <Route path="/*">.',
]);
});

test("wraps default root HydrateFallback in user-provided Layout", async ({
Expand Down
3 changes: 3 additions & 0 deletions jest/jest.config.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ module.exports = {
"\\.[jt]sx?$": require.resolve("./transform"),
},
watchPathIgnorePatterns: [...ignorePatterns, "\\/node_modules\\/"],
globals: {
__DEV__: true,
},
};
6 changes: 6 additions & 0 deletions packages/react-router-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {

ssr: {
external: ssrExternals,
resolve: {
conditions: viteCommand === "build" ? [] : ["development"],
externalConditions:
viteCommand === "build" ? [] : ["development"],
},
},
optimizeDeps: {
include: [
Expand Down Expand Up @@ -858,6 +863,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => {
"react-router/dom",
"react-router-dom",
],
conditions: viteCommand === "build" ? [] : ["development"],
},
base: viteUserConfig.base,

Expand Down
6 changes: 3 additions & 3 deletions packages/react-router/lib/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ import {
import type { ViewTransition } from "./dom/global";
import { warnOnce } from "./server-runtime/warnings";

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

/**
* @private
Expand Down
6 changes: 3 additions & 3 deletions packages/react-router/lib/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ import {
} from "./router/utils";
import type { SerializeFrom } from "./types";

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

/**
Resolves a URL against the current location.
Expand Down
49 changes: 30 additions & 19 deletions packages/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,53 @@
"license": "MIT",
"author": "Remix Software <[email protected]>",
"sideEffects": false,
"types": "./dist/index.d.ts",
"main": "./dist/index.js",
"unpkg": "./dist/umd/react-router.production.min.js",
"module": "./dist/index.mjs",
"types": "./dist/production/index.d.ts",
"main": "./dist/production/index.js",
"module": "./dist/production/index.mjs",
"exports": {
".": {
"node": {
"types": "./dist/index.d.ts",
"module-sync": "./dist/index.mjs",
"default": "./dist/index.js"
"types": "./dist/production/index.d.ts",
"development": {
"module-sync": "./dist/development/index.mjs",
"default": "./dist/development/index.js"
},
"module-sync": "./dist/production/index.mjs",
"default": "./dist/production/index.js"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
"types": "./dist/production/index.d.mts",
"development": "./dist/development/index.mjs",
"default": "./dist/production/index.mjs"
},
"default": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
"types": "./dist/production/index.d.ts",
"development": "./dist/development/index.js",
"default": "./dist/production/index.js"
}
},
"./types": {
"types": "./dist/lib/types.d.ts"
"types": "./dist/production/lib/types.d.ts"
},
"./dom": {
"node": {
"types": "./dist/dom-export.d.ts",
"module-sync": "./dist/dom-export.mjs",
"default": "./dist/dom-export.js"
"types": "./dist/production/dom-export.d.ts",
"development": {
"module-sync": "./dist/development/dom-export.mjs",
"default": "./dist/development/dom-export.js"
},
"module-sync": "./dist/production/dom-export.mjs",
"default": "./dist/production/dom-export.js"
},
"import": {
"types": "./dist/dom-export.d.mts",
"default": "./dist/dom-export.mjs"
"types": "./dist/production/dom-export.d.mts",
"development": "./dist/development/dom-export.mjs",
"default": "./dist/production/dom-export.mjs"
},
"default": {
"types": "./dist/dom-export.d.ts",
"default": "./dist/dom-export.js"
"types": "./dist/production/dom-export.d.ts",
"development": "./dist/development/dom-export.js",
"default": "./dist/production/dom-export.js"
}
},
"./package.json": "./package.json"
Expand Down
59 changes: 32 additions & 27 deletions packages/react-router/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,37 @@ import pkg from "./package.json";

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

export default defineConfig([
{
clean: false,
entry,
format: ["cjs"],
outDir: "dist",
dts: true,
banner: {
js: createBanner(pkg.name, pkg.version),
const config = (enableDevWarnings: boolean) =>
defineConfig([
{
clean: false,
entry,
format: ["cjs"],
outDir: enableDevWarnings ? "dist/development" : "dist/production",
dts: true,
banner: {
js: createBanner(pkg.name, pkg.version),
},
define: {
"import.meta.hot": "undefined",
REACT_ROUTER_VERSION: JSON.stringify(pkg.version),
__DEV__: JSON.stringify(enableDevWarnings),
},
},
define: {
"import.meta.hot": "undefined",
REACT_ROUTER_VERSION: JSON.stringify(pkg.version),
{
clean: false,
entry,
format: ["esm"],
outDir: enableDevWarnings ? "dist/development" : "dist/production",
dts: true,
banner: {
js: createBanner(pkg.name, pkg.version),
},
define: {
REACT_ROUTER_VERSION: JSON.stringify(pkg.version),
__DEV__: JSON.stringify(enableDevWarnings),
},
},
},
{
clean: false,
entry,
format: ["esm"],
outDir: "dist",
dts: true,
banner: {
js: createBanner(pkg.name, pkg.version),
},
define: {
REACT_ROUTER_VERSION: JSON.stringify(pkg.version),
},
},
]);
]);

export default defineConfig([...config(false), ...config(true)]);
Loading