@react-router/dev 7.13.0 → 7.13.1-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -15
- package/dist/cli/index.js +68 -56
- package/dist/config.d.ts +4 -0
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +2 -1
- package/dist/vite.js +760 -216
- package/package.json +6 -6
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v7.13.0
|
|
2
|
+
* @react-router/dev v7.13.1-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -48,8 +48,8 @@ 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
55
|
var import_react_router2 = require("react-router");
|
|
@@ -246,7 +246,7 @@ function validateRouteConfig({
|
|
|
246
246
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
247
247
|
root ? `${root}` : [],
|
|
248
248
|
nested ? Object.entries(nested).map(
|
|
249
|
-
([
|
|
249
|
+
([path10, message]) => `Path: routes.${path10}
|
|
250
250
|
${message}`
|
|
251
251
|
) : []
|
|
252
252
|
].flat().join("\n\n")
|
|
@@ -431,7 +431,7 @@ async function resolveConfig({
|
|
|
431
431
|
basename: basename3,
|
|
432
432
|
buildDirectory: userBuildDirectory,
|
|
433
433
|
buildEnd,
|
|
434
|
-
prerender,
|
|
434
|
+
prerender: prerender2,
|
|
435
435
|
routeDiscovery: userRouteDiscovery,
|
|
436
436
|
serverBuildFile,
|
|
437
437
|
serverBundles,
|
|
@@ -445,15 +445,15 @@ async function resolveConfig({
|
|
|
445
445
|
if (!ssr && serverBundles) {
|
|
446
446
|
serverBundles = void 0;
|
|
447
447
|
}
|
|
448
|
-
if (
|
|
448
|
+
if (prerender2) {
|
|
449
449
|
let isValidPrerenderPathsConfig = (p) => typeof p === "boolean" || typeof p === "function" || Array.isArray(p);
|
|
450
|
-
let isValidPrerenderConfig = isValidPrerenderPathsConfig(
|
|
450
|
+
let isValidPrerenderConfig = isValidPrerenderPathsConfig(prerender2) || typeof prerender2 === "object" && "paths" in prerender2 && isValidPrerenderPathsConfig(prerender2.paths);
|
|
451
451
|
if (!isValidPrerenderConfig) {
|
|
452
452
|
return err(
|
|
453
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."
|
|
454
454
|
);
|
|
455
455
|
}
|
|
456
|
-
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;
|
|
457
457
|
if (!isValidConcurrencyConfig) {
|
|
458
458
|
return err(
|
|
459
459
|
"The `prerender.unstable_concurrency` config must be a positive integer if specified."
|
|
@@ -562,6 +562,7 @@ async function resolveConfig({
|
|
|
562
562
|
unstable_optimizeDeps: userAndPresetConfigs.future?.unstable_optimizeDeps ?? false,
|
|
563
563
|
unstable_subResourceIntegrity: userAndPresetConfigs.future?.unstable_subResourceIntegrity ?? false,
|
|
564
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
|
|
@@ -573,7 +574,7 @@ async function resolveConfig({
|
|
|
573
574
|
buildDirectory,
|
|
574
575
|
buildEnd,
|
|
575
576
|
future,
|
|
576
|
-
prerender,
|
|
577
|
+
prerender: prerender2,
|
|
577
578
|
routes,
|
|
578
579
|
routeDiscovery,
|
|
579
580
|
serverBuildFile,
|
|
@@ -640,11 +641,11 @@ async function createConfigLoader({
|
|
|
640
641
|
if (!fsWatcher) {
|
|
641
642
|
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
642
643
|
ignoreInitial: true,
|
|
643
|
-
ignored: (
|
|
644
|
-
let dirname4 = import_pathe3.default.dirname(
|
|
644
|
+
ignored: (path10) => {
|
|
645
|
+
let dirname4 = import_pathe3.default.dirname(path10);
|
|
645
646
|
return !dirname4.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
646
647
|
// that are at the root level, not nested in subdirectories
|
|
647
|
-
|
|
648
|
+
path10 !== root && // Watch the root directory itself
|
|
648
649
|
dirname4 !== root;
|
|
649
650
|
}
|
|
650
651
|
});
|
|
@@ -928,7 +929,7 @@ function fullpath(lineage2) {
|
|
|
928
929
|
if (lineage2.length === 1 && route?.id === "root") return "/";
|
|
929
930
|
const isLayout = route && route.index !== true && route.path === void 0;
|
|
930
931
|
if (isLayout) return void 0;
|
|
931
|
-
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("/");
|
|
932
933
|
}
|
|
933
934
|
|
|
934
935
|
// typegen/generate.ts
|
|
@@ -1108,8 +1109,8 @@ function routeModulesType(ctx) {
|
|
|
1108
1109
|
);
|
|
1109
1110
|
}
|
|
1110
1111
|
function isInAppDirectory(ctx, routeFile) {
|
|
1111
|
-
const
|
|
1112
|
-
return
|
|
1112
|
+
const path10 = Path3.resolve(ctx.config.appDirectory, routeFile);
|
|
1113
|
+
return path10.startsWith(ctx.config.appDirectory);
|
|
1113
1114
|
}
|
|
1114
1115
|
function getRouteAnnotations({
|
|
1115
1116
|
ctx,
|
|
@@ -1221,21 +1222,21 @@ function getRouteAnnotations({
|
|
|
1221
1222
|
return { filename: filename2, content };
|
|
1222
1223
|
}
|
|
1223
1224
|
function relativeImportSource(from, to) {
|
|
1224
|
-
let
|
|
1225
|
-
let extension = Path3.extname(
|
|
1226
|
-
|
|
1227
|
-
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;
|
|
1228
1229
|
if (!extension || /\.(js|ts)x?$/.test(extension)) {
|
|
1229
1230
|
extension = ".js";
|
|
1230
1231
|
}
|
|
1231
|
-
return
|
|
1232
|
+
return path10 + extension;
|
|
1232
1233
|
}
|
|
1233
1234
|
function rootDirsPath(ctx, typesPath) {
|
|
1234
1235
|
const rel = Path3.relative(typesDirectory(ctx), typesPath);
|
|
1235
1236
|
return Path3.join(ctx.rootDirectory, rel);
|
|
1236
1237
|
}
|
|
1237
|
-
function paramsType(
|
|
1238
|
-
const params = parse2(
|
|
1238
|
+
function paramsType(path10) {
|
|
1239
|
+
const params = parse2(path10);
|
|
1239
1240
|
return t2.tsTypeLiteral(
|
|
1240
1241
|
Object.entries(params).map(([param, isRequired]) => {
|
|
1241
1242
|
const property = t2.tsPropertySignature(
|
|
@@ -1504,11 +1505,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
|
|
|
1504
1505
|
let cssContent = void 0;
|
|
1505
1506
|
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1506
1507
|
traverse(ast, {
|
|
1507
|
-
VariableDeclaration(
|
|
1508
|
-
const declaration =
|
|
1508
|
+
VariableDeclaration(path10) {
|
|
1509
|
+
const declaration = path10.node.declarations[0];
|
|
1509
1510
|
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1510
1511
|
cssContent = declaration.init.value;
|
|
1511
|
-
|
|
1512
|
+
path10.stop();
|
|
1512
1513
|
}
|
|
1513
1514
|
}
|
|
1514
1515
|
});
|
|
@@ -1547,10 +1548,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1547
1548
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1548
1549
|
let removedExportLocalNames = /* @__PURE__ */ new Set();
|
|
1549
1550
|
traverse(ast, {
|
|
1550
|
-
ExportDeclaration(
|
|
1551
|
-
if (
|
|
1552
|
-
if (
|
|
1553
|
-
|
|
1551
|
+
ExportDeclaration(path10) {
|
|
1552
|
+
if (path10.node.type === "ExportNamedDeclaration") {
|
|
1553
|
+
if (path10.node.specifiers.length) {
|
|
1554
|
+
path10.node.specifiers = path10.node.specifiers.filter((specifier) => {
|
|
1554
1555
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1555
1556
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1556
1557
|
exportsFiltered = true;
|
|
@@ -1562,12 +1563,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1562
1563
|
}
|
|
1563
1564
|
return true;
|
|
1564
1565
|
});
|
|
1565
|
-
if (
|
|
1566
|
-
markedForRemoval.add(
|
|
1566
|
+
if (path10.node.specifiers.length === 0) {
|
|
1567
|
+
markedForRemoval.add(path10);
|
|
1567
1568
|
}
|
|
1568
1569
|
}
|
|
1569
|
-
if (
|
|
1570
|
-
let declaration =
|
|
1570
|
+
if (path10.node.declaration?.type === "VariableDeclaration") {
|
|
1571
|
+
let declaration = path10.node.declaration;
|
|
1571
1572
|
declaration.declarations = declaration.declarations.filter(
|
|
1572
1573
|
(declaration2) => {
|
|
1573
1574
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1581,30 +1582,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1581
1582
|
}
|
|
1582
1583
|
);
|
|
1583
1584
|
if (declaration.declarations.length === 0) {
|
|
1584
|
-
markedForRemoval.add(
|
|
1585
|
+
markedForRemoval.add(path10);
|
|
1585
1586
|
}
|
|
1586
1587
|
}
|
|
1587
|
-
if (
|
|
1588
|
-
let id =
|
|
1588
|
+
if (path10.node.declaration?.type === "FunctionDeclaration") {
|
|
1589
|
+
let id = path10.node.declaration.id;
|
|
1589
1590
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1590
|
-
markedForRemoval.add(
|
|
1591
|
+
markedForRemoval.add(path10);
|
|
1591
1592
|
}
|
|
1592
1593
|
}
|
|
1593
|
-
if (
|
|
1594
|
-
let id =
|
|
1594
|
+
if (path10.node.declaration?.type === "ClassDeclaration") {
|
|
1595
|
+
let id = path10.node.declaration.id;
|
|
1595
1596
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1596
|
-
markedForRemoval.add(
|
|
1597
|
+
markedForRemoval.add(path10);
|
|
1597
1598
|
}
|
|
1598
1599
|
}
|
|
1599
1600
|
}
|
|
1600
|
-
if (
|
|
1601
|
+
if (path10.node.type === "ExportDefaultDeclaration") {
|
|
1601
1602
|
if (exportsToRemove.includes("default")) {
|
|
1602
|
-
markedForRemoval.add(
|
|
1603
|
-
if (
|
|
1604
|
-
if (
|
|
1605
|
-
removedExportLocalNames.add(
|
|
1606
|
-
} else if ((
|
|
1607
|
-
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);
|
|
1608
1609
|
}
|
|
1609
1610
|
}
|
|
1610
1611
|
}
|
|
@@ -1612,21 +1613,21 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1612
1613
|
}
|
|
1613
1614
|
});
|
|
1614
1615
|
traverse(ast, {
|
|
1615
|
-
ExpressionStatement(
|
|
1616
|
-
if (!
|
|
1616
|
+
ExpressionStatement(path10) {
|
|
1617
|
+
if (!path10.parentPath.isProgram()) {
|
|
1617
1618
|
return;
|
|
1618
1619
|
}
|
|
1619
|
-
if (
|
|
1620
|
-
const left =
|
|
1620
|
+
if (path10.node.expression.type === "AssignmentExpression") {
|
|
1621
|
+
const left = path10.node.expression.left;
|
|
1621
1622
|
if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
|
|
1622
|
-
markedForRemoval.add(
|
|
1623
|
+
markedForRemoval.add(path10);
|
|
1623
1624
|
}
|
|
1624
1625
|
}
|
|
1625
1626
|
}
|
|
1626
1627
|
});
|
|
1627
1628
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1628
|
-
for (let
|
|
1629
|
-
|
|
1629
|
+
for (let path10 of markedForRemoval) {
|
|
1630
|
+
path10.remove();
|
|
1630
1631
|
}
|
|
1631
1632
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1632
1633
|
}
|
|
@@ -1709,28 +1710,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1709
1710
|
)
|
|
1710
1711
|
);
|
|
1711
1712
|
}
|
|
1712
|
-
function assertNodePath(
|
|
1713
|
+
function assertNodePath(path10) {
|
|
1713
1714
|
invariant(
|
|
1714
|
-
|
|
1715
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1715
|
+
path10 && !Array.isArray(path10),
|
|
1716
|
+
`Expected a Path, but got ${Array.isArray(path10) ? "an array" : path10}`
|
|
1716
1717
|
);
|
|
1717
1718
|
}
|
|
1718
|
-
function assertNodePathIsStatement(
|
|
1719
|
+
function assertNodePathIsStatement(path10) {
|
|
1719
1720
|
invariant(
|
|
1720
|
-
|
|
1721
|
-
`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}`
|
|
1722
1723
|
);
|
|
1723
1724
|
}
|
|
1724
|
-
function assertNodePathIsVariableDeclarator(
|
|
1725
|
+
function assertNodePathIsVariableDeclarator(path10) {
|
|
1725
1726
|
invariant(
|
|
1726
|
-
|
|
1727
|
-
`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}`
|
|
1728
1729
|
);
|
|
1729
1730
|
}
|
|
1730
|
-
function assertNodePathIsPattern(
|
|
1731
|
+
function assertNodePathIsPattern(path10) {
|
|
1731
1732
|
invariant(
|
|
1732
|
-
|
|
1733
|
-
`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}`
|
|
1734
1735
|
);
|
|
1735
1736
|
}
|
|
1736
1737
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1766,8 +1767,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1766
1767
|
}
|
|
1767
1768
|
let isWithinExportDestructuring = Boolean(
|
|
1768
1769
|
identifier.findParent(
|
|
1769
|
-
(
|
|
1770
|
-
|
|
1770
|
+
(path10) => Boolean(
|
|
1771
|
+
path10.isPattern() && path10.parentPath?.isVariableDeclarator() && path10.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1771
1772
|
)
|
|
1772
1773
|
)
|
|
1773
1774
|
);
|
|
@@ -1845,7 +1846,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1845
1846
|
for (let specifier of node.specifiers) {
|
|
1846
1847
|
if (t.isIdentifier(specifier.exported)) {
|
|
1847
1848
|
let name = specifier.exported.name;
|
|
1848
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1849
|
+
let specifierPath = exportPath.get("specifiers").find((path10) => path10.node === specifier);
|
|
1849
1850
|
invariant(
|
|
1850
1851
|
specifierPath,
|
|
1851
1852
|
`Expected to find specifier path for ${name}`
|
|
@@ -1862,22 +1863,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1862
1863
|
}
|
|
1863
1864
|
);
|
|
1864
1865
|
}
|
|
1865
|
-
function getDependentIdentifiersForPath(
|
|
1866
|
+
function getDependentIdentifiersForPath(path10, state) {
|
|
1866
1867
|
let { visited, identifiers } = state ?? {
|
|
1867
1868
|
visited: /* @__PURE__ */ new Set(),
|
|
1868
1869
|
identifiers: /* @__PURE__ */ new Set()
|
|
1869
1870
|
};
|
|
1870
|
-
if (visited.has(
|
|
1871
|
+
if (visited.has(path10)) {
|
|
1871
1872
|
return identifiers;
|
|
1872
1873
|
}
|
|
1873
|
-
visited.add(
|
|
1874
|
-
|
|
1875
|
-
Identifier(
|
|
1876
|
-
if (identifiers.has(
|
|
1874
|
+
visited.add(path10);
|
|
1875
|
+
path10.traverse({
|
|
1876
|
+
Identifier(path11) {
|
|
1877
|
+
if (identifiers.has(path11)) {
|
|
1877
1878
|
return;
|
|
1878
1879
|
}
|
|
1879
|
-
identifiers.add(
|
|
1880
|
-
let binding =
|
|
1880
|
+
identifiers.add(path11);
|
|
1881
|
+
let binding = path11.scope.getBinding(path11.node.name);
|
|
1881
1882
|
if (!binding) {
|
|
1882
1883
|
return;
|
|
1883
1884
|
}
|
|
@@ -1899,7 +1900,7 @@ function getDependentIdentifiersForPath(path9, state) {
|
|
|
1899
1900
|
}
|
|
1900
1901
|
}
|
|
1901
1902
|
});
|
|
1902
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1903
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path10);
|
|
1903
1904
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1904
1905
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1905
1906
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1908,9 +1909,9 @@ function getDependentIdentifiersForPath(path9, state) {
|
|
|
1908
1909
|
identifiers
|
|
1909
1910
|
});
|
|
1910
1911
|
}
|
|
1911
|
-
if (withinExportStatement &&
|
|
1912
|
-
t.isPattern(
|
|
1913
|
-
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());
|
|
1914
1915
|
assertNodePath(variableDeclarator);
|
|
1915
1916
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1916
1917
|
visited,
|
|
@@ -1919,16 +1920,16 @@ function getDependentIdentifiersForPath(path9, state) {
|
|
|
1919
1920
|
}
|
|
1920
1921
|
return identifiers;
|
|
1921
1922
|
}
|
|
1922
|
-
function getTopLevelStatementPathForPath(
|
|
1923
|
-
let ancestry =
|
|
1923
|
+
function getTopLevelStatementPathForPath(path10) {
|
|
1924
|
+
let ancestry = path10.getAncestry();
|
|
1924
1925
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1925
1926
|
assertNodePathIsStatement(topLevelStatement);
|
|
1926
1927
|
return topLevelStatement;
|
|
1927
1928
|
}
|
|
1928
1929
|
function getTopLevelStatementsForPaths(paths) {
|
|
1929
1930
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1930
|
-
for (let
|
|
1931
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1931
|
+
for (let path10 of paths) {
|
|
1932
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path10);
|
|
1932
1933
|
topLevelStatements.add(topLevelStatement.node);
|
|
1933
1934
|
}
|
|
1934
1935
|
return topLevelStatements;
|
|
@@ -2322,24 +2323,24 @@ function isNamedComponentExport(name) {
|
|
|
2322
2323
|
}
|
|
2323
2324
|
var decorateComponentExportsWithProps = (ast) => {
|
|
2324
2325
|
const hocs = [];
|
|
2325
|
-
function getHocUid(
|
|
2326
|
-
const uid =
|
|
2326
|
+
function getHocUid(path10, hocName) {
|
|
2327
|
+
const uid = path10.scope.generateUidIdentifier(hocName);
|
|
2327
2328
|
hocs.push([hocName, uid]);
|
|
2328
2329
|
return uid;
|
|
2329
2330
|
}
|
|
2330
2331
|
traverse(ast, {
|
|
2331
|
-
ExportDeclaration(
|
|
2332
|
-
if (
|
|
2333
|
-
const declaration =
|
|
2332
|
+
ExportDeclaration(path10) {
|
|
2333
|
+
if (path10.isExportDefaultDeclaration()) {
|
|
2334
|
+
const declaration = path10.get("declaration");
|
|
2334
2335
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2335
2336
|
if (expr) {
|
|
2336
|
-
const uid = getHocUid(
|
|
2337
|
+
const uid = getHocUid(path10, "UNSAFE_withComponentProps");
|
|
2337
2338
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2338
2339
|
}
|
|
2339
2340
|
return;
|
|
2340
2341
|
}
|
|
2341
|
-
if (
|
|
2342
|
-
const decl =
|
|
2342
|
+
if (path10.isExportNamedDeclaration()) {
|
|
2343
|
+
const decl = path10.get("declaration");
|
|
2343
2344
|
if (decl.isVariableDeclaration()) {
|
|
2344
2345
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2345
2346
|
const id = varDeclarator.get("id");
|
|
@@ -2349,7 +2350,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2349
2350
|
if (!id.isIdentifier()) return;
|
|
2350
2351
|
const { name } = id.node;
|
|
2351
2352
|
if (!isNamedComponentExport(name)) return;
|
|
2352
|
-
const uid = getHocUid(
|
|
2353
|
+
const uid = getHocUid(path10, `UNSAFE_with${name}Props`);
|
|
2353
2354
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2354
2355
|
});
|
|
2355
2356
|
return;
|
|
@@ -2359,7 +2360,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2359
2360
|
if (!id) return;
|
|
2360
2361
|
const { name } = id;
|
|
2361
2362
|
if (!isNamedComponentExport(name)) return;
|
|
2362
|
-
const uid = getHocUid(
|
|
2363
|
+
const uid = getHocUid(path10, `UNSAFE_with${name}Props`);
|
|
2363
2364
|
decl.replaceWith(
|
|
2364
2365
|
t.variableDeclaration("const", [
|
|
2365
2366
|
t.variableDeclarator(
|
|
@@ -2480,6 +2481,222 @@ function warnOnClientSourceMaps() {
|
|
|
2480
2481
|
};
|
|
2481
2482
|
}
|
|
2482
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
|
+
|
|
2483
2700
|
// vite/plugin.ts
|
|
2484
2701
|
function extractPluginContext(viteConfig) {
|
|
2485
2702
|
return viteConfig["__reactRouterPluginContext"];
|
|
@@ -2541,8 +2758,8 @@ var virtualHmrRuntime = create("hmr-runtime");
|
|
|
2541
2758
|
var virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
2542
2759
|
var normalizeRelativeFilePath = (file, reactRouterConfig) => {
|
|
2543
2760
|
let vite2 = getVite();
|
|
2544
|
-
let fullPath =
|
|
2545
|
-
let relativePath =
|
|
2761
|
+
let fullPath = path7.resolve(reactRouterConfig.appDirectory, file);
|
|
2762
|
+
let relativePath = path7.relative(reactRouterConfig.appDirectory, fullPath);
|
|
2546
2763
|
return vite2.normalizePath(relativePath).split("?")[0];
|
|
2547
2764
|
};
|
|
2548
2765
|
var virtual = {
|
|
@@ -2565,7 +2782,7 @@ var getHash = (source, maxLength) => {
|
|
|
2565
2782
|
var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
|
|
2566
2783
|
let vite2 = getVite();
|
|
2567
2784
|
let rootRelativeFilePath = vite2.normalizePath(
|
|
2568
|
-
|
|
2785
|
+
path7.relative(ctx.rootDirectory, absoluteFilePath)
|
|
2569
2786
|
);
|
|
2570
2787
|
let entryChunk = viteManifest[rootRelativeFilePath];
|
|
2571
2788
|
if (!entryChunk) {
|
|
@@ -2656,7 +2873,7 @@ function resolveDependantChunks(viteManifest, entryChunks) {
|
|
|
2656
2873
|
function getAllDynamicCssFiles(ctx, viteManifest) {
|
|
2657
2874
|
let allDynamicCssFiles = /* @__PURE__ */ new Set();
|
|
2658
2875
|
for (let route of Object.values(ctx.reactRouterConfig.routes)) {
|
|
2659
|
-
let routeFile =
|
|
2876
|
+
let routeFile = path7.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
2660
2877
|
let entryChunk = resolveChunk(
|
|
2661
2878
|
ctx,
|
|
2662
2879
|
viteManifest,
|
|
@@ -2695,8 +2912,8 @@ function dedupe(array2) {
|
|
|
2695
2912
|
return [...new Set(array2)];
|
|
2696
2913
|
}
|
|
2697
2914
|
var writeFileSafe = async (file, contents) => {
|
|
2698
|
-
await (0,
|
|
2699
|
-
await (0,
|
|
2915
|
+
await (0, import_promises3.mkdir)(path7.dirname(file), { recursive: true });
|
|
2916
|
+
await (0, import_promises3.writeFile)(file, contents);
|
|
2700
2917
|
};
|
|
2701
2918
|
var getExportNames = (code) => {
|
|
2702
2919
|
let [, exportSpecifiers] = (0, import_es_module_lexer.parse)(code);
|
|
@@ -2721,7 +2938,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2721
2938
|
}
|
|
2722
2939
|
let ssr = true;
|
|
2723
2940
|
let { pluginContainer, moduleGraph } = viteChildCompiler;
|
|
2724
|
-
let routePath =
|
|
2941
|
+
let routePath = path7.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
|
|
2725
2942
|
let url2 = resolveFileUrl(ctx, routePath);
|
|
2726
2943
|
let resolveId = async () => {
|
|
2727
2944
|
let result = await pluginContainer.resolveId(url2, void 0, { ssr });
|
|
@@ -2730,7 +2947,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
|
|
|
2730
2947
|
};
|
|
2731
2948
|
let [id, code] = await Promise.all([
|
|
2732
2949
|
resolveId(),
|
|
2733
|
-
readRouteFile?.() ?? (0,
|
|
2950
|
+
readRouteFile?.() ?? (0, import_promises3.readFile)(routePath, "utf-8"),
|
|
2734
2951
|
// pluginContainer.transform(...) fails if we don't do this first:
|
|
2735
2952
|
moduleGraph.ensureEntryFromUrl(url2, ssr)
|
|
2736
2953
|
]);
|
|
@@ -2763,12 +2980,12 @@ var resolveEnvironmentBuildContext = ({
|
|
|
2763
2980
|
};
|
|
2764
2981
|
return resolvedBuildContext;
|
|
2765
2982
|
};
|
|
2766
|
-
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) =>
|
|
2983
|
+
var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path7.join(
|
|
2767
2984
|
reactRouterConfig.buildDirectory,
|
|
2768
2985
|
"server",
|
|
2769
2986
|
...serverBundleId ? [serverBundleId] : []
|
|
2770
2987
|
);
|
|
2771
|
-
var getClientBuildDirectory = (reactRouterConfig) =>
|
|
2988
|
+
var getClientBuildDirectory = (reactRouterConfig) => path7.join(reactRouterConfig.buildDirectory, "client");
|
|
2772
2989
|
var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
2773
2990
|
if (!ctx.buildManifest) {
|
|
2774
2991
|
return void 0;
|
|
@@ -2786,14 +3003,14 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
|
|
|
2786
3003
|
);
|
|
2787
3004
|
return Object.keys(serverBundleRoutes);
|
|
2788
3005
|
};
|
|
2789
|
-
var defaultEntriesDir =
|
|
2790
|
-
|
|
3006
|
+
var defaultEntriesDir = path7.resolve(
|
|
3007
|
+
path7.dirname(require.resolve("@react-router/dev/package.json")),
|
|
2791
3008
|
"dist",
|
|
2792
3009
|
"config",
|
|
2793
3010
|
"defaults"
|
|
2794
3011
|
);
|
|
2795
3012
|
var defaultEntries = (0, import_node_fs2.readdirSync)(defaultEntriesDir).map(
|
|
2796
|
-
(filename2) =>
|
|
3013
|
+
(filename2) => path7.join(defaultEntriesDir, filename2)
|
|
2797
3014
|
);
|
|
2798
3015
|
invariant(defaultEntries.length > 0, "No default entries found");
|
|
2799
3016
|
var reactRouterDevLoadContext = () => void 0;
|
|
@@ -2843,6 +3060,8 @@ var reactRouterVitePlugin = () => {
|
|
|
2843
3060
|
firstLoad = false;
|
|
2844
3061
|
ctx = {
|
|
2845
3062
|
environmentBuildContext,
|
|
3063
|
+
reactRouterManifest: null,
|
|
3064
|
+
prerenderPaths: null,
|
|
2846
3065
|
reactRouterConfig,
|
|
2847
3066
|
rootDirectory,
|
|
2848
3067
|
entryClientFilePath,
|
|
@@ -2867,6 +3086,12 @@ var reactRouterVitePlugin = () => {
|
|
|
2867
3086
|
ctx.reactRouterConfig.ssr,
|
|
2868
3087
|
routes
|
|
2869
3088
|
);
|
|
3089
|
+
if (!ctx.prerenderPaths) {
|
|
3090
|
+
ctx.prerenderPaths = /* @__PURE__ */ new Set();
|
|
3091
|
+
}
|
|
3092
|
+
for (let path10 of prerenderPaths) {
|
|
3093
|
+
ctx.prerenderPaths.add(path10);
|
|
3094
|
+
}
|
|
2870
3095
|
let isSpaMode = isSpaModeEnabled(ctx.reactRouterConfig);
|
|
2871
3096
|
return `
|
|
2872
3097
|
import * as entryServer from ${JSON.stringify(
|
|
@@ -2889,7 +3114,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2889
3114
|
virtual.serverManifest.id
|
|
2890
3115
|
)};
|
|
2891
3116
|
export const assetsBuildDirectory = ${JSON.stringify(
|
|
2892
|
-
|
|
3117
|
+
path7.relative(
|
|
2893
3118
|
ctx.rootDirectory,
|
|
2894
3119
|
getClientBuildDirectory(ctx.reactRouterConfig)
|
|
2895
3120
|
)
|
|
@@ -2929,8 +3154,8 @@ var reactRouterVitePlugin = () => {
|
|
|
2929
3154
|
`;
|
|
2930
3155
|
};
|
|
2931
3156
|
let loadViteManifest = async (directory) => {
|
|
2932
|
-
let manifestContents = await (0,
|
|
2933
|
-
|
|
3157
|
+
let manifestContents = await (0, import_promises3.readFile)(
|
|
3158
|
+
path7.resolve(directory, ".vite", "manifest.json"),
|
|
2934
3159
|
"utf-8"
|
|
2935
3160
|
);
|
|
2936
3161
|
return JSON.parse(manifestContents);
|
|
@@ -2954,8 +3179,8 @@ var reactRouterVitePlugin = () => {
|
|
|
2954
3179
|
const entryNormalizedPath = "parentPath" in entry && typeof entry.parentPath === "string" ? entry.parentPath : entry.path;
|
|
2955
3180
|
let contents;
|
|
2956
3181
|
try {
|
|
2957
|
-
contents = await (0,
|
|
2958
|
-
|
|
3182
|
+
contents = await (0, import_promises3.readFile)(
|
|
3183
|
+
path7.join(entryNormalizedPath, entry.name),
|
|
2959
3184
|
"utf-8"
|
|
2960
3185
|
);
|
|
2961
3186
|
} catch (e) {
|
|
@@ -2964,9 +3189,9 @@ var reactRouterVitePlugin = () => {
|
|
|
2964
3189
|
}
|
|
2965
3190
|
let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
|
|
2966
3191
|
let filepath = getVite().normalizePath(
|
|
2967
|
-
|
|
3192
|
+
path7.relative(
|
|
2968
3193
|
clientBuildDirectory,
|
|
2969
|
-
|
|
3194
|
+
path7.join(entryNormalizedPath, entry.name)
|
|
2970
3195
|
)
|
|
2971
3196
|
);
|
|
2972
3197
|
sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
|
|
@@ -2999,7 +3224,7 @@ var reactRouterVitePlugin = () => {
|
|
|
2999
3224
|
);
|
|
3000
3225
|
let enforceSplitRouteModules = ctx.reactRouterConfig.future.v8_splitRouteModules === "enforce";
|
|
3001
3226
|
for (let route of Object.values(ctx.reactRouterConfig.routes)) {
|
|
3002
|
-
let routeFile =
|
|
3227
|
+
let routeFile = path7.join(ctx.reactRouterConfig.appDirectory, route.file);
|
|
3003
3228
|
let sourceExports = routeManifestExports[route.id];
|
|
3004
3229
|
let hasClientAction = sourceExports.includes("clientAction");
|
|
3005
3230
|
let hasClientLoader = sourceExports.includes("clientLoader");
|
|
@@ -3034,6 +3259,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3034
3259
|
hasClientAction,
|
|
3035
3260
|
hasClientLoader,
|
|
3036
3261
|
hasClientMiddleware,
|
|
3262
|
+
hasDefaultExport: sourceExports.includes("default"),
|
|
3037
3263
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
3038
3264
|
...getReactRouterManifestBuildAssets(
|
|
3039
3265
|
ctx,
|
|
@@ -3071,7 +3297,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3071
3297
|
}
|
|
3072
3298
|
let fingerprintedValues = { entry, routes: browserRoutes };
|
|
3073
3299
|
let version = getHash(JSON.stringify(fingerprintedValues), 8);
|
|
3074
|
-
let manifestPath =
|
|
3300
|
+
let manifestPath = path7.posix.join(
|
|
3075
3301
|
viteConfig2.build.assetsDir,
|
|
3076
3302
|
`manifest-${version}.js`
|
|
3077
3303
|
);
|
|
@@ -3083,7 +3309,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3083
3309
|
sri: void 0
|
|
3084
3310
|
};
|
|
3085
3311
|
await writeFileSafe(
|
|
3086
|
-
|
|
3312
|
+
path7.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
|
|
3087
3313
|
`window.__reactRouterManifest=${JSON.stringify(
|
|
3088
3314
|
reactRouterBrowserManifest
|
|
3089
3315
|
)};`
|
|
@@ -3159,6 +3385,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3159
3385
|
hasClientAction,
|
|
3160
3386
|
hasClientLoader,
|
|
3161
3387
|
hasClientMiddleware,
|
|
3388
|
+
hasDefaultExport: sourceExports.includes("default"),
|
|
3162
3389
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
3163
3390
|
imports: []
|
|
3164
3391
|
};
|
|
@@ -3541,31 +3768,61 @@ var reactRouterVitePlugin = () => {
|
|
|
3541
3768
|
};
|
|
3542
3769
|
},
|
|
3543
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
|
+
}
|
|
3544
3812
|
return () => {
|
|
3545
3813
|
if (!ctx.reactRouterConfig.ssr) {
|
|
3546
3814
|
return;
|
|
3547
3815
|
}
|
|
3548
3816
|
previewServer.middlewares.use(async (req, res, next) => {
|
|
3549
3817
|
try {
|
|
3550
|
-
let
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
"index.js"
|
|
3818
|
+
let handler = await getHandler();
|
|
3819
|
+
let request = await fromNodeRequest(req, res);
|
|
3820
|
+
let response = await handler(
|
|
3821
|
+
request,
|
|
3822
|
+
await reactRouterDevLoadContext(request)
|
|
3556
3823
|
);
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
let nodeHandler = async (nodeReq, nodeRes) => {
|
|
3560
|
-
let req2 = await fromNodeRequest(nodeReq, nodeRes);
|
|
3561
|
-
let res2 = await handler(
|
|
3562
|
-
req2,
|
|
3563
|
-
await reactRouterDevLoadContext(req2)
|
|
3564
|
-
);
|
|
3565
|
-
const { sendResponse } = await import("@remix-run/node-fetch-server");
|
|
3566
|
-
await sendResponse(nodeRes, res2);
|
|
3567
|
-
};
|
|
3568
|
-
await nodeHandler(req, res);
|
|
3824
|
+
const { sendResponse } = await import("@remix-run/node-fetch-server");
|
|
3825
|
+
await sendResponse(res, response);
|
|
3569
3826
|
} catch (error) {
|
|
3570
3827
|
next(error);
|
|
3571
3828
|
}
|
|
@@ -3592,19 +3849,19 @@ var reactRouterVitePlugin = () => {
|
|
|
3592
3849
|
let removedAssetPaths = [];
|
|
3593
3850
|
let copiedAssetPaths = [];
|
|
3594
3851
|
for (let ssrAssetPath of ssrAssetPaths) {
|
|
3595
|
-
let src =
|
|
3596
|
-
let dest =
|
|
3852
|
+
let src = path7.join(serverBuildDirectory, ssrAssetPath);
|
|
3853
|
+
let dest = path7.join(clientBuildDirectory, ssrAssetPath);
|
|
3597
3854
|
if (!userSsrEmitAssets) {
|
|
3598
3855
|
if (!(0, import_node_fs2.existsSync)(dest)) {
|
|
3599
|
-
await (0,
|
|
3600
|
-
await (0,
|
|
3856
|
+
await (0, import_promises3.mkdir)(path7.dirname(dest), { recursive: true });
|
|
3857
|
+
await (0, import_promises3.rename)(src, dest);
|
|
3601
3858
|
movedAssetPaths.push(dest);
|
|
3602
3859
|
} else {
|
|
3603
|
-
await (0,
|
|
3860
|
+
await (0, import_promises3.rm)(src, { force: true, recursive: true });
|
|
3604
3861
|
removedAssetPaths.push(dest);
|
|
3605
3862
|
}
|
|
3606
3863
|
} else if (!(0, import_node_fs2.existsSync)(dest)) {
|
|
3607
|
-
await (0,
|
|
3864
|
+
await (0, import_promises3.cp)(src, dest, { recursive: true });
|
|
3608
3865
|
copiedAssetPaths.push(dest);
|
|
3609
3866
|
}
|
|
3610
3867
|
}
|
|
@@ -3614,21 +3871,21 @@ var reactRouterVitePlugin = () => {
|
|
|
3614
3871
|
);
|
|
3615
3872
|
await Promise.all(
|
|
3616
3873
|
ssrCssPaths.map(async (cssPath) => {
|
|
3617
|
-
let src =
|
|
3618
|
-
await (0,
|
|
3874
|
+
let src = path7.join(serverBuildDirectory, cssPath);
|
|
3875
|
+
await (0, import_promises3.rm)(src, { force: true, recursive: true });
|
|
3619
3876
|
removedAssetPaths.push(src);
|
|
3620
3877
|
})
|
|
3621
3878
|
);
|
|
3622
3879
|
}
|
|
3623
3880
|
let cleanedAssetPaths = [...removedAssetPaths, ...movedAssetPaths];
|
|
3624
3881
|
let handledAssetPaths = [...cleanedAssetPaths, ...copiedAssetPaths];
|
|
3625
|
-
let cleanedAssetDirs = new Set(cleanedAssetPaths.map(
|
|
3882
|
+
let cleanedAssetDirs = new Set(cleanedAssetPaths.map(path7.dirname));
|
|
3626
3883
|
await Promise.all(
|
|
3627
3884
|
Array.from(cleanedAssetDirs).map(async (dir) => {
|
|
3628
3885
|
try {
|
|
3629
|
-
const files = await (0,
|
|
3886
|
+
const files = await (0, import_promises3.readdir)(dir, { recursive: true });
|
|
3630
3887
|
if (files.length === 0) {
|
|
3631
|
-
await (0,
|
|
3888
|
+
await (0, import_promises3.rm)(dir, { force: true, recursive: true });
|
|
3632
3889
|
}
|
|
3633
3890
|
} catch {
|
|
3634
3891
|
}
|
|
@@ -3644,7 +3901,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3644
3901
|
[
|
|
3645
3902
|
`${import_picocolors4.default.green("\u2713")} ${message}`,
|
|
3646
3903
|
...paths.map(
|
|
3647
|
-
(assetPath) => import_picocolors4.default.dim(
|
|
3904
|
+
(assetPath) => import_picocolors4.default.dim(path7.relative(ctx.rootDirectory, assetPath))
|
|
3648
3905
|
)
|
|
3649
3906
|
].join("\n")
|
|
3650
3907
|
);
|
|
@@ -3665,6 +3922,9 @@ var reactRouterVitePlugin = () => {
|
|
|
3665
3922
|
if (handledAssetPaths.length) {
|
|
3666
3923
|
viteConfig.logger.info("");
|
|
3667
3924
|
}
|
|
3925
|
+
if (future.unstable_previewServerPrerendering) {
|
|
3926
|
+
return;
|
|
3927
|
+
}
|
|
3668
3928
|
process.env.IS_RR_BUILD_REQUEST = "yes";
|
|
3669
3929
|
if (isPrerenderingEnabled(ctx.reactRouterConfig)) {
|
|
3670
3930
|
await handlePrerender(
|
|
@@ -3738,7 +3998,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3738
3998
|
);
|
|
3739
3999
|
let isMainChunkExport = (name) => !chunkedExports.includes(name);
|
|
3740
4000
|
let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
|
|
3741
|
-
let chunkBasePath = `./${
|
|
4001
|
+
let chunkBasePath = `./${path7.basename(id)}`;
|
|
3742
4002
|
return [
|
|
3743
4003
|
`export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
|
|
3744
4004
|
chunkBasePath,
|
|
@@ -3758,7 +4018,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3758
4018
|
async transform(code, id, options) {
|
|
3759
4019
|
if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
|
|
3760
4020
|
let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
|
|
3761
|
-
let routeFileName =
|
|
4021
|
+
let routeFileName = path7.basename(routeModuleId);
|
|
3762
4022
|
let sourceExports = await getRouteModuleExports(
|
|
3763
4023
|
viteChildCompiler,
|
|
3764
4024
|
ctx,
|
|
@@ -3838,6 +4098,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3838
4098
|
viteConfig,
|
|
3839
4099
|
routeIds
|
|
3840
4100
|
})).reactRouterServerManifest : await getReactRouterManifestForDev();
|
|
4101
|
+
ctx.reactRouterManifest = reactRouterManifest;
|
|
3841
4102
|
if (!ctx.reactRouterConfig.ssr) {
|
|
3842
4103
|
invariant(viteConfig);
|
|
3843
4104
|
validateSsrFalsePrerenderExports(
|
|
@@ -3885,7 +4146,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3885
4146
|
}
|
|
3886
4147
|
let vite2 = getVite();
|
|
3887
4148
|
let importerShort = vite2.normalizePath(
|
|
3888
|
-
|
|
4149
|
+
path7.relative(ctx.rootDirectory, importer)
|
|
3889
4150
|
);
|
|
3890
4151
|
if (isRoute(ctx.reactRouterConfig, importer)) {
|
|
3891
4152
|
let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
|
|
@@ -4007,17 +4268,17 @@ var reactRouterVitePlugin = () => {
|
|
|
4007
4268
|
},
|
|
4008
4269
|
async load(id) {
|
|
4009
4270
|
if (id !== virtualHmrRuntime.resolvedId) return;
|
|
4010
|
-
let reactRefreshDir =
|
|
4271
|
+
let reactRefreshDir = path7.dirname(
|
|
4011
4272
|
require.resolve("react-refresh/package.json")
|
|
4012
4273
|
);
|
|
4013
|
-
let reactRefreshRuntimePath =
|
|
4274
|
+
let reactRefreshRuntimePath = path7.join(
|
|
4014
4275
|
reactRefreshDir,
|
|
4015
4276
|
"cjs/react-refresh-runtime.development.js"
|
|
4016
4277
|
);
|
|
4017
4278
|
return [
|
|
4018
4279
|
"const exports = {}",
|
|
4019
|
-
await (0,
|
|
4020
|
-
await (0,
|
|
4280
|
+
await (0, import_promises3.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
4281
|
+
await (0, import_promises3.readFile)(require.resolve("./static/refresh-utils.mjs"), "utf8"),
|
|
4021
4282
|
"export default exports"
|
|
4022
4283
|
].join("\n");
|
|
4023
4284
|
}
|
|
@@ -4117,6 +4378,223 @@ var reactRouterVitePlugin = () => {
|
|
|
4117
4378
|
}
|
|
4118
4379
|
}
|
|
4119
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
|
+
}),
|
|
4120
4598
|
validatePluginOrder(),
|
|
4121
4599
|
warnOnClientSourceMaps()
|
|
4122
4600
|
];
|
|
@@ -4180,7 +4658,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
4180
4658
|
function getRoute(pluginConfig, file) {
|
|
4181
4659
|
let vite2 = getVite();
|
|
4182
4660
|
let routePath = vite2.normalizePath(
|
|
4183
|
-
|
|
4661
|
+
path7.relative(pluginConfig.appDirectory, file)
|
|
4184
4662
|
);
|
|
4185
4663
|
let route = Object.values(pluginConfig.routes).find(
|
|
4186
4664
|
(r) => vite2.normalizePath(r.file) === routePath
|
|
@@ -4219,7 +4697,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
4219
4697
|
caseSensitive: route.caseSensitive,
|
|
4220
4698
|
url: combineURLs(
|
|
4221
4699
|
ctx.publicPath,
|
|
4222
|
-
"/" +
|
|
4700
|
+
"/" + path7.relative(
|
|
4223
4701
|
ctx.rootDirectory,
|
|
4224
4702
|
resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
|
|
4225
4703
|
)
|
|
@@ -4235,6 +4713,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
|
|
|
4235
4713
|
hasLoader: sourceExports.includes("loader"),
|
|
4236
4714
|
hasClientLoader: sourceExports.includes("clientLoader"),
|
|
4237
4715
|
hasClientMiddleware: sourceExports.includes("clientMiddleware"),
|
|
4716
|
+
hasDefaultExport: sourceExports.includes("default"),
|
|
4238
4717
|
hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
|
|
4239
4718
|
imports: []
|
|
4240
4719
|
};
|
|
@@ -4247,7 +4726,7 @@ function isSpaModeEnabled(reactRouterConfig) {
|
|
|
4247
4726
|
return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
|
|
4248
4727
|
}
|
|
4249
4728
|
async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
|
|
4250
|
-
let serverBuildPath =
|
|
4729
|
+
let serverBuildPath = path7.join(serverBuildDirectory, serverBuildFile);
|
|
4251
4730
|
let build = await import(url.pathToFileURL(serverBuildPath).toString());
|
|
4252
4731
|
let { createRequestHandler: createHandler } = await import("react-router");
|
|
4253
4732
|
return {
|
|
@@ -4289,9 +4768,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
|
|
|
4289
4768
|
"SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
|
|
4290
4769
|
);
|
|
4291
4770
|
}
|
|
4292
|
-
await (0,
|
|
4293
|
-
let prettyDir =
|
|
4294
|
-
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);
|
|
4295
4774
|
if (build.prerender.length > 0) {
|
|
4296
4775
|
viteConfig.logger.info(
|
|
4297
4776
|
`Prerender (html): SPA Fallback -> ${import_picocolors4.default.bold(prettyPath)}`
|
|
@@ -4307,17 +4786,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4307
4786
|
serverBuildPath
|
|
4308
4787
|
);
|
|
4309
4788
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
4310
|
-
for (let
|
|
4311
|
-
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(/^\/\/+/, "/"));
|
|
4312
4791
|
if (!matches) {
|
|
4313
4792
|
throw new Error(
|
|
4314
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4793
|
+
`Unable to prerender path because it does not match any routes: ${path10}`
|
|
4315
4794
|
);
|
|
4316
4795
|
}
|
|
4317
4796
|
}
|
|
4318
4797
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
4319
|
-
let prerenderSinglePath = async (
|
|
4320
|
-
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${
|
|
4798
|
+
let prerenderSinglePath = async (path10) => {
|
|
4799
|
+
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path10}/`.replace(/^\/\/+/, "/"));
|
|
4321
4800
|
if (!matches) {
|
|
4322
4801
|
return;
|
|
4323
4802
|
}
|
|
@@ -4330,7 +4809,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4330
4809
|
if (manifestRoute.loader) {
|
|
4331
4810
|
await prerenderData(
|
|
4332
4811
|
handler,
|
|
4333
|
-
|
|
4812
|
+
path10,
|
|
4334
4813
|
[leafRoute.id],
|
|
4335
4814
|
clientBuildDirectory,
|
|
4336
4815
|
reactRouterConfig,
|
|
@@ -4338,7 +4817,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4338
4817
|
);
|
|
4339
4818
|
await prerenderResourceRoute(
|
|
4340
4819
|
handler,
|
|
4341
|
-
|
|
4820
|
+
path10,
|
|
4342
4821
|
clientBuildDirectory,
|
|
4343
4822
|
reactRouterConfig,
|
|
4344
4823
|
viteConfig
|
|
@@ -4356,7 +4835,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4356
4835
|
if (!isResourceRoute && hasLoaders) {
|
|
4357
4836
|
data = await prerenderData(
|
|
4358
4837
|
handler,
|
|
4359
|
-
|
|
4838
|
+
path10,
|
|
4360
4839
|
null,
|
|
4361
4840
|
clientBuildDirectory,
|
|
4362
4841
|
reactRouterConfig,
|
|
@@ -4365,7 +4844,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4365
4844
|
}
|
|
4366
4845
|
await prerenderRoute(
|
|
4367
4846
|
handler,
|
|
4368
|
-
|
|
4847
|
+
path10,
|
|
4369
4848
|
clientBuildDirectory,
|
|
4370
4849
|
reactRouterConfig,
|
|
4371
4850
|
viteConfig,
|
|
@@ -4378,9 +4857,9 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4378
4857
|
}
|
|
4379
4858
|
};
|
|
4380
4859
|
let concurrency = 1;
|
|
4381
|
-
let { prerender } = reactRouterConfig;
|
|
4382
|
-
if (typeof
|
|
4383
|
-
concurrency =
|
|
4860
|
+
let { prerender: prerender2 } = reactRouterConfig;
|
|
4861
|
+
if (typeof prerender2 === "object" && "unstable_concurrency" in prerender2) {
|
|
4862
|
+
concurrency = prerender2.unstable_concurrency ?? 1;
|
|
4384
4863
|
}
|
|
4385
4864
|
const pMap = await import("p-map");
|
|
4386
4865
|
await pMap.default(build.prerender, prerenderSinglePath, { concurrency });
|
|
@@ -4439,12 +4918,12 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
|
|
|
4439
4918
|
${normalizedPath}`
|
|
4440
4919
|
);
|
|
4441
4920
|
}
|
|
4442
|
-
let outfile =
|
|
4443
|
-
await (0,
|
|
4444
|
-
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);
|
|
4445
4924
|
viteConfig.logger.info(
|
|
4446
4925
|
`Prerender (data): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4447
|
-
|
|
4926
|
+
path7.relative(viteConfig.root, outfile)
|
|
4448
4927
|
)}`
|
|
4449
4928
|
);
|
|
4450
4929
|
return data;
|
|
@@ -4479,16 +4958,16 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
|
|
|
4479
4958
|
${html}`
|
|
4480
4959
|
);
|
|
4481
4960
|
}
|
|
4482
|
-
let outfile =
|
|
4961
|
+
let outfile = path7.join(
|
|
4483
4962
|
clientBuildDirectory,
|
|
4484
4963
|
...normalizedPath.split("/"),
|
|
4485
4964
|
"index.html"
|
|
4486
4965
|
);
|
|
4487
|
-
await (0,
|
|
4488
|
-
await (0,
|
|
4966
|
+
await (0, import_promises3.mkdir)(path7.dirname(outfile), { recursive: true });
|
|
4967
|
+
await (0, import_promises3.writeFile)(outfile, html);
|
|
4489
4968
|
viteConfig.logger.info(
|
|
4490
4969
|
`Prerender (html): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4491
|
-
|
|
4970
|
+
path7.relative(viteConfig.root, outfile)
|
|
4492
4971
|
)}`
|
|
4493
4972
|
);
|
|
4494
4973
|
}
|
|
@@ -4503,24 +4982,24 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
|
|
|
4503
4982
|
${content.toString("utf8")}`
|
|
4504
4983
|
);
|
|
4505
4984
|
}
|
|
4506
|
-
let outfile =
|
|
4507
|
-
await (0,
|
|
4508
|
-
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);
|
|
4509
4988
|
viteConfig.logger.info(
|
|
4510
4989
|
`Prerender (resource): ${prerenderPath} -> ${import_picocolors4.default.bold(
|
|
4511
|
-
|
|
4990
|
+
path7.relative(viteConfig.root, outfile)
|
|
4512
4991
|
)}`
|
|
4513
4992
|
);
|
|
4514
4993
|
}
|
|
4515
|
-
async function getPrerenderPaths(
|
|
4516
|
-
if (
|
|
4994
|
+
async function getPrerenderPaths(prerender2, ssr, routes, logWarning = false) {
|
|
4995
|
+
if (prerender2 == null || prerender2 === false) {
|
|
4517
4996
|
return [];
|
|
4518
4997
|
}
|
|
4519
4998
|
let pathsConfig;
|
|
4520
|
-
if (typeof
|
|
4521
|
-
pathsConfig =
|
|
4999
|
+
if (typeof prerender2 === "object" && "paths" in prerender2) {
|
|
5000
|
+
pathsConfig = prerender2.paths;
|
|
4522
5001
|
} else {
|
|
4523
|
-
pathsConfig =
|
|
5002
|
+
pathsConfig = prerender2;
|
|
4524
5003
|
}
|
|
4525
5004
|
if (pathsConfig === false) {
|
|
4526
5005
|
return [];
|
|
@@ -4591,14 +5070,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4591
5070
|
}
|
|
4592
5071
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4593
5072
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4594
|
-
for (let
|
|
5073
|
+
for (let path10 of prerenderPaths) {
|
|
4595
5074
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4596
5075
|
prerenderRoutes,
|
|
4597
|
-
`/${
|
|
5076
|
+
`/${path10}/`.replace(/^\/\/+/, "/")
|
|
4598
5077
|
);
|
|
4599
5078
|
invariant(
|
|
4600
5079
|
matches,
|
|
4601
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
5080
|
+
`Unable to prerender path because it does not match any routes: ${path10}`
|
|
4602
5081
|
);
|
|
4603
5082
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4604
5083
|
}
|
|
@@ -4765,11 +5244,11 @@ function validateRouteChunks({
|
|
|
4765
5244
|
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
4766
5245
|
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
4767
5246
|
let isWithinRoot = () => {
|
|
4768
|
-
let relativePath =
|
|
4769
|
-
return !relativePath.startsWith("..") && !
|
|
5247
|
+
let relativePath = path7.relative(ctx.rootDirectory, buildDirectory);
|
|
5248
|
+
return !relativePath.startsWith("..") && !path7.isAbsolute(relativePath);
|
|
4770
5249
|
};
|
|
4771
5250
|
if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
|
|
4772
|
-
await (0,
|
|
5251
|
+
await (0, import_promises3.rm)(buildDirectory, { force: true, recursive: true });
|
|
4773
5252
|
}
|
|
4774
5253
|
}
|
|
4775
5254
|
async function cleanViteManifests(environmentsOptions, ctx) {
|
|
@@ -4777,7 +5256,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4777
5256
|
([environmentName, options]) => {
|
|
4778
5257
|
let outDir = options.build?.outDir;
|
|
4779
5258
|
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
4780
|
-
return
|
|
5259
|
+
return path7.join(outDir, ".vite/manifest.json");
|
|
4781
5260
|
}
|
|
4782
5261
|
);
|
|
4783
5262
|
await Promise.all(
|
|
@@ -4785,12 +5264,12 @@ async function cleanViteManifests(environmentsOptions, ctx) {
|
|
|
4785
5264
|
let manifestExists = (0, import_node_fs2.existsSync)(viteManifestPath);
|
|
4786
5265
|
if (!manifestExists) return;
|
|
4787
5266
|
if (!ctx.viteManifestEnabled) {
|
|
4788
|
-
await (0,
|
|
5267
|
+
await (0, import_promises3.rm)(viteManifestPath, { force: true, recursive: true });
|
|
4789
5268
|
}
|
|
4790
|
-
let viteDir =
|
|
4791
|
-
let viteDirFiles = await (0,
|
|
5269
|
+
let viteDir = path7.dirname(viteManifestPath);
|
|
5270
|
+
let viteDirFiles = await (0, import_promises3.readdir)(viteDir, { recursive: true });
|
|
4792
5271
|
if (viteDirFiles.length === 0) {
|
|
4793
|
-
await (0,
|
|
5272
|
+
await (0, import_promises3.rm)(viteDir, { force: true, recursive: true });
|
|
4794
5273
|
}
|
|
4795
5274
|
})
|
|
4796
5275
|
);
|
|
@@ -4805,12 +5284,12 @@ async function getBuildManifest({
|
|
|
4805
5284
|
}
|
|
4806
5285
|
let { normalizePath } = await import("vite");
|
|
4807
5286
|
let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
|
|
4808
|
-
let resolvedAppDirectory =
|
|
5287
|
+
let resolvedAppDirectory = path7.resolve(rootDirectory, appDirectory);
|
|
4809
5288
|
let rootRelativeRoutes = Object.fromEntries(
|
|
4810
5289
|
Object.entries(routes).map(([id, route]) => {
|
|
4811
|
-
let filePath =
|
|
5290
|
+
let filePath = path7.join(resolvedAppDirectory, route.file);
|
|
4812
5291
|
let rootRelativeFilePath = normalizePath(
|
|
4813
|
-
|
|
5292
|
+
path7.relative(rootDirectory, filePath)
|
|
4814
5293
|
);
|
|
4815
5294
|
return [id, { ...route, file: rootRelativeFilePath }];
|
|
4816
5295
|
})
|
|
@@ -4828,7 +5307,7 @@ async function getBuildManifest({
|
|
|
4828
5307
|
(route2) => configRouteToBranchRoute({
|
|
4829
5308
|
...route2,
|
|
4830
5309
|
// Ensure absolute paths are passed to the serverBundles function
|
|
4831
|
-
file:
|
|
5310
|
+
file: path7.join(resolvedAppDirectory, route2.file)
|
|
4832
5311
|
})
|
|
4833
5312
|
)
|
|
4834
5313
|
});
|
|
@@ -4852,10 +5331,10 @@ async function getBuildManifest({
|
|
|
4852
5331
|
buildManifest.serverBundles[serverBundleId] ??= {
|
|
4853
5332
|
id: serverBundleId,
|
|
4854
5333
|
file: normalizePath(
|
|
4855
|
-
|
|
4856
|
-
|
|
5334
|
+
path7.join(
|
|
5335
|
+
path7.relative(
|
|
4857
5336
|
rootDirectory,
|
|
4858
|
-
|
|
5337
|
+
path7.join(serverBuildDirectory, serverBundleId)
|
|
4859
5338
|
),
|
|
4860
5339
|
reactRouterConfig.serverBuildFile
|
|
4861
5340
|
)
|
|
@@ -4874,10 +5353,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
|
|
|
4874
5353
|
}
|
|
4875
5354
|
async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
4876
5355
|
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
4877
|
-
let packageRoot =
|
|
5356
|
+
let packageRoot = path7.dirname(
|
|
4878
5357
|
require.resolve("@react-router/dev/package.json")
|
|
4879
5358
|
);
|
|
4880
|
-
let { moduleSyncEnabled } = await import(`file:///${
|
|
5359
|
+
let { moduleSyncEnabled } = await import(`file:///${path7.join(packageRoot, "module-sync-enabled/index.mjs")}`);
|
|
4881
5360
|
let vite2 = getVite();
|
|
4882
5361
|
function getBaseOptions({
|
|
4883
5362
|
viteUserConfig
|
|
@@ -4956,7 +5435,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4956
5435
|
ctx.entryClientFilePath,
|
|
4957
5436
|
...Object.values(ctx.reactRouterConfig.routes).flatMap(
|
|
4958
5437
|
(route) => {
|
|
4959
|
-
let routeFilePath =
|
|
5438
|
+
let routeFilePath = path7.resolve(
|
|
4960
5439
|
ctx.reactRouterConfig.appDirectory,
|
|
4961
5440
|
route.file
|
|
4962
5441
|
);
|
|
@@ -4980,7 +5459,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4980
5459
|
) : null;
|
|
4981
5460
|
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
4982
5461
|
let assetsDir = (ctx.reactRouterConfig.future.v8_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
|
|
4983
|
-
return
|
|
5462
|
+
return path7.posix.join(
|
|
4984
5463
|
assetsDir,
|
|
4985
5464
|
`[name]${routeChunkSuffix}-[hash].js`
|
|
4986
5465
|
);
|
|
@@ -5046,13 +5525,78 @@ async function asyncFlatten(arr) {
|
|
|
5046
5525
|
} while (arr.some((v2) => v2?.then));
|
|
5047
5526
|
return arr;
|
|
5048
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
|
+
}
|
|
5049
5593
|
|
|
5050
5594
|
// vite/rsc/plugin.ts
|
|
5051
5595
|
var import_es_module_lexer3 = require("es-module-lexer");
|
|
5052
5596
|
var Path5 = __toESM(require("pathe"));
|
|
5053
5597
|
var babel2 = __toESM(require("@babel/core"));
|
|
5054
5598
|
var import_picocolors5 = __toESM(require("picocolors"));
|
|
5055
|
-
var
|
|
5599
|
+
var import_promises4 = require("fs/promises");
|
|
5056
5600
|
var import_pathe6 = __toESM(require("pathe"));
|
|
5057
5601
|
|
|
5058
5602
|
// vite/rsc/virtual-route-config.ts
|
|
@@ -5763,8 +6307,8 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5763
6307
|
);
|
|
5764
6308
|
return [
|
|
5765
6309
|
"const exports = {}",
|
|
5766
|
-
await (0,
|
|
5767
|
-
await (0,
|
|
6310
|
+
await (0, import_promises4.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
6311
|
+
await (0, import_promises4.readFile)(
|
|
5768
6312
|
require.resolve("./static/rsc-refresh-utils.mjs"),
|
|
5769
6313
|
"utf8"
|
|
5770
6314
|
),
|
|
@@ -5826,7 +6370,7 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
5826
6370
|
const normalizedPath = import_pathe6.default.normalize(mod.file);
|
|
5827
6371
|
const routeId = routeIdByFile?.get(normalizedPath);
|
|
5828
6372
|
if (routeId !== void 0) {
|
|
5829
|
-
const routeSource = await (0,
|
|
6373
|
+
const routeSource = await (0, import_promises4.readFile)(normalizedPath, "utf8");
|
|
5830
6374
|
const virtualRouteModuleCode = (await server.environments.rsc.pluginContainer.transform(
|
|
5831
6375
|
routeSource,
|
|
5832
6376
|
`${normalizedPath}?route-module`
|