@react-router/dev 7.8.0 → 7.8.1-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -7
- package/dist/cli/index.js +11 -3
- package/dist/config/default-rsc-entries/entry.client.tsx +2 -0
- package/dist/config.js +1 -1
- package/dist/internal.js +358 -76
- package/dist/routes.js +1 -1
- package/dist/static/rsc-refresh-utils.mjs +126 -0
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.js +30 -18
- package/package.json +6 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# `@react-router/dev`
|
|
2
2
|
|
|
3
|
+
## 7.8.1-pre.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Update generated `Route.MetaArgs` type so `loaderData` is only potentially undefined when an `ErrorBoundary` export is present ([#14173](https://github.com/remix-run/react-router/pull/14173))
|
|
8
|
+
- Updated dependencies:
|
|
9
|
+
- `react-router@7.8.1-pre.0`
|
|
10
|
+
- `@react-router/node@7.8.1-pre.0`
|
|
11
|
+
- `@react-router/serve@7.8.1-pre.0`
|
|
12
|
+
|
|
3
13
|
## 7.8.0
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -708,7 +718,6 @@
|
|
|
708
718
|
```
|
|
709
719
|
|
|
710
720
|
This initial implementation targets type inference for:
|
|
711
|
-
|
|
712
721
|
- `Params` : Path parameters from your routing config in `routes.ts` including file-based routing
|
|
713
722
|
- `LoaderData` : Loader data from `loader` and/or `clientLoader` within your route module
|
|
714
723
|
- `ActionData` : Action data from `action` and/or `clientAction` within your route module
|
|
@@ -723,7 +732,6 @@
|
|
|
723
732
|
```
|
|
724
733
|
|
|
725
734
|
Check out our docs for more:
|
|
726
|
-
|
|
727
735
|
- [_Explanations > Type Safety_](https://reactrouter.com/dev/guides/explanation/type-safety)
|
|
728
736
|
- [_How-To > Setting up type safety_](https://reactrouter.com/dev/guides/how-to/setting-up-type-safety)
|
|
729
737
|
|
|
@@ -923,7 +931,6 @@
|
|
|
923
931
|
- Vite: Provide `Unstable_ServerBundlesFunction` and `Unstable_VitePluginConfig` types ([#8654](https://github.com/remix-run/remix/pull/8654))
|
|
924
932
|
|
|
925
933
|
- Vite: add `--sourcemapClient` and `--sourcemapServer` flags to `remix vite:build` ([#8613](https://github.com/remix-run/remix/pull/8613))
|
|
926
|
-
|
|
927
934
|
- `--sourcemapClient`
|
|
928
935
|
|
|
929
936
|
- `--sourcemapClient=inline`
|
|
@@ -1260,7 +1267,6 @@
|
|
|
1260
1267
|
- Add support for `clientLoader`/`clientAction`/`HydrateFallback` route exports ([RFC](https://github.com/remix-run/remix/discussions/7634)) ([#8173](https://github.com/remix-run/remix/pull/8173))
|
|
1261
1268
|
|
|
1262
1269
|
Remix now supports loaders/actions that run on the client (in addition to, or instead of the loader/action that runs on the server). While we still recommend server loaders/actions for the majority of your data needs in a Remix app - these provide some levers you can pull for more advanced use-cases such as:
|
|
1263
|
-
|
|
1264
1270
|
- Leveraging a data source local to the browser (i.e., `localStorage`)
|
|
1265
1271
|
- Managing a client-side cache of server data (like `IndexedDB`)
|
|
1266
1272
|
- Bypassing the Remix server in a BFF setup and hitting your API directly from the browser
|
|
@@ -1664,7 +1670,6 @@
|
|
|
1664
1670
|
- Output esbuild metafiles for bundle analysis ([#6772](https://github.com/remix-run/remix/pull/6772))
|
|
1665
1671
|
|
|
1666
1672
|
Written to server build directory (`build/` by default):
|
|
1667
|
-
|
|
1668
1673
|
- `metafile.css.json`
|
|
1669
1674
|
- `metafile.js.json` (browser JS)
|
|
1670
1675
|
- `metafile.server.json` (server JS)
|
|
@@ -1762,7 +1767,6 @@
|
|
|
1762
1767
|
- built-in tls support ([#6483](https://github.com/remix-run/remix/pull/6483))
|
|
1763
1768
|
|
|
1764
1769
|
New options:
|
|
1765
|
-
|
|
1766
1770
|
- `--tls-key` / `tlsKey`: TLS key
|
|
1767
1771
|
- `--tls-cert` / `tlsCert`: TLS Certificate
|
|
1768
1772
|
|
|
@@ -2033,7 +2037,6 @@
|
|
|
2033
2037
|
```
|
|
2034
2038
|
|
|
2035
2039
|
The dev server will:
|
|
2036
|
-
|
|
2037
2040
|
- force `NODE_ENV=development` and warn you if it was previously set to something else
|
|
2038
2041
|
- rebuild your app whenever your Remix app code changes
|
|
2039
2042
|
- restart your app server whenever rebuilds succeed
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @react-router/dev v7.8.0
|
|
3
|
+
* @react-router/dev v7.8.1-pre.0
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -1417,6 +1417,13 @@ var init_with_props = __esm({
|
|
|
1417
1417
|
}
|
|
1418
1418
|
});
|
|
1419
1419
|
|
|
1420
|
+
// vite/plugins/validate-plugin-order.ts
|
|
1421
|
+
var init_validate_plugin_order = __esm({
|
|
1422
|
+
"vite/plugins/validate-plugin-order.ts"() {
|
|
1423
|
+
"use strict";
|
|
1424
|
+
}
|
|
1425
|
+
});
|
|
1426
|
+
|
|
1420
1427
|
// vite/plugin.ts
|
|
1421
1428
|
async function resolveViteConfig({
|
|
1422
1429
|
configFile,
|
|
@@ -1685,6 +1692,7 @@ var init_plugin = __esm({
|
|
|
1685
1692
|
init_vite();
|
|
1686
1693
|
init_config();
|
|
1687
1694
|
init_with_props();
|
|
1695
|
+
init_validate_plugin_order();
|
|
1688
1696
|
CLIENT_NON_COMPONENT_EXPORTS = [
|
|
1689
1697
|
"clientAction",
|
|
1690
1698
|
"clientLoader",
|
|
@@ -1824,7 +1832,7 @@ async function viteAppBuild(root, {
|
|
|
1824
1832
|
},
|
|
1825
1833
|
configResolved(config) {
|
|
1826
1834
|
let hasReactRouterPlugin = config.plugins.find(
|
|
1827
|
-
(plugin) => plugin.name === "react-router" || plugin.name === "react-router/rsc
|
|
1835
|
+
(plugin) => plugin.name === "react-router" || plugin.name === "react-router/rsc"
|
|
1828
1836
|
);
|
|
1829
1837
|
if (!hasReactRouterPlugin) {
|
|
1830
1838
|
throw new Error(
|
|
@@ -1964,7 +1972,7 @@ async function dev(root, {
|
|
|
1964
1972
|
logLevel
|
|
1965
1973
|
});
|
|
1966
1974
|
if (!server.config.plugins.find(
|
|
1967
|
-
(plugin) => plugin.name === "react-router" || plugin.name === "react-router/rsc
|
|
1975
|
+
(plugin) => plugin.name === "react-router" || plugin.name === "react-router/rsc"
|
|
1968
1976
|
)) {
|
|
1969
1977
|
console.error(
|
|
1970
1978
|
import_picocolors6.default.red("React Router Vite plugin not found in Vite config")
|
package/dist/config.js
CHANGED
package/dist/internal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v7.8.0
|
|
2
|
+
* @react-router/dev v7.8.1-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -46,8 +46,8 @@ module.exports = __toCommonJS(internal_exports);
|
|
|
46
46
|
|
|
47
47
|
// vite/rsc/plugin.ts
|
|
48
48
|
var import_plugin_rsc = __toESM(require("@vitejs/plugin-rsc"));
|
|
49
|
-
var import_plugin_react = __toESM(require("@vitejs/plugin-react"));
|
|
50
49
|
var import_es_module_lexer2 = require("es-module-lexer");
|
|
50
|
+
var babel = __toESM(require("@babel/core"));
|
|
51
51
|
|
|
52
52
|
// vite/virtual-module.ts
|
|
53
53
|
function create(name) {
|
|
@@ -247,7 +247,7 @@ function validateRouteConfig({
|
|
|
247
247
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
248
248
|
root ? `${root}` : [],
|
|
249
249
|
nested ? Object.entries(nested).map(
|
|
250
|
-
([
|
|
250
|
+
([path5, message]) => `Path: routes.${path5}
|
|
251
251
|
${message}`
|
|
252
252
|
) : []
|
|
253
253
|
].flat().join("\n\n")
|
|
@@ -581,11 +581,11 @@ async function createConfigLoader({
|
|
|
581
581
|
if (!fsWatcher) {
|
|
582
582
|
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
583
583
|
ignoreInitial: true,
|
|
584
|
-
ignored: (
|
|
585
|
-
let dirname4 = import_pathe3.default.dirname(
|
|
584
|
+
ignored: (path5) => {
|
|
585
|
+
let dirname4 = import_pathe3.default.dirname(path5);
|
|
586
586
|
return !dirname4.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
587
587
|
// that are at the root level, not nested in subdirectories
|
|
588
|
-
|
|
588
|
+
path5 !== root && // Watch the root directory itself
|
|
589
589
|
dirname4 !== root;
|
|
590
590
|
}
|
|
591
591
|
});
|
|
@@ -785,7 +785,7 @@ function fullpath(lineage2) {
|
|
|
785
785
|
if (lineage2.length === 1 && route?.id === "root") return "/";
|
|
786
786
|
const isLayout = route && route.index !== true && route.path === void 0;
|
|
787
787
|
if (isLayout) return void 0;
|
|
788
|
-
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((
|
|
788
|
+
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path5) => path5 !== void 0 && path5 !== "").join("/");
|
|
789
789
|
}
|
|
790
790
|
|
|
791
791
|
// typegen/generate.ts
|
|
@@ -941,8 +941,8 @@ function routeFilesType({
|
|
|
941
941
|
);
|
|
942
942
|
}
|
|
943
943
|
function isInAppDirectory(ctx, routeFile) {
|
|
944
|
-
const
|
|
945
|
-
return
|
|
944
|
+
const path5 = Path3.resolve(ctx.config.appDirectory, routeFile);
|
|
945
|
+
return path5.startsWith(ctx.config.appDirectory);
|
|
946
946
|
}
|
|
947
947
|
function getRouteAnnotations({
|
|
948
948
|
ctx,
|
|
@@ -1054,21 +1054,21 @@ function getRouteAnnotations({
|
|
|
1054
1054
|
return { filename: filename2, content };
|
|
1055
1055
|
}
|
|
1056
1056
|
function relativeImportSource(from, to) {
|
|
1057
|
-
let
|
|
1058
|
-
let extension = Path3.extname(
|
|
1059
|
-
|
|
1060
|
-
if (!
|
|
1057
|
+
let path5 = Path3.relative(Path3.dirname(from), to);
|
|
1058
|
+
let extension = Path3.extname(path5);
|
|
1059
|
+
path5 = Path3.join(Path3.dirname(path5), Pathe.filename(path5));
|
|
1060
|
+
if (!path5.startsWith("../")) path5 = "./" + path5;
|
|
1061
1061
|
if (!extension || /\.(js|ts)x?$/.test(extension)) {
|
|
1062
1062
|
extension = ".js";
|
|
1063
1063
|
}
|
|
1064
|
-
return
|
|
1064
|
+
return path5 + extension;
|
|
1065
1065
|
}
|
|
1066
1066
|
function rootDirsPath(ctx, typesPath) {
|
|
1067
1067
|
const rel = Path3.relative(typesDirectory(ctx), typesPath);
|
|
1068
1068
|
return Path3.join(ctx.rootDirectory, rel);
|
|
1069
1069
|
}
|
|
1070
|
-
function paramsType(
|
|
1071
|
-
const params = parse2(
|
|
1070
|
+
function paramsType(path5) {
|
|
1071
|
+
const params = parse2(path5);
|
|
1072
1072
|
return t2.tsTypeLiteral(
|
|
1073
1073
|
Object.entries(params).map(([param, isRequired]) => {
|
|
1074
1074
|
const property = t2.tsPropertySignature(
|
|
@@ -1158,14 +1158,16 @@ async function watch(rootDirectory, { mode, logger }) {
|
|
|
1158
1158
|
|
|
1159
1159
|
// vite/rsc/plugin.ts
|
|
1160
1160
|
var import_fs = require("fs");
|
|
1161
|
-
var
|
|
1161
|
+
var import_promises2 = require("fs/promises");
|
|
1162
|
+
var import_pathe5 = __toESM(require("pathe"));
|
|
1162
1163
|
|
|
1163
1164
|
// vite/rsc/virtual-route-config.ts
|
|
1164
|
-
var
|
|
1165
|
-
function
|
|
1165
|
+
var import_pathe4 = __toESM(require("pathe"));
|
|
1166
|
+
function createVirtualRouteConfig({
|
|
1166
1167
|
appDirectory,
|
|
1167
1168
|
routeConfig
|
|
1168
1169
|
}) {
|
|
1170
|
+
let routeIdByFile = /* @__PURE__ */ new Map();
|
|
1169
1171
|
let code = "export default [";
|
|
1170
1172
|
const closeRouteSymbol = Symbol("CLOSE_ROUTE");
|
|
1171
1173
|
let stack = [
|
|
@@ -1179,12 +1181,13 @@ function createVirtualRouteConfigCode({
|
|
|
1179
1181
|
continue;
|
|
1180
1182
|
}
|
|
1181
1183
|
code += "{";
|
|
1184
|
+
const routeFile = import_pathe4.default.resolve(appDirectory, route.file);
|
|
1185
|
+
const routeId = route.id || createRouteId2(route.file, appDirectory);
|
|
1186
|
+
routeIdByFile.set(routeFile, routeId);
|
|
1182
1187
|
code += `lazy: () => import(${JSON.stringify(
|
|
1183
|
-
`${
|
|
1188
|
+
`${routeFile}?route-module${routeId === "root" ? "&root-route=true" : ""}`
|
|
1184
1189
|
)}),`;
|
|
1185
|
-
code += `id: ${JSON.stringify(
|
|
1186
|
-
route.id || createRouteId2(route.file, appDirectory)
|
|
1187
|
-
)},`;
|
|
1190
|
+
code += `id: ${JSON.stringify(routeId)},`;
|
|
1188
1191
|
if (typeof route.path === "string") {
|
|
1189
1192
|
code += `path: ${JSON.stringify(route.path)},`;
|
|
1190
1193
|
}
|
|
@@ -1203,10 +1206,10 @@ function createVirtualRouteConfigCode({
|
|
|
1203
1206
|
}
|
|
1204
1207
|
}
|
|
1205
1208
|
code += "];\n";
|
|
1206
|
-
return code;
|
|
1209
|
+
return { code, routeIdByFile };
|
|
1207
1210
|
}
|
|
1208
1211
|
function createRouteId2(file, appDirectory) {
|
|
1209
|
-
return
|
|
1212
|
+
return import_pathe4.default.relative(appDirectory, file).replace(/\\+/, "/").slice(0, -import_pathe4.default.extname(file).length);
|
|
1210
1213
|
}
|
|
1211
1214
|
|
|
1212
1215
|
// vite/rsc/virtual-route-modules.ts
|
|
@@ -1220,10 +1223,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1220
1223
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1221
1224
|
let removedExportLocalNames = /* @__PURE__ */ new Set();
|
|
1222
1225
|
traverse(ast, {
|
|
1223
|
-
ExportDeclaration(
|
|
1224
|
-
if (
|
|
1225
|
-
if (
|
|
1226
|
-
|
|
1226
|
+
ExportDeclaration(path5) {
|
|
1227
|
+
if (path5.node.type === "ExportNamedDeclaration") {
|
|
1228
|
+
if (path5.node.specifiers.length) {
|
|
1229
|
+
path5.node.specifiers = path5.node.specifiers.filter((specifier) => {
|
|
1227
1230
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1228
1231
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1229
1232
|
exportsFiltered = true;
|
|
@@ -1235,12 +1238,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1235
1238
|
}
|
|
1236
1239
|
return true;
|
|
1237
1240
|
});
|
|
1238
|
-
if (
|
|
1239
|
-
markedForRemoval.add(
|
|
1241
|
+
if (path5.node.specifiers.length === 0) {
|
|
1242
|
+
markedForRemoval.add(path5);
|
|
1240
1243
|
}
|
|
1241
1244
|
}
|
|
1242
|
-
if (
|
|
1243
|
-
let declaration =
|
|
1245
|
+
if (path5.node.declaration?.type === "VariableDeclaration") {
|
|
1246
|
+
let declaration = path5.node.declaration;
|
|
1244
1247
|
declaration.declarations = declaration.declarations.filter(
|
|
1245
1248
|
(declaration2) => {
|
|
1246
1249
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1254,30 +1257,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1254
1257
|
}
|
|
1255
1258
|
);
|
|
1256
1259
|
if (declaration.declarations.length === 0) {
|
|
1257
|
-
markedForRemoval.add(
|
|
1260
|
+
markedForRemoval.add(path5);
|
|
1258
1261
|
}
|
|
1259
1262
|
}
|
|
1260
|
-
if (
|
|
1261
|
-
let id =
|
|
1263
|
+
if (path5.node.declaration?.type === "FunctionDeclaration") {
|
|
1264
|
+
let id = path5.node.declaration.id;
|
|
1262
1265
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1263
|
-
markedForRemoval.add(
|
|
1266
|
+
markedForRemoval.add(path5);
|
|
1264
1267
|
}
|
|
1265
1268
|
}
|
|
1266
|
-
if (
|
|
1267
|
-
let id =
|
|
1269
|
+
if (path5.node.declaration?.type === "ClassDeclaration") {
|
|
1270
|
+
let id = path5.node.declaration.id;
|
|
1268
1271
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1269
|
-
markedForRemoval.add(
|
|
1272
|
+
markedForRemoval.add(path5);
|
|
1270
1273
|
}
|
|
1271
1274
|
}
|
|
1272
1275
|
}
|
|
1273
|
-
if (
|
|
1276
|
+
if (path5.node.type === "ExportDefaultDeclaration") {
|
|
1274
1277
|
if (exportsToRemove.includes("default")) {
|
|
1275
|
-
markedForRemoval.add(
|
|
1276
|
-
if (
|
|
1277
|
-
if (
|
|
1278
|
-
removedExportLocalNames.add(
|
|
1279
|
-
} else if ((
|
|
1280
|
-
removedExportLocalNames.add(
|
|
1278
|
+
markedForRemoval.add(path5);
|
|
1279
|
+
if (path5.node.declaration) {
|
|
1280
|
+
if (path5.node.declaration.type === "Identifier") {
|
|
1281
|
+
removedExportLocalNames.add(path5.node.declaration.name);
|
|
1282
|
+
} else if ((path5.node.declaration.type === "FunctionDeclaration" || path5.node.declaration.type === "ClassDeclaration") && path5.node.declaration.id) {
|
|
1283
|
+
removedExportLocalNames.add(path5.node.declaration.id.name);
|
|
1281
1284
|
}
|
|
1282
1285
|
}
|
|
1283
1286
|
}
|
|
@@ -1285,21 +1288,21 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1285
1288
|
}
|
|
1286
1289
|
});
|
|
1287
1290
|
traverse(ast, {
|
|
1288
|
-
ExpressionStatement(
|
|
1289
|
-
if (!
|
|
1291
|
+
ExpressionStatement(path5) {
|
|
1292
|
+
if (!path5.parentPath.isProgram()) {
|
|
1290
1293
|
return;
|
|
1291
1294
|
}
|
|
1292
|
-
if (
|
|
1293
|
-
const left =
|
|
1295
|
+
if (path5.node.expression.type === "AssignmentExpression") {
|
|
1296
|
+
const left = path5.node.expression.left;
|
|
1294
1297
|
if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
|
|
1295
|
-
markedForRemoval.add(
|
|
1298
|
+
markedForRemoval.add(path5);
|
|
1296
1299
|
}
|
|
1297
1300
|
}
|
|
1298
1301
|
}
|
|
1299
1302
|
});
|
|
1300
1303
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1301
|
-
for (let
|
|
1302
|
-
|
|
1304
|
+
for (let path5 of markedForRemoval) {
|
|
1305
|
+
path5.remove();
|
|
1303
1306
|
}
|
|
1304
1307
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1305
1308
|
}
|
|
@@ -1381,26 +1384,28 @@ function isClientRouteExport(name) {
|
|
|
1381
1384
|
}
|
|
1382
1385
|
function transformVirtualRouteModules({
|
|
1383
1386
|
id,
|
|
1384
|
-
code
|
|
1387
|
+
code,
|
|
1388
|
+
viteCommand
|
|
1385
1389
|
}) {
|
|
1386
1390
|
if (!id.includes("route-module")) {
|
|
1387
1391
|
return;
|
|
1388
1392
|
}
|
|
1389
1393
|
if (isVirtualRouteModuleId(id)) {
|
|
1390
|
-
return createVirtualRouteModuleCode({ id, code });
|
|
1394
|
+
return createVirtualRouteModuleCode({ id, code, viteCommand });
|
|
1391
1395
|
}
|
|
1392
1396
|
if (isVirtualServerRouteModuleId(id)) {
|
|
1393
1397
|
return createVirtualServerRouteModuleCode({ id, code });
|
|
1394
1398
|
}
|
|
1395
1399
|
if (isVirtualClientRouteModuleId(id)) {
|
|
1396
|
-
return createVirtualClientRouteModuleCode({ id, code });
|
|
1400
|
+
return createVirtualClientRouteModuleCode({ id, code, viteCommand });
|
|
1397
1401
|
}
|
|
1398
1402
|
}
|
|
1399
1403
|
async function createVirtualRouteModuleCode({
|
|
1400
1404
|
id,
|
|
1401
|
-
code: routeSource
|
|
1405
|
+
code: routeSource,
|
|
1406
|
+
viteCommand
|
|
1402
1407
|
}) {
|
|
1403
|
-
const { staticExports, isServerFirstRoute } = parseRouteExports(routeSource);
|
|
1408
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
1404
1409
|
const clientModuleId = getVirtualClientModuleId(id);
|
|
1405
1410
|
const serverModuleId = getVirtualServerModuleId(id);
|
|
1406
1411
|
let code = "";
|
|
@@ -1417,6 +1422,10 @@ async function createVirtualRouteModuleCode({
|
|
|
1417
1422
|
`;
|
|
1418
1423
|
}
|
|
1419
1424
|
}
|
|
1425
|
+
if (viteCommand === "serve" && !hasClientExports) {
|
|
1426
|
+
code += `export { __ensureClientRouteModuleForHMR } from "${clientModuleId}";
|
|
1427
|
+
`;
|
|
1428
|
+
}
|
|
1420
1429
|
} else {
|
|
1421
1430
|
for (const staticExport of staticExports) {
|
|
1422
1431
|
if (isClientRouteExport(staticExport)) {
|
|
@@ -1461,9 +1470,10 @@ function createVirtualServerRouteModuleCode({
|
|
|
1461
1470
|
}
|
|
1462
1471
|
function createVirtualClientRouteModuleCode({
|
|
1463
1472
|
id,
|
|
1464
|
-
code: routeSource
|
|
1473
|
+
code: routeSource,
|
|
1474
|
+
viteCommand
|
|
1465
1475
|
}) {
|
|
1466
|
-
const { staticExports, isServerFirstRoute } = parseRouteExports(routeSource);
|
|
1476
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
1467
1477
|
const exportsToRemove = isServerFirstRoute ? [...SERVER_ONLY_ROUTE_EXPORTS, ...COMPONENT_EXPORTS] : SERVER_ONLY_ROUTE_EXPORTS;
|
|
1468
1478
|
const clientRouteModuleAst = import_parser.parse(routeSource, {
|
|
1469
1479
|
sourceType: "module"
|
|
@@ -1484,16 +1494,24 @@ import { createElement as __rr_createElement } from "react";
|
|
|
1484
1494
|
`;
|
|
1485
1495
|
generatorResult.code += `}
|
|
1486
1496
|
`;
|
|
1497
|
+
}
|
|
1498
|
+
if (viteCommand === "serve" && isServerFirstRoute && !hasClientExports) {
|
|
1499
|
+
generatorResult.code += `
|
|
1500
|
+
export const __ensureClientRouteModuleForHMR = true;`;
|
|
1487
1501
|
}
|
|
1488
1502
|
return generatorResult;
|
|
1489
1503
|
}
|
|
1490
1504
|
function parseRouteExports(code) {
|
|
1491
1505
|
const [, exportSpecifiers] = (0, import_es_module_lexer.parse)(code);
|
|
1492
1506
|
const staticExports = exportSpecifiers.map(({ n: name }) => name);
|
|
1507
|
+
const isServerFirstRoute = staticExports.some(
|
|
1508
|
+
(staticExport) => staticExport === "ServerComponent"
|
|
1509
|
+
);
|
|
1493
1510
|
return {
|
|
1494
1511
|
staticExports,
|
|
1495
|
-
isServerFirstRoute
|
|
1496
|
-
|
|
1512
|
+
isServerFirstRoute,
|
|
1513
|
+
hasClientExports: staticExports.some(
|
|
1514
|
+
isServerFirstRoute ? isClientNonComponentExport : isClientRouteExport
|
|
1497
1515
|
)
|
|
1498
1516
|
};
|
|
1499
1517
|
}
|
|
@@ -1516,16 +1534,45 @@ function isVirtualServerRouteModuleId(id) {
|
|
|
1516
1534
|
return /(\?|&)server-route-module(&|$)/.test(id);
|
|
1517
1535
|
}
|
|
1518
1536
|
|
|
1537
|
+
// vite/plugins/validate-plugin-order.ts
|
|
1538
|
+
function validatePluginOrder() {
|
|
1539
|
+
return {
|
|
1540
|
+
name: "react-router:validate-plugin-order",
|
|
1541
|
+
configResolved(viteConfig) {
|
|
1542
|
+
let pluginIndex = (pluginName) => {
|
|
1543
|
+
pluginName = Array.isArray(pluginName) ? pluginName : [pluginName];
|
|
1544
|
+
return viteConfig.plugins.findIndex(
|
|
1545
|
+
(plugin) => pluginName.includes(plugin.name)
|
|
1546
|
+
);
|
|
1547
|
+
};
|
|
1548
|
+
let rollupPrePlugins = [
|
|
1549
|
+
{ pluginName: "@mdx-js/rollup", displayName: "@mdx-js/rollup" }
|
|
1550
|
+
];
|
|
1551
|
+
for (let prePlugin of rollupPrePlugins) {
|
|
1552
|
+
let prePluginIndex = pluginIndex(prePlugin.pluginName);
|
|
1553
|
+
if (prePluginIndex >= 0 && prePluginIndex > pluginIndex(["react-router", "react-router/rsc"])) {
|
|
1554
|
+
throw new Error(
|
|
1555
|
+
`The "${prePlugin.displayName}" plugin should be placed before the React Router plugin in your Vite config file`
|
|
1556
|
+
);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1519
1563
|
// vite/rsc/plugin.ts
|
|
1520
1564
|
function reactRouterRSCVitePlugin() {
|
|
1521
1565
|
let configLoader;
|
|
1522
1566
|
let config;
|
|
1523
1567
|
let typegenWatcherPromise;
|
|
1568
|
+
let viteCommand;
|
|
1569
|
+
let routeIdByFile;
|
|
1524
1570
|
return [
|
|
1525
1571
|
{
|
|
1526
|
-
name: "react-router/rsc
|
|
1572
|
+
name: "react-router/rsc",
|
|
1527
1573
|
async config(viteUserConfig, { command, mode }) {
|
|
1528
1574
|
await import_es_module_lexer2.init;
|
|
1575
|
+
viteCommand = command;
|
|
1529
1576
|
const rootDirectory = getRootDirectory(viteUserConfig);
|
|
1530
1577
|
const watch2 = command === "serve";
|
|
1531
1578
|
configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
|
|
@@ -1533,10 +1580,62 @@ function reactRouterRSCVitePlugin() {
|
|
|
1533
1580
|
if (!configResult.ok) throw new Error(configResult.error);
|
|
1534
1581
|
config = configResult.value;
|
|
1535
1582
|
return {
|
|
1583
|
+
resolve: {
|
|
1584
|
+
dedupe: [
|
|
1585
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
1586
|
+
"react",
|
|
1587
|
+
"react-dom",
|
|
1588
|
+
// Avoid router duplicates since mismatching routers cause `Error:
|
|
1589
|
+
// You must render this element inside a <Remix> element`.
|
|
1590
|
+
"react-router",
|
|
1591
|
+
"react-router/dom",
|
|
1592
|
+
"react-router-dom"
|
|
1593
|
+
]
|
|
1594
|
+
},
|
|
1595
|
+
optimizeDeps: {
|
|
1596
|
+
esbuildOptions: {
|
|
1597
|
+
jsx: "automatic"
|
|
1598
|
+
},
|
|
1599
|
+
include: [
|
|
1600
|
+
// Pre-bundle React dependencies to avoid React duplicates,
|
|
1601
|
+
// even if React dependencies are not direct dependencies.
|
|
1602
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
1603
|
+
"react",
|
|
1604
|
+
"react/jsx-runtime",
|
|
1605
|
+
"react/jsx-dev-runtime",
|
|
1606
|
+
"react-dom",
|
|
1607
|
+
"react-dom/client"
|
|
1608
|
+
]
|
|
1609
|
+
},
|
|
1610
|
+
esbuild: {
|
|
1611
|
+
jsx: "automatic",
|
|
1612
|
+
jsxDev: viteCommand !== "build"
|
|
1613
|
+
},
|
|
1536
1614
|
environments: {
|
|
1537
1615
|
client: { build: { outDir: "build/client" } },
|
|
1538
1616
|
rsc: { build: { outDir: "build/server" } },
|
|
1539
1617
|
ssr: { build: { outDir: "build/server/__ssr_build" } }
|
|
1618
|
+
},
|
|
1619
|
+
build: {
|
|
1620
|
+
rollupOptions: {
|
|
1621
|
+
// Copied from https://github.com/vitejs/vite-plugin-react/blob/c602225271d4acf462ba00f8d6d8a2e42492c5cd/packages/common/warning.ts
|
|
1622
|
+
onwarn(warning, defaultHandler) {
|
|
1623
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
if (viteUserConfig.build?.rollupOptions?.onwarn) {
|
|
1630
|
+
viteUserConfig.build.rollupOptions.onwarn(
|
|
1631
|
+
warning,
|
|
1632
|
+
defaultHandler
|
|
1633
|
+
);
|
|
1634
|
+
} else {
|
|
1635
|
+
defaultHandler(warning);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1540
1639
|
}
|
|
1541
1640
|
};
|
|
1542
1641
|
},
|
|
@@ -1575,56 +1674,239 @@ function reactRouterRSCVitePlugin() {
|
|
|
1575
1674
|
},
|
|
1576
1675
|
load(id) {
|
|
1577
1676
|
if (id === virtual.routeConfig.resolvedId) {
|
|
1578
|
-
|
|
1677
|
+
const result = createVirtualRouteConfig({
|
|
1579
1678
|
appDirectory: config.appDirectory,
|
|
1580
1679
|
routeConfig: config.unstable_routeConfig
|
|
1581
1680
|
});
|
|
1681
|
+
routeIdByFile = result.routeIdByFile;
|
|
1682
|
+
return result.code;
|
|
1582
1683
|
}
|
|
1583
1684
|
}
|
|
1584
1685
|
},
|
|
1585
1686
|
{
|
|
1586
1687
|
name: "react-router/rsc/virtual-route-modules",
|
|
1587
1688
|
transform(code, id) {
|
|
1588
|
-
return transformVirtualRouteModules({ code, id });
|
|
1689
|
+
return transformVirtualRouteModules({ code, id, viteCommand });
|
|
1589
1690
|
}
|
|
1590
1691
|
},
|
|
1591
|
-
|
|
1692
|
+
{
|
|
1693
|
+
name: "react-router/rsc/hmr/inject-runtime",
|
|
1694
|
+
enforce: "pre",
|
|
1695
|
+
resolveId(id) {
|
|
1696
|
+
if (id === virtual.injectHmrRuntime.id) {
|
|
1697
|
+
return virtual.injectHmrRuntime.resolvedId;
|
|
1698
|
+
}
|
|
1699
|
+
},
|
|
1700
|
+
async load(id) {
|
|
1701
|
+
if (id !== virtual.injectHmrRuntime.resolvedId) return;
|
|
1702
|
+
return viteCommand === "serve" ? [
|
|
1703
|
+
`import RefreshRuntime from "${virtual.hmrRuntime.id}"`,
|
|
1704
|
+
"RefreshRuntime.injectIntoGlobalHook(window)",
|
|
1705
|
+
"window.$RefreshReg$ = () => {}",
|
|
1706
|
+
"window.$RefreshSig$ = () => (type) => type",
|
|
1707
|
+
"window.__vite_plugin_react_preamble_installed__ = true"
|
|
1708
|
+
].join("\n") : "";
|
|
1709
|
+
}
|
|
1710
|
+
},
|
|
1711
|
+
{
|
|
1712
|
+
name: "react-router/rsc/hmr/runtime",
|
|
1713
|
+
enforce: "pre",
|
|
1714
|
+
resolveId(id) {
|
|
1715
|
+
if (id === virtual.hmrRuntime.id) return virtual.hmrRuntime.resolvedId;
|
|
1716
|
+
},
|
|
1717
|
+
async load(id) {
|
|
1718
|
+
if (id !== virtual.hmrRuntime.resolvedId) return;
|
|
1719
|
+
const reactRefreshDir = import_pathe5.default.dirname(
|
|
1720
|
+
require.resolve("react-refresh/package.json")
|
|
1721
|
+
);
|
|
1722
|
+
const reactRefreshRuntimePath = import_pathe5.default.join(
|
|
1723
|
+
reactRefreshDir,
|
|
1724
|
+
"cjs/react-refresh-runtime.development.js"
|
|
1725
|
+
);
|
|
1726
|
+
return [
|
|
1727
|
+
"const exports = {}",
|
|
1728
|
+
await (0, import_promises2.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
1729
|
+
await (0, import_promises2.readFile)(
|
|
1730
|
+
require.resolve("./static/rsc-refresh-utils.mjs"),
|
|
1731
|
+
"utf8"
|
|
1732
|
+
),
|
|
1733
|
+
"export default exports"
|
|
1734
|
+
].join("\n");
|
|
1735
|
+
}
|
|
1736
|
+
},
|
|
1737
|
+
{
|
|
1738
|
+
name: "react-router/rsc/hmr/react-refresh",
|
|
1739
|
+
async transform(code, id, options) {
|
|
1740
|
+
if (viteCommand !== "serve") return;
|
|
1741
|
+
if (id.includes("/node_modules/")) return;
|
|
1742
|
+
const filepath = id.split("?")[0];
|
|
1743
|
+
const extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
|
|
1744
|
+
if (!extensionsRE.test(filepath)) return;
|
|
1745
|
+
const devRuntime = "react/jsx-dev-runtime";
|
|
1746
|
+
const ssr = options?.ssr === true;
|
|
1747
|
+
const isJSX = filepath.endsWith("x");
|
|
1748
|
+
const useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
1749
|
+
if (!useFastRefresh) return;
|
|
1750
|
+
const routeId = routeIdByFile?.get(filepath);
|
|
1751
|
+
if (routeId !== void 0) {
|
|
1752
|
+
return { code: addRefreshWrapper({ routeId, code, id }) };
|
|
1753
|
+
}
|
|
1754
|
+
const result = await babel.transformAsync(code, {
|
|
1755
|
+
babelrc: false,
|
|
1756
|
+
configFile: false,
|
|
1757
|
+
filename: id,
|
|
1758
|
+
sourceFileName: filepath,
|
|
1759
|
+
parserOpts: {
|
|
1760
|
+
sourceType: "module",
|
|
1761
|
+
allowAwaitOutsideFunction: true
|
|
1762
|
+
},
|
|
1763
|
+
plugins: [[require("react-refresh/babel"), { skipEnvCheck: true }]],
|
|
1764
|
+
sourceMaps: true
|
|
1765
|
+
});
|
|
1766
|
+
if (result === null) return;
|
|
1767
|
+
code = result.code;
|
|
1768
|
+
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
1769
|
+
if (refreshContentRE.test(code)) {
|
|
1770
|
+
code = addRefreshWrapper({ code, id });
|
|
1771
|
+
}
|
|
1772
|
+
return { code, map: result.map };
|
|
1773
|
+
}
|
|
1774
|
+
},
|
|
1775
|
+
{
|
|
1776
|
+
name: "react-router/rsc/hmr/updates",
|
|
1777
|
+
async hotUpdate({ server, file, modules }) {
|
|
1778
|
+
if (this.environment.name !== "rsc") return;
|
|
1779
|
+
const isServerOnlyChange = (server.environments.client.moduleGraph.getModulesByFile(file)?.size ?? 0) === 0;
|
|
1780
|
+
for (const mod of getModulesWithImporters(modules)) {
|
|
1781
|
+
if (!mod.file) continue;
|
|
1782
|
+
const normalizedPath = import_pathe5.default.normalize(mod.file);
|
|
1783
|
+
const routeId = routeIdByFile?.get(normalizedPath);
|
|
1784
|
+
if (routeId !== void 0) {
|
|
1785
|
+
const routeSource = await (0, import_promises2.readFile)(normalizedPath, "utf8");
|
|
1786
|
+
const virtualRouteModuleCode = (await server.environments.rsc.pluginContainer.transform(
|
|
1787
|
+
routeSource,
|
|
1788
|
+
`${normalizedPath}?route-module`
|
|
1789
|
+
)).code;
|
|
1790
|
+
const { staticExports } = parseRouteExports(virtualRouteModuleCode);
|
|
1791
|
+
const hasAction = staticExports.includes("action");
|
|
1792
|
+
const hasComponent = staticExports.includes("default");
|
|
1793
|
+
const hasErrorBoundary = staticExports.includes("ErrorBoundary");
|
|
1794
|
+
const hasLoader = staticExports.includes("loader");
|
|
1795
|
+
server.hot.send({
|
|
1796
|
+
type: "custom",
|
|
1797
|
+
event: "react-router:hmr",
|
|
1798
|
+
data: {
|
|
1799
|
+
routeId,
|
|
1800
|
+
isServerOnlyChange,
|
|
1801
|
+
hasAction,
|
|
1802
|
+
hasComponent,
|
|
1803
|
+
hasErrorBoundary,
|
|
1804
|
+
hasLoader
|
|
1805
|
+
}
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
return modules;
|
|
1810
|
+
}
|
|
1811
|
+
},
|
|
1812
|
+
validatePluginOrder(),
|
|
1592
1813
|
(0, import_plugin_rsc.default)({ entries: getRscEntries() })
|
|
1593
1814
|
];
|
|
1594
1815
|
}
|
|
1595
1816
|
var virtual = {
|
|
1596
|
-
routeConfig: create("unstable_rsc/routes")
|
|
1817
|
+
routeConfig: create("unstable_rsc/routes"),
|
|
1818
|
+
injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
|
|
1819
|
+
hmrRuntime: create("unstable_rsc/runtime")
|
|
1597
1820
|
};
|
|
1598
1821
|
function getRootDirectory(viteUserConfig) {
|
|
1599
1822
|
return viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
1600
1823
|
}
|
|
1601
1824
|
function getRscEntries() {
|
|
1602
|
-
const entriesDir = (0,
|
|
1825
|
+
const entriesDir = (0, import_pathe5.join)(
|
|
1603
1826
|
getDevPackageRoot(),
|
|
1604
1827
|
"dist",
|
|
1605
1828
|
"config",
|
|
1606
1829
|
"default-rsc-entries"
|
|
1607
1830
|
);
|
|
1608
1831
|
return {
|
|
1609
|
-
client: (0,
|
|
1610
|
-
rsc: (0,
|
|
1611
|
-
ssr: (0,
|
|
1832
|
+
client: (0, import_pathe5.join)(entriesDir, "entry.client.tsx"),
|
|
1833
|
+
rsc: (0, import_pathe5.join)(entriesDir, "entry.rsc.tsx"),
|
|
1834
|
+
ssr: (0, import_pathe5.join)(entriesDir, "entry.ssr.tsx")
|
|
1612
1835
|
};
|
|
1613
1836
|
}
|
|
1614
1837
|
function getDevPackageRoot() {
|
|
1615
|
-
const currentDir = (0,
|
|
1838
|
+
const currentDir = (0, import_pathe5.dirname)(__dirname);
|
|
1616
1839
|
let dir = currentDir;
|
|
1617
|
-
while (dir !== (0,
|
|
1840
|
+
while (dir !== (0, import_pathe5.dirname)(dir)) {
|
|
1618
1841
|
try {
|
|
1619
|
-
const packageJsonPath = (0,
|
|
1842
|
+
const packageJsonPath = (0, import_pathe5.join)(dir, "package.json");
|
|
1620
1843
|
(0, import_fs.readFileSync)(packageJsonPath, "utf-8");
|
|
1621
1844
|
return dir;
|
|
1622
1845
|
} catch {
|
|
1623
|
-
dir = (0,
|
|
1846
|
+
dir = (0, import_pathe5.dirname)(dir);
|
|
1624
1847
|
}
|
|
1625
1848
|
}
|
|
1626
1849
|
throw new Error("Could not find package.json");
|
|
1627
1850
|
}
|
|
1851
|
+
function getModulesWithImporters(modules) {
|
|
1852
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1853
|
+
const result = /* @__PURE__ */ new Set();
|
|
1854
|
+
function walk(module2) {
|
|
1855
|
+
if (visited.has(module2)) return;
|
|
1856
|
+
visited.add(module2);
|
|
1857
|
+
result.add(module2);
|
|
1858
|
+
for (const importer of module2.importers) {
|
|
1859
|
+
walk(importer);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
for (const module2 of modules) {
|
|
1863
|
+
walk(module2);
|
|
1864
|
+
}
|
|
1865
|
+
return result;
|
|
1866
|
+
}
|
|
1867
|
+
function addRefreshWrapper({
|
|
1868
|
+
routeId,
|
|
1869
|
+
code,
|
|
1870
|
+
id
|
|
1871
|
+
}) {
|
|
1872
|
+
const acceptExports = routeId !== void 0 ? CLIENT_NON_COMPONENT_EXPORTS : [];
|
|
1873
|
+
return REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id)) + code + REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(routeId));
|
|
1874
|
+
}
|
|
1875
|
+
var REACT_REFRESH_HEADER = `
|
|
1876
|
+
import RefreshRuntime from "${virtual.hmrRuntime.id}";
|
|
1877
|
+
|
|
1878
|
+
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
1879
|
+
let prevRefreshReg;
|
|
1880
|
+
let prevRefreshSig;
|
|
1881
|
+
|
|
1882
|
+
if (import.meta.hot && !inWebWorker) {
|
|
1883
|
+
if (!window.__vite_plugin_react_preamble_installed__) {
|
|
1884
|
+
throw new Error(
|
|
1885
|
+
"React Router Vite plugin can't detect preamble. Something is wrong."
|
|
1886
|
+
);
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
prevRefreshReg = window.$RefreshReg$;
|
|
1890
|
+
prevRefreshSig = window.$RefreshSig$;
|
|
1891
|
+
window.$RefreshReg$ = (type, id) => {
|
|
1892
|
+
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
1893
|
+
};
|
|
1894
|
+
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
1895
|
+
}`.replaceAll("\n", "");
|
|
1896
|
+
var REACT_REFRESH_FOOTER = `
|
|
1897
|
+
if (import.meta.hot && !inWebWorker) {
|
|
1898
|
+
window.$RefreshReg$ = prevRefreshReg;
|
|
1899
|
+
window.$RefreshSig$ = prevRefreshSig;
|
|
1900
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
1901
|
+
RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
|
|
1902
|
+
import.meta.hot.accept((nextExports) => {
|
|
1903
|
+
if (!nextExports) return;
|
|
1904
|
+
__ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
|
|
1905
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
|
|
1906
|
+
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
1907
|
+
});
|
|
1908
|
+
});
|
|
1909
|
+
}`;
|
|
1628
1910
|
|
|
1629
1911
|
// internal.ts
|
|
1630
1912
|
var __INTERNAL_DO_NOT_USE_OR_YOU_WILL_GET_A_STRONGLY_WORDED_LETTER__ = {
|
package/dist/routes.js
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// adapted from https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/refreshUtils.js
|
|
2
|
+
// This file gets injected into the browser as a part of the HMR runtime
|
|
3
|
+
|
|
4
|
+
function debounce(fn, delay) {
|
|
5
|
+
let handle;
|
|
6
|
+
return () => {
|
|
7
|
+
clearTimeout(handle);
|
|
8
|
+
handle = setTimeout(fn, delay);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* eslint-disable no-undef */
|
|
13
|
+
const enqueueUpdate = debounce(async () => {
|
|
14
|
+
if (routeUpdates.size > 0) {
|
|
15
|
+
const routeUpdateByRouteId = new Map();
|
|
16
|
+
for (const routeUpdate of routeUpdates) {
|
|
17
|
+
const routeId = routeUpdate.routeId;
|
|
18
|
+
const routeModule = window.__reactRouterRouteModuleUpdates.get(routeId);
|
|
19
|
+
if (routeModule) {
|
|
20
|
+
routeUpdateByRouteId.set(routeId, { routeModule, ...routeUpdate });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
routeUpdates.clear();
|
|
24
|
+
__reactRouterDataRouter._updateRoutesForHMR(routeUpdateByRouteId);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
window.__reactRouterHdrActive = true;
|
|
29
|
+
await __reactRouterDataRouter.revalidate();
|
|
30
|
+
} finally {
|
|
31
|
+
window.__reactRouterHdrActive = false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.performReactRefresh();
|
|
35
|
+
}, 16);
|
|
36
|
+
|
|
37
|
+
// Taken from https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/lib/runtime/RefreshUtils.js#L141
|
|
38
|
+
// This allows to resister components not detected by SWC like styled component
|
|
39
|
+
function registerExportsForReactRefresh(filename, moduleExports) {
|
|
40
|
+
for (const key in moduleExports) {
|
|
41
|
+
if (key === "__esModule") continue;
|
|
42
|
+
const exportValue = moduleExports[key];
|
|
43
|
+
if (exports.isLikelyComponentType(exportValue)) {
|
|
44
|
+
// 'export' is required to avoid key collision when renamed exports that
|
|
45
|
+
// shadow a local component name: https://github.com/vitejs/vite-plugin-react/issues/116
|
|
46
|
+
// The register function has an identity check to not register twice the same component,
|
|
47
|
+
// so this is safe to not used the same key here.
|
|
48
|
+
exports.register(exportValue, filename + " export " + key);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function validateRefreshBoundaryAndEnqueueUpdate(
|
|
54
|
+
prevExports,
|
|
55
|
+
nextExports,
|
|
56
|
+
// non-component exports that are handled by the framework (e.g. `meta` and `links` for route modules)
|
|
57
|
+
acceptExports = [],
|
|
58
|
+
) {
|
|
59
|
+
if (
|
|
60
|
+
!predicateOnExport(
|
|
61
|
+
prevExports,
|
|
62
|
+
(key) => key in nextExports || acceptExports.includes(key),
|
|
63
|
+
)
|
|
64
|
+
) {
|
|
65
|
+
return "Could not Fast Refresh (export removed)";
|
|
66
|
+
}
|
|
67
|
+
if (
|
|
68
|
+
!predicateOnExport(
|
|
69
|
+
nextExports,
|
|
70
|
+
(key) => key in prevExports || acceptExports.includes(key),
|
|
71
|
+
)
|
|
72
|
+
) {
|
|
73
|
+
return "Could not Fast Refresh (new export)";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let hasExports = false;
|
|
77
|
+
const allExportsAreHandledOrUnchanged = predicateOnExport(
|
|
78
|
+
nextExports,
|
|
79
|
+
(key, value) => {
|
|
80
|
+
hasExports = true;
|
|
81
|
+
// React Router can handle additional exports (e.g. `meta` and `links`)
|
|
82
|
+
if (acceptExports.includes(key)) return true;
|
|
83
|
+
// React Fast Refresh can handle component exports
|
|
84
|
+
if (exports.isLikelyComponentType(value)) return true;
|
|
85
|
+
// Unchanged exports are implicitly handled
|
|
86
|
+
return prevExports[key] === nextExports[key];
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
if (hasExports && allExportsAreHandledOrUnchanged) {
|
|
90
|
+
enqueueUpdate();
|
|
91
|
+
} else {
|
|
92
|
+
return "Could not Fast Refresh. Learn more at https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#consistent-components-exports";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function predicateOnExport(moduleExports, predicate) {
|
|
97
|
+
for (const key in moduleExports) {
|
|
98
|
+
if (key === "__esModule") continue;
|
|
99
|
+
const desc = Object.getOwnPropertyDescriptor(moduleExports, key);
|
|
100
|
+
if (desc && desc.get) return false;
|
|
101
|
+
if (!predicate(key, moduleExports[key])) return false;
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Hides vite-ignored dynamic import so that Vite can skip analysis if no other
|
|
107
|
+
// dynamic import is present (https://github.com/vitejs/vite/pull/12732)
|
|
108
|
+
function __hmr_import(module) {
|
|
109
|
+
return import(/* @vite-ignore */ module);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const routeUpdates = new Set();
|
|
113
|
+
window.__reactRouterRouteModuleUpdates = new Map();
|
|
114
|
+
|
|
115
|
+
import.meta.hot.on("react-router:hmr", async (routeUpdate) => {
|
|
116
|
+
routeUpdates.add(routeUpdate);
|
|
117
|
+
if (routeUpdate.isServerOnlyChange) {
|
|
118
|
+
enqueueUpdate();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
exports.__hmr_import = __hmr_import;
|
|
123
|
+
exports.registerExportsForReactRefresh = registerExportsForReactRefresh;
|
|
124
|
+
exports.validateRefreshBoundaryAndEnqueueUpdate =
|
|
125
|
+
validateRefreshBoundaryAndEnqueueUpdate;
|
|
126
|
+
exports.enqueueUpdate = enqueueUpdate;
|
package/dist/vite/cloudflare.js
CHANGED
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v7.8.0
|
|
2
|
+
* @react-router/dev v7.8.1-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -2329,6 +2329,32 @@ function toFunctionExpression(decl) {
|
|
|
2329
2329
|
);
|
|
2330
2330
|
}
|
|
2331
2331
|
|
|
2332
|
+
// vite/plugins/validate-plugin-order.ts
|
|
2333
|
+
function validatePluginOrder() {
|
|
2334
|
+
return {
|
|
2335
|
+
name: "react-router:validate-plugin-order",
|
|
2336
|
+
configResolved(viteConfig) {
|
|
2337
|
+
let pluginIndex = (pluginName) => {
|
|
2338
|
+
pluginName = Array.isArray(pluginName) ? pluginName : [pluginName];
|
|
2339
|
+
return viteConfig.plugins.findIndex(
|
|
2340
|
+
(plugin) => pluginName.includes(plugin.name)
|
|
2341
|
+
);
|
|
2342
|
+
};
|
|
2343
|
+
let rollupPrePlugins = [
|
|
2344
|
+
{ pluginName: "@mdx-js/rollup", displayName: "@mdx-js/rollup" }
|
|
2345
|
+
];
|
|
2346
|
+
for (let prePlugin of rollupPrePlugins) {
|
|
2347
|
+
let prePluginIndex = pluginIndex(prePlugin.pluginName);
|
|
2348
|
+
if (prePluginIndex >= 0 && prePluginIndex > pluginIndex(["react-router", "react-router/rsc"])) {
|
|
2349
|
+
throw new Error(
|
|
2350
|
+
`The "${prePlugin.displayName}" plugin should be placed before the React Router plugin in your Vite config file`
|
|
2351
|
+
);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
};
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2332
2358
|
// vite/plugin.ts
|
|
2333
2359
|
function extractPluginContext(viteConfig) {
|
|
2334
2360
|
return viteConfig["__reactRouterPluginContext"];
|
|
@@ -2671,10 +2697,6 @@ var reactRouterVitePlugin = () => {
|
|
|
2671
2697
|
buildManifest
|
|
2672
2698
|
};
|
|
2673
2699
|
};
|
|
2674
|
-
let pluginIndex = (pluginName) => {
|
|
2675
|
-
invariant(viteConfig);
|
|
2676
|
-
return viteConfig.plugins.findIndex((plugin) => plugin.name === pluginName);
|
|
2677
|
-
};
|
|
2678
2700
|
let getServerEntry = async ({ routeIds }) => {
|
|
2679
2701
|
invariant(viteConfig, "viteconfig required to generate the server entry");
|
|
2680
2702
|
let routes = routeIds ? (
|
|
@@ -3238,17 +3260,6 @@ var reactRouterVitePlugin = () => {
|
|
|
3238
3260
|
childCompilerConfigFile,
|
|
3239
3261
|
"Vite config file was unable to be resolved for React Router child compiler"
|
|
3240
3262
|
);
|
|
3241
|
-
let rollupPrePlugins = [
|
|
3242
|
-
{ pluginName: "@mdx-js/rollup", displayName: "@mdx-js/rollup" }
|
|
3243
|
-
];
|
|
3244
|
-
for (let prePlugin of rollupPrePlugins) {
|
|
3245
|
-
let prePluginIndex = pluginIndex(prePlugin.pluginName);
|
|
3246
|
-
if (prePluginIndex >= 0 && prePluginIndex > pluginIndex("react-router")) {
|
|
3247
|
-
throw new Error(
|
|
3248
|
-
`The "${prePlugin.displayName}" plugin should be placed before the React Router plugin in your Vite config file`
|
|
3249
|
-
);
|
|
3250
|
-
}
|
|
3251
|
-
}
|
|
3252
3263
|
const childCompilerPlugins = await asyncFlatten(
|
|
3253
3264
|
childCompilerConfigFile.config.plugins ?? []
|
|
3254
3265
|
);
|
|
@@ -3266,7 +3277,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3266
3277
|
envFile: false,
|
|
3267
3278
|
plugins: [
|
|
3268
3279
|
childCompilerPlugins.filter(
|
|
3269
|
-
(plugin) => typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name !== "react-router" && plugin.name !== "react-router:route-exports" && plugin.name !== "react-router:hmr-updates"
|
|
3280
|
+
(plugin) => typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name !== "react-router" && plugin.name !== "react-router:route-exports" && plugin.name !== "react-router:hmr-updates" && plugin.name !== "react-router:validate-plugin-order"
|
|
3270
3281
|
).map((plugin) => ({
|
|
3271
3282
|
...plugin,
|
|
3272
3283
|
configureServer: void 0,
|
|
@@ -3955,7 +3966,8 @@ var reactRouterVitePlugin = () => {
|
|
|
3955
3966
|
server.environments.client.reloadModule(clientModule);
|
|
3956
3967
|
}
|
|
3957
3968
|
}
|
|
3958
|
-
}
|
|
3969
|
+
},
|
|
3970
|
+
validatePluginOrder()
|
|
3959
3971
|
];
|
|
3960
3972
|
};
|
|
3961
3973
|
function getParentClientNodes(clientModuleGraph, module2) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-router/dev",
|
|
3
|
-
"version": "7.8.0",
|
|
3
|
+
"version": "7.8.1-pre.0",
|
|
4
4
|
"description": "Dev tools and CLI for React Router",
|
|
5
5
|
"homepage": "https://reactrouter.com",
|
|
6
6
|
"bugs": {
|
|
@@ -73,7 +73,6 @@
|
|
|
73
73
|
"@babel/traverse": "^7.27.7",
|
|
74
74
|
"@babel/types": "^7.27.7",
|
|
75
75
|
"@npmcli/package-json": "^4.0.1",
|
|
76
|
-
"@vitejs/plugin-react": "^4.5.2",
|
|
77
76
|
"@vitejs/plugin-rsc": "0.4.11",
|
|
78
77
|
"arg": "^5.0.1",
|
|
79
78
|
"babel-dead-code-elimination": "^1.0.6",
|
|
@@ -92,7 +91,7 @@
|
|
|
92
91
|
"tinyglobby": "^0.2.14",
|
|
93
92
|
"valibot": "^0.41.0",
|
|
94
93
|
"vite-node": "^3.2.2",
|
|
95
|
-
"@react-router/node": "7.8.0"
|
|
94
|
+
"@react-router/node": "7.8.1-pre.0"
|
|
96
95
|
},
|
|
97
96
|
"devDependencies": {
|
|
98
97
|
"@types/babel__core": "^7.20.5",
|
|
@@ -115,15 +114,15 @@
|
|
|
115
114
|
"vite": "^6.1.0",
|
|
116
115
|
"wireit": "0.14.9",
|
|
117
116
|
"wrangler": "^4.23.0",
|
|
118
|
-
"@react-router/serve": "7.8.0",
|
|
119
|
-
"react-router": "^7.8.0"
|
|
117
|
+
"@react-router/serve": "7.8.1-pre.0",
|
|
118
|
+
"react-router": "^7.8.1-pre.0"
|
|
120
119
|
},
|
|
121
120
|
"peerDependencies": {
|
|
122
121
|
"typescript": "^5.1.0",
|
|
123
122
|
"vite": "^5.1.0 || ^6.0.0 || ^7.0.0",
|
|
124
123
|
"wrangler": "^3.28.2 || ^4.0.0",
|
|
125
|
-
"@react-router/serve": "^7.8.0",
|
|
126
|
-
"react-router": "^7.8.0"
|
|
124
|
+
"@react-router/serve": "^7.8.1-pre.0",
|
|
125
|
+
"react-router": "^7.8.1-pre.0"
|
|
127
126
|
},
|
|
128
127
|
"peerDependenciesMeta": {
|
|
129
128
|
"@react-router/serve": {
|