@c0va23/react-router-dev 7.8.3-alpha.1 → 7.9.4-patch.1
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 +173 -0
- package/dist/cli/index.js +102 -52
- package/dist/config/default-rsc-entries/entry.rsc.tsx +3 -0
- package/dist/config/default-rsc-entries/entry.ssr.tsx +2 -4
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +13 -79
- package/dist/vite.d.ts +3 -1
- package/dist/vite.js +1140 -235
- package/package.json +19 -24
- package/LICENSE.md +0 -23
- package/dist/internal.d.ts +0 -9
- package/dist/internal.js +0 -2216
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @c0va23/react-router-dev v7.
|
|
2
|
+
* @c0va23/react-router-dev v7.9.4-patch.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -40,7 +40,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
40
40
|
// vite.ts
|
|
41
41
|
var vite_exports = {};
|
|
42
42
|
__export(vite_exports, {
|
|
43
|
-
reactRouter: () => reactRouterVitePlugin
|
|
43
|
+
reactRouter: () => reactRouterVitePlugin,
|
|
44
|
+
unstable_reactRouterRSC: () => reactRouterRSCVitePlugin
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(vite_exports);
|
|
46
47
|
|
|
@@ -51,11 +52,12 @@ var import_promises2 = require("fs/promises");
|
|
|
51
52
|
var path6 = __toESM(require("path"));
|
|
52
53
|
var url = __toESM(require("url"));
|
|
53
54
|
var babel = __toESM(require("@babel/core"));
|
|
55
|
+
var import_node_fetch_server2 = require("@remix-run/node-fetch-server");
|
|
54
56
|
var import_react_router2 = require("react-router");
|
|
55
57
|
var import_es_module_lexer = require("es-module-lexer");
|
|
56
58
|
var import_pick3 = __toESM(require("lodash/pick"));
|
|
57
59
|
var import_jsesc = __toESM(require("jsesc"));
|
|
58
|
-
var
|
|
60
|
+
var import_picocolors4 = __toESM(require("picocolors"));
|
|
59
61
|
var import_kebabCase = __toESM(require("lodash/kebabCase"));
|
|
60
62
|
|
|
61
63
|
// typegen/index.ts
|
|
@@ -246,7 +248,7 @@ function validateRouteConfig({
|
|
|
246
248
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
247
249
|
root ? `${root}` : [],
|
|
248
250
|
nested ? Object.entries(nested).map(
|
|
249
|
-
([
|
|
251
|
+
([path9, message]) => `Path: routes.${path9}
|
|
250
252
|
${message}`
|
|
251
253
|
) : []
|
|
252
254
|
].flat().join("\n\n")
|
|
@@ -479,7 +481,7 @@ async function resolveConfig({
|
|
|
479
481
|
}
|
|
480
482
|
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
481
483
|
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
482
|
-
let rootRouteFile = findEntry(appDirectory, "root");
|
|
484
|
+
let rootRouteFile = findEntry(appDirectory, "root", { absolute: true });
|
|
483
485
|
if (!rootRouteFile) {
|
|
484
486
|
let rootRouteDisplayPath = import_pathe3.default.relative(
|
|
485
487
|
root,
|
|
@@ -520,7 +522,7 @@ async function resolveConfig({
|
|
|
520
522
|
{
|
|
521
523
|
id: "root",
|
|
522
524
|
path: "",
|
|
523
|
-
file: rootRouteFile,
|
|
525
|
+
file: import_pathe3.default.relative(appDirectory, rootRouteFile),
|
|
524
526
|
children: result.routeConfig
|
|
525
527
|
}
|
|
526
528
|
];
|
|
@@ -539,11 +541,11 @@ async function resolveConfig({
|
|
|
539
541
|
}
|
|
540
542
|
}
|
|
541
543
|
let future = {
|
|
542
|
-
v8_middleware:
|
|
543
|
-
unstable_optimizeDeps:
|
|
544
|
-
unstable_splitRouteModules:
|
|
545
|
-
unstable_subResourceIntegrity:
|
|
546
|
-
unstable_viteEnvironmentApi:
|
|
544
|
+
v8_middleware: userAndPresetConfigs.future?.v8_middleware ?? false,
|
|
545
|
+
unstable_optimizeDeps: userAndPresetConfigs.future?.unstable_optimizeDeps ?? false,
|
|
546
|
+
unstable_splitRouteModules: userAndPresetConfigs.future?.unstable_splitRouteModules ?? false,
|
|
547
|
+
unstable_subResourceIntegrity: userAndPresetConfigs.future?.unstable_subResourceIntegrity ?? false,
|
|
548
|
+
unstable_viteEnvironmentApi: userAndPresetConfigs.future?.unstable_viteEnvironmentApi ?? false
|
|
547
549
|
};
|
|
548
550
|
let reactRouterConfig = deepFreeze({
|
|
549
551
|
appDirectory,
|
|
@@ -617,12 +619,12 @@ async function createConfigLoader({
|
|
|
617
619
|
if (!fsWatcher) {
|
|
618
620
|
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
619
621
|
ignoreInitial: true,
|
|
620
|
-
ignored: (
|
|
621
|
-
let
|
|
622
|
-
return !
|
|
622
|
+
ignored: (path9) => {
|
|
623
|
+
let dirname5 = import_pathe3.default.dirname(path9);
|
|
624
|
+
return !dirname5.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
623
625
|
// that are at the root level, not nested in subdirectories
|
|
624
|
-
|
|
625
|
-
|
|
626
|
+
path9 !== root && // Watch the root directory itself
|
|
627
|
+
dirname5 !== root;
|
|
626
628
|
}
|
|
627
629
|
});
|
|
628
630
|
fsWatcher.on("all", async (...args) => {
|
|
@@ -814,7 +816,8 @@ function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /
|
|
|
814
816
|
async function createContext2({
|
|
815
817
|
rootDirectory,
|
|
816
818
|
watch: watch2,
|
|
817
|
-
mode
|
|
819
|
+
mode,
|
|
820
|
+
rsc
|
|
818
821
|
}) {
|
|
819
822
|
const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
|
|
820
823
|
const configResult = await configLoader.getConfig();
|
|
@@ -825,7 +828,8 @@ async function createContext2({
|
|
|
825
828
|
return {
|
|
826
829
|
configLoader,
|
|
827
830
|
rootDirectory,
|
|
828
|
-
config
|
|
831
|
+
config,
|
|
832
|
+
rsc
|
|
829
833
|
};
|
|
830
834
|
}
|
|
831
835
|
|
|
@@ -880,7 +884,7 @@ function fullpath(lineage2) {
|
|
|
880
884
|
if (lineage2.length === 1 && route?.id === "root") return "/";
|
|
881
885
|
const isLayout = route && route.index !== true && route.path === void 0;
|
|
882
886
|
if (isLayout) return void 0;
|
|
883
|
-
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((
|
|
887
|
+
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path9) => path9 !== void 0 && path9 !== "").join("/");
|
|
884
888
|
}
|
|
885
889
|
|
|
886
890
|
// typegen/generate.ts
|
|
@@ -896,7 +900,7 @@ function generateFuture(ctx) {
|
|
|
896
900
|
|
|
897
901
|
declare module "react-router" {
|
|
898
902
|
interface Future {
|
|
899
|
-
|
|
903
|
+
v8_middleware: ${ctx.config.future.v8_middleware}
|
|
900
904
|
}
|
|
901
905
|
}
|
|
902
906
|
`;
|
|
@@ -964,9 +968,10 @@ function generateRoutes(ctx) {
|
|
|
964
968
|
interface Register {
|
|
965
969
|
pages: Pages
|
|
966
970
|
routeFiles: RouteFiles
|
|
971
|
+
routeModules: RouteModules
|
|
967
972
|
}
|
|
968
973
|
}
|
|
969
|
-
` + "\n\n" + generate(pagesType(allPages)).code + "\n\n" + generate(routeFilesType({ fileToRoutes, routeToPages })).code
|
|
974
|
+
` + "\n\n" + generate(pagesType(allPages)).code + "\n\n" + generate(routeFilesType({ fileToRoutes, routeToPages })).code + "\n\n" + generate(routeModulesType(ctx)).code
|
|
970
975
|
};
|
|
971
976
|
const allAnnotations = Array.from(fileToRoutes.entries()).filter(([file]) => isInAppDirectory(ctx, file)).map(
|
|
972
977
|
([file, routeIds]) => getRouteAnnotations({ ctx, file, routeIds, lineages })
|
|
@@ -1035,9 +1040,31 @@ function routeFilesType({
|
|
|
1035
1040
|
)
|
|
1036
1041
|
);
|
|
1037
1042
|
}
|
|
1043
|
+
function routeModulesType(ctx) {
|
|
1044
|
+
return t2.tsTypeAliasDeclaration(
|
|
1045
|
+
t2.identifier("RouteModules"),
|
|
1046
|
+
null,
|
|
1047
|
+
t2.tsTypeLiteral(
|
|
1048
|
+
Object.values(ctx.config.routes).map(
|
|
1049
|
+
(route) => t2.tsPropertySignature(
|
|
1050
|
+
t2.stringLiteral(route.id),
|
|
1051
|
+
t2.tsTypeAnnotation(
|
|
1052
|
+
t2.tsTypeQuery(
|
|
1053
|
+
t2.tsImportType(
|
|
1054
|
+
t2.stringLiteral(
|
|
1055
|
+
`./${Path3.relative(ctx.rootDirectory, ctx.config.appDirectory)}/${route.file}`
|
|
1056
|
+
)
|
|
1057
|
+
)
|
|
1058
|
+
)
|
|
1059
|
+
)
|
|
1060
|
+
)
|
|
1061
|
+
)
|
|
1062
|
+
)
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1038
1065
|
function isInAppDirectory(ctx, routeFile) {
|
|
1039
|
-
const
|
|
1040
|
-
return
|
|
1066
|
+
const path9 = Path3.resolve(ctx.config.appDirectory, routeFile);
|
|
1067
|
+
return path9.startsWith(ctx.config.appDirectory);
|
|
1041
1068
|
}
|
|
1042
1069
|
function getRouteAnnotations({
|
|
1043
1070
|
ctx,
|
|
@@ -1102,7 +1129,7 @@ function getRouteAnnotations({
|
|
|
1102
1129
|
module: Module
|
|
1103
1130
|
}>
|
|
1104
1131
|
` + "\n\n" + generate(matchesType).code + "\n\n" + import_dedent.default`
|
|
1105
|
-
type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }>;
|
|
1132
|
+
type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }, ${ctx.rsc}>;
|
|
1106
1133
|
|
|
1107
1134
|
export namespace Route {
|
|
1108
1135
|
// links
|
|
@@ -1149,21 +1176,21 @@ function getRouteAnnotations({
|
|
|
1149
1176
|
return { filename: filename2, content };
|
|
1150
1177
|
}
|
|
1151
1178
|
function relativeImportSource(from, to) {
|
|
1152
|
-
let
|
|
1153
|
-
let extension = Path3.extname(
|
|
1154
|
-
|
|
1155
|
-
if (!
|
|
1179
|
+
let path9 = Path3.relative(Path3.dirname(from), to);
|
|
1180
|
+
let extension = Path3.extname(path9);
|
|
1181
|
+
path9 = Path3.join(Path3.dirname(path9), Pathe.filename(path9));
|
|
1182
|
+
if (!path9.startsWith("../")) path9 = "./" + path9;
|
|
1156
1183
|
if (!extension || /\.(js|ts)x?$/.test(extension)) {
|
|
1157
1184
|
extension = ".js";
|
|
1158
1185
|
}
|
|
1159
|
-
return
|
|
1186
|
+
return path9 + extension;
|
|
1160
1187
|
}
|
|
1161
1188
|
function rootDirsPath(ctx, typesPath) {
|
|
1162
1189
|
const rel = Path3.relative(typesDirectory(ctx), typesPath);
|
|
1163
1190
|
return Path3.join(ctx.rootDirectory, rel);
|
|
1164
1191
|
}
|
|
1165
|
-
function paramsType(
|
|
1166
|
-
const params = parse2(
|
|
1192
|
+
function paramsType(path9) {
|
|
1193
|
+
const params = parse2(path9);
|
|
1167
1194
|
return t2.tsTypeLiteral(
|
|
1168
1195
|
Object.entries(params).map(([param, isRequired]) => {
|
|
1169
1196
|
const property = t2.tsPropertySignature(
|
|
@@ -1213,8 +1240,8 @@ async function write(...files) {
|
|
|
1213
1240
|
})
|
|
1214
1241
|
);
|
|
1215
1242
|
}
|
|
1216
|
-
async function watch(rootDirectory, { mode, logger }) {
|
|
1217
|
-
const ctx = await createContext2({ rootDirectory, mode, watch: true });
|
|
1243
|
+
async function watch(rootDirectory, { mode, logger, rsc }) {
|
|
1244
|
+
const ctx = await createContext2({ rootDirectory, mode, rsc, watch: true });
|
|
1218
1245
|
await import_promises.default.rm(typesDirectory(ctx), { recursive: true, force: true });
|
|
1219
1246
|
await write(
|
|
1220
1247
|
generateFuture(ctx),
|
|
@@ -1252,81 +1279,14 @@ async function watch(rootDirectory, { mode, logger }) {
|
|
|
1252
1279
|
}
|
|
1253
1280
|
|
|
1254
1281
|
// vite/node-adapter.ts
|
|
1255
|
-
var
|
|
1256
|
-
var import_node_tls = require("tls");
|
|
1257
|
-
var import_node_stream = require("stream");
|
|
1258
|
-
var import_set_cookie_parser = require("set-cookie-parser");
|
|
1259
|
-
var import_node = require("@react-router/node");
|
|
1260
|
-
function fromNodeHeaders(nodeReq) {
|
|
1261
|
-
let nodeHeaders = nodeReq.headers;
|
|
1262
|
-
if (nodeReq.httpVersionMajor >= 2) {
|
|
1263
|
-
nodeHeaders = { ...nodeHeaders };
|
|
1264
|
-
if (nodeHeaders[":authority"]) {
|
|
1265
|
-
nodeHeaders.host = nodeHeaders[":authority"];
|
|
1266
|
-
}
|
|
1267
|
-
delete nodeHeaders[":authority"];
|
|
1268
|
-
delete nodeHeaders[":method"];
|
|
1269
|
-
delete nodeHeaders[":path"];
|
|
1270
|
-
delete nodeHeaders[":scheme"];
|
|
1271
|
-
}
|
|
1272
|
-
let headers = new Headers();
|
|
1273
|
-
for (let [key, values] of Object.entries(nodeHeaders)) {
|
|
1274
|
-
if (values) {
|
|
1275
|
-
if (Array.isArray(values)) {
|
|
1276
|
-
for (let value of values) {
|
|
1277
|
-
headers.append(key, value);
|
|
1278
|
-
}
|
|
1279
|
-
} else {
|
|
1280
|
-
headers.set(key, values);
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
return headers;
|
|
1285
|
-
}
|
|
1282
|
+
var import_node_fetch_server = require("@remix-run/node-fetch-server");
|
|
1286
1283
|
function fromNodeRequest(nodeReq, nodeRes) {
|
|
1287
|
-
let protocol = nodeReq.socket instanceof import_node_tls.TLSSocket && nodeReq.socket.encrypted ? "https" : "http";
|
|
1288
|
-
let origin = nodeReq.headers.origin && "null" !== nodeReq.headers.origin ? nodeReq.headers.origin : `${protocol}://${nodeReq.headers.host}`;
|
|
1289
1284
|
invariant(
|
|
1290
1285
|
nodeReq.originalUrl,
|
|
1291
1286
|
"Expected `nodeReq.originalUrl` to be defined"
|
|
1292
1287
|
);
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
let init = {
|
|
1296
|
-
method: nodeReq.method,
|
|
1297
|
-
headers: fromNodeHeaders(nodeReq),
|
|
1298
|
-
signal: controller.signal
|
|
1299
|
-
};
|
|
1300
|
-
nodeRes.on("finish", () => controller = null);
|
|
1301
|
-
nodeRes.on("close", () => controller?.abort());
|
|
1302
|
-
if (nodeReq.method !== "GET" && nodeReq.method !== "HEAD") {
|
|
1303
|
-
init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
|
|
1304
|
-
init.duplex = "half";
|
|
1305
|
-
}
|
|
1306
|
-
return new Request(url2.href, init);
|
|
1307
|
-
}
|
|
1308
|
-
async function toNodeRequest(res, nodeRes) {
|
|
1309
|
-
nodeRes.statusCode = res.status;
|
|
1310
|
-
if (!nodeRes.req || nodeRes.req.httpVersionMajor < 2) {
|
|
1311
|
-
nodeRes.statusMessage = res.statusText;
|
|
1312
|
-
}
|
|
1313
|
-
let cookiesStrings = [];
|
|
1314
|
-
for (let [name, value] of res.headers) {
|
|
1315
|
-
if (name === "set-cookie") {
|
|
1316
|
-
cookiesStrings.push(...(0, import_set_cookie_parser.splitCookiesString)(value));
|
|
1317
|
-
} else nodeRes.setHeader(name, value);
|
|
1318
|
-
}
|
|
1319
|
-
if (cookiesStrings.length) {
|
|
1320
|
-
nodeRes.setHeader("set-cookie", cookiesStrings);
|
|
1321
|
-
}
|
|
1322
|
-
if (res.body) {
|
|
1323
|
-
let responseBody = res.body;
|
|
1324
|
-
let readable = import_node_stream.Readable.from(responseBody);
|
|
1325
|
-
readable.pipe(nodeRes);
|
|
1326
|
-
await (0, import_node_events.once)(readable, "end");
|
|
1327
|
-
} else {
|
|
1328
|
-
nodeRes.end();
|
|
1329
|
-
}
|
|
1288
|
+
nodeReq.url = nodeReq.originalUrl;
|
|
1289
|
+
return (0, import_node_fetch_server.createRequest)(nodeReq, nodeRes);
|
|
1330
1290
|
}
|
|
1331
1291
|
|
|
1332
1292
|
// vite/styles.ts
|
|
@@ -1499,11 +1459,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
|
|
|
1499
1459
|
let cssContent = void 0;
|
|
1500
1460
|
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1501
1461
|
traverse(ast, {
|
|
1502
|
-
VariableDeclaration(
|
|
1503
|
-
const declaration =
|
|
1462
|
+
VariableDeclaration(path9) {
|
|
1463
|
+
const declaration = path9.node.declarations[0];
|
|
1504
1464
|
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1505
1465
|
cssContent = declaration.init.value;
|
|
1506
|
-
|
|
1466
|
+
path9.stop();
|
|
1507
1467
|
}
|
|
1508
1468
|
}
|
|
1509
1469
|
});
|
|
@@ -1542,10 +1502,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1542
1502
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1543
1503
|
let removedExportLocalNames = /* @__PURE__ */ new Set();
|
|
1544
1504
|
traverse(ast, {
|
|
1545
|
-
ExportDeclaration(
|
|
1546
|
-
if (
|
|
1547
|
-
if (
|
|
1548
|
-
|
|
1505
|
+
ExportDeclaration(path9) {
|
|
1506
|
+
if (path9.node.type === "ExportNamedDeclaration") {
|
|
1507
|
+
if (path9.node.specifiers.length) {
|
|
1508
|
+
path9.node.specifiers = path9.node.specifiers.filter((specifier) => {
|
|
1549
1509
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1550
1510
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1551
1511
|
exportsFiltered = true;
|
|
@@ -1557,12 +1517,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1557
1517
|
}
|
|
1558
1518
|
return true;
|
|
1559
1519
|
});
|
|
1560
|
-
if (
|
|
1561
|
-
markedForRemoval.add(
|
|
1520
|
+
if (path9.node.specifiers.length === 0) {
|
|
1521
|
+
markedForRemoval.add(path9);
|
|
1562
1522
|
}
|
|
1563
1523
|
}
|
|
1564
|
-
if (
|
|
1565
|
-
let declaration =
|
|
1524
|
+
if (path9.node.declaration?.type === "VariableDeclaration") {
|
|
1525
|
+
let declaration = path9.node.declaration;
|
|
1566
1526
|
declaration.declarations = declaration.declarations.filter(
|
|
1567
1527
|
(declaration2) => {
|
|
1568
1528
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1576,30 +1536,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1576
1536
|
}
|
|
1577
1537
|
);
|
|
1578
1538
|
if (declaration.declarations.length === 0) {
|
|
1579
|
-
markedForRemoval.add(
|
|
1539
|
+
markedForRemoval.add(path9);
|
|
1580
1540
|
}
|
|
1581
1541
|
}
|
|
1582
|
-
if (
|
|
1583
|
-
let id =
|
|
1542
|
+
if (path9.node.declaration?.type === "FunctionDeclaration") {
|
|
1543
|
+
let id = path9.node.declaration.id;
|
|
1584
1544
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1585
|
-
markedForRemoval.add(
|
|
1545
|
+
markedForRemoval.add(path9);
|
|
1586
1546
|
}
|
|
1587
1547
|
}
|
|
1588
|
-
if (
|
|
1589
|
-
let id =
|
|
1548
|
+
if (path9.node.declaration?.type === "ClassDeclaration") {
|
|
1549
|
+
let id = path9.node.declaration.id;
|
|
1590
1550
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1591
|
-
markedForRemoval.add(
|
|
1551
|
+
markedForRemoval.add(path9);
|
|
1592
1552
|
}
|
|
1593
1553
|
}
|
|
1594
1554
|
}
|
|
1595
|
-
if (
|
|
1555
|
+
if (path9.node.type === "ExportDefaultDeclaration") {
|
|
1596
1556
|
if (exportsToRemove.includes("default")) {
|
|
1597
|
-
markedForRemoval.add(
|
|
1598
|
-
if (
|
|
1599
|
-
if (
|
|
1600
|
-
removedExportLocalNames.add(
|
|
1601
|
-
} else if ((
|
|
1602
|
-
removedExportLocalNames.add(
|
|
1557
|
+
markedForRemoval.add(path9);
|
|
1558
|
+
if (path9.node.declaration) {
|
|
1559
|
+
if (path9.node.declaration.type === "Identifier") {
|
|
1560
|
+
removedExportLocalNames.add(path9.node.declaration.name);
|
|
1561
|
+
} else if ((path9.node.declaration.type === "FunctionDeclaration" || path9.node.declaration.type === "ClassDeclaration") && path9.node.declaration.id) {
|
|
1562
|
+
removedExportLocalNames.add(path9.node.declaration.id.name);
|
|
1603
1563
|
}
|
|
1604
1564
|
}
|
|
1605
1565
|
}
|
|
@@ -1607,21 +1567,21 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1607
1567
|
}
|
|
1608
1568
|
});
|
|
1609
1569
|
traverse(ast, {
|
|
1610
|
-
ExpressionStatement(
|
|
1611
|
-
if (!
|
|
1570
|
+
ExpressionStatement(path9) {
|
|
1571
|
+
if (!path9.parentPath.isProgram()) {
|
|
1612
1572
|
return;
|
|
1613
1573
|
}
|
|
1614
|
-
if (
|
|
1615
|
-
const left =
|
|
1574
|
+
if (path9.node.expression.type === "AssignmentExpression") {
|
|
1575
|
+
const left = path9.node.expression.left;
|
|
1616
1576
|
if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
|
|
1617
|
-
markedForRemoval.add(
|
|
1577
|
+
markedForRemoval.add(path9);
|
|
1618
1578
|
}
|
|
1619
1579
|
}
|
|
1620
1580
|
}
|
|
1621
1581
|
});
|
|
1622
1582
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1623
|
-
for (let
|
|
1624
|
-
|
|
1583
|
+
for (let path9 of markedForRemoval) {
|
|
1584
|
+
path9.remove();
|
|
1625
1585
|
}
|
|
1626
1586
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1627
1587
|
}
|
|
@@ -1704,28 +1664,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1704
1664
|
)
|
|
1705
1665
|
);
|
|
1706
1666
|
}
|
|
1707
|
-
function assertNodePath(
|
|
1667
|
+
function assertNodePath(path9) {
|
|
1708
1668
|
invariant(
|
|
1709
|
-
|
|
1710
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1669
|
+
path9 && !Array.isArray(path9),
|
|
1670
|
+
`Expected a Path, but got ${Array.isArray(path9) ? "an array" : path9}`
|
|
1711
1671
|
);
|
|
1712
1672
|
}
|
|
1713
|
-
function assertNodePathIsStatement(
|
|
1673
|
+
function assertNodePathIsStatement(path9) {
|
|
1714
1674
|
invariant(
|
|
1715
|
-
|
|
1716
|
-
`Expected a Statement path, but got ${Array.isArray(
|
|
1675
|
+
path9 && !Array.isArray(path9) && t.isStatement(path9.node),
|
|
1676
|
+
`Expected a Statement path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1717
1677
|
);
|
|
1718
1678
|
}
|
|
1719
|
-
function assertNodePathIsVariableDeclarator(
|
|
1679
|
+
function assertNodePathIsVariableDeclarator(path9) {
|
|
1720
1680
|
invariant(
|
|
1721
|
-
|
|
1722
|
-
`Expected an Identifier path, but got ${Array.isArray(
|
|
1681
|
+
path9 && !Array.isArray(path9) && t.isVariableDeclarator(path9.node),
|
|
1682
|
+
`Expected an Identifier path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1723
1683
|
);
|
|
1724
1684
|
}
|
|
1725
|
-
function assertNodePathIsPattern(
|
|
1685
|
+
function assertNodePathIsPattern(path9) {
|
|
1726
1686
|
invariant(
|
|
1727
|
-
|
|
1728
|
-
`Expected a Pattern path, but got ${Array.isArray(
|
|
1687
|
+
path9 && !Array.isArray(path9) && t.isPattern(path9.node),
|
|
1688
|
+
`Expected a Pattern path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1729
1689
|
);
|
|
1730
1690
|
}
|
|
1731
1691
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1761,8 +1721,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1761
1721
|
}
|
|
1762
1722
|
let isWithinExportDestructuring = Boolean(
|
|
1763
1723
|
identifier.findParent(
|
|
1764
|
-
(
|
|
1765
|
-
|
|
1724
|
+
(path9) => Boolean(
|
|
1725
|
+
path9.isPattern() && path9.parentPath?.isVariableDeclarator() && path9.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1766
1726
|
)
|
|
1767
1727
|
)
|
|
1768
1728
|
);
|
|
@@ -1840,7 +1800,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1840
1800
|
for (let specifier of node.specifiers) {
|
|
1841
1801
|
if (t.isIdentifier(specifier.exported)) {
|
|
1842
1802
|
let name = specifier.exported.name;
|
|
1843
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1803
|
+
let specifierPath = exportPath.get("specifiers").find((path9) => path9.node === specifier);
|
|
1844
1804
|
invariant(
|
|
1845
1805
|
specifierPath,
|
|
1846
1806
|
`Expected to find specifier path for ${name}`
|
|
@@ -1857,22 +1817,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1857
1817
|
}
|
|
1858
1818
|
);
|
|
1859
1819
|
}
|
|
1860
|
-
function getDependentIdentifiersForPath(
|
|
1820
|
+
function getDependentIdentifiersForPath(path9, state) {
|
|
1861
1821
|
let { visited, identifiers } = state ?? {
|
|
1862
1822
|
visited: /* @__PURE__ */ new Set(),
|
|
1863
1823
|
identifiers: /* @__PURE__ */ new Set()
|
|
1864
1824
|
};
|
|
1865
|
-
if (visited.has(
|
|
1825
|
+
if (visited.has(path9)) {
|
|
1866
1826
|
return identifiers;
|
|
1867
1827
|
}
|
|
1868
|
-
visited.add(
|
|
1869
|
-
|
|
1870
|
-
Identifier(
|
|
1871
|
-
if (identifiers.has(
|
|
1828
|
+
visited.add(path9);
|
|
1829
|
+
path9.traverse({
|
|
1830
|
+
Identifier(path10) {
|
|
1831
|
+
if (identifiers.has(path10)) {
|
|
1872
1832
|
return;
|
|
1873
1833
|
}
|
|
1874
|
-
identifiers.add(
|
|
1875
|
-
let binding =
|
|
1834
|
+
identifiers.add(path10);
|
|
1835
|
+
let binding = path10.scope.getBinding(path10.node.name);
|
|
1876
1836
|
if (!binding) {
|
|
1877
1837
|
return;
|
|
1878
1838
|
}
|
|
@@ -1894,7 +1854,7 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1894
1854
|
}
|
|
1895
1855
|
}
|
|
1896
1856
|
});
|
|
1897
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1857
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path9);
|
|
1898
1858
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1899
1859
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1900
1860
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1903,9 +1863,9 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1903
1863
|
identifiers
|
|
1904
1864
|
});
|
|
1905
1865
|
}
|
|
1906
|
-
if (withinExportStatement &&
|
|
1907
|
-
t.isPattern(
|
|
1908
|
-
let variableDeclarator =
|
|
1866
|
+
if (withinExportStatement && path9.isIdentifier() && (t.isPattern(path9.parentPath.node) || // [foo]
|
|
1867
|
+
t.isPattern(path9.parentPath.parentPath?.node))) {
|
|
1868
|
+
let variableDeclarator = path9.findParent((p) => p.isVariableDeclarator());
|
|
1909
1869
|
assertNodePath(variableDeclarator);
|
|
1910
1870
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1911
1871
|
visited,
|
|
@@ -1914,16 +1874,16 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1914
1874
|
}
|
|
1915
1875
|
return identifiers;
|
|
1916
1876
|
}
|
|
1917
|
-
function getTopLevelStatementPathForPath(
|
|
1918
|
-
let ancestry =
|
|
1877
|
+
function getTopLevelStatementPathForPath(path9) {
|
|
1878
|
+
let ancestry = path9.getAncestry();
|
|
1919
1879
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1920
1880
|
assertNodePathIsStatement(topLevelStatement);
|
|
1921
1881
|
return topLevelStatement;
|
|
1922
1882
|
}
|
|
1923
1883
|
function getTopLevelStatementsForPaths(paths) {
|
|
1924
1884
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1925
|
-
for (let
|
|
1926
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1885
|
+
for (let path9 of paths) {
|
|
1886
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path9);
|
|
1927
1887
|
topLevelStatements.add(topLevelStatement.node);
|
|
1928
1888
|
}
|
|
1929
1889
|
return topLevelStatements;
|
|
@@ -2317,24 +2277,24 @@ function isNamedComponentExport(name) {
|
|
|
2317
2277
|
}
|
|
2318
2278
|
var decorateComponentExportsWithProps = (ast) => {
|
|
2319
2279
|
const hocs = [];
|
|
2320
|
-
function getHocUid(
|
|
2321
|
-
const uid =
|
|
2280
|
+
function getHocUid(path9, hocName) {
|
|
2281
|
+
const uid = path9.scope.generateUidIdentifier(hocName);
|
|
2322
2282
|
hocs.push([hocName, uid]);
|
|
2323
2283
|
return uid;
|
|
2324
2284
|
}
|
|
2325
2285
|
traverse(ast, {
|
|
2326
|
-
ExportDeclaration(
|
|
2327
|
-
if (
|
|
2328
|
-
const declaration =
|
|
2286
|
+
ExportDeclaration(path9) {
|
|
2287
|
+
if (path9.isExportDefaultDeclaration()) {
|
|
2288
|
+
const declaration = path9.get("declaration");
|
|
2329
2289
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2330
2290
|
if (expr) {
|
|
2331
|
-
const uid = getHocUid(
|
|
2291
|
+
const uid = getHocUid(path9, "UNSAFE_withComponentProps");
|
|
2332
2292
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2333
2293
|
}
|
|
2334
2294
|
return;
|
|
2335
2295
|
}
|
|
2336
|
-
if (
|
|
2337
|
-
const decl =
|
|
2296
|
+
if (path9.isExportNamedDeclaration()) {
|
|
2297
|
+
const decl = path9.get("declaration");
|
|
2338
2298
|
if (decl.isVariableDeclaration()) {
|
|
2339
2299
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2340
2300
|
const id = varDeclarator.get("id");
|
|
@@ -2344,7 +2304,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2344
2304
|
if (!id.isIdentifier()) return;
|
|
2345
2305
|
const { name } = id.node;
|
|
2346
2306
|
if (!isNamedComponentExport(name)) return;
|
|
2347
|
-
const uid = getHocUid(
|
|
2307
|
+
const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
|
|
2348
2308
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2349
2309
|
});
|
|
2350
2310
|
return;
|
|
@@ -2354,7 +2314,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2354
2314
|
if (!id) return;
|
|
2355
2315
|
const { name } = id;
|
|
2356
2316
|
if (!isNamedComponentExport(name)) return;
|
|
2357
|
-
const uid = getHocUid(
|
|
2317
|
+
const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
|
|
2358
2318
|
decl.replaceWith(
|
|
2359
2319
|
t.variableDeclaration("const", [
|
|
2360
2320
|
t.variableDeclarator(
|
|
@@ -2388,6 +2348,26 @@ function toFunctionExpression(decl) {
|
|
|
2388
2348
|
);
|
|
2389
2349
|
}
|
|
2390
2350
|
|
|
2351
|
+
// vite/load-dotenv.ts
|
|
2352
|
+
async function loadDotenv({
|
|
2353
|
+
rootDirectory,
|
|
2354
|
+
viteUserConfig,
|
|
2355
|
+
mode
|
|
2356
|
+
}) {
|
|
2357
|
+
const vite2 = await import("vite");
|
|
2358
|
+
Object.assign(
|
|
2359
|
+
process.env,
|
|
2360
|
+
vite2.loadEnv(
|
|
2361
|
+
mode,
|
|
2362
|
+
viteUserConfig.envDir ?? rootDirectory,
|
|
2363
|
+
// We override the default prefix of "VITE_" with a blank string since
|
|
2364
|
+
// we're targeting the server, so we want to load all environment
|
|
2365
|
+
// variables, not just those explicitly marked for the client
|
|
2366
|
+
""
|
|
2367
|
+
)
|
|
2368
|
+
);
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2391
2371
|
// vite/plugins/validate-plugin-order.ts
|
|
2392
2372
|
function validatePluginOrder() {
|
|
2393
2373
|
return {
|
|
@@ -2420,6 +2400,41 @@ function validatePluginOrder() {
|
|
|
2420
2400
|
};
|
|
2421
2401
|
}
|
|
2422
2402
|
|
|
2403
|
+
// vite/plugins/warn-on-client-source-maps.ts
|
|
2404
|
+
var import_picocolors3 = __toESM(require("picocolors"));
|
|
2405
|
+
function warnOnClientSourceMaps() {
|
|
2406
|
+
let viteConfig;
|
|
2407
|
+
let viteCommand;
|
|
2408
|
+
let logged = false;
|
|
2409
|
+
return {
|
|
2410
|
+
name: "react-router:warn-on-client-source-maps",
|
|
2411
|
+
config(_, configEnv) {
|
|
2412
|
+
viteCommand = configEnv.command;
|
|
2413
|
+
},
|
|
2414
|
+
configResolved(config) {
|
|
2415
|
+
viteConfig = config;
|
|
2416
|
+
},
|
|
2417
|
+
buildStart() {
|
|
2418
|
+
invariant(viteConfig);
|
|
2419
|
+
if (!logged && viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && (viteConfig.build.sourcemap || viteConfig.environments?.client?.build.sourcemap)) {
|
|
2420
|
+
viteConfig.logger.warn(
|
|
2421
|
+
import_picocolors3.default.yellow(
|
|
2422
|
+
"\n" + import_picocolors3.default.bold(" \u26A0\uFE0F Source maps are enabled in production\n") + [
|
|
2423
|
+
"This makes your server code publicly",
|
|
2424
|
+
"visible in the browser. This is highly",
|
|
2425
|
+
"discouraged! If you insist, ensure that",
|
|
2426
|
+
"you are using environment variables for",
|
|
2427
|
+
"secrets and not hard-coding them in",
|
|
2428
|
+
"your source code."
|
|
2429
|
+
].map((line) => " " + line).join("\n") + "\n"
|
|
2430
|
+
)
|
|
2431
|
+
);
|
|
2432
|
+
logged = true;
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2423
2438
|
// vite/plugin.ts
|
|
2424
2439
|
function extractPluginContext(viteConfig) {
|
|
2425
2440
|
return viteConfig["__reactRouterPluginContext"];
|
|
@@ -2730,7 +2745,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2730
2745
|
let publicPath = viteUserConfig.base ?? "/";
|
|
2731
2746
|
if (reactRouterConfig.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !reactRouterConfig.basename.startsWith(publicPath)) {
|
|
2732
2747
|
logger.error(
|
|
2733
|
-
|
|
2748
|
+
import_picocolors4.default.red(
|
|
2734
2749
|
"When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
|
|
2735
2750
|
)
|
|
2736
2751
|
);
|
|
@@ -3117,6 +3132,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3117
3132
|
if (viteCommand === "serve") {
|
|
3118
3133
|
typegenWatcherPromise = watch(rootDirectory, {
|
|
3119
3134
|
mode,
|
|
3135
|
+
rsc: false,
|
|
3120
3136
|
// ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
|
|
3121
3137
|
logger: vite2.createLogger("warn", { prefix: "[react-router]" })
|
|
3122
3138
|
});
|
|
@@ -3127,17 +3143,11 @@ var reactRouterVitePlugin = () => {
|
|
|
3127
3143
|
watch: viteCommand === "serve"
|
|
3128
3144
|
});
|
|
3129
3145
|
await updatePluginContext();
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
// We override the default prefix of "VITE_" with a blank string since
|
|
3136
|
-
// we're targeting the server, so we want to load all environment
|
|
3137
|
-
// variables, not just those explicitly marked for the client
|
|
3138
|
-
""
|
|
3139
|
-
)
|
|
3140
|
-
);
|
|
3146
|
+
await loadDotenv({
|
|
3147
|
+
rootDirectory,
|
|
3148
|
+
viteUserConfig,
|
|
3149
|
+
mode
|
|
3150
|
+
});
|
|
3141
3151
|
let environments = await getEnvironmentsOptions(ctx, viteCommand, {
|
|
3142
3152
|
viteUserConfig
|
|
3143
3153
|
});
|
|
@@ -3329,23 +3339,6 @@ var reactRouterVitePlugin = () => {
|
|
|
3329
3339
|
cssModulesManifest[id] = code;
|
|
3330
3340
|
}
|
|
3331
3341
|
},
|
|
3332
|
-
buildStart() {
|
|
3333
|
-
invariant(viteConfig);
|
|
3334
|
-
if (viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && viteConfig.build.sourcemap) {
|
|
3335
|
-
viteConfig.logger.warn(
|
|
3336
|
-
import_picocolors3.default.yellow(
|
|
3337
|
-
"\n" + import_picocolors3.default.bold(" \u26A0\uFE0F Source maps are enabled in production\n") + [
|
|
3338
|
-
"This makes your server code publicly",
|
|
3339
|
-
"visible in the browser. This is highly",
|
|
3340
|
-
"discouraged! If you insist, ensure that",
|
|
3341
|
-
"you are using environment variables for",
|
|
3342
|
-
"secrets and not hard-coding them in",
|
|
3343
|
-
"your source code."
|
|
3344
|
-
].map((line) => " " + line).join("\n") + "\n"
|
|
3345
|
-
)
|
|
3346
|
-
);
|
|
3347
|
-
}
|
|
3348
|
-
},
|
|
3349
3342
|
async configureServer(viteDevServer) {
|
|
3350
3343
|
(0, import_react_router2.unstable_setDevServerHooks)({
|
|
3351
3344
|
// Give the request handler access to the critical CSS in dev to avoid a
|
|
@@ -3385,7 +3378,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3385
3378
|
return;
|
|
3386
3379
|
}
|
|
3387
3380
|
let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
|
|
3388
|
-
logger.info(
|
|
3381
|
+
logger.info(import_picocolors4.default.green(message), {
|
|
3389
3382
|
clear: true,
|
|
3390
3383
|
timestamp: true
|
|
3391
3384
|
});
|
|
@@ -3445,7 +3438,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3445
3438
|
req2,
|
|
3446
3439
|
await reactRouterDevLoadContext(req2)
|
|
3447
3440
|
);
|
|
3448
|
-
await
|
|
3441
|
+
await (0, import_node_fetch_server2.sendResponse)(nodeRes, res2);
|
|
3449
3442
|
};
|
|
3450
3443
|
await nodeHandler(req, res);
|
|
3451
3444
|
} catch (error) {
|
|
@@ -3525,9 +3518,9 @@ var reactRouterVitePlugin = () => {
|
|
|
3525
3518
|
if (paths.length) {
|
|
3526
3519
|
viteConfig.logger.info(
|
|
3527
3520
|
[
|
|
3528
|
-
`${
|
|
3521
|
+
`${import_picocolors4.default.green("\u2713")} ${message}`,
|
|
3529
3522
|
...paths.map(
|
|
3530
|
-
(assetPath) =>
|
|
3523
|
+
(assetPath) => import_picocolors4.default.dim(path6.relative(ctx.rootDirectory, assetPath))
|
|
3531
3524
|
)
|
|
3532
3525
|
].join("\n")
|
|
3533
3526
|
);
|
|
@@ -3571,7 +3564,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3571
3564
|
viteConfig.logger.info(
|
|
3572
3565
|
[
|
|
3573
3566
|
"Removing the server build in",
|
|
3574
|
-
|
|
3567
|
+
import_picocolors4.default.green(serverBuildDirectory),
|
|
3575
3568
|
"due to ssr:false"
|
|
3576
3569
|
].join(" ")
|
|
3577
3570
|
);
|
|
@@ -3776,7 +3769,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3776
3769
|
).join(", ");
|
|
3777
3770
|
throw Error(
|
|
3778
3771
|
[
|
|
3779
|
-
|
|
3772
|
+
import_picocolors4.default.red(`Server-only module referenced by client`),
|
|
3780
3773
|
"",
|
|
3781
3774
|
` '${id}' imported by route '${importerShort}'`,
|
|
3782
3775
|
"",
|
|
@@ -3785,18 +3778,18 @@ var reactRouterVitePlugin = () => {
|
|
|
3785
3778
|
"",
|
|
3786
3779
|
` But other route exports in '${importerShort}' depend on '${id}'.`,
|
|
3787
3780
|
"",
|
|
3788
|
-
" See https://
|
|
3781
|
+
" See https://reactrouter.com/explanation/code-splitting#removal-of-server-code",
|
|
3789
3782
|
""
|
|
3790
3783
|
].join("\n")
|
|
3791
3784
|
);
|
|
3792
3785
|
}
|
|
3793
3786
|
throw Error(
|
|
3794
3787
|
[
|
|
3795
|
-
|
|
3788
|
+
import_picocolors4.default.red(`Server-only module referenced by client`),
|
|
3796
3789
|
"",
|
|
3797
3790
|
` '${id}' imported by '${importerShort}'`,
|
|
3798
3791
|
"",
|
|
3799
|
-
" See https://
|
|
3792
|
+
" See https://reactrouter.com/explanation/code-splitting#removal-of-server-code",
|
|
3800
3793
|
""
|
|
3801
3794
|
].join("\n")
|
|
3802
3795
|
);
|
|
@@ -4002,7 +3995,8 @@ var reactRouterVitePlugin = () => {
|
|
|
4002
3995
|
}
|
|
4003
3996
|
}
|
|
4004
3997
|
},
|
|
4005
|
-
validatePluginOrder()
|
|
3998
|
+
validatePluginOrder(),
|
|
3999
|
+
warnOnClientSourceMaps()
|
|
4006
4000
|
];
|
|
4007
4001
|
};
|
|
4008
4002
|
function getParentClientNodes(clientModuleGraph, module2) {
|
|
@@ -4186,10 +4180,10 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
4186
4180
|
let prettyPath = path6.join(prettyDir, filename2);
|
|
4187
4181
|
if (build.prerender.length > 0) {
|
|
4188
4182
|
viteConfig.logger.info(
|
|
4189
|
-
`Prerender (html): SPA Fallback -> ${
|
|
4183
|
+
`Prerender (html): SPA Fallback -> ${import_picocolors4.default.bold(prettyPath)}`
|
|
4190
4184
|
);
|
|
4191
4185
|
} else {
|
|
4192
|
-
viteConfig.logger.info(`SPA Mode: Generated ${
|
|
4186
|
+
viteConfig.logger.info(`SPA Mode: Generated ${import_picocolors4.default.bold(prettyPath)}`);
|
|
4193
4187
|
}
|
|
4194
4188
|
}
|
|
4195
4189
|
async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, serverBuildPath, clientBuildDirectory) {
|
|
@@ -4199,17 +4193,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4199
4193
|
serverBuildPath
|
|
4200
4194
|
);
|
|
4201
4195
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
4202
|
-
for (let
|
|
4203
|
-
let matches = (0, import_react_router2.matchRoutes)(routes, `/${
|
|
4196
|
+
for (let path9 of build.prerender) {
|
|
4197
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path9}/`.replace(/^\/\/+/, "/"));
|
|
4204
4198
|
if (!matches) {
|
|
4205
4199
|
throw new Error(
|
|
4206
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4200
|
+
`Unable to prerender path because it does not match any routes: ${path9}`
|
|
4207
4201
|
);
|
|
4208
4202
|
}
|
|
4209
4203
|
}
|
|
4210
4204
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
4211
|
-
for (let
|
|
4212
|
-
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${
|
|
4205
|
+
for (let path9 of build.prerender) {
|
|
4206
|
+
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path9}/`.replace(/^\/\/+/, "/"));
|
|
4213
4207
|
if (!matches) {
|
|
4214
4208
|
continue;
|
|
4215
4209
|
}
|
|
@@ -4222,7 +4216,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4222
4216
|
if (manifestRoute.loader) {
|
|
4223
4217
|
await prerenderData(
|
|
4224
4218
|
handler,
|
|
4225
|
-
|
|
4219
|
+
path9,
|
|
4226
4220
|
[leafRoute.id],
|
|
4227
4221
|
clientBuildDirectory,
|
|
4228
4222
|
reactRouterConfig,
|
|
@@ -4230,7 +4224,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4230
4224
|
);
|
|
4231
4225
|
await prerenderResourceRoute(
|
|
4232
4226
|
handler,
|
|
4233
|
-
|
|
4227
|
+
path9,
|
|
4234
4228
|
clientBuildDirectory,
|
|
4235
4229
|
reactRouterConfig,
|
|
4236
4230
|
viteConfig
|
|
@@ -4248,7 +4242,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4248
4242
|
if (!isResourceRoute && hasLoaders) {
|
|
4249
4243
|
data = await prerenderData(
|
|
4250
4244
|
handler,
|
|
4251
|
-
|
|
4245
|
+
path9,
|
|
4252
4246
|
null,
|
|
4253
4247
|
clientBuildDirectory,
|
|
4254
4248
|
reactRouterConfig,
|
|
@@ -4257,7 +4251,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4257
4251
|
}
|
|
4258
4252
|
await prerenderRoute(
|
|
4259
4253
|
handler,
|
|
4260
|
-
|
|
4254
|
+
path9,
|
|
4261
4255
|
clientBuildDirectory,
|
|
4262
4256
|
reactRouterConfig,
|
|
4263
4257
|
viteConfig,
|
|
@@ -4314,7 +4308,7 @@ ${normalizedPath}`
|
|
|
4314
4308
|
await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
|
|
4315
4309
|
await (0, import_promises2.writeFile)(outfile, data);
|
|
4316
4310
|
viteConfig.logger.info(
|
|
4317
|
-
`Prerender (data): ${prerenderPath} -> ${
|
|
4311
|
+
`Prerender (data): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4318
4312
|
path6.relative(viteConfig.root, outfile)
|
|
4319
4313
|
)}`
|
|
4320
4314
|
);
|
|
@@ -4358,7 +4352,7 @@ ${html}`
|
|
|
4358
4352
|
await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
|
|
4359
4353
|
await (0, import_promises2.writeFile)(outfile, html);
|
|
4360
4354
|
viteConfig.logger.info(
|
|
4361
|
-
`Prerender (html): ${prerenderPath} -> ${
|
|
4355
|
+
`Prerender (html): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4362
4356
|
path6.relative(viteConfig.root, outfile)
|
|
4363
4357
|
)}`
|
|
4364
4358
|
);
|
|
@@ -4378,7 +4372,7 @@ ${content.toString("utf8")}`
|
|
|
4378
4372
|
await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
|
|
4379
4373
|
await (0, import_promises2.writeFile)(outfile, content);
|
|
4380
4374
|
viteConfig.logger.info(
|
|
4381
|
-
`Prerender (resource): ${prerenderPath} -> ${
|
|
4375
|
+
`Prerender (resource): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4382
4376
|
path6.relative(viteConfig.root, outfile)
|
|
4383
4377
|
)}`
|
|
4384
4378
|
);
|
|
@@ -4391,7 +4385,7 @@ async function getPrerenderPaths(prerender, ssr, routes, logWarning = false) {
|
|
|
4391
4385
|
let { paths, paramRoutes } = getStaticPrerenderPaths(prerenderRoutes);
|
|
4392
4386
|
if (logWarning && !ssr && paramRoutes.length > 0) {
|
|
4393
4387
|
console.warn(
|
|
4394
|
-
|
|
4388
|
+
import_picocolors4.default.yellow(
|
|
4395
4389
|
[
|
|
4396
4390
|
"\u26A0\uFE0F Paths with dynamic/splat params cannot be prerendered when using `prerender: true`. You may want to use the `prerender()` API to prerender the following paths:",
|
|
4397
4391
|
...paramRoutes.map((p) => " - " + p)
|
|
@@ -4453,14 +4447,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4453
4447
|
}
|
|
4454
4448
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4455
4449
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4456
|
-
for (let
|
|
4450
|
+
for (let path9 of prerenderPaths) {
|
|
4457
4451
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4458
4452
|
prerenderRoutes,
|
|
4459
|
-
`/${
|
|
4453
|
+
`/${path9}/`.replace(/^\/\/+/, "/")
|
|
4460
4454
|
);
|
|
4461
4455
|
invariant(
|
|
4462
4456
|
matches,
|
|
4463
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4457
|
+
`Unable to prerender path because it does not match any routes: ${path9}`
|
|
4464
4458
|
);
|
|
4465
4459
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4466
4460
|
}
|
|
@@ -4498,7 +4492,7 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4498
4492
|
}
|
|
4499
4493
|
}
|
|
4500
4494
|
if (errors.length > 0) {
|
|
4501
|
-
viteConfig.logger.error(
|
|
4495
|
+
viteConfig.logger.error(import_picocolors4.default.red(errors.join("\n")));
|
|
4502
4496
|
throw new Error(
|
|
4503
4497
|
"Invalid route exports found when prerendering with `ssr:false`"
|
|
4504
4498
|
);
|
|
@@ -4908,7 +4902,918 @@ async function asyncFlatten(arr) {
|
|
|
4908
4902
|
} while (arr.some((v2) => v2?.then));
|
|
4909
4903
|
return arr;
|
|
4910
4904
|
}
|
|
4905
|
+
|
|
4906
|
+
// vite/rsc/plugin.ts
|
|
4907
|
+
var import_es_module_lexer3 = require("es-module-lexer");
|
|
4908
|
+
var Path5 = __toESM(require("pathe"));
|
|
4909
|
+
var babel2 = __toESM(require("@babel/core"));
|
|
4910
|
+
var import_picocolors5 = __toESM(require("picocolors"));
|
|
4911
|
+
var import_fs = require("fs");
|
|
4912
|
+
var import_promises3 = require("fs/promises");
|
|
4913
|
+
var import_pathe6 = __toESM(require("pathe"));
|
|
4914
|
+
|
|
4915
|
+
// vite/rsc/virtual-route-config.ts
|
|
4916
|
+
var import_pathe5 = __toESM(require("pathe"));
|
|
4917
|
+
function createVirtualRouteConfig({
|
|
4918
|
+
appDirectory,
|
|
4919
|
+
routeConfig
|
|
4920
|
+
}) {
|
|
4921
|
+
let routeIdByFile = /* @__PURE__ */ new Map();
|
|
4922
|
+
let code = "export default [";
|
|
4923
|
+
const closeRouteSymbol = Symbol("CLOSE_ROUTE");
|
|
4924
|
+
let stack = [
|
|
4925
|
+
...routeConfig
|
|
4926
|
+
];
|
|
4927
|
+
while (stack.length > 0) {
|
|
4928
|
+
const route = stack.pop();
|
|
4929
|
+
if (!route) break;
|
|
4930
|
+
if (route === closeRouteSymbol) {
|
|
4931
|
+
code += "]},";
|
|
4932
|
+
continue;
|
|
4933
|
+
}
|
|
4934
|
+
code += "{";
|
|
4935
|
+
const routeFile = import_pathe5.default.resolve(appDirectory, route.file);
|
|
4936
|
+
const routeId = route.id || createRouteId2(route.file, appDirectory);
|
|
4937
|
+
routeIdByFile.set(routeFile, routeId);
|
|
4938
|
+
code += `lazy: () => import(${JSON.stringify(
|
|
4939
|
+
`${routeFile}?route-module`
|
|
4940
|
+
)}),`;
|
|
4941
|
+
code += `id: ${JSON.stringify(routeId)},`;
|
|
4942
|
+
if (typeof route.path === "string") {
|
|
4943
|
+
code += `path: ${JSON.stringify(route.path)},`;
|
|
4944
|
+
}
|
|
4945
|
+
if (route.index) {
|
|
4946
|
+
code += `index: true,`;
|
|
4947
|
+
}
|
|
4948
|
+
if (route.caseSensitive) {
|
|
4949
|
+
code += `caseSensitive: true,`;
|
|
4950
|
+
}
|
|
4951
|
+
if (route.children) {
|
|
4952
|
+
code += ["children:["];
|
|
4953
|
+
stack.push(closeRouteSymbol);
|
|
4954
|
+
stack.push(...[...route.children].reverse());
|
|
4955
|
+
} else {
|
|
4956
|
+
code += "},";
|
|
4957
|
+
}
|
|
4958
|
+
}
|
|
4959
|
+
code += "];\n";
|
|
4960
|
+
return { code, routeIdByFile };
|
|
4961
|
+
}
|
|
4962
|
+
function createRouteId2(file, appDirectory) {
|
|
4963
|
+
return import_pathe5.default.relative(appDirectory, file).replace(/\\+/, "/").slice(0, -import_pathe5.default.extname(file).length);
|
|
4964
|
+
}
|
|
4965
|
+
|
|
4966
|
+
// vite/rsc/virtual-route-modules.ts
|
|
4967
|
+
var import_es_module_lexer2 = require("es-module-lexer");
|
|
4968
|
+
var SERVER_ONLY_COMPONENT_EXPORTS = ["ServerComponent"];
|
|
4969
|
+
var SERVER_ONLY_ROUTE_EXPORTS2 = [
|
|
4970
|
+
...SERVER_ONLY_COMPONENT_EXPORTS,
|
|
4971
|
+
"loader",
|
|
4972
|
+
"action",
|
|
4973
|
+
"middleware",
|
|
4974
|
+
"headers"
|
|
4975
|
+
];
|
|
4976
|
+
var SERVER_ONLY_ROUTE_EXPORTS_SET = new Set(SERVER_ONLY_ROUTE_EXPORTS2);
|
|
4977
|
+
function isServerOnlyRouteExport(name) {
|
|
4978
|
+
return SERVER_ONLY_ROUTE_EXPORTS_SET.has(name);
|
|
4979
|
+
}
|
|
4980
|
+
var COMMON_COMPONENT_EXPORTS = [
|
|
4981
|
+
"ErrorBoundary",
|
|
4982
|
+
"HydrateFallback",
|
|
4983
|
+
"Layout"
|
|
4984
|
+
];
|
|
4985
|
+
var SERVER_FIRST_COMPONENT_EXPORTS = [
|
|
4986
|
+
...COMMON_COMPONENT_EXPORTS,
|
|
4987
|
+
...SERVER_ONLY_COMPONENT_EXPORTS
|
|
4988
|
+
];
|
|
4989
|
+
var SERVER_FIRST_COMPONENT_EXPORTS_SET = new Set(
|
|
4990
|
+
SERVER_FIRST_COMPONENT_EXPORTS
|
|
4991
|
+
);
|
|
4992
|
+
function isServerFirstComponentExport(name) {
|
|
4993
|
+
return SERVER_FIRST_COMPONENT_EXPORTS_SET.has(
|
|
4994
|
+
name
|
|
4995
|
+
);
|
|
4996
|
+
}
|
|
4997
|
+
var CLIENT_COMPONENT_EXPORTS = [
|
|
4998
|
+
...COMMON_COMPONENT_EXPORTS,
|
|
4999
|
+
"default"
|
|
5000
|
+
];
|
|
5001
|
+
var CLIENT_NON_COMPONENT_EXPORTS2 = [
|
|
5002
|
+
"clientAction",
|
|
5003
|
+
"clientLoader",
|
|
5004
|
+
"clientMiddleware",
|
|
5005
|
+
"handle",
|
|
5006
|
+
"meta",
|
|
5007
|
+
"links",
|
|
5008
|
+
"shouldRevalidate"
|
|
5009
|
+
];
|
|
5010
|
+
var CLIENT_NON_COMPONENT_EXPORTS_SET = new Set(CLIENT_NON_COMPONENT_EXPORTS2);
|
|
5011
|
+
function isClientNonComponentExport(name) {
|
|
5012
|
+
return CLIENT_NON_COMPONENT_EXPORTS_SET.has(name);
|
|
5013
|
+
}
|
|
5014
|
+
var CLIENT_ROUTE_EXPORTS2 = [
|
|
5015
|
+
...CLIENT_NON_COMPONENT_EXPORTS2,
|
|
5016
|
+
...CLIENT_COMPONENT_EXPORTS
|
|
5017
|
+
];
|
|
5018
|
+
var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS2);
|
|
5019
|
+
function isClientRouteExport(name) {
|
|
5020
|
+
return CLIENT_ROUTE_EXPORTS_SET.has(name);
|
|
5021
|
+
}
|
|
5022
|
+
var ROUTE_EXPORTS = [
|
|
5023
|
+
...SERVER_ONLY_ROUTE_EXPORTS2,
|
|
5024
|
+
...CLIENT_ROUTE_EXPORTS2
|
|
5025
|
+
];
|
|
5026
|
+
var ROUTE_EXPORTS_SET = new Set(ROUTE_EXPORTS);
|
|
5027
|
+
function isRouteExport(name) {
|
|
5028
|
+
return ROUTE_EXPORTS_SET.has(name);
|
|
5029
|
+
}
|
|
5030
|
+
function isCustomRouteExport(name) {
|
|
5031
|
+
return !isRouteExport(name);
|
|
5032
|
+
}
|
|
5033
|
+
function hasReactServerCondition(viteEnvironment) {
|
|
5034
|
+
return viteEnvironment.config.resolve.conditions.includes("react-server");
|
|
5035
|
+
}
|
|
5036
|
+
function transformVirtualRouteModules({
|
|
5037
|
+
id,
|
|
5038
|
+
code,
|
|
5039
|
+
viteCommand,
|
|
5040
|
+
routeIdByFile,
|
|
5041
|
+
rootRouteFile,
|
|
5042
|
+
viteEnvironment
|
|
5043
|
+
}) {
|
|
5044
|
+
if (isVirtualRouteModuleId(id) || routeIdByFile.has(id)) {
|
|
5045
|
+
return createVirtualRouteModuleCode({
|
|
5046
|
+
id,
|
|
5047
|
+
code,
|
|
5048
|
+
rootRouteFile,
|
|
5049
|
+
viteCommand,
|
|
5050
|
+
viteEnvironment
|
|
5051
|
+
});
|
|
5052
|
+
}
|
|
5053
|
+
if (isVirtualServerRouteModuleId(id)) {
|
|
5054
|
+
return createVirtualServerRouteModuleCode({
|
|
5055
|
+
id,
|
|
5056
|
+
code,
|
|
5057
|
+
viteEnvironment
|
|
5058
|
+
});
|
|
5059
|
+
}
|
|
5060
|
+
if (isVirtualClientRouteModuleId(id)) {
|
|
5061
|
+
return createVirtualClientRouteModuleCode({
|
|
5062
|
+
id,
|
|
5063
|
+
code,
|
|
5064
|
+
rootRouteFile,
|
|
5065
|
+
viteCommand
|
|
5066
|
+
});
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
5069
|
+
async function createVirtualRouteModuleCode({
|
|
5070
|
+
id,
|
|
5071
|
+
code: routeSource,
|
|
5072
|
+
rootRouteFile,
|
|
5073
|
+
viteCommand,
|
|
5074
|
+
viteEnvironment
|
|
5075
|
+
}) {
|
|
5076
|
+
const isReactServer = hasReactServerCondition(viteEnvironment);
|
|
5077
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
5078
|
+
const clientModuleId = getVirtualClientModuleId(id);
|
|
5079
|
+
const serverModuleId = getVirtualServerModuleId(id);
|
|
5080
|
+
let code = "";
|
|
5081
|
+
if (isServerFirstRoute) {
|
|
5082
|
+
if (staticExports.some(isServerFirstComponentExport)) {
|
|
5083
|
+
code += `import React from "react";
|
|
5084
|
+
`;
|
|
5085
|
+
}
|
|
5086
|
+
for (const staticExport of staticExports) {
|
|
5087
|
+
if (isClientNonComponentExport(staticExport)) {
|
|
5088
|
+
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5089
|
+
`;
|
|
5090
|
+
} else if (isReactServer && isServerFirstComponentExport(staticExport) && // Layout wraps all other component exports so doesn't need CSS injected
|
|
5091
|
+
staticExport !== "Layout") {
|
|
5092
|
+
code += `import { ${staticExport} as ${staticExport}WithoutCss } from "${serverModuleId}";
|
|
5093
|
+
`;
|
|
5094
|
+
code += `export ${staticExport === "ServerComponent" ? "default " : " "}function ${staticExport}(props) {
|
|
5095
|
+
`;
|
|
5096
|
+
code += ` return React.createElement(React.Fragment, null,
|
|
5097
|
+
`;
|
|
5098
|
+
code += ` import.meta.viteRsc.loadCss(),
|
|
5099
|
+
`;
|
|
5100
|
+
code += ` React.createElement(${staticExport}WithoutCss, props),
|
|
5101
|
+
`;
|
|
5102
|
+
code += ` );
|
|
5103
|
+
`;
|
|
5104
|
+
code += `}
|
|
5105
|
+
`;
|
|
5106
|
+
} else if (isReactServer && isRouteExport(staticExport)) {
|
|
5107
|
+
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5108
|
+
`;
|
|
5109
|
+
} else if (isCustomRouteExport(staticExport)) {
|
|
5110
|
+
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5111
|
+
`;
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5114
|
+
if (viteCommand === "serve" && !hasClientExports) {
|
|
5115
|
+
code += `export { __ensureClientRouteModuleForHMR } from "${clientModuleId}";
|
|
5116
|
+
`;
|
|
5117
|
+
}
|
|
5118
|
+
} else {
|
|
5119
|
+
for (const staticExport of staticExports) {
|
|
5120
|
+
if (isClientRouteExport(staticExport)) {
|
|
5121
|
+
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5122
|
+
`;
|
|
5123
|
+
} else if (isReactServer && isServerOnlyRouteExport(staticExport)) {
|
|
5124
|
+
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5125
|
+
`;
|
|
5126
|
+
} else if (isCustomRouteExport(staticExport)) {
|
|
5127
|
+
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5128
|
+
`;
|
|
5129
|
+
}
|
|
5130
|
+
}
|
|
5131
|
+
}
|
|
5132
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5133
|
+
code += `export { ErrorBoundary } from "${clientModuleId}";
|
|
5134
|
+
`;
|
|
5135
|
+
}
|
|
5136
|
+
return code;
|
|
5137
|
+
}
|
|
5138
|
+
function createVirtualServerRouteModuleCode({
|
|
5139
|
+
id,
|
|
5140
|
+
code: routeSource,
|
|
5141
|
+
viteEnvironment
|
|
5142
|
+
}) {
|
|
5143
|
+
if (!hasReactServerCondition(viteEnvironment)) {
|
|
5144
|
+
throw new Error(
|
|
5145
|
+
[
|
|
5146
|
+
"Virtual server route module was loaded outside of the RSC environment.",
|
|
5147
|
+
`Environment Name: ${viteEnvironment.name}`,
|
|
5148
|
+
`Module ID: ${id}`
|
|
5149
|
+
].join("\n")
|
|
5150
|
+
);
|
|
5151
|
+
}
|
|
5152
|
+
const { staticExports, isServerFirstRoute } = parseRouteExports(routeSource);
|
|
5153
|
+
const clientModuleId = getVirtualClientModuleId(id);
|
|
5154
|
+
const serverRouteModuleAst = import_parser.parse(routeSource, {
|
|
5155
|
+
sourceType: "module"
|
|
5156
|
+
});
|
|
5157
|
+
removeExports(
|
|
5158
|
+
serverRouteModuleAst,
|
|
5159
|
+
isServerFirstRoute ? CLIENT_NON_COMPONENT_EXPORTS2 : CLIENT_ROUTE_EXPORTS2
|
|
5160
|
+
);
|
|
5161
|
+
const generatorResult = generate(serverRouteModuleAst);
|
|
5162
|
+
if (!isServerFirstRoute) {
|
|
5163
|
+
for (const staticExport of staticExports) {
|
|
5164
|
+
if (isClientRouteExport(staticExport)) {
|
|
5165
|
+
generatorResult.code += "\n";
|
|
5166
|
+
generatorResult.code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5167
|
+
`;
|
|
5168
|
+
}
|
|
5169
|
+
}
|
|
5170
|
+
}
|
|
5171
|
+
return generatorResult;
|
|
5172
|
+
}
|
|
5173
|
+
function createVirtualClientRouteModuleCode({
|
|
5174
|
+
id,
|
|
5175
|
+
code: routeSource,
|
|
5176
|
+
rootRouteFile,
|
|
5177
|
+
viteCommand
|
|
5178
|
+
}) {
|
|
5179
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
5180
|
+
const exportsToRemove = isServerFirstRoute ? [...SERVER_ONLY_ROUTE_EXPORTS2, ...CLIENT_COMPONENT_EXPORTS] : SERVER_ONLY_ROUTE_EXPORTS2;
|
|
5181
|
+
const clientRouteModuleAst = import_parser.parse(routeSource, {
|
|
5182
|
+
sourceType: "module"
|
|
5183
|
+
});
|
|
5184
|
+
removeExports(clientRouteModuleAst, exportsToRemove);
|
|
5185
|
+
const generatorResult = generate(clientRouteModuleAst);
|
|
5186
|
+
generatorResult.code = '"use client";' + generatorResult.code;
|
|
5187
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5188
|
+
const hasRootLayout = staticExports.includes("Layout");
|
|
5189
|
+
generatorResult.code += `
|
|
5190
|
+
import { createElement as __rr_createElement } from "react";
|
|
5191
|
+
`;
|
|
5192
|
+
generatorResult.code += `import { UNSAFE_RSCDefaultRootErrorBoundary } from "react-router";
|
|
5193
|
+
`;
|
|
5194
|
+
generatorResult.code += `export function ErrorBoundary() {
|
|
5195
|
+
`;
|
|
5196
|
+
generatorResult.code += ` return __rr_createElement(UNSAFE_RSCDefaultRootErrorBoundary, { hasRootLayout: ${hasRootLayout} });
|
|
5197
|
+
`;
|
|
5198
|
+
generatorResult.code += `}
|
|
5199
|
+
`;
|
|
5200
|
+
}
|
|
5201
|
+
if (viteCommand === "serve" && isServerFirstRoute && !hasClientExports) {
|
|
5202
|
+
generatorResult.code += `
|
|
5203
|
+
export const __ensureClientRouteModuleForHMR = true;`;
|
|
5204
|
+
}
|
|
5205
|
+
return generatorResult;
|
|
5206
|
+
}
|
|
5207
|
+
function parseRouteExports(code) {
|
|
5208
|
+
const [, exportSpecifiers] = (0, import_es_module_lexer2.parse)(code);
|
|
5209
|
+
const staticExports = exportSpecifiers.map(({ n: name }) => name);
|
|
5210
|
+
const isServerFirstRoute = staticExports.some(
|
|
5211
|
+
(staticExport) => staticExport === "ServerComponent"
|
|
5212
|
+
);
|
|
5213
|
+
return {
|
|
5214
|
+
staticExports,
|
|
5215
|
+
isServerFirstRoute,
|
|
5216
|
+
hasClientExports: staticExports.some(
|
|
5217
|
+
isServerFirstRoute ? isClientNonComponentExport : isClientRouteExport
|
|
5218
|
+
)
|
|
5219
|
+
};
|
|
5220
|
+
}
|
|
5221
|
+
function getVirtualClientModuleId(id) {
|
|
5222
|
+
return `${id.split("?")[0]}?client-route-module`;
|
|
5223
|
+
}
|
|
5224
|
+
function getVirtualServerModuleId(id) {
|
|
5225
|
+
return `${id.split("?")[0]}?server-route-module`;
|
|
5226
|
+
}
|
|
5227
|
+
function isVirtualRouteModuleId(id) {
|
|
5228
|
+
return /(\?|&)route-module(&|$)/.test(id);
|
|
5229
|
+
}
|
|
5230
|
+
function isVirtualClientRouteModuleId(id) {
|
|
5231
|
+
return /(\?|&)client-route-module(&|$)/.test(id);
|
|
5232
|
+
}
|
|
5233
|
+
function isVirtualServerRouteModuleId(id) {
|
|
5234
|
+
return /(\?|&)server-route-module(&|$)/.test(id);
|
|
5235
|
+
}
|
|
5236
|
+
function isRootRouteFile({
|
|
5237
|
+
id,
|
|
5238
|
+
rootRouteFile
|
|
5239
|
+
}) {
|
|
5240
|
+
const filePath = id.split("?")[0];
|
|
5241
|
+
return filePath === rootRouteFile;
|
|
5242
|
+
}
|
|
5243
|
+
|
|
5244
|
+
// vite/rsc/plugin.ts
|
|
5245
|
+
function reactRouterRSCVitePlugin() {
|
|
5246
|
+
let configLoader;
|
|
5247
|
+
let typegenWatcherPromise;
|
|
5248
|
+
let viteCommand;
|
|
5249
|
+
let resolvedViteConfig;
|
|
5250
|
+
let routeIdByFile;
|
|
5251
|
+
let logger;
|
|
5252
|
+
const defaultEntries2 = getDefaultEntries();
|
|
5253
|
+
let config;
|
|
5254
|
+
let rootRouteFile;
|
|
5255
|
+
function updateConfig(newConfig) {
|
|
5256
|
+
config = newConfig;
|
|
5257
|
+
rootRouteFile = Path5.resolve(
|
|
5258
|
+
newConfig.appDirectory,
|
|
5259
|
+
newConfig.routes.root.file
|
|
5260
|
+
);
|
|
5261
|
+
}
|
|
5262
|
+
return [
|
|
5263
|
+
{
|
|
5264
|
+
name: "react-router/rsc",
|
|
5265
|
+
async config(viteUserConfig, { command, mode }) {
|
|
5266
|
+
await import_es_module_lexer3.init;
|
|
5267
|
+
await preloadVite();
|
|
5268
|
+
viteCommand = command;
|
|
5269
|
+
const rootDirectory = getRootDirectory(viteUserConfig);
|
|
5270
|
+
const watch2 = command === "serve";
|
|
5271
|
+
configLoader = await createConfigLoader({
|
|
5272
|
+
rootDirectory,
|
|
5273
|
+
mode,
|
|
5274
|
+
watch: watch2,
|
|
5275
|
+
validateConfig: (userConfig) => {
|
|
5276
|
+
let errors = [];
|
|
5277
|
+
if (userConfig.buildEnd) errors.push("buildEnd");
|
|
5278
|
+
if (userConfig.prerender) errors.push("prerender");
|
|
5279
|
+
if (userConfig.presets?.length) errors.push("presets");
|
|
5280
|
+
if (userConfig.routeDiscovery) errors.push("routeDiscovery");
|
|
5281
|
+
if (userConfig.serverBundles) errors.push("serverBundles");
|
|
5282
|
+
if (userConfig.ssr === false) errors.push("ssr: false");
|
|
5283
|
+
if (userConfig.future?.unstable_splitRouteModules)
|
|
5284
|
+
errors.push("future.unstable_splitRouteModules");
|
|
5285
|
+
if (userConfig.future?.unstable_viteEnvironmentApi === false)
|
|
5286
|
+
errors.push("future.unstable_viteEnvironmentApi: false");
|
|
5287
|
+
if (userConfig.future?.v8_middleware === false)
|
|
5288
|
+
errors.push("future.v8_middleware: false");
|
|
5289
|
+
if (userConfig.future?.unstable_subResourceIntegrity)
|
|
5290
|
+
errors.push("future.unstable_subResourceIntegrity");
|
|
5291
|
+
if (errors.length) {
|
|
5292
|
+
return `RSC Framework Mode does not currently support the following React Router config:
|
|
5293
|
+
${errors.map((x) => ` - ${x}`).join("\n")}
|
|
5294
|
+
`;
|
|
5295
|
+
}
|
|
5296
|
+
}
|
|
5297
|
+
});
|
|
5298
|
+
const configResult = await configLoader.getConfig();
|
|
5299
|
+
if (!configResult.ok) throw new Error(configResult.error);
|
|
5300
|
+
updateConfig(configResult.value);
|
|
5301
|
+
if (viteUserConfig.base && config.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !config.basename.startsWith(viteUserConfig.base)) {
|
|
5302
|
+
throw new Error(
|
|
5303
|
+
"When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
|
|
5304
|
+
);
|
|
5305
|
+
}
|
|
5306
|
+
await loadDotenv({
|
|
5307
|
+
rootDirectory,
|
|
5308
|
+
viteUserConfig,
|
|
5309
|
+
mode
|
|
5310
|
+
});
|
|
5311
|
+
const vite2 = await import("vite");
|
|
5312
|
+
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
5313
|
+
prefix: "[react-router]"
|
|
5314
|
+
});
|
|
5315
|
+
return {
|
|
5316
|
+
resolve: {
|
|
5317
|
+
dedupe: [
|
|
5318
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
5319
|
+
"react",
|
|
5320
|
+
"react-dom",
|
|
5321
|
+
// Avoid router duplicates since mismatching routers cause `Error:
|
|
5322
|
+
// You must render this element inside a <Remix> element`.
|
|
5323
|
+
"react-router",
|
|
5324
|
+
"react-router/dom",
|
|
5325
|
+
...hasDependency({ name: "react-router-dom", rootDirectory }) ? ["react-router-dom"] : []
|
|
5326
|
+
]
|
|
5327
|
+
},
|
|
5328
|
+
optimizeDeps: {
|
|
5329
|
+
entries: getOptimizeDepsEntries({
|
|
5330
|
+
entryClientFilePath: defaultEntries2.client,
|
|
5331
|
+
reactRouterConfig: config
|
|
5332
|
+
}),
|
|
5333
|
+
esbuildOptions: {
|
|
5334
|
+
jsx: "automatic"
|
|
5335
|
+
},
|
|
5336
|
+
include: [
|
|
5337
|
+
// Pre-bundle React dependencies to avoid React duplicates,
|
|
5338
|
+
// even if React dependencies are not direct dependencies.
|
|
5339
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
5340
|
+
"react",
|
|
5341
|
+
"react/jsx-runtime",
|
|
5342
|
+
"react/jsx-dev-runtime",
|
|
5343
|
+
"react-dom",
|
|
5344
|
+
"react-dom/client",
|
|
5345
|
+
"react-router/internal/react-server-client"
|
|
5346
|
+
]
|
|
5347
|
+
},
|
|
5348
|
+
esbuild: {
|
|
5349
|
+
jsx: "automatic",
|
|
5350
|
+
jsxDev: viteCommand !== "build"
|
|
5351
|
+
},
|
|
5352
|
+
environments: {
|
|
5353
|
+
client: {
|
|
5354
|
+
build: {
|
|
5355
|
+
rollupOptions: {
|
|
5356
|
+
input: {
|
|
5357
|
+
index: defaultEntries2.client
|
|
5358
|
+
}
|
|
5359
|
+
},
|
|
5360
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "client")
|
|
5361
|
+
},
|
|
5362
|
+
optimizeDeps: {
|
|
5363
|
+
include: [
|
|
5364
|
+
"react-router > cookie",
|
|
5365
|
+
"react-router > set-cookie-parser"
|
|
5366
|
+
]
|
|
5367
|
+
}
|
|
5368
|
+
},
|
|
5369
|
+
rsc: {
|
|
5370
|
+
build: {
|
|
5371
|
+
rollupOptions: {
|
|
5372
|
+
input: {
|
|
5373
|
+
// We use a virtual entry here so that consumers can import
|
|
5374
|
+
// it as `virtual:react-router/unstable_rsc/rsc-entry`
|
|
5375
|
+
// without needing to know the actual file path, which is
|
|
5376
|
+
// important when using the default entries.
|
|
5377
|
+
index: defaultEntries2.rsc
|
|
5378
|
+
},
|
|
5379
|
+
output: {
|
|
5380
|
+
entryFileNames: config.serverBuildFile,
|
|
5381
|
+
format: config.serverModuleFormat
|
|
5382
|
+
}
|
|
5383
|
+
},
|
|
5384
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "server")
|
|
5385
|
+
}
|
|
5386
|
+
},
|
|
5387
|
+
ssr: {
|
|
5388
|
+
build: {
|
|
5389
|
+
rollupOptions: {
|
|
5390
|
+
input: {
|
|
5391
|
+
index: defaultEntries2.ssr
|
|
5392
|
+
},
|
|
5393
|
+
output: {
|
|
5394
|
+
// Note: We don't set `entryFileNames` here because it's
|
|
5395
|
+
// considered private to the RSC environment build, and
|
|
5396
|
+
// @vitejs/plugin-rsc currently breaks if it's set to
|
|
5397
|
+
// something other than `index.js`.
|
|
5398
|
+
format: config.serverModuleFormat
|
|
5399
|
+
}
|
|
5400
|
+
},
|
|
5401
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "server/__ssr_build")
|
|
5402
|
+
}
|
|
5403
|
+
}
|
|
5404
|
+
},
|
|
5405
|
+
build: {
|
|
5406
|
+
rollupOptions: {
|
|
5407
|
+
// Copied from https://github.com/vitejs/vite-plugin-react/blob/c602225271d4acf462ba00f8d6d8a2e42492c5cd/packages/common/warning.ts
|
|
5408
|
+
onwarn(warning, defaultHandler) {
|
|
5409
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
|
|
5410
|
+
return;
|
|
5411
|
+
}
|
|
5412
|
+
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
|
5413
|
+
return;
|
|
5414
|
+
}
|
|
5415
|
+
if (viteUserConfig.build?.rollupOptions?.onwarn) {
|
|
5416
|
+
viteUserConfig.build.rollupOptions.onwarn(
|
|
5417
|
+
warning,
|
|
5418
|
+
defaultHandler
|
|
5419
|
+
);
|
|
5420
|
+
} else {
|
|
5421
|
+
defaultHandler(warning);
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
}
|
|
5425
|
+
}
|
|
5426
|
+
};
|
|
5427
|
+
},
|
|
5428
|
+
configResolved(viteConfig) {
|
|
5429
|
+
resolvedViteConfig = viteConfig;
|
|
5430
|
+
},
|
|
5431
|
+
async configureServer(viteDevServer) {
|
|
5432
|
+
configLoader.onChange(
|
|
5433
|
+
async ({
|
|
5434
|
+
result,
|
|
5435
|
+
configCodeChanged,
|
|
5436
|
+
routeConfigCodeChanged,
|
|
5437
|
+
configChanged,
|
|
5438
|
+
routeConfigChanged
|
|
5439
|
+
}) => {
|
|
5440
|
+
if (!result.ok) {
|
|
5441
|
+
invalidateVirtualModules2(viteDevServer);
|
|
5442
|
+
logger.error(result.error, {
|
|
5443
|
+
clear: true,
|
|
5444
|
+
timestamp: true
|
|
5445
|
+
});
|
|
5446
|
+
return;
|
|
5447
|
+
}
|
|
5448
|
+
let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
|
|
5449
|
+
logger.info(import_picocolors5.default.green(message), {
|
|
5450
|
+
clear: true,
|
|
5451
|
+
timestamp: true
|
|
5452
|
+
});
|
|
5453
|
+
updateConfig(result.value);
|
|
5454
|
+
if (configChanged || routeConfigChanged) {
|
|
5455
|
+
invalidateVirtualModules2(viteDevServer);
|
|
5456
|
+
}
|
|
5457
|
+
}
|
|
5458
|
+
);
|
|
5459
|
+
},
|
|
5460
|
+
async buildEnd() {
|
|
5461
|
+
await configLoader.close();
|
|
5462
|
+
}
|
|
5463
|
+
},
|
|
5464
|
+
/* @__PURE__ */ (() => {
|
|
5465
|
+
let logged = false;
|
|
5466
|
+
function logExperimentalNotice() {
|
|
5467
|
+
if (logged) return;
|
|
5468
|
+
logged = true;
|
|
5469
|
+
logger.info(
|
|
5470
|
+
import_picocolors5.default.yellow(
|
|
5471
|
+
`${viteCommand === "serve" ? " " : ""}\u{1F9EA} Using React Router's RSC Framework Mode (experimental)`
|
|
5472
|
+
)
|
|
5473
|
+
);
|
|
5474
|
+
}
|
|
5475
|
+
return {
|
|
5476
|
+
name: "react-router/rsc/log-experimental-notice",
|
|
5477
|
+
sharedDuringBuild: true,
|
|
5478
|
+
buildStart: logExperimentalNotice,
|
|
5479
|
+
configureServer: logExperimentalNotice
|
|
5480
|
+
};
|
|
5481
|
+
})(),
|
|
5482
|
+
{
|
|
5483
|
+
name: "react-router/rsc/typegen",
|
|
5484
|
+
async config(viteUserConfig, { command, mode }) {
|
|
5485
|
+
if (command === "serve") {
|
|
5486
|
+
const vite2 = await import("vite");
|
|
5487
|
+
typegenWatcherPromise = watch(
|
|
5488
|
+
getRootDirectory(viteUserConfig),
|
|
5489
|
+
{
|
|
5490
|
+
mode,
|
|
5491
|
+
rsc: true,
|
|
5492
|
+
// ignore `info` logs from typegen since they are
|
|
5493
|
+
// redundant when Vite plugin logs are active
|
|
5494
|
+
logger: vite2.createLogger("warn", {
|
|
5495
|
+
prefix: "[react-router]"
|
|
5496
|
+
})
|
|
5497
|
+
}
|
|
5498
|
+
);
|
|
5499
|
+
}
|
|
5500
|
+
},
|
|
5501
|
+
async buildEnd() {
|
|
5502
|
+
(await typegenWatcherPromise)?.close();
|
|
5503
|
+
}
|
|
5504
|
+
},
|
|
5505
|
+
{
|
|
5506
|
+
name: "react-router/rsc/virtual-rsc-entry",
|
|
5507
|
+
resolveId(id) {
|
|
5508
|
+
if (id === virtual2.rscEntry.id) return defaultEntries2.rsc;
|
|
5509
|
+
}
|
|
5510
|
+
},
|
|
5511
|
+
{
|
|
5512
|
+
name: "react-router/rsc/virtual-route-config",
|
|
5513
|
+
resolveId(id) {
|
|
5514
|
+
if (id === virtual2.routeConfig.id) {
|
|
5515
|
+
return virtual2.routeConfig.resolvedId;
|
|
5516
|
+
}
|
|
5517
|
+
},
|
|
5518
|
+
load(id) {
|
|
5519
|
+
if (id === virtual2.routeConfig.resolvedId) {
|
|
5520
|
+
const result = createVirtualRouteConfig({
|
|
5521
|
+
appDirectory: config.appDirectory,
|
|
5522
|
+
routeConfig: config.unstable_routeConfig
|
|
5523
|
+
});
|
|
5524
|
+
routeIdByFile = result.routeIdByFile;
|
|
5525
|
+
return result.code;
|
|
5526
|
+
}
|
|
5527
|
+
}
|
|
5528
|
+
},
|
|
5529
|
+
{
|
|
5530
|
+
name: "react-router/rsc/virtual-route-modules",
|
|
5531
|
+
transform(code, id) {
|
|
5532
|
+
if (!routeIdByFile) return;
|
|
5533
|
+
return transformVirtualRouteModules({
|
|
5534
|
+
code,
|
|
5535
|
+
id,
|
|
5536
|
+
viteCommand,
|
|
5537
|
+
routeIdByFile,
|
|
5538
|
+
rootRouteFile,
|
|
5539
|
+
viteEnvironment: this.environment
|
|
5540
|
+
});
|
|
5541
|
+
}
|
|
5542
|
+
},
|
|
5543
|
+
{
|
|
5544
|
+
name: "react-router/rsc/virtual-basename",
|
|
5545
|
+
resolveId(id) {
|
|
5546
|
+
if (id === virtual2.basename.id) {
|
|
5547
|
+
return virtual2.basename.resolvedId;
|
|
5548
|
+
}
|
|
5549
|
+
},
|
|
5550
|
+
load(id) {
|
|
5551
|
+
if (id === virtual2.basename.resolvedId) {
|
|
5552
|
+
return `export default ${JSON.stringify(config.basename)};`;
|
|
5553
|
+
}
|
|
5554
|
+
}
|
|
5555
|
+
},
|
|
5556
|
+
{
|
|
5557
|
+
name: "react-router/rsc/hmr/inject-runtime",
|
|
5558
|
+
enforce: "pre",
|
|
5559
|
+
resolveId(id) {
|
|
5560
|
+
if (id === virtual2.injectHmrRuntime.id) {
|
|
5561
|
+
return virtual2.injectHmrRuntime.resolvedId;
|
|
5562
|
+
}
|
|
5563
|
+
},
|
|
5564
|
+
async load(id) {
|
|
5565
|
+
if (id !== virtual2.injectHmrRuntime.resolvedId) return;
|
|
5566
|
+
return viteCommand === "serve" ? [
|
|
5567
|
+
`import RefreshRuntime from "${virtual2.hmrRuntime.id}"`,
|
|
5568
|
+
"RefreshRuntime.injectIntoGlobalHook(window)",
|
|
5569
|
+
"window.$RefreshReg$ = () => {}",
|
|
5570
|
+
"window.$RefreshSig$ = () => (type) => type",
|
|
5571
|
+
"window.__vite_plugin_react_preamble_installed__ = true"
|
|
5572
|
+
].join("\n") : "";
|
|
5573
|
+
}
|
|
5574
|
+
},
|
|
5575
|
+
{
|
|
5576
|
+
name: "react-router/rsc/hmr/runtime",
|
|
5577
|
+
enforce: "pre",
|
|
5578
|
+
resolveId(id) {
|
|
5579
|
+
if (id === virtual2.hmrRuntime.id) return virtual2.hmrRuntime.resolvedId;
|
|
5580
|
+
},
|
|
5581
|
+
async load(id) {
|
|
5582
|
+
if (id !== virtual2.hmrRuntime.resolvedId) return;
|
|
5583
|
+
const reactRefreshDir = import_pathe6.default.dirname(
|
|
5584
|
+
require.resolve("react-refresh/package.json")
|
|
5585
|
+
);
|
|
5586
|
+
const reactRefreshRuntimePath = import_pathe6.default.join(
|
|
5587
|
+
reactRefreshDir,
|
|
5588
|
+
"cjs/react-refresh-runtime.development.js"
|
|
5589
|
+
);
|
|
5590
|
+
return [
|
|
5591
|
+
"const exports = {}",
|
|
5592
|
+
await (0, import_promises3.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
5593
|
+
await (0, import_promises3.readFile)(
|
|
5594
|
+
require.resolve("./static/rsc-refresh-utils.mjs"),
|
|
5595
|
+
"utf8"
|
|
5596
|
+
),
|
|
5597
|
+
"export default exports"
|
|
5598
|
+
].join("\n");
|
|
5599
|
+
}
|
|
5600
|
+
},
|
|
5601
|
+
{
|
|
5602
|
+
name: "react-router/rsc/hmr/react-refresh",
|
|
5603
|
+
async transform(code, id, options) {
|
|
5604
|
+
if (viteCommand !== "serve") return;
|
|
5605
|
+
if (id.includes("/node_modules/")) return;
|
|
5606
|
+
const filepath = id.split("?")[0];
|
|
5607
|
+
const extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
|
|
5608
|
+
if (!extensionsRE.test(filepath)) return;
|
|
5609
|
+
const devRuntime = "react/jsx-dev-runtime";
|
|
5610
|
+
const ssr = options?.ssr === true;
|
|
5611
|
+
const isJSX = filepath.endsWith("x");
|
|
5612
|
+
const useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
5613
|
+
if (!useFastRefresh) return;
|
|
5614
|
+
if (isVirtualClientRouteModuleId(id)) {
|
|
5615
|
+
const routeId = routeIdByFile?.get(filepath);
|
|
5616
|
+
return { code: addRefreshWrapper2({ routeId, code, id }) };
|
|
5617
|
+
}
|
|
5618
|
+
const result = await babel2.transformAsync(code, {
|
|
5619
|
+
babelrc: false,
|
|
5620
|
+
configFile: false,
|
|
5621
|
+
filename: id,
|
|
5622
|
+
sourceFileName: filepath,
|
|
5623
|
+
parserOpts: {
|
|
5624
|
+
sourceType: "module",
|
|
5625
|
+
allowAwaitOutsideFunction: true
|
|
5626
|
+
},
|
|
5627
|
+
plugins: [[require("react-refresh/babel"), { skipEnvCheck: true }]],
|
|
5628
|
+
sourceMaps: true
|
|
5629
|
+
});
|
|
5630
|
+
if (result === null) return;
|
|
5631
|
+
code = result.code;
|
|
5632
|
+
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
5633
|
+
if (refreshContentRE.test(code)) {
|
|
5634
|
+
code = addRefreshWrapper2({ code, id });
|
|
5635
|
+
}
|
|
5636
|
+
return { code, map: result.map };
|
|
5637
|
+
}
|
|
5638
|
+
},
|
|
5639
|
+
{
|
|
5640
|
+
name: "react-router/rsc/hmr/updates",
|
|
5641
|
+
async hotUpdate({ server, file, modules }) {
|
|
5642
|
+
if (this.environment.name !== "rsc") return;
|
|
5643
|
+
const clientModules = server.environments.client.moduleGraph.getModulesByFile(file);
|
|
5644
|
+
const vite2 = await import("vite");
|
|
5645
|
+
const isServerOnlyChange = !clientModules || clientModules.size === 0 || // Handle CSS injected from server-first routes (with ?direct query
|
|
5646
|
+
// string) since the client graph has a reference to the CSS
|
|
5647
|
+
vite2.isCSSRequest(file) && Array.from(clientModules).some(
|
|
5648
|
+
(mod) => mod.id?.includes("?direct")
|
|
5649
|
+
);
|
|
5650
|
+
for (const mod of getModulesWithImporters(modules)) {
|
|
5651
|
+
if (!mod.file) continue;
|
|
5652
|
+
const normalizedPath = import_pathe6.default.normalize(mod.file);
|
|
5653
|
+
const routeId = routeIdByFile?.get(normalizedPath);
|
|
5654
|
+
if (routeId !== void 0) {
|
|
5655
|
+
const routeSource = await (0, import_promises3.readFile)(normalizedPath, "utf8");
|
|
5656
|
+
const virtualRouteModuleCode = (await server.environments.rsc.pluginContainer.transform(
|
|
5657
|
+
routeSource,
|
|
5658
|
+
`${normalizedPath}?route-module`
|
|
5659
|
+
)).code;
|
|
5660
|
+
const { staticExports } = parseRouteExports(virtualRouteModuleCode);
|
|
5661
|
+
const hasAction = staticExports.includes("action");
|
|
5662
|
+
const hasComponent = staticExports.includes("default");
|
|
5663
|
+
const hasErrorBoundary = staticExports.includes("ErrorBoundary");
|
|
5664
|
+
const hasLoader = staticExports.includes("loader");
|
|
5665
|
+
server.hot.send({
|
|
5666
|
+
type: "custom",
|
|
5667
|
+
event: "react-router:hmr",
|
|
5668
|
+
data: {
|
|
5669
|
+
routeId,
|
|
5670
|
+
isServerOnlyChange,
|
|
5671
|
+
hasAction,
|
|
5672
|
+
hasComponent,
|
|
5673
|
+
hasErrorBoundary,
|
|
5674
|
+
hasLoader
|
|
5675
|
+
}
|
|
5676
|
+
});
|
|
5677
|
+
}
|
|
5678
|
+
}
|
|
5679
|
+
return modules;
|
|
5680
|
+
}
|
|
5681
|
+
},
|
|
5682
|
+
{
|
|
5683
|
+
name: "react-router/rsc/virtual-react-router-serve-config",
|
|
5684
|
+
resolveId(id) {
|
|
5685
|
+
if (id === virtual2.reactRouterServeConfig.id) {
|
|
5686
|
+
return virtual2.reactRouterServeConfig.resolvedId;
|
|
5687
|
+
}
|
|
5688
|
+
},
|
|
5689
|
+
load(id) {
|
|
5690
|
+
if (id === virtual2.reactRouterServeConfig.resolvedId) {
|
|
5691
|
+
const rscOutDir = resolvedViteConfig.environments.rsc?.build?.outDir;
|
|
5692
|
+
invariant(rscOutDir, "RSC build directory config not found");
|
|
5693
|
+
const clientOutDir = resolvedViteConfig.environments.client?.build?.outDir;
|
|
5694
|
+
invariant(clientOutDir, "Client build directory config not found");
|
|
5695
|
+
const assetsBuildDirectory = Path5.relative(rscOutDir, clientOutDir);
|
|
5696
|
+
const publicPath = resolvedViteConfig.base;
|
|
5697
|
+
return `export default ${JSON.stringify({
|
|
5698
|
+
assetsBuildDirectory,
|
|
5699
|
+
publicPath
|
|
5700
|
+
})};`;
|
|
5701
|
+
}
|
|
5702
|
+
}
|
|
5703
|
+
},
|
|
5704
|
+
validatePluginOrder(),
|
|
5705
|
+
warnOnClientSourceMaps()
|
|
5706
|
+
];
|
|
5707
|
+
}
|
|
5708
|
+
var virtual2 = {
|
|
5709
|
+
routeConfig: create("unstable_rsc/routes"),
|
|
5710
|
+
injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
|
|
5711
|
+
hmrRuntime: create("unstable_rsc/runtime"),
|
|
5712
|
+
basename: create("unstable_rsc/basename"),
|
|
5713
|
+
rscEntry: create("unstable_rsc/rsc-entry"),
|
|
5714
|
+
reactRouterServeConfig: create("unstable_rsc/react-router-serve-config")
|
|
5715
|
+
};
|
|
5716
|
+
function invalidateVirtualModules2(viteDevServer) {
|
|
5717
|
+
for (const vmod of Object.values(virtual2)) {
|
|
5718
|
+
for (const env of Object.values(viteDevServer.environments)) {
|
|
5719
|
+
const mod = env.moduleGraph.getModuleById(vmod.resolvedId);
|
|
5720
|
+
if (mod) {
|
|
5721
|
+
env.moduleGraph.invalidateModule(mod);
|
|
5722
|
+
}
|
|
5723
|
+
}
|
|
5724
|
+
}
|
|
5725
|
+
}
|
|
5726
|
+
function getRootDirectory(viteUserConfig) {
|
|
5727
|
+
return viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
5728
|
+
}
|
|
5729
|
+
function getDevPackageRoot() {
|
|
5730
|
+
const currentDir = (0, import_pathe6.dirname)(__dirname);
|
|
5731
|
+
let dir = currentDir;
|
|
5732
|
+
while (dir !== (0, import_pathe6.dirname)(dir)) {
|
|
5733
|
+
try {
|
|
5734
|
+
const packageJsonPath = (0, import_pathe6.join)(dir, "package.json");
|
|
5735
|
+
(0, import_fs.readFileSync)(packageJsonPath, "utf-8");
|
|
5736
|
+
return dir;
|
|
5737
|
+
} catch {
|
|
5738
|
+
dir = (0, import_pathe6.dirname)(dir);
|
|
5739
|
+
}
|
|
5740
|
+
}
|
|
5741
|
+
throw new Error("Could not find package.json");
|
|
5742
|
+
}
|
|
5743
|
+
function getDefaultEntries() {
|
|
5744
|
+
const defaultEntriesDir2 = (0, import_pathe6.join)(
|
|
5745
|
+
getDevPackageRoot(),
|
|
5746
|
+
"dist",
|
|
5747
|
+
"config",
|
|
5748
|
+
"default-rsc-entries"
|
|
5749
|
+
);
|
|
5750
|
+
return {
|
|
5751
|
+
rsc: (0, import_pathe6.join)(defaultEntriesDir2, "entry.rsc.tsx"),
|
|
5752
|
+
ssr: (0, import_pathe6.join)(defaultEntriesDir2, "entry.ssr.tsx"),
|
|
5753
|
+
client: (0, import_pathe6.join)(defaultEntriesDir2, "entry.client.tsx")
|
|
5754
|
+
};
|
|
5755
|
+
}
|
|
5756
|
+
function getModulesWithImporters(modules) {
|
|
5757
|
+
const visited = /* @__PURE__ */ new Set();
|
|
5758
|
+
const result = /* @__PURE__ */ new Set();
|
|
5759
|
+
function walk(module2) {
|
|
5760
|
+
if (visited.has(module2)) return;
|
|
5761
|
+
visited.add(module2);
|
|
5762
|
+
result.add(module2);
|
|
5763
|
+
for (const importer of module2.importers) {
|
|
5764
|
+
walk(importer);
|
|
5765
|
+
}
|
|
5766
|
+
}
|
|
5767
|
+
for (const module2 of modules) {
|
|
5768
|
+
walk(module2);
|
|
5769
|
+
}
|
|
5770
|
+
return result;
|
|
5771
|
+
}
|
|
5772
|
+
function addRefreshWrapper2({
|
|
5773
|
+
routeId,
|
|
5774
|
+
code,
|
|
5775
|
+
id
|
|
5776
|
+
}) {
|
|
5777
|
+
const acceptExports = routeId !== void 0 ? CLIENT_NON_COMPONENT_EXPORTS2 : [];
|
|
5778
|
+
return REACT_REFRESH_HEADER2.replaceAll("__SOURCE__", JSON.stringify(id)) + code + REACT_REFRESH_FOOTER2.replaceAll("__SOURCE__", JSON.stringify(id)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(routeId));
|
|
5779
|
+
}
|
|
5780
|
+
var REACT_REFRESH_HEADER2 = `
|
|
5781
|
+
import RefreshRuntime from "${virtual2.hmrRuntime.id}";
|
|
5782
|
+
|
|
5783
|
+
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
5784
|
+
let prevRefreshReg;
|
|
5785
|
+
let prevRefreshSig;
|
|
5786
|
+
|
|
5787
|
+
if (import.meta.hot && !inWebWorker) {
|
|
5788
|
+
if (!window.__vite_plugin_react_preamble_installed__) {
|
|
5789
|
+
throw new Error(
|
|
5790
|
+
"React Router Vite plugin can't detect preamble. Something is wrong."
|
|
5791
|
+
);
|
|
5792
|
+
}
|
|
5793
|
+
|
|
5794
|
+
prevRefreshReg = window.$RefreshReg$;
|
|
5795
|
+
prevRefreshSig = window.$RefreshSig$;
|
|
5796
|
+
window.$RefreshReg$ = (type, id) => {
|
|
5797
|
+
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
5798
|
+
};
|
|
5799
|
+
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
5800
|
+
}`.replaceAll("\n", "");
|
|
5801
|
+
var REACT_REFRESH_FOOTER2 = `
|
|
5802
|
+
if (import.meta.hot && !inWebWorker) {
|
|
5803
|
+
window.$RefreshReg$ = prevRefreshReg;
|
|
5804
|
+
window.$RefreshSig$ = prevRefreshSig;
|
|
5805
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
5806
|
+
RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
|
|
5807
|
+
import.meta.hot.accept((nextExports) => {
|
|
5808
|
+
if (!nextExports) return;
|
|
5809
|
+
__ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
|
|
5810
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
|
|
5811
|
+
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
5812
|
+
});
|
|
5813
|
+
});
|
|
5814
|
+
}`;
|
|
4911
5815
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4912
5816
|
0 && (module.exports = {
|
|
4913
|
-
reactRouter
|
|
5817
|
+
reactRouter,
|
|
5818
|
+
unstable_reactRouterRSC
|
|
4914
5819
|
});
|