@c0va23/react-router-dev 7.10.1 → 7.13.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 +84 -8
- package/dist/cli/index.js +72 -59
- package/dist/config/default-rsc-entries/entry.rsc.tsx +33 -11
- package/dist/config/default-rsc-entries/entry.ssr.tsx +22 -15
- package/dist/config.d.ts +51 -0
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +11 -9
- package/dist/vite.js +892 -280
- package/package.json +21 -10
- package/rsc-types.d.ts +21 -0
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v7.
|
|
2
|
+
* @react-router/dev v7.13.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -48,11 +48,10 @@ module.exports = __toCommonJS(vite_exports);
|
|
|
48
48
|
// vite/plugin.ts
|
|
49
49
|
var import_node_crypto = require("crypto");
|
|
50
50
|
var import_node_fs2 = require("fs");
|
|
51
|
-
var
|
|
52
|
-
var
|
|
51
|
+
var import_promises3 = require("fs/promises");
|
|
52
|
+
var path7 = __toESM(require("path"));
|
|
53
53
|
var url = __toESM(require("url"));
|
|
54
54
|
var babel = __toESM(require("@babel/core"));
|
|
55
|
-
var import_node_fetch_server2 = require("@remix-run/node-fetch-server");
|
|
56
55
|
var import_react_router2 = require("react-router");
|
|
57
56
|
var import_es_module_lexer = require("es-module-lexer");
|
|
58
57
|
var import_pick3 = __toESM(require("lodash/pick"));
|
|
@@ -247,7 +246,7 @@ function validateRouteConfig({
|
|
|
247
246
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
248
247
|
root ? `${root}` : [],
|
|
249
248
|
nested ? Object.entries(nested).map(
|
|
250
|
-
([
|
|
249
|
+
([path10, message]) => `Path: routes.${path10}
|
|
251
250
|
${message}`
|
|
252
251
|
) : []
|
|
253
252
|
].flat().join("\n\n")
|
|
@@ -432,7 +431,7 @@ async function resolveConfig({
|
|
|
432
431
|
basename: basename3,
|
|
433
432
|
buildDirectory: userBuildDirectory,
|
|
434
433
|
buildEnd,
|
|
435
|
-
prerender,
|
|
434
|
+
prerender: prerender2,
|
|
436
435
|
routeDiscovery: userRouteDiscovery,
|
|
437
436
|
serverBuildFile,
|
|
438
437
|
serverBundles,
|
|
@@ -446,15 +445,15 @@ async function resolveConfig({
|
|
|
446
445
|
if (!ssr && serverBundles) {
|
|
447
446
|
serverBundles = void 0;
|
|
448
447
|
}
|
|
449
|
-
if (
|
|
448
|
+
if (prerender2) {
|
|
450
449
|
let isValidPrerenderPathsConfig = (p) => typeof p === "boolean" || typeof p === "function" || Array.isArray(p);
|
|
451
|
-
let isValidPrerenderConfig = isValidPrerenderPathsConfig(
|
|
450
|
+
let isValidPrerenderConfig = isValidPrerenderPathsConfig(prerender2) || typeof prerender2 === "object" && "paths" in prerender2 && isValidPrerenderPathsConfig(prerender2.paths);
|
|
452
451
|
if (!isValidPrerenderConfig) {
|
|
453
452
|
return err(
|
|
454
453
|
"The `prerender`/`prerender.paths` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths."
|
|
455
454
|
);
|
|
456
455
|
}
|
|
457
|
-
let isValidConcurrencyConfig = typeof
|
|
456
|
+
let isValidConcurrencyConfig = typeof prerender2 != "object" || !("unstable_concurrency" in prerender2) || typeof prerender2.unstable_concurrency === "number" && Number.isInteger(prerender2.unstable_concurrency) && prerender2.unstable_concurrency > 0;
|
|
458
457
|
if (!isValidConcurrencyConfig) {
|
|
459
458
|
return err(
|
|
460
459
|
"The `prerender.unstable_concurrency` config must be a positive integer if specified."
|
|
@@ -562,23 +561,27 @@ async function resolveConfig({
|
|
|
562
561
|
let future = {
|
|
563
562
|
unstable_optimizeDeps: userAndPresetConfigs.future?.unstable_optimizeDeps ?? false,
|
|
564
563
|
unstable_subResourceIntegrity: userAndPresetConfigs.future?.unstable_subResourceIntegrity ?? false,
|
|
564
|
+
unstable_trailingSlashAwareDataRequests: userAndPresetConfigs.future?.unstable_trailingSlashAwareDataRequests ?? false,
|
|
565
|
+
unstable_previewServerPrerendering: userAndPresetConfigs.future?.unstable_previewServerPrerendering ?? false,
|
|
565
566
|
v8_middleware: userAndPresetConfigs.future?.v8_middleware ?? false,
|
|
566
567
|
v8_splitRouteModules: userAndPresetConfigs.future?.v8_splitRouteModules ?? false,
|
|
567
568
|
v8_viteEnvironmentApi: userAndPresetConfigs.future?.v8_viteEnvironmentApi ?? false
|
|
568
569
|
};
|
|
570
|
+
let allowedActionOrigins = userAndPresetConfigs.allowedActionOrigins ?? false;
|
|
569
571
|
let reactRouterConfig = deepFreeze({
|
|
570
572
|
appDirectory,
|
|
571
573
|
basename: basename3,
|
|
572
574
|
buildDirectory,
|
|
573
575
|
buildEnd,
|
|
574
576
|
future,
|
|
575
|
-
prerender,
|
|
577
|
+
prerender: prerender2,
|
|
576
578
|
routes,
|
|
577
579
|
routeDiscovery,
|
|
578
580
|
serverBuildFile,
|
|
579
581
|
serverBundles,
|
|
580
582
|
serverModuleFormat,
|
|
581
583
|
ssr,
|
|
584
|
+
allowedActionOrigins,
|
|
582
585
|
unstable_routeConfig: routeConfig
|
|
583
586
|
});
|
|
584
587
|
for (let preset of reactRouterUserConfig.presets ?? []) {
|
|
@@ -638,12 +641,12 @@ async function createConfigLoader({
|
|
|
638
641
|
if (!fsWatcher) {
|
|
639
642
|
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
640
643
|
ignoreInitial: true,
|
|
641
|
-
ignored: (
|
|
642
|
-
let
|
|
643
|
-
return !
|
|
644
|
+
ignored: (path10) => {
|
|
645
|
+
let dirname4 = import_pathe3.default.dirname(path10);
|
|
646
|
+
return !dirname4.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
644
647
|
// that are at the root level, not nested in subdirectories
|
|
645
|
-
|
|
646
|
-
|
|
648
|
+
path10 !== root && // Watch the root directory itself
|
|
649
|
+
dirname4 !== root;
|
|
647
650
|
}
|
|
648
651
|
});
|
|
649
652
|
fsWatcher.on("all", async (...args) => {
|
|
@@ -775,6 +778,30 @@ async function resolveEntryFiles({
|
|
|
775
778
|
let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
|
|
776
779
|
return { entryClientFilePath, entryServerFilePath };
|
|
777
780
|
}
|
|
781
|
+
async function resolveRSCEntryFiles({
|
|
782
|
+
reactRouterConfig
|
|
783
|
+
}) {
|
|
784
|
+
let { appDirectory } = reactRouterConfig;
|
|
785
|
+
let defaultsDirectory = import_pathe3.default.resolve(
|
|
786
|
+
import_pathe3.default.dirname(require.resolve("@react-router/dev/package.json")),
|
|
787
|
+
"dist",
|
|
788
|
+
"config",
|
|
789
|
+
"default-rsc-entries"
|
|
790
|
+
);
|
|
791
|
+
let userEntryClientFile = findEntry(appDirectory, "entry.client", {
|
|
792
|
+
absolute: true
|
|
793
|
+
});
|
|
794
|
+
let userEntryRSCFile = findEntry(appDirectory, "entry.rsc", {
|
|
795
|
+
absolute: true
|
|
796
|
+
});
|
|
797
|
+
let userEntrySSRFile = findEntry(appDirectory, "entry.ssr", {
|
|
798
|
+
absolute: true
|
|
799
|
+
});
|
|
800
|
+
let client = userEntryClientFile ?? import_pathe3.default.join(defaultsDirectory, "entry.client.tsx");
|
|
801
|
+
let rsc = userEntryRSCFile ?? import_pathe3.default.join(defaultsDirectory, "entry.rsc.tsx");
|
|
802
|
+
let ssr = userEntrySSRFile ?? import_pathe3.default.join(defaultsDirectory, "entry.ssr.tsx");
|
|
803
|
+
return { client, rsc, ssr };
|
|
804
|
+
}
|
|
778
805
|
function omitRoutes(config) {
|
|
779
806
|
return {
|
|
780
807
|
...config,
|
|
@@ -902,7 +929,7 @@ function fullpath(lineage2) {
|
|
|
902
929
|
if (lineage2.length === 1 && route?.id === "root") return "/";
|
|
903
930
|
const isLayout = route && route.index !== true && route.path === void 0;
|
|
904
931
|
if (isLayout) return void 0;
|
|
905
|
-
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((
|
|
932
|
+
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path10) => path10 !== void 0 && path10 !== "").join("/");
|
|
906
933
|
}
|
|
907
934
|
|
|
908
935
|
// typegen/generate.ts
|
|
@@ -942,6 +969,7 @@ function generateServerBuild(ctx) {
|
|
|
942
969
|
export const routeDiscovery: ServerBuild["routeDiscovery"];
|
|
943
970
|
export const routes: ServerBuild["routes"];
|
|
944
971
|
export const ssr: ServerBuild["ssr"];
|
|
972
|
+
export const allowedActionOrigins: ServerBuild["allowedActionOrigins"];
|
|
945
973
|
export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
|
|
946
974
|
}
|
|
947
975
|
`;
|
|
@@ -1081,8 +1109,8 @@ function routeModulesType(ctx) {
|
|
|
1081
1109
|
);
|
|
1082
1110
|
}
|
|
1083
1111
|
function isInAppDirectory(ctx, routeFile) {
|
|
1084
|
-
const
|
|
1085
|
-
return
|
|
1112
|
+
const path10 = Path3.resolve(ctx.config.appDirectory, routeFile);
|
|
1113
|
+
return path10.startsWith(ctx.config.appDirectory);
|
|
1086
1114
|
}
|
|
1087
1115
|
function getRouteAnnotations({
|
|
1088
1116
|
ctx,
|
|
@@ -1194,21 +1222,21 @@ function getRouteAnnotations({
|
|
|
1194
1222
|
return { filename: filename2, content };
|
|
1195
1223
|
}
|
|
1196
1224
|
function relativeImportSource(from, to) {
|
|
1197
|
-
let
|
|
1198
|
-
let extension = Path3.extname(
|
|
1199
|
-
|
|
1200
|
-
if (!
|
|
1225
|
+
let path10 = Path3.relative(Path3.dirname(from), to);
|
|
1226
|
+
let extension = Path3.extname(path10);
|
|
1227
|
+
path10 = Path3.join(Path3.dirname(path10), Pathe.filename(path10));
|
|
1228
|
+
if (!path10.startsWith("../")) path10 = "./" + path10;
|
|
1201
1229
|
if (!extension || /\.(js|ts)x?$/.test(extension)) {
|
|
1202
1230
|
extension = ".js";
|
|
1203
1231
|
}
|
|
1204
|
-
return
|
|
1232
|
+
return path10 + extension;
|
|
1205
1233
|
}
|
|
1206
1234
|
function rootDirsPath(ctx, typesPath) {
|
|
1207
1235
|
const rel = Path3.relative(typesDirectory(ctx), typesPath);
|
|
1208
1236
|
return Path3.join(ctx.rootDirectory, rel);
|
|
1209
1237
|
}
|
|
1210
|
-
function paramsType(
|
|
1211
|
-
const params = parse2(
|
|
1238
|
+
function paramsType(path10) {
|
|
1239
|
+
const params = parse2(path10);
|
|
1212
1240
|
return t2.tsTypeLiteral(
|
|
1213
1241
|
Object.entries(params).map(([param, isRequired]) => {
|
|
1214
1242
|
const property = t2.tsPropertySignature(
|
|
@@ -1297,14 +1325,14 @@ async function watch(rootDirectory, { mode, logger, rsc }) {
|
|
|
1297
1325
|
}
|
|
1298
1326
|
|
|
1299
1327
|
// vite/node-adapter.ts
|
|
1300
|
-
|
|
1301
|
-
function fromNodeRequest(nodeReq, nodeRes) {
|
|
1328
|
+
async function fromNodeRequest(nodeReq, nodeRes) {
|
|
1302
1329
|
invariant(
|
|
1303
1330
|
nodeReq.originalUrl,
|
|
1304
1331
|
"Expected `nodeReq.originalUrl` to be defined"
|
|
1305
1332
|
);
|
|
1306
1333
|
nodeReq.url = nodeReq.originalUrl;
|
|
1307
|
-
|
|
1334
|
+
const { createRequest } = await import("@remix-run/node-fetch-server");
|
|
1335
|
+
return createRequest(nodeReq, nodeRes);
|
|
1308
1336
|
}
|
|
1309
1337
|
|
|
1310
1338
|
// vite/styles.ts
|
|
@@ -1477,11 +1505,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
|
|
|
1477
1505
|
let cssContent = void 0;
|
|
1478
1506
|
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1479
1507
|
traverse(ast, {
|
|
1480
|
-
VariableDeclaration(
|
|
1481
|
-
const declaration =
|
|
1508
|
+
VariableDeclaration(path10) {
|
|
1509
|
+
const declaration = path10.node.declarations[0];
|
|
1482
1510
|
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1483
1511
|
cssContent = declaration.init.value;
|
|
1484
|
-
|
|
1512
|
+
path10.stop();
|
|
1485
1513
|
}
|
|
1486
1514
|
}
|
|
1487
1515
|
});
|
|
@@ -1520,10 +1548,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1520
1548
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1521
1549
|
let removedExportLocalNames = /* @__PURE__ */ new Set();
|
|
1522
1550
|
traverse(ast, {
|
|
1523
|
-
ExportDeclaration(
|
|
1524
|
-
if (
|
|
1525
|
-
if (
|
|
1526
|
-
|
|
1551
|
+
ExportDeclaration(path10) {
|
|
1552
|
+
if (path10.node.type === "ExportNamedDeclaration") {
|
|
1553
|
+
if (path10.node.specifiers.length) {
|
|
1554
|
+
path10.node.specifiers = path10.node.specifiers.filter((specifier) => {
|
|
1527
1555
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1528
1556
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1529
1557
|
exportsFiltered = true;
|
|
@@ -1535,12 +1563,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1535
1563
|
}
|
|
1536
1564
|
return true;
|
|
1537
1565
|
});
|
|
1538
|
-
if (
|
|
1539
|
-
markedForRemoval.add(
|
|
1566
|
+
if (path10.node.specifiers.length === 0) {
|
|
1567
|
+
markedForRemoval.add(path10);
|
|
1540
1568
|
}
|
|
1541
1569
|
}
|
|
1542
|
-
if (
|
|
1543
|
-
let declaration =
|
|
1570
|
+
if (path10.node.declaration?.type === "VariableDeclaration") {
|
|
1571
|
+
let declaration = path10.node.declaration;
|
|
1544
1572
|
declaration.declarations = declaration.declarations.filter(
|
|
1545
1573
|
(declaration2) => {
|
|
1546
1574
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1554,30 +1582,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1554
1582
|
}
|
|
1555
1583
|
);
|
|
1556
1584
|
if (declaration.declarations.length === 0) {
|
|
1557
|
-
markedForRemoval.add(
|
|
1585
|
+
markedForRemoval.add(path10);
|
|
1558
1586
|
}
|
|
1559
1587
|
}
|
|
1560
|
-
if (
|
|
1561
|
-
let id =
|
|
1588
|
+
if (path10.node.declaration?.type === "FunctionDeclaration") {
|
|
1589
|
+
let id = path10.node.declaration.id;
|
|
1562
1590
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1563
|
-
markedForRemoval.add(
|
|
1591
|
+
markedForRemoval.add(path10);
|
|
1564
1592
|
}
|
|
1565
1593
|
}
|
|
1566
|
-
if (
|
|
1567
|
-
let id =
|
|
1594
|
+
if (path10.node.declaration?.type === "ClassDeclaration") {
|
|
1595
|
+
let id = path10.node.declaration.id;
|
|
1568
1596
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1569
|
-
markedForRemoval.add(
|
|
1597
|
+
markedForRemoval.add(path10);
|
|
1570
1598
|
}
|
|
1571
1599
|
}
|
|
1572
1600
|
}
|
|
1573
|
-
if (
|
|
1601
|
+
if (path10.node.type === "ExportDefaultDeclaration") {
|
|
1574
1602
|
if (exportsToRemove.includes("default")) {
|
|
1575
|
-
markedForRemoval.add(
|
|
1576
|
-
if (
|
|
1577
|
-
if (
|
|
1578
|
-
removedExportLocalNames.add(
|
|
1579
|
-
} else if ((
|
|
1580
|
-
removedExportLocalNames.add(
|
|
1603
|
+
markedForRemoval.add(path10);
|
|
1604
|
+
if (path10.node.declaration) {
|
|
1605
|
+
if (path10.node.declaration.type === "Identifier") {
|
|
1606
|
+
removedExportLocalNames.add(path10.node.declaration.name);
|
|
1607
|
+
} else if ((path10.node.declaration.type === "FunctionDeclaration" || path10.node.declaration.type === "ClassDeclaration") && path10.node.declaration.id) {
|
|
1608
|
+
removedExportLocalNames.add(path10.node.declaration.id.name);
|
|
1581
1609
|
}
|
|
1582
1610
|
}
|
|
1583
1611
|
}
|
|
@@ -1585,21 +1613,21 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1585
1613
|
}
|
|
1586
1614
|
});
|
|
1587
1615
|
traverse(ast, {
|
|
1588
|
-
ExpressionStatement(
|
|
1589
|
-
if (!
|
|
1616
|
+
ExpressionStatement(path10) {
|
|
1617
|
+
if (!path10.parentPath.isProgram()) {
|
|
1590
1618
|
return;
|
|
1591
1619
|
}
|
|
1592
|
-
if (
|
|
1593
|
-
const left =
|
|
1620
|
+
if (path10.node.expression.type === "AssignmentExpression") {
|
|
1621
|
+
const left = path10.node.expression.left;
|
|
1594
1622
|
if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
|
|
1595
|
-
markedForRemoval.add(
|
|
1623
|
+
markedForRemoval.add(path10);
|
|
1596
1624
|
}
|
|
1597
1625
|
}
|
|
1598
1626
|
}
|
|
1599
1627
|
});
|
|
1600
1628
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1601
|
-
for (let
|
|
1602
|
-
|
|
1629
|
+
for (let path10 of markedForRemoval) {
|
|
1630
|
+
path10.remove();
|
|
1603
1631
|
}
|
|
1604
1632
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1605
1633
|
}
|
|
@@ -1682,28 +1710,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1682
1710
|
)
|
|
1683
1711
|
);
|
|
1684
1712
|
}
|
|
1685
|
-
function assertNodePath(
|
|
1713
|
+
function assertNodePath(path10) {
|
|
1686
1714
|
invariant(
|
|
1687
|
-
|
|
1688
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1715
|
+
path10 && !Array.isArray(path10),
|
|
1716
|
+
`Expected a Path, but got ${Array.isArray(path10) ? "an array" : path10}`
|
|
1689
1717
|
);
|
|
1690
1718
|
}
|
|
1691
|
-
function assertNodePathIsStatement(
|
|
1719
|
+
function assertNodePathIsStatement(path10) {
|
|
1692
1720
|
invariant(
|
|
1693
|
-
|
|
1694
|
-
`Expected a Statement path, but got ${Array.isArray(
|
|
1721
|
+
path10 && !Array.isArray(path10) && t.isStatement(path10.node),
|
|
1722
|
+
`Expected a Statement path, but got ${Array.isArray(path10) ? "an array" : path10?.node?.type}`
|
|
1695
1723
|
);
|
|
1696
1724
|
}
|
|
1697
|
-
function assertNodePathIsVariableDeclarator(
|
|
1725
|
+
function assertNodePathIsVariableDeclarator(path10) {
|
|
1698
1726
|
invariant(
|
|
1699
|
-
|
|
1700
|
-
`Expected an Identifier path, but got ${Array.isArray(
|
|
1727
|
+
path10 && !Array.isArray(path10) && t.isVariableDeclarator(path10.node),
|
|
1728
|
+
`Expected an Identifier path, but got ${Array.isArray(path10) ? "an array" : path10?.node?.type}`
|
|
1701
1729
|
);
|
|
1702
1730
|
}
|
|
1703
|
-
function assertNodePathIsPattern(
|
|
1731
|
+
function assertNodePathIsPattern(path10) {
|
|
1704
1732
|
invariant(
|
|
1705
|
-
|
|
1706
|
-
`Expected a Pattern path, but got ${Array.isArray(
|
|
1733
|
+
path10 && !Array.isArray(path10) && t.isPattern(path10.node),
|
|
1734
|
+
`Expected a Pattern path, but got ${Array.isArray(path10) ? "an array" : path10?.node?.type}`
|
|
1707
1735
|
);
|
|
1708
1736
|
}
|
|
1709
1737
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1739,8 +1767,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1739
1767
|
}
|
|
1740
1768
|
let isWithinExportDestructuring = Boolean(
|
|
1741
1769
|
identifier.findParent(
|
|
1742
|
-
(
|
|
1743
|
-
|
|
1770
|
+
(path10) => Boolean(
|
|
1771
|
+
path10.isPattern() && path10.parentPath?.isVariableDeclarator() && path10.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1744
1772
|
)
|
|
1745
1773
|
)
|
|
1746
1774
|
);
|
|
@@ -1818,7 +1846,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1818
1846
|
for (let specifier of node.specifiers) {
|
|
1819
1847
|
if (t.isIdentifier(specifier.exported)) {
|
|
1820
1848
|
let name = specifier.exported.name;
|
|
1821
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1849
|
+
let specifierPath = exportPath.get("specifiers").find((path10) => path10.node === specifier);
|
|
1822
1850
|
invariant(
|
|
1823
1851
|
specifierPath,
|
|
1824
1852
|
`Expected to find specifier path for ${name}`
|
|
@@ -1835,22 +1863,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1835
1863
|
}
|
|
1836
1864
|
);
|
|
1837
1865
|
}
|
|
1838
|
-
function getDependentIdentifiersForPath(
|
|
1866
|
+
function getDependentIdentifiersForPath(path10, state) {
|
|
1839
1867
|
let { visited, identifiers } = state ?? {
|
|
1840
1868
|
visited: /* @__PURE__ */ new Set(),
|
|
1841
1869
|
identifiers: /* @__PURE__ */ new Set()
|
|
1842
1870
|
};
|
|
1843
|
-
if (visited.has(
|
|
1871
|
+
if (visited.has(path10)) {
|
|
1844
1872
|
return identifiers;
|
|
1845
1873
|
}
|
|
1846
|
-
visited.add(
|
|
1847
|
-
|
|
1848
|
-
Identifier(
|
|
1849
|
-
if (identifiers.has(
|
|
1874
|
+
visited.add(path10);
|
|
1875
|
+
path10.traverse({
|
|
1876
|
+
Identifier(path11) {
|
|
1877
|
+
if (identifiers.has(path11)) {
|
|
1850
1878
|
return;
|
|
1851
1879
|
}
|
|
1852
|
-
identifiers.add(
|
|
1853
|
-
let binding =
|
|
1880
|
+
identifiers.add(path11);
|
|
1881
|
+
let binding = path11.scope.getBinding(path11.node.name);
|
|
1854
1882
|
if (!binding) {
|
|
1855
1883
|
return;
|
|
1856
1884
|
}
|
|
@@ -1872,7 +1900,7 @@ function getDependentIdentifiersForPath(path9, state) {
|
|
|
1872
1900
|
}
|
|
1873
1901
|
}
|
|
1874
1902
|
});
|
|
1875
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1903
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path10);
|
|
1876
1904
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1877
1905
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1878
1906
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1881,9 +1909,9 @@ function getDependentIdentifiersForPath(path9, state) {
|
|
|
1881
1909
|
identifiers
|
|
1882
1910
|
});
|
|
1883
1911
|
}
|
|
1884
|
-
if (withinExportStatement &&
|
|
1885
|
-
t.isPattern(
|
|
1886
|
-
let variableDeclarator =
|
|
1912
|
+
if (withinExportStatement && path10.isIdentifier() && (t.isPattern(path10.parentPath.node) || // [foo]
|
|
1913
|
+
t.isPattern(path10.parentPath.parentPath?.node))) {
|
|
1914
|
+
let variableDeclarator = path10.findParent((p) => p.isVariableDeclarator());
|
|
1887
1915
|
assertNodePath(variableDeclarator);
|
|
1888
1916
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1889
1917
|
visited,
|
|
@@ -1892,16 +1920,16 @@ function getDependentIdentifiersForPath(path9, state) {
|
|
|
1892
1920
|
}
|
|
1893
1921
|
return identifiers;
|
|
1894
1922
|
}
|
|
1895
|
-
function getTopLevelStatementPathForPath(
|
|
1896
|
-
let ancestry =
|
|
1923
|
+
function getTopLevelStatementPathForPath(path10) {
|
|
1924
|
+
let ancestry = path10.getAncestry();
|
|
1897
1925
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1898
1926
|
assertNodePathIsStatement(topLevelStatement);
|
|
1899
1927
|
return topLevelStatement;
|
|
1900
1928
|
}
|
|
1901
1929
|
function getTopLevelStatementsForPaths(paths) {
|
|
1902
1930
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1903
|
-
for (let
|
|
1904
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1931
|
+
for (let path10 of paths) {
|
|
1932
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path10);
|
|
1905
1933
|
topLevelStatements.add(topLevelStatement.node);
|
|
1906
1934
|
}
|
|
1907
1935
|
return topLevelStatements;
|
|
@@ -2295,24 +2323,24 @@ function isNamedComponentExport(name) {
|
|
|
2295
2323
|
}
|
|
2296
2324
|
var decorateComponentExportsWithProps = (ast) => {
|
|
2297
2325
|
const hocs = [];
|
|
2298
|
-
function getHocUid(
|
|
2299
|
-
const uid =
|
|
2326
|
+
function getHocUid(path10, hocName) {
|
|
2327
|
+
const uid = path10.scope.generateUidIdentifier(hocName);
|
|
2300
2328
|
hocs.push([hocName, uid]);
|
|
2301
2329
|
return uid;
|
|
2302
2330
|
}
|
|
2303
2331
|
traverse(ast, {
|
|
2304
|
-
ExportDeclaration(
|
|
2305
|
-
if (
|
|
2306
|
-
const declaration =
|
|
2332
|
+
ExportDeclaration(path10) {
|
|
2333
|
+
if (path10.isExportDefaultDeclaration()) {
|
|
2334
|
+
const declaration = path10.get("declaration");
|
|
2307
2335
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2308
2336
|
if (expr) {
|
|
2309
|
-
const uid = getHocUid(
|
|
2337
|
+
const uid = getHocUid(path10, "UNSAFE_withComponentProps");
|
|
2310
2338
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2311
2339
|
}
|
|
2312
2340
|
return;
|
|
2313
2341
|
}
|
|
2314
|
-
if (
|
|
2315
|
-
const decl =
|
|
2342
|
+
if (path10.isExportNamedDeclaration()) {
|
|
2343
|
+
const decl = path10.get("declaration");
|
|
2316
2344
|
if (decl.isVariableDeclaration()) {
|
|
2317
2345
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2318
2346
|
const id = varDeclarator.get("id");
|
|
@@ -2322,7 +2350,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2322
2350
|
if (!id.isIdentifier()) return;
|
|
2323
2351
|
const { name } = id.node;
|
|
2324
2352
|
if (!isNamedComponentExport(name)) return;
|
|
2325
|
-
const uid = getHocUid(
|
|
2353
|
+
const uid = getHocUid(path10, `UNSAFE_with${name}Props`);
|
|
2326
2354
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2327
2355
|
});
|
|
2328
2356
|
return;
|
|
@@ -2332,7 +2360,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2332
2360
|
if (!id) return;
|
|
2333
2361
|
const { name } = id;
|
|
2334
2362
|
if (!isNamedComponentExport(name)) return;
|
|
2335
|
-
const uid = getHocUid(
|
|
2363
|
+
const uid = getHocUid(path10, `UNSAFE_with${name}Props`);
|
|
2336
2364
|
decl.replaceWith(
|
|
2337
2365
|
t.variableDeclaration("const", [
|
|
2338
2366
|
t.variableDeclarator(
|
|
@@ -2453,6 +2481,222 @@ function warnOnClientSourceMaps() {
|
|
|
2453
2481
|
};
|
|
2454
2482
|
}
|
|
2455
2483
|
|
|
2484
|
+
// vite/plugins/prerender.ts
|
|
2485
|
+
var import_promises2 = require("fs/promises");
|
|
2486
|
+
var import_node_path = __toESM(require("path"));
|
|
2487
|
+
function normalizePrerenderRequest(input) {
|
|
2488
|
+
if (typeof input === "string" || input instanceof Request) {
|
|
2489
|
+
return { request: input, metadata: void 0 };
|
|
2490
|
+
}
|
|
2491
|
+
return { request: input.request, metadata: input.metadata };
|
|
2492
|
+
}
|
|
2493
|
+
function normalizePostProcessResult(result) {
|
|
2494
|
+
if (Array.isArray(result)) {
|
|
2495
|
+
return { files: result, requests: [] };
|
|
2496
|
+
}
|
|
2497
|
+
return { files: result.files, requests: result.requests ?? [] };
|
|
2498
|
+
}
|
|
2499
|
+
function prerender(options) {
|
|
2500
|
+
const {
|
|
2501
|
+
config,
|
|
2502
|
+
requests,
|
|
2503
|
+
postProcess = defaultPostProcess,
|
|
2504
|
+
handleError = defaultHandleError,
|
|
2505
|
+
logFile,
|
|
2506
|
+
finalize
|
|
2507
|
+
} = options;
|
|
2508
|
+
let viteConfig;
|
|
2509
|
+
return {
|
|
2510
|
+
name: "prerender",
|
|
2511
|
+
configResolved(resolvedConfig) {
|
|
2512
|
+
viteConfig = resolvedConfig;
|
|
2513
|
+
},
|
|
2514
|
+
writeBundle: {
|
|
2515
|
+
async handler() {
|
|
2516
|
+
const pluginContext = this;
|
|
2517
|
+
const rawRequests = typeof requests === "function" ? await requests.call(pluginContext) : requests;
|
|
2518
|
+
const prerenderRequests = rawRequests.map(normalizePrerenderRequest);
|
|
2519
|
+
if (prerenderRequests.length === 0) {
|
|
2520
|
+
return;
|
|
2521
|
+
}
|
|
2522
|
+
const prerenderConfig = typeof config === "function" ? await config.call(pluginContext) : config;
|
|
2523
|
+
const {
|
|
2524
|
+
buildDirectory = viteConfig.environments.client.build.outDir,
|
|
2525
|
+
concurrency = 1,
|
|
2526
|
+
retryCount = 0,
|
|
2527
|
+
retryDelay = 500,
|
|
2528
|
+
maxRedirects = 0,
|
|
2529
|
+
timeout = 1e4
|
|
2530
|
+
} = prerenderConfig ?? {};
|
|
2531
|
+
const previewServer = await startPreviewServer(viteConfig);
|
|
2532
|
+
try {
|
|
2533
|
+
const baseUrl = getResolvedUrl(previewServer);
|
|
2534
|
+
async function prerenderRequest(input, metadata) {
|
|
2535
|
+
let attemptCount = 0;
|
|
2536
|
+
let redirectCount = 0;
|
|
2537
|
+
const request = new Request(input);
|
|
2538
|
+
const url2 = new URL(request.url);
|
|
2539
|
+
if (url2.origin !== baseUrl.origin) {
|
|
2540
|
+
url2.hostname = baseUrl.hostname;
|
|
2541
|
+
url2.protocol = baseUrl.protocol;
|
|
2542
|
+
url2.port = baseUrl.port;
|
|
2543
|
+
}
|
|
2544
|
+
async function attempt(url3) {
|
|
2545
|
+
try {
|
|
2546
|
+
const signal = AbortSignal.timeout(timeout);
|
|
2547
|
+
const prerenderReq = new Request(url3, request);
|
|
2548
|
+
const response = await fetch(prerenderReq, {
|
|
2549
|
+
redirect: "manual",
|
|
2550
|
+
signal
|
|
2551
|
+
});
|
|
2552
|
+
if (response.status >= 300 && response.status < 400 && response.headers.has("location") && ++redirectCount <= maxRedirects) {
|
|
2553
|
+
const location = response.headers.get("location");
|
|
2554
|
+
const responseURL = new URL(response.url);
|
|
2555
|
+
const locationUrl = new URL(location, response.url);
|
|
2556
|
+
if (responseURL.origin !== locationUrl.origin) {
|
|
2557
|
+
return await postProcess.call(
|
|
2558
|
+
pluginContext,
|
|
2559
|
+
request,
|
|
2560
|
+
response,
|
|
2561
|
+
metadata
|
|
2562
|
+
);
|
|
2563
|
+
}
|
|
2564
|
+
const redirectUrl = new URL(location, url3);
|
|
2565
|
+
return await attempt(redirectUrl);
|
|
2566
|
+
}
|
|
2567
|
+
if (response.status >= 500 && ++attemptCount <= retryCount) {
|
|
2568
|
+
await new Promise(
|
|
2569
|
+
(resolve6) => setTimeout(resolve6, retryDelay)
|
|
2570
|
+
);
|
|
2571
|
+
return attempt(url3);
|
|
2572
|
+
}
|
|
2573
|
+
return await postProcess.call(
|
|
2574
|
+
pluginContext,
|
|
2575
|
+
request,
|
|
2576
|
+
response,
|
|
2577
|
+
metadata
|
|
2578
|
+
);
|
|
2579
|
+
} catch (error) {
|
|
2580
|
+
if (++attemptCount <= retryCount) {
|
|
2581
|
+
await new Promise(
|
|
2582
|
+
(resolve6) => setTimeout(resolve6, retryDelay)
|
|
2583
|
+
);
|
|
2584
|
+
return attempt(url3);
|
|
2585
|
+
}
|
|
2586
|
+
handleError.call(
|
|
2587
|
+
pluginContext,
|
|
2588
|
+
request,
|
|
2589
|
+
error instanceof Error ? error : new Error(error?.toString() ?? "Unknown error"),
|
|
2590
|
+
metadata
|
|
2591
|
+
);
|
|
2592
|
+
return [];
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
return attempt(url2);
|
|
2596
|
+
}
|
|
2597
|
+
async function prerender2(input, metadata) {
|
|
2598
|
+
const result = await prerenderRequest(input, metadata);
|
|
2599
|
+
const { files, requests: requests2 } = normalizePostProcessResult(result);
|
|
2600
|
+
for (const file of files) {
|
|
2601
|
+
await writePrerenderFile(file, metadata);
|
|
2602
|
+
}
|
|
2603
|
+
for (const followUp of requests2) {
|
|
2604
|
+
const normalized = normalizePrerenderRequest(followUp);
|
|
2605
|
+
await prerender2(normalized.request, normalized.metadata);
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
async function writePrerenderFile(file, metadata) {
|
|
2609
|
+
const normalizedPath = file.path.startsWith("/") ? file.path.slice(1) : file.path;
|
|
2610
|
+
const outputPath = import_node_path.default.join(
|
|
2611
|
+
buildDirectory,
|
|
2612
|
+
...normalizedPath.split("/")
|
|
2613
|
+
);
|
|
2614
|
+
await (0, import_promises2.mkdir)(import_node_path.default.dirname(outputPath), { recursive: true });
|
|
2615
|
+
await (0, import_promises2.writeFile)(outputPath, file.contents);
|
|
2616
|
+
const relativePath = import_node_path.default.relative(viteConfig.root, outputPath);
|
|
2617
|
+
if (logFile) {
|
|
2618
|
+
logFile.call(pluginContext, relativePath, metadata);
|
|
2619
|
+
}
|
|
2620
|
+
return relativePath;
|
|
2621
|
+
}
|
|
2622
|
+
const pMap = await import("p-map");
|
|
2623
|
+
await pMap.default(
|
|
2624
|
+
prerenderRequests,
|
|
2625
|
+
async ({ request, metadata }) => {
|
|
2626
|
+
await prerender2(request, metadata);
|
|
2627
|
+
},
|
|
2628
|
+
{ concurrency }
|
|
2629
|
+
);
|
|
2630
|
+
if (finalize) {
|
|
2631
|
+
await finalize.call(pluginContext, buildDirectory);
|
|
2632
|
+
}
|
|
2633
|
+
} finally {
|
|
2634
|
+
await new Promise((resolve6, reject) => {
|
|
2635
|
+
previewServer.httpServer.close((err2) => {
|
|
2636
|
+
if (err2) {
|
|
2637
|
+
reject(err2);
|
|
2638
|
+
} else {
|
|
2639
|
+
resolve6();
|
|
2640
|
+
}
|
|
2641
|
+
});
|
|
2642
|
+
});
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
};
|
|
2647
|
+
}
|
|
2648
|
+
async function defaultPostProcess(request, response) {
|
|
2649
|
+
const prerenderPath = new URL(request.url).pathname;
|
|
2650
|
+
if (!response.ok) {
|
|
2651
|
+
throw new Error(
|
|
2652
|
+
`Prerender: Request failed for ${prerenderPath}: ${response.status} ${response.statusText}`
|
|
2653
|
+
);
|
|
2654
|
+
}
|
|
2655
|
+
return [
|
|
2656
|
+
{
|
|
2657
|
+
path: `${prerenderPath}/index.html`,
|
|
2658
|
+
contents: await response.text()
|
|
2659
|
+
}
|
|
2660
|
+
];
|
|
2661
|
+
}
|
|
2662
|
+
function defaultHandleError(request, error) {
|
|
2663
|
+
const prerenderPath = new URL(request.url).pathname;
|
|
2664
|
+
if (request.signal?.aborted) {
|
|
2665
|
+
throw new Error(
|
|
2666
|
+
`Prerender: Request timed out for ${prerenderPath}: ${error.message}`
|
|
2667
|
+
);
|
|
2668
|
+
}
|
|
2669
|
+
throw new Error(
|
|
2670
|
+
`Prerender: Request failed for ${prerenderPath}: ${error.message}`
|
|
2671
|
+
);
|
|
2672
|
+
}
|
|
2673
|
+
async function startPreviewServer(viteConfig) {
|
|
2674
|
+
const vite2 = await import("vite");
|
|
2675
|
+
try {
|
|
2676
|
+
return await vite2.preview({
|
|
2677
|
+
configFile: viteConfig.configFile,
|
|
2678
|
+
logLevel: "silent",
|
|
2679
|
+
preview: {
|
|
2680
|
+
port: 0,
|
|
2681
|
+
open: false
|
|
2682
|
+
}
|
|
2683
|
+
});
|
|
2684
|
+
} catch (error) {
|
|
2685
|
+
throw new Error("Prerender: Failed to start Vite preview server", {
|
|
2686
|
+
cause: error
|
|
2687
|
+
});
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
function getResolvedUrl(previewServer) {
|
|
2691
|
+
const baseUrl = previewServer.resolvedUrls?.local[0];
|
|
2692
|
+
if (!baseUrl) {
|
|
2693
|
+
throw new Error(
|
|
2694
|
+
"Prerender: No resolved URL is available from the Vite preview server"
|
|
2695
|
+
);
|
|
2696
|
+
}
|
|
2697
|
+
return new URL(baseUrl);
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2456
2700
|
// vite/plugin.ts
|
|
2457
2701
|
function extractPluginContext(viteConfig) {
|
|
2458
2702
|
return viteConfig["__reactRouterPluginContext"];
|
|
@@ -2514,8 +2758,8 @@ var virtualHmrRuntime = create("hmr-runtime");
|
|
|
2514
2758
|
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
2515
2759
|
var normalizeRelativeFilePath = (file, reactRouterConfig) => {
|
|
2516
2760
|
let vite2 = getVite();
|
|
2517
|
-
let fullPath =
|
|
2518
|
-
let relativePath =
|
|
2761
|
+
let fullPath = path7.resolve(reactRouterConfig.appDirectory, file);
|
|
2762
|
+
let relativePath = path7.relative(reactRouterConfig.appDirectory, fullPath);
|
|
2519
2763
|
return vite2.normalizePath(relativePath).split("?")[0];
|
|
2520
2764
|
};
|
|
2521
2765
|
var virtual = {
|
|
@@ -2538,7 +2782,7 @@ var getHash = (source, maxLength) => {
|
|
|
2538
2782
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
2539
2783
|
let vite2 = getVite();
|
|
2540
2784
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
2541
|
-
|
|
2785
|
+
path7.relative(ctx.rootDirectory, absoluteFilePath)
|
|
2542
2786
|
);
|
|
2543
2787
|
let entryChunk = viteManifest[rootRelativeFilePath];
|
|
2544
2788
|
if (!entryChunk) {
|
|
@@ -2629,7 +2873,7 @@ function resolveDependantChunks(viteManifest, entryChunks) {
|
|
|
2629
2873
|
function getAllDynamicCssFiles(ctx, viteManifest) {
|
|
2630
2874
|
let allDynamicCssFiles = /* @__PURE__ */ new Set();
|
|
2631
2875
|
for (let route of Object.values(ctx.reactRouterConfig.routes)) {
|
|
2632
|
-
let routeFile =
|
|
2876
|
+
let routeFile = path7.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
2633
2877
|
let entryChunk = resolveChunk(
|
|
2634
2878
|
ctx,
|
|
2635
2879
|
viteManifest,
|
|
@@ -2668,8 +2912,8 @@ function dedupe(array2) {
|
|
|
2668
2912
|
return [...new Set(array2)];
|
|
2669
2913
|
}
|
|
2670
2914
|
var writeFileSafe = async (file, contents) => {
|
|
2671
|
-
await (0,
|
|
2672
|
-
await (0,
|
|
2915
|
+
await (0, import_promises3.mkdir)(path7.dirname(file), { recursive: true });
|
|
2916
|
+
await (0, import_promises3.writeFile)(file, contents);
|
|
2673
2917
|
};
|
|
2674
2918
|
var getExportNames = (code) => {
|
|
2675
2919
|
let [, exportSpecifiers] = (0, import_es_module_lexer.parse)(code);
|
|
@@ -2694,7 +2938,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2694
2938
|
}
|
|
2695
2939
|
let ssr = true;
|
|
2696
2940
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
2697
|
-
let routePath =
|
|
2941
|
+
let routePath = path7.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
2698
2942
|
let url2 = resolveFileUrl(ctx, routePath);
|
|
2699
2943
|
let resolveId = async () => {
|
|
2700
2944
|
let result = await pluginContainer.resolveId(url2, void 0, { ssr });
|
|
@@ -2703,7 +2947,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2703
2947
|
};
|
|
2704
2948
|
let [id, code] = await Promise.all([
|
|
2705
2949
|
resolveId(),
|
|
2706
|
-
readRouteFile?.() ?? (0,
|
|
2950
|
+
readRouteFile?.() ?? (0, import_promises3.readFile)(routePath, "utf-8"),
|
|
2707
2951
|
// pluginContainer.transform(...) fails if we don't do this first:
|
|
2708
2952
|
moduleGraph.ensureEntryFromUrl(url2, ssr)
|
|
2709
2953
|
]);
|
|
@@ -2736,12 +2980,12 @@ var resolveEnvironmentBuildContext = ({
|
|
|
2736
2980
|
};
|
|
2737
2981
|
return resolvedBuildContext;
|
|
2738
2982
|
};
|
|
2739
|
-
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) =>
|
|
2983
|
+
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path7.join(
|
|
2740
2984
|
reactRouterConfig.buildDirectory,
|
|
2741
2985
|
"server",
|
|
2742
2986
|
...serverBundleId ? [serverBundleId] : []
|
|
2743
2987
|
);
|
|
2744
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
2988
|
+
var getClientBuildDirectory = (reactRouterConfig) => path7.join(reactRouterConfig.buildDirectory, "client");
|
|
2745
2989
|
var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
2746
2990
|
if (!ctx.buildManifest) {
|
|
2747
2991
|
return void 0;
|
|
@@ -2759,14 +3003,14 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
|
2759
3003
|
);
|
|
2760
3004
|
return Object.keys(serverBundleRoutes);
|
|
2761
3005
|
};
|
|
2762
|
-
var defaultEntriesDir =
|
|
2763
|
-
|
|
3006
|
+
var defaultEntriesDir = path7.resolve(
|
|
3007
|
+
path7.dirname(require.resolve("@react-router/dev/package.json")),
|
|
2764
3008
|
"dist",
|
|
2765
3009
|
"config",
|
|
2766
3010
|
"defaults"
|
|
2767
3011
|
);
|
|
2768
3012
|
var defaultEntries = (0, import_node_fs2.readdirSync)(defaultEntriesDir).map(
|
|
2769
|
-
(filename2) =>
|
|
3013
|
+
(filename2) => path7.join(defaultEntriesDir, filename2)
|
|
2770
3014
|
);
|
|
2771
3015
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
2772
3016
|
var reactRouterDevLoadContext = () => void 0;
|
|
@@ -2816,6 +3060,8 @@ var reactRouterVitePlugin = () => {
|
|
|
2816
3060
|
firstLoad = false;
|
|
2817
3061
|
ctx = {
|
|
2818
3062
|
environmentBuildContext,
|
|
3063
|
+
reactRouterManifest: null,
|
|
3064
|
+
prerenderPaths: null,
|
|
2819
3065
|
reactRouterConfig,
|
|
2820
3066
|
rootDirectory,
|
|
2821
3067
|
entryClientFilePath,
|
|
@@ -2840,6 +3086,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2840
3086
|
ctx.reactRouterConfig.ssr,
|
|
2841
3087
|
routes
|
|
2842
3088
|
);
|
|
3089
|
+
if (!ctx.prerenderPaths) {
|
|
3090
|
+
ctx.prerenderPaths = /* @__PURE__ */ new Set();
|
|
3091
|
+
}
|
|
3092
|
+
for (let path10 of prerenderPaths) {
|
|
3093
|
+
ctx.prerenderPaths.add(path10);
|
|
3094
|
+
}
|
|
2843
3095
|
let isSpaMode = isSpaModeEnabled(ctx.reactRouterConfig);
|
|
2844
3096
|
return `
|
|
2845
3097
|
import * as entryServer from ${JSON.stringify(
|
|
@@ -2862,7 +3114,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2862
3114
|
virtual.serverManifest.id
|
|
2863
3115
|
)};
|
|
2864
3116
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
2865
|
-
|
|
3117
|
+
path7.relative(
|
|
2866
3118
|
ctx.rootDirectory,
|
|
2867
3119
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
2868
3120
|
)
|
|
@@ -2897,11 +3149,13 @@ var reactRouterVitePlugin = () => {
|
|
|
2897
3149
|
href: "${ctx.publicPath}@react-router/critical.css?pathname=" + pathname,
|
|
2898
3150
|
};
|
|
2899
3151
|
}
|
|
2900
|
-
` : ""}
|
|
3152
|
+
` : ""}
|
|
3153
|
+
export const allowedActionOrigins = ${JSON.stringify(ctx.reactRouterConfig.allowedActionOrigins)};
|
|
3154
|
+
`;
|
|
2901
3155
|
};
|
|
2902
3156
|
let loadViteManifest = async (directory) => {
|
|
2903
|
-
let manifestContents = await (0,
|
|
2904
|
-
|
|
3157
|
+
let manifestContents = await (0, import_promises3.readFile)(
|
|
3158
|
+
path7.resolve(directory, ".vite", "manifest.json"),
|
|
2905
3159
|
"utf-8"
|
|
2906
3160
|
);
|
|
2907
3161
|
return JSON.parse(manifestContents);
|
|
@@ -2925,8 +3179,8 @@ var reactRouterVitePlugin = () => {
|
|
|
2925
3179
|
const entryNormalizedPath = "parentPath" in entry && typeof entry.parentPath === "string" ? entry.parentPath : entry.path;
|
|
2926
3180
|
let contents;
|
|
2927
3181
|
try {
|
|
2928
|
-
contents = await (0,
|
|
2929
|
-
|
|
3182
|
+
contents = await (0, import_promises3.readFile)(
|
|
3183
|
+
path7.join(entryNormalizedPath, entry.name),
|
|
2930
3184
|
"utf-8"
|
|
2931
3185
|
);
|
|
2932
3186
|
} catch (e) {
|
|
@@ -2935,9 +3189,9 @@ var reactRouterVitePlugin = () => {
|
|
|
2935
3189
|
}
|
|
2936
3190
|
let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
|
|
2937
3191
|
let filepath = getVite().normalizePath(
|
|
2938
|
-
|
|
3192
|
+
path7.relative(
|
|
2939
3193
|
clientBuildDirectory,
|
|
2940
|
-
|
|
3194
|
+
path7.join(entryNormalizedPath, entry.name)
|
|
2941
3195
|
)
|
|
2942
3196
|
);
|
|
2943
3197
|
sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
|
|
@@ -2970,7 +3224,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2970
3224
|
);
|
|
2971
3225
|
let enforceSplitRouteModules = ctx.reactRouterConfig.future.v8_splitRouteModules === "enforce";
|
|
2972
3226
|
for (let route of Object.values(ctx.reactRouterConfig.routes)) {
|
|
2973
|
-
let routeFile =
|
|
3227
|
+
let routeFile = path7.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
2974
3228
|
let sourceExports = routeManifestExports[route.id];
|
|
2975
3229
|
let hasClientAction = sourceExports.includes("clientAction");
|
|
2976
3230
|
let hasClientLoader = sourceExports.includes("clientLoader");
|
|
@@ -3005,6 +3259,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3005
3259
|
hasClientAction,
|
|
3006
3260
|
hasClientLoader,
|
|
3007
3261
|
hasClientMiddleware,
|
|
3262
|
+
hasDefaultExport: sourceExports.includes("default"),
|
|
3008
3263
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
3009
3264
|
...getReactRouterManifestBuildAssets(
|
|
3010
3265
|
ctx,
|
|
@@ -3042,7 +3297,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3042
3297
|
}
|
|
3043
3298
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
3044
3299
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
3045
|
-
let manifestPath =
|
|
3300
|
+
let manifestPath = path7.posix.join(
|
|
3046
3301
|
viteConfig2.build.assetsDir,
|
|
3047
3302
|
`manifest-${version}.js`
|
|
3048
3303
|
);
|
|
@@ -3054,7 +3309,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3054
3309
|
sri: void 0
|
|
3055
3310
|
};
|
|
3056
3311
|
await writeFileSafe(
|
|
3057
|
-
|
|
3312
|
+
path7.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
3058
3313
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
3059
3314
|
reactRouterBrowserManifest
|
|
3060
3315
|
)};`
|
|
@@ -3130,6 +3385,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3130
3385
|
hasClientAction,
|
|
3131
3386
|
hasClientLoader,
|
|
3132
3387
|
hasClientMiddleware,
|
|
3388
|
+
hasDefaultExport: sourceExports.includes("default"),
|
|
3133
3389
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
3134
3390
|
imports: []
|
|
3135
3391
|
};
|
|
@@ -3495,12 +3751,13 @@ var reactRouterVitePlugin = () => {
|
|
|
3495
3751
|
}
|
|
3496
3752
|
let handler = (0, import_react_router2.createRequestHandler)(build, "development");
|
|
3497
3753
|
let nodeHandler = async (nodeReq, nodeRes) => {
|
|
3498
|
-
let req2 = fromNodeRequest(nodeReq, nodeRes);
|
|
3754
|
+
let req2 = await fromNodeRequest(nodeReq, nodeRes);
|
|
3499
3755
|
let res2 = await handler(
|
|
3500
3756
|
req2,
|
|
3501
3757
|
await reactRouterDevLoadContext(req2)
|
|
3502
3758
|
);
|
|
3503
|
-
|
|
3759
|
+
const { sendResponse } = await import("@remix-run/node-fetch-server");
|
|
3760
|
+
await sendResponse(nodeRes, res2);
|
|
3504
3761
|
};
|
|
3505
3762
|
await nodeHandler(req, res);
|
|
3506
3763
|
} catch (error) {
|
|
@@ -3510,6 +3767,68 @@ var reactRouterVitePlugin = () => {
|
|
|
3510
3767
|
}
|
|
3511
3768
|
};
|
|
3512
3769
|
},
|
|
3770
|
+
configurePreviewServer(previewServer) {
|
|
3771
|
+
let cachedHandler = null;
|
|
3772
|
+
async function getHandler() {
|
|
3773
|
+
if (cachedHandler) return cachedHandler;
|
|
3774
|
+
let serverBuildFiles = [];
|
|
3775
|
+
let buildManifest = ctx.buildManifest ?? (ctx.reactRouterConfig.serverBundles ? await getBuildManifest({
|
|
3776
|
+
reactRouterConfig: ctx.reactRouterConfig,
|
|
3777
|
+
rootDirectory: ctx.rootDirectory
|
|
3778
|
+
}) : null);
|
|
3779
|
+
if (buildManifest?.serverBundles) {
|
|
3780
|
+
for (let bundle of Object.values(buildManifest.serverBundles)) {
|
|
3781
|
+
serverBuildFiles.push(
|
|
3782
|
+
path7.resolve(ctx.rootDirectory, bundle.file)
|
|
3783
|
+
);
|
|
3784
|
+
}
|
|
3785
|
+
} else {
|
|
3786
|
+
let serverEntryPath = path7.resolve(
|
|
3787
|
+
getServerBuildDirectory(ctx.reactRouterConfig),
|
|
3788
|
+
"index.js"
|
|
3789
|
+
);
|
|
3790
|
+
serverBuildFiles.push(serverEntryPath);
|
|
3791
|
+
}
|
|
3792
|
+
let handlers = [];
|
|
3793
|
+
for (let file of serverBuildFiles) {
|
|
3794
|
+
let build = await import(url.pathToFileURL(file).href);
|
|
3795
|
+
handlers.push((0, import_react_router2.createRequestHandler)(build, "production"));
|
|
3796
|
+
}
|
|
3797
|
+
cachedHandler = async (request, loadContext) => {
|
|
3798
|
+
let response;
|
|
3799
|
+
for (let handler of handlers) {
|
|
3800
|
+
response = await handler(request, loadContext);
|
|
3801
|
+
if (response.status !== 404) {
|
|
3802
|
+
return response;
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
if (response) {
|
|
3806
|
+
return response;
|
|
3807
|
+
}
|
|
3808
|
+
throw new Error("No handlers were found for the request.");
|
|
3809
|
+
};
|
|
3810
|
+
return cachedHandler;
|
|
3811
|
+
}
|
|
3812
|
+
return () => {
|
|
3813
|
+
if (!ctx.reactRouterConfig.ssr) {
|
|
3814
|
+
return;
|
|
3815
|
+
}
|
|
3816
|
+
previewServer.middlewares.use(async (req, res, next) => {
|
|
3817
|
+
try {
|
|
3818
|
+
let handler = await getHandler();
|
|
3819
|
+
let request = await fromNodeRequest(req, res);
|
|
3820
|
+
let response = await handler(
|
|
3821
|
+
request,
|
|
3822
|
+
await reactRouterDevLoadContext(request)
|
|
3823
|
+
);
|
|
3824
|
+
const { sendResponse } = await import("@remix-run/node-fetch-server");
|
|
3825
|
+
await sendResponse(res, response);
|
|
3826
|
+
} catch (error) {
|
|
3827
|
+
next(error);
|
|
3828
|
+
}
|
|
3829
|
+
});
|
|
3830
|
+
};
|
|
3831
|
+
},
|
|
3513
3832
|
writeBundle: {
|
|
3514
3833
|
// After the SSR build is finished, we inspect the Vite manifest for
|
|
3515
3834
|
// the SSR build and move server-only assets to client assets directory
|
|
@@ -3530,19 +3849,19 @@ var reactRouterVitePlugin = () => {
|
|
|
3530
3849
|
let removedAssetPaths = [];
|
|
3531
3850
|
let copiedAssetPaths = [];
|
|
3532
3851
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
3533
|
-
let src =
|
|
3534
|
-
let dest =
|
|
3852
|
+
let src = path7.join(serverBuildDirectory, ssrAssetPath);
|
|
3853
|
+
let dest = path7.join(clientBuildDirectory, ssrAssetPath);
|
|
3535
3854
|
if (!userSsrEmitAssets) {
|
|
3536
3855
|
if (!(0, import_node_fs2.existsSync)(dest)) {
|
|
3537
|
-
await (0,
|
|
3538
|
-
await (0,
|
|
3856
|
+
await (0, import_promises3.mkdir)(path7.dirname(dest), { recursive: true });
|
|
3857
|
+
await (0, import_promises3.rename)(src, dest);
|
|
3539
3858
|
movedAssetPaths.push(dest);
|
|
3540
3859
|
} else {
|
|
3541
|
-
await (0,
|
|
3860
|
+
await (0, import_promises3.rm)(src, { force: true, recursive: true });
|
|
3542
3861
|
removedAssetPaths.push(dest);
|
|
3543
3862
|
}
|
|
3544
3863
|
} else if (!(0, import_node_fs2.existsSync)(dest)) {
|
|
3545
|
-
await (0,
|
|
3864
|
+
await (0, import_promises3.cp)(src, dest, { recursive: true });
|
|
3546
3865
|
copiedAssetPaths.push(dest);
|
|
3547
3866
|
}
|
|
3548
3867
|
}
|
|
@@ -3552,21 +3871,21 @@ var reactRouterVitePlugin = () => {
|
|
|
3552
3871
|
);
|
|
3553
3872
|
await Promise.all(
|
|
3554
3873
|
ssrCssPaths.map(async (cssPath) => {
|
|
3555
|
-
let src =
|
|
3556
|
-
await (0,
|
|
3874
|
+
let src = path7.join(serverBuildDirectory, cssPath);
|
|
3875
|
+
await (0, import_promises3.rm)(src, { force: true, recursive: true });
|
|
3557
3876
|
removedAssetPaths.push(src);
|
|
3558
3877
|
})
|
|
3559
3878
|
);
|
|
3560
3879
|
}
|
|
3561
3880
|
let cleanedAssetPaths = [...removedAssetPaths, ...movedAssetPaths];
|
|
3562
3881
|
let handledAssetPaths = [...cleanedAssetPaths, ...copiedAssetPaths];
|
|
3563
|
-
let cleanedAssetDirs = new Set(cleanedAssetPaths.map(
|
|
3882
|
+
let cleanedAssetDirs = new Set(cleanedAssetPaths.map(path7.dirname));
|
|
3564
3883
|
await Promise.all(
|
|
3565
3884
|
Array.from(cleanedAssetDirs).map(async (dir) => {
|
|
3566
3885
|
try {
|
|
3567
|
-
const files = await (0,
|
|
3886
|
+
const files = await (0, import_promises3.readdir)(dir, { recursive: true });
|
|
3568
3887
|
if (files.length === 0) {
|
|
3569
|
-
await (0,
|
|
3888
|
+
await (0, import_promises3.rm)(dir, { force: true, recursive: true });
|
|
3570
3889
|
}
|
|
3571
3890
|
} catch {
|
|
3572
3891
|
}
|
|
@@ -3582,7 +3901,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3582
3901
|
[
|
|
3583
3902
|
`${import_picocolors4.default.green("\u2713")} ${message}`,
|
|
3584
3903
|
...paths.map(
|
|
3585
|
-
(assetPath) => import_picocolors4.default.dim(
|
|
3904
|
+
(assetPath) => import_picocolors4.default.dim(path7.relative(ctx.rootDirectory, assetPath))
|
|
3586
3905
|
)
|
|
3587
3906
|
].join("\n")
|
|
3588
3907
|
);
|
|
@@ -3603,6 +3922,9 @@ var reactRouterVitePlugin = () => {
|
|
|
3603
3922
|
if (handledAssetPaths.length) {
|
|
3604
3923
|
viteConfig.logger.info("");
|
|
3605
3924
|
}
|
|
3925
|
+
if (future.unstable_previewServerPrerendering) {
|
|
3926
|
+
return;
|
|
3927
|
+
}
|
|
3606
3928
|
process.env.IS_RR_BUILD_REQUEST = "yes";
|
|
3607
3929
|
if (isPrerenderingEnabled(ctx.reactRouterConfig)) {
|
|
3608
3930
|
await handlePrerender(
|
|
@@ -3676,7 +3998,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3676
3998
|
);
|
|
3677
3999
|
let isMainChunkExport = (name) => !chunkedExports.includes(name);
|
|
3678
4000
|
let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
|
|
3679
|
-
let chunkBasePath = `./${
|
|
4001
|
+
let chunkBasePath = `./${path7.basename(id)}`;
|
|
3680
4002
|
return [
|
|
3681
4003
|
`export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
|
|
3682
4004
|
chunkBasePath,
|
|
@@ -3696,7 +4018,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3696
4018
|
async transform(code, id, options) {
|
|
3697
4019
|
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
3698
4020
|
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
3699
|
-
let routeFileName =
|
|
4021
|
+
let routeFileName = path7.basename(routeModuleId);
|
|
3700
4022
|
let sourceExports = await getRouteModuleExports(
|
|
3701
4023
|
viteChildCompiler,
|
|
3702
4024
|
ctx,
|
|
@@ -3776,6 +4098,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3776
4098
|
viteConfig,
|
|
3777
4099
|
routeIds
|
|
3778
4100
|
})).reactRouterServerManifest : await getReactRouterManifestForDev();
|
|
4101
|
+
ctx.reactRouterManifest = reactRouterManifest;
|
|
3779
4102
|
if (!ctx.reactRouterConfig.ssr) {
|
|
3780
4103
|
invariant(viteConfig);
|
|
3781
4104
|
validateSsrFalsePrerenderExports(
|
|
@@ -3823,7 +4146,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3823
4146
|
}
|
|
3824
4147
|
let vite2 = getVite();
|
|
3825
4148
|
let importerShort = vite2.normalizePath(
|
|
3826
|
-
|
|
4149
|
+
path7.relative(ctx.rootDirectory, importer)
|
|
3827
4150
|
);
|
|
3828
4151
|
if (isRoute(ctx.reactRouterConfig, importer)) {
|
|
3829
4152
|
let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
|
|
@@ -3945,17 +4268,17 @@ var reactRouterVitePlugin = () => {
|
|
|
3945
4268
|
},
|
|
3946
4269
|
async load(id) {
|
|
3947
4270
|
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
3948
|
-
let reactRefreshDir =
|
|
4271
|
+
let reactRefreshDir = path7.dirname(
|
|
3949
4272
|
require.resolve("react-refresh/package.json")
|
|
3950
4273
|
);
|
|
3951
|
-
let reactRefreshRuntimePath =
|
|
4274
|
+
let reactRefreshRuntimePath = path7.join(
|
|
3952
4275
|
reactRefreshDir,
|
|
3953
4276
|
"cjs/react-refresh-runtime.development.js"
|
|
3954
4277
|
);
|
|
3955
4278
|
return [
|
|
3956
4279
|
"const exports = {}",
|
|
3957
|
-
await (0,
|
|
3958
|
-
await (0,
|
|
4280
|
+
await (0, import_promises3.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
4281
|
+
await (0, import_promises3.readFile)(require.resolve("./static/refresh-utils.mjs"), "utf8"),
|
|
3959
4282
|
"export default exports"
|
|
3960
4283
|
].join("\n");
|
|
3961
4284
|
}
|
|
@@ -4047,44 +4370,251 @@ var reactRouterVitePlugin = () => {
|
|
|
4047
4370
|
if (this.environment.name !== "ssr" && modules.length <= 0) {
|
|
4048
4371
|
return;
|
|
4049
4372
|
}
|
|
4050
|
-
let clientModules =
|
|
4051
|
-
|
|
4052
|
-
(mod) => getParentClientNodes(server.environments.client.moduleGraph, mod)
|
|
4053
|
-
)
|
|
4373
|
+
let clientModules = modules.flatMap(
|
|
4374
|
+
(mod) => getParentClientNodes(server.environments.client.moduleGraph, mod)
|
|
4054
4375
|
);
|
|
4055
4376
|
for (let clientModule of clientModules) {
|
|
4056
4377
|
server.environments.client.reloadModule(clientModule);
|
|
4057
4378
|
}
|
|
4058
4379
|
}
|
|
4059
4380
|
},
|
|
4381
|
+
prerender({
|
|
4382
|
+
config() {
|
|
4383
|
+
process.env.IS_RR_BUILD_REQUEST = "yes";
|
|
4384
|
+
return {
|
|
4385
|
+
// Required as viteConfig.environments.client.build.outDir is only available in Vite v6+
|
|
4386
|
+
buildDirectory: getClientBuildDirectory(ctx.reactRouterConfig),
|
|
4387
|
+
concurrency: getPrerenderConcurrencyConfig(ctx.reactRouterConfig)
|
|
4388
|
+
};
|
|
4389
|
+
},
|
|
4390
|
+
async requests() {
|
|
4391
|
+
invariant(viteConfig);
|
|
4392
|
+
let { future } = ctx.reactRouterConfig;
|
|
4393
|
+
if (future.v8_viteEnvironmentApi ? this.environment.name === "client" : !viteConfigEnv.isSsrBuild) {
|
|
4394
|
+
return [];
|
|
4395
|
+
}
|
|
4396
|
+
if (!future.unstable_previewServerPrerendering) {
|
|
4397
|
+
return [];
|
|
4398
|
+
}
|
|
4399
|
+
let requests = [];
|
|
4400
|
+
if (isPrerenderingEnabled(ctx.reactRouterConfig)) {
|
|
4401
|
+
invariant(ctx.prerenderPaths !== null, "Prerender paths missing");
|
|
4402
|
+
invariant(
|
|
4403
|
+
ctx.reactRouterManifest !== null,
|
|
4404
|
+
"Prerender manifest missing"
|
|
4405
|
+
);
|
|
4406
|
+
let { reactRouterConfig, reactRouterManifest, prerenderPaths } = ctx;
|
|
4407
|
+
assertPrerenderPathsMatchRoutes(
|
|
4408
|
+
reactRouterConfig,
|
|
4409
|
+
Array.from(prerenderPaths)
|
|
4410
|
+
);
|
|
4411
|
+
let buildRoutes = createPrerenderRoutes(reactRouterManifest.routes);
|
|
4412
|
+
for (let prerenderPath of prerenderPaths) {
|
|
4413
|
+
let matches = (0, import_react_router2.matchRoutes)(
|
|
4414
|
+
buildRoutes,
|
|
4415
|
+
`/${prerenderPath}/`.replace(/^\/\/+/, "/")
|
|
4416
|
+
);
|
|
4417
|
+
if (!matches) {
|
|
4418
|
+
continue;
|
|
4419
|
+
}
|
|
4420
|
+
let leafRoute = matches[matches.length - 1].route;
|
|
4421
|
+
let manifestRoute = reactRouterManifest.routes[leafRoute.id];
|
|
4422
|
+
let isResourceRoute = manifestRoute && !manifestRoute.hasDefaultExport && !manifestRoute.hasErrorBoundary;
|
|
4423
|
+
if (isResourceRoute) {
|
|
4424
|
+
if (manifestRoute?.hasLoader) {
|
|
4425
|
+
requests.push(
|
|
4426
|
+
// Prerender a .data file for turbo-stream consumption
|
|
4427
|
+
createDataRequest(
|
|
4428
|
+
prerenderPath,
|
|
4429
|
+
reactRouterConfig,
|
|
4430
|
+
[leafRoute.id],
|
|
4431
|
+
true
|
|
4432
|
+
),
|
|
4433
|
+
// Prerender a raw file for external consumption
|
|
4434
|
+
createResourceRouteRequest(prerenderPath, reactRouterConfig)
|
|
4435
|
+
);
|
|
4436
|
+
} else {
|
|
4437
|
+
viteConfig.logger.warn(
|
|
4438
|
+
`\u26A0\uFE0F Skipping prerendering for resource route without a loader: ${leafRoute.id}`
|
|
4439
|
+
);
|
|
4440
|
+
}
|
|
4441
|
+
} else {
|
|
4442
|
+
let hasLoaders = matches.some(
|
|
4443
|
+
(m) => reactRouterManifest.routes[m.route.id]?.hasLoader
|
|
4444
|
+
);
|
|
4445
|
+
if (hasLoaders) {
|
|
4446
|
+
requests.push(
|
|
4447
|
+
createDataRequest(prerenderPath, reactRouterConfig, null)
|
|
4448
|
+
);
|
|
4449
|
+
} else {
|
|
4450
|
+
requests.push(
|
|
4451
|
+
createRouteRequest(prerenderPath, reactRouterConfig)
|
|
4452
|
+
);
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
if (!ctx.reactRouterConfig.ssr) {
|
|
4458
|
+
requests.push(createSpaModeRequest(ctx.reactRouterConfig));
|
|
4459
|
+
}
|
|
4460
|
+
return requests;
|
|
4461
|
+
},
|
|
4462
|
+
async postProcess(request, response, metadata) {
|
|
4463
|
+
invariant(metadata);
|
|
4464
|
+
if (metadata.type === "data") {
|
|
4465
|
+
let pathname2 = new URL(request.url).pathname;
|
|
4466
|
+
if (response.status !== 200 && response.status !== 202) {
|
|
4467
|
+
throw new Error(
|
|
4468
|
+
`Prerender (data): Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${metadata.path}\` path.
|
|
4469
|
+
${pathname2}`,
|
|
4470
|
+
{ cause: response }
|
|
4471
|
+
);
|
|
4472
|
+
}
|
|
4473
|
+
let data = await response.text();
|
|
4474
|
+
return {
|
|
4475
|
+
files: [
|
|
4476
|
+
{
|
|
4477
|
+
path: pathname2,
|
|
4478
|
+
contents: data
|
|
4479
|
+
}
|
|
4480
|
+
],
|
|
4481
|
+
// After saving the .data file, request the HTML page.
|
|
4482
|
+
// The data is passed along to be embedded in the response header.
|
|
4483
|
+
requests: !metadata.isResourceRoute ? [createRouteRequest(metadata.path, ctx.reactRouterConfig, data)] : []
|
|
4484
|
+
};
|
|
4485
|
+
}
|
|
4486
|
+
if (metadata.type === "resource") {
|
|
4487
|
+
let pathname2 = new URL(request.url).pathname;
|
|
4488
|
+
let contents = new Uint8Array(await response.arrayBuffer());
|
|
4489
|
+
if (response.status !== 200) {
|
|
4490
|
+
throw new Error(
|
|
4491
|
+
`Prerender (resource): Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${pathname2}\` path.
|
|
4492
|
+
${new TextDecoder().decode(contents)}`
|
|
4493
|
+
);
|
|
4494
|
+
}
|
|
4495
|
+
return [
|
|
4496
|
+
{
|
|
4497
|
+
path: pathname2,
|
|
4498
|
+
contents
|
|
4499
|
+
}
|
|
4500
|
+
];
|
|
4501
|
+
}
|
|
4502
|
+
let html = await response.text();
|
|
4503
|
+
if (metadata.type === "spa") {
|
|
4504
|
+
if (response.status !== 200) {
|
|
4505
|
+
throw new Error(
|
|
4506
|
+
`SPA Mode: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your SPA Fallback HTML file.
|
|
4507
|
+
` + html
|
|
4508
|
+
);
|
|
4509
|
+
}
|
|
4510
|
+
if (!html.includes("window.__reactRouterContext =") || !html.includes("window.__reactRouterRouteModules =")) {
|
|
4511
|
+
throw new Error(
|
|
4512
|
+
"SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
|
|
4513
|
+
);
|
|
4514
|
+
}
|
|
4515
|
+
return [
|
|
4516
|
+
{
|
|
4517
|
+
path: "/__spa-fallback.html",
|
|
4518
|
+
contents: html
|
|
4519
|
+
}
|
|
4520
|
+
];
|
|
4521
|
+
}
|
|
4522
|
+
let pathname = new URL(request.url).pathname;
|
|
4523
|
+
if (redirectStatusCodes.has(response.status)) {
|
|
4524
|
+
let location = response.headers.get("Location");
|
|
4525
|
+
let delay = response.status === 302 ? 2 : 0;
|
|
4526
|
+
html = `<!doctype html>
|
|
4527
|
+
<head>
|
|
4528
|
+
<title>Redirecting to: ${location}</title>
|
|
4529
|
+
<meta http-equiv="refresh" content="${delay};url=${location}">
|
|
4530
|
+
<meta name="robots" content="noindex">
|
|
4531
|
+
</head>
|
|
4532
|
+
<body>
|
|
4533
|
+
<a href="${location}">
|
|
4534
|
+
Redirecting from <code>${pathname}</code> to <code>${location}</code>
|
|
4535
|
+
</a>
|
|
4536
|
+
</body>
|
|
4537
|
+
</html>`;
|
|
4538
|
+
} else if (response.status !== 200) {
|
|
4539
|
+
throw new Error(
|
|
4540
|
+
`Prerender (html): Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${pathname}\` path.
|
|
4541
|
+
${html}`
|
|
4542
|
+
);
|
|
4543
|
+
}
|
|
4544
|
+
return [
|
|
4545
|
+
{
|
|
4546
|
+
path: `${pathname}/index.html`,
|
|
4547
|
+
contents: html
|
|
4548
|
+
}
|
|
4549
|
+
];
|
|
4550
|
+
},
|
|
4551
|
+
logFile(outputPath, metadata) {
|
|
4552
|
+
invariant(viteConfig);
|
|
4553
|
+
invariant(metadata);
|
|
4554
|
+
if (metadata.type === "spa") {
|
|
4555
|
+
return;
|
|
4556
|
+
}
|
|
4557
|
+
viteConfig.logger.info(
|
|
4558
|
+
`Prerender (${metadata.type}): ${metadata.path} -> ${import_picocolors4.default.bold(outputPath)}`
|
|
4559
|
+
);
|
|
4560
|
+
},
|
|
4561
|
+
async finalize(buildDirectory) {
|
|
4562
|
+
invariant(viteConfig);
|
|
4563
|
+
let { ssr, future } = ctx.reactRouterConfig;
|
|
4564
|
+
if (!ssr) {
|
|
4565
|
+
let spaFallback = path7.join(buildDirectory, "__spa-fallback.html");
|
|
4566
|
+
let index = path7.join(buildDirectory, "index.html");
|
|
4567
|
+
let finalSpaPath;
|
|
4568
|
+
if ((0, import_node_fs2.existsSync)(spaFallback) && !(0, import_node_fs2.existsSync)(index)) {
|
|
4569
|
+
await (0, import_promises3.rename)(spaFallback, index);
|
|
4570
|
+
finalSpaPath = index;
|
|
4571
|
+
} else if ((0, import_node_fs2.existsSync)(spaFallback)) {
|
|
4572
|
+
finalSpaPath = spaFallback;
|
|
4573
|
+
}
|
|
4574
|
+
if (finalSpaPath) {
|
|
4575
|
+
let prettyPath = path7.relative(viteConfig.root, finalSpaPath);
|
|
4576
|
+
if (ctx.prerenderPaths && ctx.prerenderPaths.size > 0) {
|
|
4577
|
+
viteConfig.logger.info(
|
|
4578
|
+
`Prerender (html): SPA Fallback -> ${import_picocolors4.default.bold(prettyPath)}`
|
|
4579
|
+
);
|
|
4580
|
+
} else {
|
|
4581
|
+
viteConfig.logger.info(
|
|
4582
|
+
`SPA Mode: Generated ${import_picocolors4.default.bold(prettyPath)}`
|
|
4583
|
+
);
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
let serverBuildDirectory = future.v8_viteEnvironmentApi ? this.environment.config?.build?.outDir : ctx.environmentBuildContext?.options.build?.outDir ?? getServerBuildDirectory(ctx.reactRouterConfig);
|
|
4587
|
+
viteConfig.logger.info(
|
|
4588
|
+
[
|
|
4589
|
+
"Removing the server build in",
|
|
4590
|
+
import_picocolors4.default.green(serverBuildDirectory),
|
|
4591
|
+
"due to ssr:false"
|
|
4592
|
+
].join(" ")
|
|
4593
|
+
);
|
|
4594
|
+
(0, import_node_fs2.rmSync)(serverBuildDirectory, { force: true, recursive: true });
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
4597
|
+
}),
|
|
4060
4598
|
validatePluginOrder(),
|
|
4061
4599
|
warnOnClientSourceMaps()
|
|
4062
4600
|
];
|
|
4063
4601
|
};
|
|
4064
|
-
function getParentClientNodes(clientModuleGraph, module2) {
|
|
4602
|
+
function getParentClientNodes(clientModuleGraph, module2, seenNodes = /* @__PURE__ */ new Set()) {
|
|
4065
4603
|
if (!module2.id) {
|
|
4066
4604
|
return [];
|
|
4067
4605
|
}
|
|
4606
|
+
if (seenNodes.has(module2.url)) {
|
|
4607
|
+
return [];
|
|
4608
|
+
}
|
|
4609
|
+
seenNodes.add(module2.url);
|
|
4068
4610
|
let clientModule = clientModuleGraph.getModuleById(module2.id);
|
|
4069
4611
|
if (clientModule) {
|
|
4070
4612
|
return [clientModule];
|
|
4071
4613
|
}
|
|
4072
4614
|
return [...module2.importers].flatMap(
|
|
4073
|
-
(importer) => getParentClientNodes(clientModuleGraph, importer)
|
|
4615
|
+
(importer) => getParentClientNodes(clientModuleGraph, importer, seenNodes)
|
|
4074
4616
|
);
|
|
4075
4617
|
}
|
|
4076
|
-
function uniqueNodes(nodes) {
|
|
4077
|
-
let nodeUrls = /* @__PURE__ */ new Set();
|
|
4078
|
-
let unique = [];
|
|
4079
|
-
for (let node of nodes) {
|
|
4080
|
-
if (nodeUrls.has(node.url)) {
|
|
4081
|
-
continue;
|
|
4082
|
-
}
|
|
4083
|
-
nodeUrls.add(node.url);
|
|
4084
|
-
unique.push(node);
|
|
4085
|
-
}
|
|
4086
|
-
return unique;
|
|
4087
|
-
}
|
|
4088
4618
|
function addRefreshWrapper(reactRouterConfig, code, id) {
|
|
4089
4619
|
let route = getRoute(reactRouterConfig, id);
|
|
4090
4620
|
let acceptExports = route ? CLIENT_NON_COMPONENT_EXPORTS : [];
|
|
@@ -4128,7 +4658,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
4128
4658
|
function getRoute(pluginConfig, file) {
|
|
4129
4659
|
let vite2 = getVite();
|
|
4130
4660
|
let routePath = vite2.normalizePath(
|
|
4131
|
-
|
|
4661
|
+
path7.relative(pluginConfig.appDirectory, file)
|
|
4132
4662
|
);
|
|
4133
4663
|
let route = Object.values(pluginConfig.routes).find(
|
|
4134
4664
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
@@ -4167,7 +4697,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
4167
4697
|
caseSensitive: route.caseSensitive,
|
|
4168
4698
|
url: combineURLs(
|
|
4169
4699
|
ctx.publicPath,
|
|
4170
|
-
"/" +
|
|
4700
|
+
"/" + path7.relative(
|
|
4171
4701
|
ctx.rootDirectory,
|
|
4172
4702
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
4173
4703
|
)
|
|
@@ -4183,6 +4713,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
4183
4713
|
hasLoader: sourceExports.includes("loader"),
|
|
4184
4714
|
hasClientLoader: sourceExports.includes("clientLoader"),
|
|
4185
4715
|
hasClientMiddleware: sourceExports.includes("clientMiddleware"),
|
|
4716
|
+
hasDefaultExport: sourceExports.includes("default"),
|
|
4186
4717
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
4187
4718
|
imports: []
|
|
4188
4719
|
};
|
|
@@ -4195,7 +4726,7 @@ function isSpaModeEnabled(reactRouterConfig) {
|
|
|
4195
4726
|
return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
|
|
4196
4727
|
}
|
|
4197
4728
|
async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
|
|
4198
|
-
let serverBuildPath =
|
|
4729
|
+
let serverBuildPath = path7.join(serverBuildDirectory, serverBuildFile);
|
|
4199
4730
|
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
4200
4731
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
4201
4732
|
return {
|
|
@@ -4237,9 +4768,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
4237
4768
|
"SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
|
|
4238
4769
|
);
|
|
4239
4770
|
}
|
|
4240
|
-
await (0,
|
|
4241
|
-
let prettyDir =
|
|
4242
|
-
let prettyPath =
|
|
4771
|
+
await (0, import_promises3.writeFile)(path7.join(clientBuildDirectory, filename2), html);
|
|
4772
|
+
let prettyDir = path7.relative(viteConfig.root, clientBuildDirectory);
|
|
4773
|
+
let prettyPath = path7.join(prettyDir, filename2);
|
|
4243
4774
|
if (build.prerender.length > 0) {
|
|
4244
4775
|
viteConfig.logger.info(
|
|
4245
4776
|
`Prerender (html): SPA Fallback -> ${import_picocolors4.default.bold(prettyPath)}`
|
|
@@ -4255,17 +4786,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4255
4786
|
serverBuildPath
|
|
4256
4787
|
);
|
|
4257
4788
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
4258
|
-
for (let
|
|
4259
|
-
let matches = (0, import_react_router2.matchRoutes)(routes, `/${
|
|
4789
|
+
for (let path10 of build.prerender) {
|
|
4790
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path10}/`.replace(/^\/\/+/, "/"));
|
|
4260
4791
|
if (!matches) {
|
|
4261
4792
|
throw new Error(
|
|
4262
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4793
|
+
`Unable to prerender path because it does not match any routes: ${path10}`
|
|
4263
4794
|
);
|
|
4264
4795
|
}
|
|
4265
4796
|
}
|
|
4266
4797
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
4267
|
-
let prerenderSinglePath = async (
|
|
4268
|
-
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${
|
|
4798
|
+
let prerenderSinglePath = async (path10) => {
|
|
4799
|
+
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path10}/`.replace(/^\/\/+/, "/"));
|
|
4269
4800
|
if (!matches) {
|
|
4270
4801
|
return;
|
|
4271
4802
|
}
|
|
@@ -4278,7 +4809,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4278
4809
|
if (manifestRoute.loader) {
|
|
4279
4810
|
await prerenderData(
|
|
4280
4811
|
handler,
|
|
4281
|
-
|
|
4812
|
+
path10,
|
|
4282
4813
|
[leafRoute.id],
|
|
4283
4814
|
clientBuildDirectory,
|
|
4284
4815
|
reactRouterConfig,
|
|
@@ -4286,7 +4817,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4286
4817
|
);
|
|
4287
4818
|
await prerenderResourceRoute(
|
|
4288
4819
|
handler,
|
|
4289
|
-
|
|
4820
|
+
path10,
|
|
4290
4821
|
clientBuildDirectory,
|
|
4291
4822
|
reactRouterConfig,
|
|
4292
4823
|
viteConfig
|
|
@@ -4304,7 +4835,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4304
4835
|
if (!isResourceRoute && hasLoaders) {
|
|
4305
4836
|
data = await prerenderData(
|
|
4306
4837
|
handler,
|
|
4307
|
-
|
|
4838
|
+
path10,
|
|
4308
4839
|
null,
|
|
4309
4840
|
clientBuildDirectory,
|
|
4310
4841
|
reactRouterConfig,
|
|
@@ -4313,7 +4844,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4313
4844
|
}
|
|
4314
4845
|
await prerenderRoute(
|
|
4315
4846
|
handler,
|
|
4316
|
-
|
|
4847
|
+
path10,
|
|
4317
4848
|
clientBuildDirectory,
|
|
4318
4849
|
reactRouterConfig,
|
|
4319
4850
|
viteConfig,
|
|
@@ -4326,9 +4857,9 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4326
4857
|
}
|
|
4327
4858
|
};
|
|
4328
4859
|
let concurrency = 1;
|
|
4329
|
-
let { prerender } = reactRouterConfig;
|
|
4330
|
-
if (typeof
|
|
4331
|
-
concurrency =
|
|
4860
|
+
let { prerender: prerender2 } = reactRouterConfig;
|
|
4861
|
+
if (typeof prerender2 === "object" && "unstable_concurrency" in prerender2) {
|
|
4862
|
+
concurrency = prerender2.unstable_concurrency ?? 1;
|
|
4332
4863
|
}
|
|
4333
4864
|
const pMap = await import("p-map");
|
|
4334
4865
|
await pMap.default(build.prerender, prerenderSinglePath, { concurrency });
|
|
@@ -4359,7 +4890,21 @@ function getStaticPrerenderPaths(routes) {
|
|
|
4359
4890
|
};
|
|
4360
4891
|
}
|
|
4361
4892
|
async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDirectory, reactRouterConfig, viteConfig, requestInit) {
|
|
4362
|
-
let
|
|
4893
|
+
let dataRequestPath;
|
|
4894
|
+
if (reactRouterConfig.future.unstable_trailingSlashAwareDataRequests) {
|
|
4895
|
+
if (prerenderPath.endsWith("/")) {
|
|
4896
|
+
dataRequestPath = `${prerenderPath}_.data`;
|
|
4897
|
+
} else {
|
|
4898
|
+
dataRequestPath = `${prerenderPath}.data`;
|
|
4899
|
+
}
|
|
4900
|
+
} else {
|
|
4901
|
+
if (prerenderPath === "/") {
|
|
4902
|
+
dataRequestPath = "/_root.data";
|
|
4903
|
+
} else {
|
|
4904
|
+
dataRequestPath = `${prerenderPath.replace(/\/$/, "")}.data`;
|
|
4905
|
+
}
|
|
4906
|
+
}
|
|
4907
|
+
let normalizedPath = `${reactRouterConfig.basename}${dataRequestPath}`.replace(/\/\/+/g, "/");
|
|
4363
4908
|
let url2 = new URL(`http://localhost${normalizedPath}`);
|
|
4364
4909
|
if (onlyRoutes?.length) {
|
|
4365
4910
|
url2.searchParams.set("_routes", onlyRoutes.join(","));
|
|
@@ -4373,12 +4918,12 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
|
|
|
4373
4918
|
${normalizedPath}`
|
|
4374
4919
|
);
|
|
4375
4920
|
}
|
|
4376
|
-
let outfile =
|
|
4377
|
-
await (0,
|
|
4378
|
-
await (0,
|
|
4921
|
+
let outfile = path7.join(clientBuildDirectory, ...normalizedPath.split("/"));
|
|
4922
|
+
await (0, import_promises3.mkdir)(path7.dirname(outfile), { recursive: true });
|
|
4923
|
+
await (0, import_promises3.writeFile)(outfile, data);
|
|
4379
4924
|
viteConfig.logger.info(
|
|
4380
4925
|
`Prerender (data): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4381
|
-
|
|
4926
|
+
path7.relative(viteConfig.root, outfile)
|
|
4382
4927
|
)}`
|
|
4383
4928
|
);
|
|
4384
4929
|
return data;
|
|
@@ -4413,16 +4958,16 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
4413
4958
|
${html}`
|
|
4414
4959
|
);
|
|
4415
4960
|
}
|
|
4416
|
-
let outfile =
|
|
4961
|
+
let outfile = path7.join(
|
|
4417
4962
|
clientBuildDirectory,
|
|
4418
4963
|
...normalizedPath.split("/"),
|
|
4419
4964
|
"index.html"
|
|
4420
4965
|
);
|
|
4421
|
-
await (0,
|
|
4422
|
-
await (0,
|
|
4966
|
+
await (0, import_promises3.mkdir)(path7.dirname(outfile), { recursive: true });
|
|
4967
|
+
await (0, import_promises3.writeFile)(outfile, html);
|
|
4423
4968
|
viteConfig.logger.info(
|
|
4424
4969
|
`Prerender (html): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4425
|
-
|
|
4970
|
+
path7.relative(viteConfig.root, outfile)
|
|
4426
4971
|
)}`
|
|
4427
4972
|
);
|
|
4428
4973
|
}
|
|
@@ -4437,24 +4982,24 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
4437
4982
|
${content.toString("utf8")}`
|
|
4438
4983
|
);
|
|
4439
4984
|
}
|
|
4440
|
-
let outfile =
|
|
4441
|
-
await (0,
|
|
4442
|
-
await (0,
|
|
4985
|
+
let outfile = path7.join(clientBuildDirectory, ...normalizedPath.split("/"));
|
|
4986
|
+
await (0, import_promises3.mkdir)(path7.dirname(outfile), { recursive: true });
|
|
4987
|
+
await (0, import_promises3.writeFile)(outfile, content);
|
|
4443
4988
|
viteConfig.logger.info(
|
|
4444
4989
|
`Prerender (resource): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4445
|
-
|
|
4990
|
+
path7.relative(viteConfig.root, outfile)
|
|
4446
4991
|
)}`
|
|
4447
4992
|
);
|
|
4448
4993
|
}
|
|
4449
|
-
async function getPrerenderPaths(
|
|
4450
|
-
if (
|
|
4994
|
+
async function getPrerenderPaths(prerender2, ssr, routes, logWarning = false) {
|
|
4995
|
+
if (prerender2 == null || prerender2 === false) {
|
|
4451
4996
|
return [];
|
|
4452
4997
|
}
|
|
4453
4998
|
let pathsConfig;
|
|
4454
|
-
if (typeof
|
|
4455
|
-
pathsConfig =
|
|
4999
|
+
if (typeof prerender2 === "object" && "paths" in prerender2) {
|
|
5000
|
+
pathsConfig = prerender2.paths;
|
|
4456
5001
|
} else {
|
|
4457
|
-
pathsConfig =
|
|
5002
|
+
pathsConfig = prerender2;
|
|
4458
5003
|
}
|
|
4459
5004
|
if (pathsConfig === false) {
|
|
4460
5005
|
return [];
|
|
@@ -4525,14 +5070,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4525
5070
|
}
|
|
4526
5071
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4527
5072
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4528
|
-
for (let
|
|
5073
|
+
for (let path10 of prerenderPaths) {
|
|
4529
5074
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4530
5075
|
prerenderRoutes,
|
|
4531
|
-
`/${
|
|
5076
|
+
`/${path10}/`.replace(/^\/\/+/, "/")
|
|
4532
5077
|
);
|
|
4533
5078
|
invariant(
|
|
4534
5079
|
matches,
|
|
4535
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
5080
|
+
`Unable to prerender path because it does not match any routes: ${path10}`
|
|
4536
5081
|
);
|
|
4537
5082
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4538
5083
|
}
|
|
@@ -4699,11 +5244,11 @@ function validateRouteChunks({
|
|
|
4699
5244
|
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
4700
5245
|
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
4701
5246
|
let isWithinRoot = () => {
|
|
4702
|
-
let relativePath =
|
|
4703
|
-
return !relativePath.startsWith("..") && !
|
|
5247
|
+
let relativePath = path7.relative(ctx.rootDirectory, buildDirectory);
|
|
5248
|
+
return !relativePath.startsWith("..") && !path7.isAbsolute(relativePath);
|
|
4704
5249
|
};
|
|
4705
5250
|
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
4706
|
-
await (0,
|
|
5251
|
+
await (0, import_promises3.rm)(buildDirectory, { force: true, recursive: true });
|
|
4707
5252
|
}
|
|
4708
5253
|
}
|
|
4709
5254
|
async function cleanViteManifests(environmentsOptions, ctx) {
|
|
@@ -4711,7 +5256,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4711
5256
|
([environmentName, options]) => {
|
|
4712
5257
|
let outDir = options.build?.outDir;
|
|
4713
5258
|
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
4714
|
-
return
|
|
5259
|
+
return path7.join(outDir, ".vite/manifest.json");
|
|
4715
5260
|
}
|
|
4716
5261
|
);
|
|
4717
5262
|
await Promise.all(
|
|
@@ -4719,12 +5264,12 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4719
5264
|
let manifestExists = (0, import_node_fs2.existsSync)(viteManifestPath);
|
|
4720
5265
|
if (!manifestExists) return;
|
|
4721
5266
|
if (!ctx.viteManifestEnabled) {
|
|
4722
|
-
await (0,
|
|
5267
|
+
await (0, import_promises3.rm)(viteManifestPath, { force: true, recursive: true });
|
|
4723
5268
|
}
|
|
4724
|
-
let viteDir =
|
|
4725
|
-
let viteDirFiles = await (0,
|
|
5269
|
+
let viteDir = path7.dirname(viteManifestPath);
|
|
5270
|
+
let viteDirFiles = await (0, import_promises3.readdir)(viteDir, { recursive: true });
|
|
4726
5271
|
if (viteDirFiles.length === 0) {
|
|
4727
|
-
await (0,
|
|
5272
|
+
await (0, import_promises3.rm)(viteDir, { force: true, recursive: true });
|
|
4728
5273
|
}
|
|
4729
5274
|
})
|
|
4730
5275
|
);
|
|
@@ -4739,12 +5284,12 @@ async function getBuildManifest({
|
|
|
4739
5284
|
}
|
|
4740
5285
|
let { normalizePath } = await import("vite");
|
|
4741
5286
|
let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
|
|
4742
|
-
let resolvedAppDirectory =
|
|
5287
|
+
let resolvedAppDirectory = path7.resolve(rootDirectory, appDirectory);
|
|
4743
5288
|
let rootRelativeRoutes = Object.fromEntries(
|
|
4744
5289
|
Object.entries(routes).map(([id, route]) => {
|
|
4745
|
-
let filePath =
|
|
5290
|
+
let filePath = path7.join(resolvedAppDirectory, route.file);
|
|
4746
5291
|
let rootRelativeFilePath = normalizePath(
|
|
4747
|
-
|
|
5292
|
+
path7.relative(rootDirectory, filePath)
|
|
4748
5293
|
);
|
|
4749
5294
|
return [id, { ...route, file: rootRelativeFilePath }];
|
|
4750
5295
|
})
|
|
@@ -4762,7 +5307,7 @@ async function getBuildManifest({
|
|
|
4762
5307
|
(route2) => configRouteToBranchRoute({
|
|
4763
5308
|
...route2,
|
|
4764
5309
|
// Ensure absolute paths are passed to the serverBundles function
|
|
4765
|
-
file:
|
|
5310
|
+
file: path7.join(resolvedAppDirectory, route2.file)
|
|
4766
5311
|
})
|
|
4767
5312
|
)
|
|
4768
5313
|
});
|
|
@@ -4786,10 +5331,10 @@ async function getBuildManifest({
|
|
|
4786
5331
|
buildManifest.serverBundles[serverBundleId] ??= {
|
|
4787
5332
|
id: serverBundleId,
|
|
4788
5333
|
file: normalizePath(
|
|
4789
|
-
|
|
4790
|
-
|
|
5334
|
+
path7.join(
|
|
5335
|
+
path7.relative(
|
|
4791
5336
|
rootDirectory,
|
|
4792
|
-
|
|
5337
|
+
path7.join(serverBuildDirectory, serverBundleId)
|
|
4793
5338
|
),
|
|
4794
5339
|
reactRouterConfig.serverBuildFile
|
|
4795
5340
|
)
|
|
@@ -4808,10 +5353,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
|
|
|
4808
5353
|
}
|
|
4809
5354
|
async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
4810
5355
|
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
4811
|
-
let packageRoot =
|
|
5356
|
+
let packageRoot = path7.dirname(
|
|
4812
5357
|
require.resolve("@react-router/dev/package.json")
|
|
4813
5358
|
);
|
|
4814
|
-
let { moduleSyncEnabled } = await import(`file:///${
|
|
5359
|
+
let { moduleSyncEnabled } = await import(`file:///${path7.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
4815
5360
|
let vite2 = getVite();
|
|
4816
5361
|
function getBaseOptions({
|
|
4817
5362
|
viteUserConfig
|
|
@@ -4890,7 +5435,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4890
5435
|
ctx.entryClientFilePath,
|
|
4891
5436
|
...Object.values(ctx.reactRouterConfig.routes).flatMap(
|
|
4892
5437
|
(route) => {
|
|
4893
|
-
let routeFilePath =
|
|
5438
|
+
let routeFilePath = path7.resolve(
|
|
4894
5439
|
ctx.reactRouterConfig.appDirectory,
|
|
4895
5440
|
route.file
|
|
4896
5441
|
);
|
|
@@ -4914,7 +5459,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4914
5459
|
) : null;
|
|
4915
5460
|
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
4916
5461
|
let assetsDir = (ctx.reactRouterConfig.future.v8_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
|
|
4917
|
-
return
|
|
5462
|
+
return path7.posix.join(
|
|
4918
5463
|
assetsDir,
|
|
4919
5464
|
`[name]${routeChunkSuffix}-[hash].js`
|
|
4920
5465
|
);
|
|
@@ -4980,14 +5525,78 @@ async function asyncFlatten(arr) {
|
|
|
4980
5525
|
} while (arr.some((v2) => v2?.then));
|
|
4981
5526
|
return arr;
|
|
4982
5527
|
}
|
|
5528
|
+
function assertPrerenderPathsMatchRoutes(config, prerenderPaths) {
|
|
5529
|
+
let routes = createPrerenderRoutes(config.routes);
|
|
5530
|
+
for (let path10 of prerenderPaths) {
|
|
5531
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path10}/`.replace(/^\/\/+/, "/"));
|
|
5532
|
+
if (!matches) {
|
|
5533
|
+
throw new Error(
|
|
5534
|
+
`Unable to prerender path because it does not match any routes: ${path10}`
|
|
5535
|
+
);
|
|
5536
|
+
}
|
|
5537
|
+
}
|
|
5538
|
+
}
|
|
5539
|
+
function getPrerenderConcurrencyConfig(reactRouterConfig) {
|
|
5540
|
+
let concurrency = 1;
|
|
5541
|
+
let { prerender: prerender2 } = reactRouterConfig;
|
|
5542
|
+
if (typeof prerender2 === "object" && "unstable_concurrency" in prerender2) {
|
|
5543
|
+
concurrency = prerender2.unstable_concurrency ?? 1;
|
|
5544
|
+
}
|
|
5545
|
+
return concurrency;
|
|
5546
|
+
}
|
|
5547
|
+
function createDataRequest(prerenderPath, reactRouterConfig, onlyRoutes, isResourceRoute) {
|
|
5548
|
+
let normalizedPath = `${reactRouterConfig.basename}${prerenderPath === "/" ? "/_root.data" : `${prerenderPath.replace(/\/$/, "")}.data`}`.replace(/\/\/+/g, "/");
|
|
5549
|
+
let url2 = new URL(`http://localhost${normalizedPath}`);
|
|
5550
|
+
if (onlyRoutes?.length) {
|
|
5551
|
+
url2.searchParams.set("_routes", onlyRoutes.join(","));
|
|
5552
|
+
}
|
|
5553
|
+
return {
|
|
5554
|
+
request: new Request(url2),
|
|
5555
|
+
metadata: { type: "data", path: prerenderPath, isResourceRoute }
|
|
5556
|
+
};
|
|
5557
|
+
}
|
|
5558
|
+
function createRouteRequest(prerenderPath, reactRouterConfig, data) {
|
|
5559
|
+
let normalizedPath = `${reactRouterConfig.basename}${prerenderPath}/`.replace(
|
|
5560
|
+
/\/\/+/g,
|
|
5561
|
+
"/"
|
|
5562
|
+
);
|
|
5563
|
+
let headers = new Headers();
|
|
5564
|
+
if (data) {
|
|
5565
|
+
let encodedData = encodeURI(data);
|
|
5566
|
+
if (encodedData.length < 8 * 1024) {
|
|
5567
|
+
headers.set("X-React-Router-Prerender-Data", encodedData);
|
|
5568
|
+
}
|
|
5569
|
+
}
|
|
5570
|
+
return {
|
|
5571
|
+
request: new Request(`http://localhost${normalizedPath}`, { headers }),
|
|
5572
|
+
metadata: { type: "html", path: prerenderPath }
|
|
5573
|
+
};
|
|
5574
|
+
}
|
|
5575
|
+
function createResourceRouteRequest(prerenderPath, reactRouterConfig, requestInit) {
|
|
5576
|
+
let normalizedPath = `${reactRouterConfig.basename}${prerenderPath}/`.replace(/\/\/+/g, "/").replace(/\/$/g, "");
|
|
5577
|
+
return {
|
|
5578
|
+
request: new Request(`http://localhost${normalizedPath}`, requestInit),
|
|
5579
|
+
metadata: { type: "resource", path: prerenderPath }
|
|
5580
|
+
};
|
|
5581
|
+
}
|
|
5582
|
+
function createSpaModeRequest(reactRouterConfig) {
|
|
5583
|
+
return {
|
|
5584
|
+
request: new Request(`http://localhost${reactRouterConfig.basename}`, {
|
|
5585
|
+
headers: {
|
|
5586
|
+
// Enable SPA mode in the server runtime and only render down to the root
|
|
5587
|
+
"X-React-Router-SPA-Mode": "yes"
|
|
5588
|
+
}
|
|
5589
|
+
}),
|
|
5590
|
+
metadata: { type: "spa", path: "/" }
|
|
5591
|
+
};
|
|
5592
|
+
}
|
|
4983
5593
|
|
|
4984
5594
|
// vite/rsc/plugin.ts
|
|
4985
5595
|
var import_es_module_lexer3 = require("es-module-lexer");
|
|
4986
5596
|
var Path5 = __toESM(require("pathe"));
|
|
4987
5597
|
var babel2 = __toESM(require("@babel/core"));
|
|
4988
5598
|
var import_picocolors5 = __toESM(require("picocolors"));
|
|
4989
|
-
var
|
|
4990
|
-
var import_promises3 = require("fs/promises");
|
|
5599
|
+
var import_promises4 = require("fs/promises");
|
|
4991
5600
|
var import_pathe6 = __toESM(require("pathe"));
|
|
4992
5601
|
|
|
4993
5602
|
// vite/rsc/virtual-route-config.ts
|
|
@@ -5321,13 +5930,16 @@ function isRootRouteFile({
|
|
|
5321
5930
|
|
|
5322
5931
|
// vite/rsc/plugin.ts
|
|
5323
5932
|
function reactRouterRSCVitePlugin() {
|
|
5933
|
+
let runningWithinTheReactRouterMonoRepo = Boolean(
|
|
5934
|
+
arguments && arguments.length === 1 && typeof arguments[0] === "object" && arguments[0] && "__runningWithinTheReactRouterMonoRepo" in arguments[0] && arguments[0].__runningWithinTheReactRouterMonoRepo === true
|
|
5935
|
+
);
|
|
5324
5936
|
let configLoader;
|
|
5325
5937
|
let typegenWatcherPromise;
|
|
5326
5938
|
let viteCommand;
|
|
5327
5939
|
let resolvedViteConfig;
|
|
5328
5940
|
let routeIdByFile;
|
|
5329
5941
|
let logger;
|
|
5330
|
-
|
|
5942
|
+
let entries;
|
|
5331
5943
|
let config;
|
|
5332
5944
|
let rootRouteFile;
|
|
5333
5945
|
function updateConfig(newConfig) {
|
|
@@ -5390,22 +6002,34 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5390
6002
|
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
5391
6003
|
prefix: "[react-router]"
|
|
5392
6004
|
});
|
|
6005
|
+
entries = await resolveRSCEntryFiles({
|
|
6006
|
+
reactRouterConfig: config
|
|
6007
|
+
});
|
|
6008
|
+
let viteNormalizePath = (await import("vite")).normalizePath;
|
|
5393
6009
|
return {
|
|
5394
6010
|
resolve: {
|
|
5395
6011
|
dedupe: [
|
|
5396
6012
|
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
5397
6013
|
"react",
|
|
6014
|
+
"react/jsx-runtime",
|
|
6015
|
+
"react/jsx-dev-runtime",
|
|
5398
6016
|
"react-dom",
|
|
6017
|
+
"react-dom/client",
|
|
5399
6018
|
// Avoid router duplicates since mismatching routers cause `Error:
|
|
5400
6019
|
// You must render this element inside a <Remix> element`.
|
|
5401
6020
|
"react-router",
|
|
5402
6021
|
"react-router/dom",
|
|
5403
|
-
|
|
6022
|
+
"react-router/internal/react-server-client",
|
|
6023
|
+
...hasDependency({ name: "react-router-dom", rootDirectory }) ? ["react-router-dom"] : [],
|
|
6024
|
+
...hasDependency({
|
|
6025
|
+
name: "react-server-dom-webpack",
|
|
6026
|
+
rootDirectory
|
|
6027
|
+
}) ? ["react-server-dom-webpack"] : []
|
|
5404
6028
|
]
|
|
5405
6029
|
},
|
|
5406
6030
|
optimizeDeps: {
|
|
5407
6031
|
entries: getOptimizeDepsEntries({
|
|
5408
|
-
entryClientFilePath:
|
|
6032
|
+
entryClientFilePath: entries.client,
|
|
5409
6033
|
reactRouterConfig: config
|
|
5410
6034
|
}),
|
|
5411
6035
|
esbuildOptions: {
|
|
@@ -5419,8 +6043,17 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5419
6043
|
"react/jsx-runtime",
|
|
5420
6044
|
"react/jsx-dev-runtime",
|
|
5421
6045
|
"react-dom",
|
|
5422
|
-
|
|
5423
|
-
|
|
6046
|
+
...hasDependency({
|
|
6047
|
+
name: "react-server-dom-webpack",
|
|
6048
|
+
rootDirectory
|
|
6049
|
+
}) ? ["react-server-dom-webpack"] : [],
|
|
6050
|
+
...runningWithinTheReactRouterMonoRepo ? [] : [
|
|
6051
|
+
"react-router",
|
|
6052
|
+
"react-router/dom",
|
|
6053
|
+
"react-router/internal/react-server-client"
|
|
6054
|
+
],
|
|
6055
|
+
"react-router > cookie",
|
|
6056
|
+
"react-router > set-cookie-parser"
|
|
5424
6057
|
]
|
|
5425
6058
|
},
|
|
5426
6059
|
esbuild: {
|
|
@@ -5432,27 +6065,30 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5432
6065
|
build: {
|
|
5433
6066
|
rollupOptions: {
|
|
5434
6067
|
input: {
|
|
5435
|
-
index:
|
|
6068
|
+
index: entries.client
|
|
6069
|
+
},
|
|
6070
|
+
output: {
|
|
6071
|
+
manualChunks(id) {
|
|
6072
|
+
const normalized = viteNormalizePath(id);
|
|
6073
|
+
if (normalized.includes("node_modules/react/") || normalized.includes("node_modules/react-dom/") || normalized.includes(
|
|
6074
|
+
"node_modules/react-server-dom-webpack/"
|
|
6075
|
+
) || normalized.includes("node_modules/@vitejs/plugin-rsc/")) {
|
|
6076
|
+
return "react";
|
|
6077
|
+
}
|
|
6078
|
+
if (normalized.includes("node_modules/react-router/")) {
|
|
6079
|
+
return "router";
|
|
6080
|
+
}
|
|
6081
|
+
}
|
|
5436
6082
|
}
|
|
5437
6083
|
},
|
|
5438
6084
|
outDir: (0, import_pathe6.join)(config.buildDirectory, "client")
|
|
5439
|
-
},
|
|
5440
|
-
optimizeDeps: {
|
|
5441
|
-
include: [
|
|
5442
|
-
"react-router > cookie",
|
|
5443
|
-
"react-router > set-cookie-parser"
|
|
5444
|
-
]
|
|
5445
6085
|
}
|
|
5446
6086
|
},
|
|
5447
6087
|
rsc: {
|
|
5448
6088
|
build: {
|
|
5449
6089
|
rollupOptions: {
|
|
5450
6090
|
input: {
|
|
5451
|
-
|
|
5452
|
-
// it as `virtual:react-router/unstable_rsc/rsc-entry`
|
|
5453
|
-
// without needing to know the actual file path, which is
|
|
5454
|
-
// important when using the default entries.
|
|
5455
|
-
index: defaultEntries2.rsc
|
|
6091
|
+
index: entries.rsc
|
|
5456
6092
|
},
|
|
5457
6093
|
output: {
|
|
5458
6094
|
entryFileNames: config.serverBuildFile,
|
|
@@ -5460,13 +6096,18 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5460
6096
|
}
|
|
5461
6097
|
},
|
|
5462
6098
|
outDir: (0, import_pathe6.join)(config.buildDirectory, "server")
|
|
6099
|
+
},
|
|
6100
|
+
resolve: {
|
|
6101
|
+
noExternal: [
|
|
6102
|
+
"@react-router/dev/config/default-rsc-entries/entry.ssr"
|
|
6103
|
+
]
|
|
5463
6104
|
}
|
|
5464
6105
|
},
|
|
5465
6106
|
ssr: {
|
|
5466
6107
|
build: {
|
|
5467
6108
|
rollupOptions: {
|
|
5468
6109
|
input: {
|
|
5469
|
-
index:
|
|
6110
|
+
index: entries.ssr
|
|
5470
6111
|
},
|
|
5471
6112
|
output: {
|
|
5472
6113
|
// Note: We don't set `entryFileNames` here because it's
|
|
@@ -5477,6 +6118,11 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5477
6118
|
}
|
|
5478
6119
|
},
|
|
5479
6120
|
outDir: (0, import_pathe6.join)(config.buildDirectory, "server/__ssr_build")
|
|
6121
|
+
},
|
|
6122
|
+
resolve: {
|
|
6123
|
+
noExternal: [
|
|
6124
|
+
"@react-router/dev/config/default-rsc-entries/entry.rsc"
|
|
6125
|
+
]
|
|
5480
6126
|
}
|
|
5481
6127
|
}
|
|
5482
6128
|
},
|
|
@@ -5580,12 +6226,6 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5580
6226
|
(await typegenWatcherPromise)?.close();
|
|
5581
6227
|
}
|
|
5582
6228
|
},
|
|
5583
|
-
{
|
|
5584
|
-
name: "react-router/rsc/virtual-rsc-entry",
|
|
5585
|
-
resolveId(id) {
|
|
5586
|
-
if (id === virtual2.rscEntry.id) return defaultEntries2.rsc;
|
|
5587
|
-
}
|
|
5588
|
-
},
|
|
5589
6229
|
{
|
|
5590
6230
|
name: "react-router/rsc/virtual-route-config",
|
|
5591
6231
|
resolveId(id) {
|
|
@@ -5661,14 +6301,14 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5661
6301
|
const reactRefreshDir = import_pathe6.default.dirname(
|
|
5662
6302
|
require.resolve("react-refresh/package.json")
|
|
5663
6303
|
);
|
|
5664
|
-
const reactRefreshRuntimePath = import_pathe6.
|
|
6304
|
+
const reactRefreshRuntimePath = (0, import_pathe6.join)(
|
|
5665
6305
|
reactRefreshDir,
|
|
5666
6306
|
"cjs/react-refresh-runtime.development.js"
|
|
5667
6307
|
);
|
|
5668
6308
|
return [
|
|
5669
6309
|
"const exports = {}",
|
|
5670
|
-
await (0,
|
|
5671
|
-
await (0,
|
|
6310
|
+
await (0, import_promises4.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
6311
|
+
await (0, import_promises4.readFile)(
|
|
5672
6312
|
require.resolve("./static/rsc-refresh-utils.mjs"),
|
|
5673
6313
|
"utf8"
|
|
5674
6314
|
),
|
|
@@ -5730,7 +6370,7 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5730
6370
|
const normalizedPath = import_pathe6.default.normalize(mod.file);
|
|
5731
6371
|
const routeId = routeIdByFile?.get(normalizedPath);
|
|
5732
6372
|
if (routeId !== void 0) {
|
|
5733
|
-
const routeSource = await (0,
|
|
6373
|
+
const routeSource = await (0, import_promises4.readFile)(normalizedPath, "utf8");
|
|
5734
6374
|
const virtualRouteModuleCode = (await server.environments.rsc.pluginContainer.transform(
|
|
5735
6375
|
routeSource,
|
|
5736
6376
|
`${normalizedPath}?route-module`
|
|
@@ -5788,7 +6428,6 @@ var virtual2 = {
|
|
|
5788
6428
|
injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
|
|
5789
6429
|
hmrRuntime: create("unstable_rsc/runtime"),
|
|
5790
6430
|
basename: create("unstable_rsc/basename"),
|
|
5791
|
-
rscEntry: create("unstable_rsc/rsc-entry"),
|
|
5792
6431
|
reactRouterServeConfig: create("unstable_rsc/react-router-serve-config")
|
|
5793
6432
|
};
|
|
5794
6433
|
function invalidateVirtualModules2(viteDevServer) {
|
|
@@ -5804,33 +6443,6 @@ function invalidateVirtualModules2(viteDevServer) {
|
|
|
5804
6443
|
function getRootDirectory(viteUserConfig) {
|
|
5805
6444
|
return viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
5806
6445
|
}
|
|
5807
|
-
function getDevPackageRoot() {
|
|
5808
|
-
const currentDir = (0, import_pathe6.dirname)(__dirname);
|
|
5809
|
-
let dir = currentDir;
|
|
5810
|
-
while (dir !== (0, import_pathe6.dirname)(dir)) {
|
|
5811
|
-
try {
|
|
5812
|
-
const packageJsonPath = (0, import_pathe6.join)(dir, "package.json");
|
|
5813
|
-
(0, import_fs.readFileSync)(packageJsonPath, "utf-8");
|
|
5814
|
-
return dir;
|
|
5815
|
-
} catch {
|
|
5816
|
-
dir = (0, import_pathe6.dirname)(dir);
|
|
5817
|
-
}
|
|
5818
|
-
}
|
|
5819
|
-
throw new Error("Could not find package.json");
|
|
5820
|
-
}
|
|
5821
|
-
function getDefaultEntries() {
|
|
5822
|
-
const defaultEntriesDir2 = (0, import_pathe6.join)(
|
|
5823
|
-
getDevPackageRoot(),
|
|
5824
|
-
"dist",
|
|
5825
|
-
"config",
|
|
5826
|
-
"default-rsc-entries"
|
|
5827
|
-
);
|
|
5828
|
-
return {
|
|
5829
|
-
rsc: (0, import_pathe6.join)(defaultEntriesDir2, "entry.rsc.tsx"),
|
|
5830
|
-
ssr: (0, import_pathe6.join)(defaultEntriesDir2, "entry.ssr.tsx"),
|
|
5831
|
-
client: (0, import_pathe6.join)(defaultEntriesDir2, "entry.client.tsx")
|
|
5832
|
-
};
|
|
5833
|
-
}
|
|
5834
6446
|
function getModulesWithImporters(modules) {
|
|
5835
6447
|
const visited = /* @__PURE__ */ new Set();
|
|
5836
6448
|
const result = /* @__PURE__ */ new Set();
|