@react-router/dev 0.0.0-experimental-ae6d61df4 → 0.0.0-experimental-4cf5bd08c
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 +31 -0
- package/dist/cli/index.js +10 -3
- package/dist/config.d.ts +0 -4
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +1 -2
- package/dist/vite.d.ts +3 -1
- package/dist/vite.js +991 -117
- package/package.json +6 -10
- package/dist/internal.d.ts +0 -9
- package/dist/internal.js +0 -2274
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-4cf5bd08c
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -40,7 +40,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
40
40
|
// vite.ts
|
|
41
41
|
var vite_exports = {};
|
|
42
42
|
__export(vite_exports, {
|
|
43
|
-
reactRouter: () => reactRouterVitePlugin
|
|
43
|
+
reactRouter: () => reactRouterVitePlugin,
|
|
44
|
+
unstable_reactRouterRSC: () => reactRouterRSCVitePlugin
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(vite_exports);
|
|
46
47
|
|
|
@@ -246,7 +247,7 @@ function validateRouteConfig({
|
|
|
246
247
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
247
248
|
root ? `${root}` : [],
|
|
248
249
|
nested ? Object.entries(nested).map(
|
|
249
|
-
([
|
|
250
|
+
([path9, message]) => `Path: routes.${path9}
|
|
250
251
|
${message}`
|
|
251
252
|
) : []
|
|
252
253
|
].flat().join("\n\n")
|
|
@@ -558,7 +559,6 @@ async function resolveConfig({
|
|
|
558
559
|
serverBundles,
|
|
559
560
|
serverModuleFormat,
|
|
560
561
|
ssr,
|
|
561
|
-
unstable_rootRouteFile: rootRouteFile,
|
|
562
562
|
unstable_routeConfig: routeConfig
|
|
563
563
|
});
|
|
564
564
|
for (let preset of reactRouterUserConfig.presets ?? []) {
|
|
@@ -618,12 +618,12 @@ async function createConfigLoader({
|
|
|
618
618
|
if (!fsWatcher) {
|
|
619
619
|
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
620
620
|
ignoreInitial: true,
|
|
621
|
-
ignored: (
|
|
622
|
-
let
|
|
623
|
-
return !
|
|
621
|
+
ignored: (path9) => {
|
|
622
|
+
let dirname5 = import_pathe3.default.dirname(path9);
|
|
623
|
+
return !dirname5.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
624
624
|
// that are at the root level, not nested in subdirectories
|
|
625
|
-
|
|
626
|
-
|
|
625
|
+
path9 !== root && // Watch the root directory itself
|
|
626
|
+
dirname5 !== root;
|
|
627
627
|
}
|
|
628
628
|
});
|
|
629
629
|
fsWatcher.on("all", async (...args) => {
|
|
@@ -883,7 +883,7 @@ function fullpath(lineage2) {
|
|
|
883
883
|
if (lineage2.length === 1 && route?.id === "root") return "/";
|
|
884
884
|
const isLayout = route && route.index !== true && route.path === void 0;
|
|
885
885
|
if (isLayout) return void 0;
|
|
886
|
-
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((
|
|
886
|
+
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path9) => path9 !== void 0 && path9 !== "").join("/");
|
|
887
887
|
}
|
|
888
888
|
|
|
889
889
|
// typegen/generate.ts
|
|
@@ -899,7 +899,7 @@ function generateFuture(ctx) {
|
|
|
899
899
|
|
|
900
900
|
declare module "react-router" {
|
|
901
901
|
interface Future {
|
|
902
|
-
|
|
902
|
+
v8_middleware: ${ctx.config.future.v8_middleware}
|
|
903
903
|
}
|
|
904
904
|
}
|
|
905
905
|
`;
|
|
@@ -1039,8 +1039,8 @@ function routeFilesType({
|
|
|
1039
1039
|
);
|
|
1040
1040
|
}
|
|
1041
1041
|
function isInAppDirectory(ctx, routeFile) {
|
|
1042
|
-
const
|
|
1043
|
-
return
|
|
1042
|
+
const path9 = Path3.resolve(ctx.config.appDirectory, routeFile);
|
|
1043
|
+
return path9.startsWith(ctx.config.appDirectory);
|
|
1044
1044
|
}
|
|
1045
1045
|
function getRouteAnnotations({
|
|
1046
1046
|
ctx,
|
|
@@ -1152,21 +1152,21 @@ function getRouteAnnotations({
|
|
|
1152
1152
|
return { filename: filename2, content };
|
|
1153
1153
|
}
|
|
1154
1154
|
function relativeImportSource(from, to) {
|
|
1155
|
-
let
|
|
1156
|
-
let extension = Path3.extname(
|
|
1157
|
-
|
|
1158
|
-
if (!
|
|
1155
|
+
let path9 = Path3.relative(Path3.dirname(from), to);
|
|
1156
|
+
let extension = Path3.extname(path9);
|
|
1157
|
+
path9 = Path3.join(Path3.dirname(path9), Pathe.filename(path9));
|
|
1158
|
+
if (!path9.startsWith("../")) path9 = "./" + path9;
|
|
1159
1159
|
if (!extension || /\.(js|ts)x?$/.test(extension)) {
|
|
1160
1160
|
extension = ".js";
|
|
1161
1161
|
}
|
|
1162
|
-
return
|
|
1162
|
+
return path9 + extension;
|
|
1163
1163
|
}
|
|
1164
1164
|
function rootDirsPath(ctx, typesPath) {
|
|
1165
1165
|
const rel = Path3.relative(typesDirectory(ctx), typesPath);
|
|
1166
1166
|
return Path3.join(ctx.rootDirectory, rel);
|
|
1167
1167
|
}
|
|
1168
|
-
function paramsType(
|
|
1169
|
-
const params = parse2(
|
|
1168
|
+
function paramsType(path9) {
|
|
1169
|
+
const params = parse2(path9);
|
|
1170
1170
|
return t2.tsTypeLiteral(
|
|
1171
1171
|
Object.entries(params).map(([param, isRequired]) => {
|
|
1172
1172
|
const property = t2.tsPropertySignature(
|
|
@@ -1502,11 +1502,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
|
|
|
1502
1502
|
let cssContent = void 0;
|
|
1503
1503
|
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1504
1504
|
traverse(ast, {
|
|
1505
|
-
VariableDeclaration(
|
|
1506
|
-
const declaration =
|
|
1505
|
+
VariableDeclaration(path9) {
|
|
1506
|
+
const declaration = path9.node.declarations[0];
|
|
1507
1507
|
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1508
1508
|
cssContent = declaration.init.value;
|
|
1509
|
-
|
|
1509
|
+
path9.stop();
|
|
1510
1510
|
}
|
|
1511
1511
|
}
|
|
1512
1512
|
});
|
|
@@ -1545,10 +1545,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1545
1545
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1546
1546
|
let removedExportLocalNames = /* @__PURE__ */ new Set();
|
|
1547
1547
|
traverse(ast, {
|
|
1548
|
-
ExportDeclaration(
|
|
1549
|
-
if (
|
|
1550
|
-
if (
|
|
1551
|
-
|
|
1548
|
+
ExportDeclaration(path9) {
|
|
1549
|
+
if (path9.node.type === "ExportNamedDeclaration") {
|
|
1550
|
+
if (path9.node.specifiers.length) {
|
|
1551
|
+
path9.node.specifiers = path9.node.specifiers.filter((specifier) => {
|
|
1552
1552
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1553
1553
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1554
1554
|
exportsFiltered = true;
|
|
@@ -1560,12 +1560,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1560
1560
|
}
|
|
1561
1561
|
return true;
|
|
1562
1562
|
});
|
|
1563
|
-
if (
|
|
1564
|
-
markedForRemoval.add(
|
|
1563
|
+
if (path9.node.specifiers.length === 0) {
|
|
1564
|
+
markedForRemoval.add(path9);
|
|
1565
1565
|
}
|
|
1566
1566
|
}
|
|
1567
|
-
if (
|
|
1568
|
-
let declaration =
|
|
1567
|
+
if (path9.node.declaration?.type === "VariableDeclaration") {
|
|
1568
|
+
let declaration = path9.node.declaration;
|
|
1569
1569
|
declaration.declarations = declaration.declarations.filter(
|
|
1570
1570
|
(declaration2) => {
|
|
1571
1571
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1579,30 +1579,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1579
1579
|
}
|
|
1580
1580
|
);
|
|
1581
1581
|
if (declaration.declarations.length === 0) {
|
|
1582
|
-
markedForRemoval.add(
|
|
1582
|
+
markedForRemoval.add(path9);
|
|
1583
1583
|
}
|
|
1584
1584
|
}
|
|
1585
|
-
if (
|
|
1586
|
-
let id =
|
|
1585
|
+
if (path9.node.declaration?.type === "FunctionDeclaration") {
|
|
1586
|
+
let id = path9.node.declaration.id;
|
|
1587
1587
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1588
|
-
markedForRemoval.add(
|
|
1588
|
+
markedForRemoval.add(path9);
|
|
1589
1589
|
}
|
|
1590
1590
|
}
|
|
1591
|
-
if (
|
|
1592
|
-
let id =
|
|
1591
|
+
if (path9.node.declaration?.type === "ClassDeclaration") {
|
|
1592
|
+
let id = path9.node.declaration.id;
|
|
1593
1593
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1594
|
-
markedForRemoval.add(
|
|
1594
|
+
markedForRemoval.add(path9);
|
|
1595
1595
|
}
|
|
1596
1596
|
}
|
|
1597
1597
|
}
|
|
1598
|
-
if (
|
|
1598
|
+
if (path9.node.type === "ExportDefaultDeclaration") {
|
|
1599
1599
|
if (exportsToRemove.includes("default")) {
|
|
1600
|
-
markedForRemoval.add(
|
|
1601
|
-
if (
|
|
1602
|
-
if (
|
|
1603
|
-
removedExportLocalNames.add(
|
|
1604
|
-
} else if ((
|
|
1605
|
-
removedExportLocalNames.add(
|
|
1600
|
+
markedForRemoval.add(path9);
|
|
1601
|
+
if (path9.node.declaration) {
|
|
1602
|
+
if (path9.node.declaration.type === "Identifier") {
|
|
1603
|
+
removedExportLocalNames.add(path9.node.declaration.name);
|
|
1604
|
+
} else if ((path9.node.declaration.type === "FunctionDeclaration" || path9.node.declaration.type === "ClassDeclaration") && path9.node.declaration.id) {
|
|
1605
|
+
removedExportLocalNames.add(path9.node.declaration.id.name);
|
|
1606
1606
|
}
|
|
1607
1607
|
}
|
|
1608
1608
|
}
|
|
@@ -1610,21 +1610,21 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1610
1610
|
}
|
|
1611
1611
|
});
|
|
1612
1612
|
traverse(ast, {
|
|
1613
|
-
ExpressionStatement(
|
|
1614
|
-
if (!
|
|
1613
|
+
ExpressionStatement(path9) {
|
|
1614
|
+
if (!path9.parentPath.isProgram()) {
|
|
1615
1615
|
return;
|
|
1616
1616
|
}
|
|
1617
|
-
if (
|
|
1618
|
-
const left =
|
|
1617
|
+
if (path9.node.expression.type === "AssignmentExpression") {
|
|
1618
|
+
const left = path9.node.expression.left;
|
|
1619
1619
|
if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
|
|
1620
|
-
markedForRemoval.add(
|
|
1620
|
+
markedForRemoval.add(path9);
|
|
1621
1621
|
}
|
|
1622
1622
|
}
|
|
1623
1623
|
}
|
|
1624
1624
|
});
|
|
1625
1625
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1626
|
-
for (let
|
|
1627
|
-
|
|
1626
|
+
for (let path9 of markedForRemoval) {
|
|
1627
|
+
path9.remove();
|
|
1628
1628
|
}
|
|
1629
1629
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1630
1630
|
}
|
|
@@ -1707,28 +1707,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1707
1707
|
)
|
|
1708
1708
|
);
|
|
1709
1709
|
}
|
|
1710
|
-
function assertNodePath(
|
|
1710
|
+
function assertNodePath(path9) {
|
|
1711
1711
|
invariant(
|
|
1712
|
-
|
|
1713
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1712
|
+
path9 && !Array.isArray(path9),
|
|
1713
|
+
`Expected a Path, but got ${Array.isArray(path9) ? "an array" : path9}`
|
|
1714
1714
|
);
|
|
1715
1715
|
}
|
|
1716
|
-
function assertNodePathIsStatement(
|
|
1716
|
+
function assertNodePathIsStatement(path9) {
|
|
1717
1717
|
invariant(
|
|
1718
|
-
|
|
1719
|
-
`Expected a Statement path, but got ${Array.isArray(
|
|
1718
|
+
path9 && !Array.isArray(path9) && t.isStatement(path9.node),
|
|
1719
|
+
`Expected a Statement path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1720
1720
|
);
|
|
1721
1721
|
}
|
|
1722
|
-
function assertNodePathIsVariableDeclarator(
|
|
1722
|
+
function assertNodePathIsVariableDeclarator(path9) {
|
|
1723
1723
|
invariant(
|
|
1724
|
-
|
|
1725
|
-
`Expected an Identifier path, but got ${Array.isArray(
|
|
1724
|
+
path9 && !Array.isArray(path9) && t.isVariableDeclarator(path9.node),
|
|
1725
|
+
`Expected an Identifier path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1726
1726
|
);
|
|
1727
1727
|
}
|
|
1728
|
-
function assertNodePathIsPattern(
|
|
1728
|
+
function assertNodePathIsPattern(path9) {
|
|
1729
1729
|
invariant(
|
|
1730
|
-
|
|
1731
|
-
`Expected a Pattern path, but got ${Array.isArray(
|
|
1730
|
+
path9 && !Array.isArray(path9) && t.isPattern(path9.node),
|
|
1731
|
+
`Expected a Pattern path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1732
1732
|
);
|
|
1733
1733
|
}
|
|
1734
1734
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1764,8 +1764,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1764
1764
|
}
|
|
1765
1765
|
let isWithinExportDestructuring = Boolean(
|
|
1766
1766
|
identifier.findParent(
|
|
1767
|
-
(
|
|
1768
|
-
|
|
1767
|
+
(path9) => Boolean(
|
|
1768
|
+
path9.isPattern() && path9.parentPath?.isVariableDeclarator() && path9.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1769
1769
|
)
|
|
1770
1770
|
)
|
|
1771
1771
|
);
|
|
@@ -1843,7 +1843,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1843
1843
|
for (let specifier of node.specifiers) {
|
|
1844
1844
|
if (t.isIdentifier(specifier.exported)) {
|
|
1845
1845
|
let name = specifier.exported.name;
|
|
1846
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1846
|
+
let specifierPath = exportPath.get("specifiers").find((path9) => path9.node === specifier);
|
|
1847
1847
|
invariant(
|
|
1848
1848
|
specifierPath,
|
|
1849
1849
|
`Expected to find specifier path for ${name}`
|
|
@@ -1860,22 +1860,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1860
1860
|
}
|
|
1861
1861
|
);
|
|
1862
1862
|
}
|
|
1863
|
-
function getDependentIdentifiersForPath(
|
|
1863
|
+
function getDependentIdentifiersForPath(path9, state) {
|
|
1864
1864
|
let { visited, identifiers } = state ?? {
|
|
1865
1865
|
visited: /* @__PURE__ */ new Set(),
|
|
1866
1866
|
identifiers: /* @__PURE__ */ new Set()
|
|
1867
1867
|
};
|
|
1868
|
-
if (visited.has(
|
|
1868
|
+
if (visited.has(path9)) {
|
|
1869
1869
|
return identifiers;
|
|
1870
1870
|
}
|
|
1871
|
-
visited.add(
|
|
1872
|
-
|
|
1873
|
-
Identifier(
|
|
1874
|
-
if (identifiers.has(
|
|
1871
|
+
visited.add(path9);
|
|
1872
|
+
path9.traverse({
|
|
1873
|
+
Identifier(path10) {
|
|
1874
|
+
if (identifiers.has(path10)) {
|
|
1875
1875
|
return;
|
|
1876
1876
|
}
|
|
1877
|
-
identifiers.add(
|
|
1878
|
-
let binding =
|
|
1877
|
+
identifiers.add(path10);
|
|
1878
|
+
let binding = path10.scope.getBinding(path10.node.name);
|
|
1879
1879
|
if (!binding) {
|
|
1880
1880
|
return;
|
|
1881
1881
|
}
|
|
@@ -1897,7 +1897,7 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1897
1897
|
}
|
|
1898
1898
|
}
|
|
1899
1899
|
});
|
|
1900
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1900
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path9);
|
|
1901
1901
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1902
1902
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1903
1903
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1906,9 +1906,9 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1906
1906
|
identifiers
|
|
1907
1907
|
});
|
|
1908
1908
|
}
|
|
1909
|
-
if (withinExportStatement &&
|
|
1910
|
-
t.isPattern(
|
|
1911
|
-
let variableDeclarator =
|
|
1909
|
+
if (withinExportStatement && path9.isIdentifier() && (t.isPattern(path9.parentPath.node) || // [foo]
|
|
1910
|
+
t.isPattern(path9.parentPath.parentPath?.node))) {
|
|
1911
|
+
let variableDeclarator = path9.findParent((p) => p.isVariableDeclarator());
|
|
1912
1912
|
assertNodePath(variableDeclarator);
|
|
1913
1913
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1914
1914
|
visited,
|
|
@@ -1917,16 +1917,16 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1917
1917
|
}
|
|
1918
1918
|
return identifiers;
|
|
1919
1919
|
}
|
|
1920
|
-
function getTopLevelStatementPathForPath(
|
|
1921
|
-
let ancestry =
|
|
1920
|
+
function getTopLevelStatementPathForPath(path9) {
|
|
1921
|
+
let ancestry = path9.getAncestry();
|
|
1922
1922
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1923
1923
|
assertNodePathIsStatement(topLevelStatement);
|
|
1924
1924
|
return topLevelStatement;
|
|
1925
1925
|
}
|
|
1926
1926
|
function getTopLevelStatementsForPaths(paths) {
|
|
1927
1927
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1928
|
-
for (let
|
|
1929
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1928
|
+
for (let path9 of paths) {
|
|
1929
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path9);
|
|
1930
1930
|
topLevelStatements.add(topLevelStatement.node);
|
|
1931
1931
|
}
|
|
1932
1932
|
return topLevelStatements;
|
|
@@ -2320,24 +2320,24 @@ function isNamedComponentExport(name) {
|
|
|
2320
2320
|
}
|
|
2321
2321
|
var decorateComponentExportsWithProps = (ast) => {
|
|
2322
2322
|
const hocs = [];
|
|
2323
|
-
function getHocUid(
|
|
2324
|
-
const uid =
|
|
2323
|
+
function getHocUid(path9, hocName) {
|
|
2324
|
+
const uid = path9.scope.generateUidIdentifier(hocName);
|
|
2325
2325
|
hocs.push([hocName, uid]);
|
|
2326
2326
|
return uid;
|
|
2327
2327
|
}
|
|
2328
2328
|
traverse(ast, {
|
|
2329
|
-
ExportDeclaration(
|
|
2330
|
-
if (
|
|
2331
|
-
const declaration =
|
|
2329
|
+
ExportDeclaration(path9) {
|
|
2330
|
+
if (path9.isExportDefaultDeclaration()) {
|
|
2331
|
+
const declaration = path9.get("declaration");
|
|
2332
2332
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2333
2333
|
if (expr) {
|
|
2334
|
-
const uid = getHocUid(
|
|
2334
|
+
const uid = getHocUid(path9, "UNSAFE_withComponentProps");
|
|
2335
2335
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2336
2336
|
}
|
|
2337
2337
|
return;
|
|
2338
2338
|
}
|
|
2339
|
-
if (
|
|
2340
|
-
const decl =
|
|
2339
|
+
if (path9.isExportNamedDeclaration()) {
|
|
2340
|
+
const decl = path9.get("declaration");
|
|
2341
2341
|
if (decl.isVariableDeclaration()) {
|
|
2342
2342
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2343
2343
|
const id = varDeclarator.get("id");
|
|
@@ -2347,7 +2347,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2347
2347
|
if (!id.isIdentifier()) return;
|
|
2348
2348
|
const { name } = id.node;
|
|
2349
2349
|
if (!isNamedComponentExport(name)) return;
|
|
2350
|
-
const uid = getHocUid(
|
|
2350
|
+
const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
|
|
2351
2351
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2352
2352
|
});
|
|
2353
2353
|
return;
|
|
@@ -2357,7 +2357,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2357
2357
|
if (!id) return;
|
|
2358
2358
|
const { name } = id;
|
|
2359
2359
|
if (!isNamedComponentExport(name)) return;
|
|
2360
|
-
const uid = getHocUid(
|
|
2360
|
+
const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
|
|
2361
2361
|
decl.replaceWith(
|
|
2362
2362
|
t.variableDeclaration("const", [
|
|
2363
2363
|
t.variableDeclarator(
|
|
@@ -2391,6 +2391,26 @@ function toFunctionExpression(decl) {
|
|
|
2391
2391
|
);
|
|
2392
2392
|
}
|
|
2393
2393
|
|
|
2394
|
+
// vite/load-dotenv.ts
|
|
2395
|
+
async function loadDotenv({
|
|
2396
|
+
rootDirectory,
|
|
2397
|
+
viteUserConfig,
|
|
2398
|
+
mode
|
|
2399
|
+
}) {
|
|
2400
|
+
const vite2 = await import("vite");
|
|
2401
|
+
Object.assign(
|
|
2402
|
+
process.env,
|
|
2403
|
+
vite2.loadEnv(
|
|
2404
|
+
mode,
|
|
2405
|
+
viteUserConfig.envDir ?? rootDirectory,
|
|
2406
|
+
// We override the default prefix of "VITE_" with a blank string since
|
|
2407
|
+
// we're targeting the server, so we want to load all environment
|
|
2408
|
+
// variables, not just those explicitly marked for the client
|
|
2409
|
+
""
|
|
2410
|
+
)
|
|
2411
|
+
);
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2394
2414
|
// vite/plugins/validate-plugin-order.ts
|
|
2395
2415
|
function validatePluginOrder() {
|
|
2396
2416
|
return {
|
|
@@ -3166,17 +3186,11 @@ var reactRouterVitePlugin = () => {
|
|
|
3166
3186
|
watch: viteCommand === "serve"
|
|
3167
3187
|
});
|
|
3168
3188
|
await updatePluginContext();
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
// We override the default prefix of "VITE_" with a blank string since
|
|
3175
|
-
// we're targeting the server, so we want to load all environment
|
|
3176
|
-
// variables, not just those explicitly marked for the client
|
|
3177
|
-
""
|
|
3178
|
-
)
|
|
3179
|
-
);
|
|
3189
|
+
await loadDotenv({
|
|
3190
|
+
rootDirectory,
|
|
3191
|
+
viteUserConfig,
|
|
3192
|
+
mode
|
|
3193
|
+
});
|
|
3180
3194
|
let environments = await getEnvironmentsOptions(ctx, viteCommand, {
|
|
3181
3195
|
viteUserConfig
|
|
3182
3196
|
});
|
|
@@ -4222,17 +4236,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4222
4236
|
serverBuildPath
|
|
4223
4237
|
);
|
|
4224
4238
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
4225
|
-
for (let
|
|
4226
|
-
let matches = (0, import_react_router2.matchRoutes)(routes, `/${
|
|
4239
|
+
for (let path9 of build.prerender) {
|
|
4240
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path9}/`.replace(/^\/\/+/, "/"));
|
|
4227
4241
|
if (!matches) {
|
|
4228
4242
|
throw new Error(
|
|
4229
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4243
|
+
`Unable to prerender path because it does not match any routes: ${path9}`
|
|
4230
4244
|
);
|
|
4231
4245
|
}
|
|
4232
4246
|
}
|
|
4233
4247
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
4234
|
-
for (let
|
|
4235
|
-
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${
|
|
4248
|
+
for (let path9 of build.prerender) {
|
|
4249
|
+
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path9}/`.replace(/^\/\/+/, "/"));
|
|
4236
4250
|
if (!matches) {
|
|
4237
4251
|
continue;
|
|
4238
4252
|
}
|
|
@@ -4245,7 +4259,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4245
4259
|
if (manifestRoute.loader) {
|
|
4246
4260
|
await prerenderData(
|
|
4247
4261
|
handler,
|
|
4248
|
-
|
|
4262
|
+
path9,
|
|
4249
4263
|
[leafRoute.id],
|
|
4250
4264
|
clientBuildDirectory,
|
|
4251
4265
|
reactRouterConfig,
|
|
@@ -4253,7 +4267,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4253
4267
|
);
|
|
4254
4268
|
await prerenderResourceRoute(
|
|
4255
4269
|
handler,
|
|
4256
|
-
|
|
4270
|
+
path9,
|
|
4257
4271
|
clientBuildDirectory,
|
|
4258
4272
|
reactRouterConfig,
|
|
4259
4273
|
viteConfig
|
|
@@ -4271,7 +4285,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4271
4285
|
if (!isResourceRoute && hasLoaders) {
|
|
4272
4286
|
data = await prerenderData(
|
|
4273
4287
|
handler,
|
|
4274
|
-
|
|
4288
|
+
path9,
|
|
4275
4289
|
null,
|
|
4276
4290
|
clientBuildDirectory,
|
|
4277
4291
|
reactRouterConfig,
|
|
@@ -4280,7 +4294,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4280
4294
|
}
|
|
4281
4295
|
await prerenderRoute(
|
|
4282
4296
|
handler,
|
|
4283
|
-
|
|
4297
|
+
path9,
|
|
4284
4298
|
clientBuildDirectory,
|
|
4285
4299
|
reactRouterConfig,
|
|
4286
4300
|
viteConfig,
|
|
@@ -4476,14 +4490,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4476
4490
|
}
|
|
4477
4491
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4478
4492
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4479
|
-
for (let
|
|
4493
|
+
for (let path9 of prerenderPaths) {
|
|
4480
4494
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4481
4495
|
prerenderRoutes,
|
|
4482
|
-
`/${
|
|
4496
|
+
`/${path9}/`.replace(/^\/\/+/, "/")
|
|
4483
4497
|
);
|
|
4484
4498
|
invariant(
|
|
4485
4499
|
matches,
|
|
4486
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4500
|
+
`Unable to prerender path because it does not match any routes: ${path9}`
|
|
4487
4501
|
);
|
|
4488
4502
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4489
4503
|
}
|
|
@@ -4931,7 +4945,867 @@ async function asyncFlatten(arr) {
|
|
|
4931
4945
|
} while (arr.some((v2) => v2?.then));
|
|
4932
4946
|
return arr;
|
|
4933
4947
|
}
|
|
4948
|
+
|
|
4949
|
+
// vite/rsc/plugin.ts
|
|
4950
|
+
var import_es_module_lexer3 = require("es-module-lexer");
|
|
4951
|
+
var Path5 = __toESM(require("pathe"));
|
|
4952
|
+
var babel2 = __toESM(require("@babel/core"));
|
|
4953
|
+
var import_picocolors5 = __toESM(require("picocolors"));
|
|
4954
|
+
var import_fs = require("fs");
|
|
4955
|
+
var import_promises3 = require("fs/promises");
|
|
4956
|
+
var import_pathe6 = __toESM(require("pathe"));
|
|
4957
|
+
|
|
4958
|
+
// vite/rsc/virtual-route-config.ts
|
|
4959
|
+
var import_pathe5 = __toESM(require("pathe"));
|
|
4960
|
+
function createVirtualRouteConfig({
|
|
4961
|
+
appDirectory,
|
|
4962
|
+
routeConfig
|
|
4963
|
+
}) {
|
|
4964
|
+
let routeIdByFile = /* @__PURE__ */ new Map();
|
|
4965
|
+
let code = "export default [";
|
|
4966
|
+
const closeRouteSymbol = Symbol("CLOSE_ROUTE");
|
|
4967
|
+
let stack = [
|
|
4968
|
+
...routeConfig
|
|
4969
|
+
];
|
|
4970
|
+
while (stack.length > 0) {
|
|
4971
|
+
const route = stack.pop();
|
|
4972
|
+
if (!route) break;
|
|
4973
|
+
if (route === closeRouteSymbol) {
|
|
4974
|
+
code += "]},";
|
|
4975
|
+
continue;
|
|
4976
|
+
}
|
|
4977
|
+
code += "{";
|
|
4978
|
+
const routeFile = import_pathe5.default.resolve(appDirectory, route.file);
|
|
4979
|
+
const routeId = route.id || createRouteId2(route.file, appDirectory);
|
|
4980
|
+
routeIdByFile.set(routeFile, routeId);
|
|
4981
|
+
code += `lazy: () => import(${JSON.stringify(
|
|
4982
|
+
`${routeFile}?route-module`
|
|
4983
|
+
)}),`;
|
|
4984
|
+
code += `id: ${JSON.stringify(routeId)},`;
|
|
4985
|
+
if (typeof route.path === "string") {
|
|
4986
|
+
code += `path: ${JSON.stringify(route.path)},`;
|
|
4987
|
+
}
|
|
4988
|
+
if (route.index) {
|
|
4989
|
+
code += `index: true,`;
|
|
4990
|
+
}
|
|
4991
|
+
if (route.caseSensitive) {
|
|
4992
|
+
code += `caseSensitive: true,`;
|
|
4993
|
+
}
|
|
4994
|
+
if (route.children) {
|
|
4995
|
+
code += ["children:["];
|
|
4996
|
+
stack.push(closeRouteSymbol);
|
|
4997
|
+
stack.push(...[...route.children].reverse());
|
|
4998
|
+
} else {
|
|
4999
|
+
code += "},";
|
|
5000
|
+
}
|
|
5001
|
+
}
|
|
5002
|
+
code += "];\n";
|
|
5003
|
+
return { code, routeIdByFile };
|
|
5004
|
+
}
|
|
5005
|
+
function createRouteId2(file, appDirectory) {
|
|
5006
|
+
return import_pathe5.default.relative(appDirectory, file).replace(/\\+/, "/").slice(0, -import_pathe5.default.extname(file).length);
|
|
5007
|
+
}
|
|
5008
|
+
|
|
5009
|
+
// vite/rsc/virtual-route-modules.ts
|
|
5010
|
+
var import_es_module_lexer2 = require("es-module-lexer");
|
|
5011
|
+
var SERVER_ONLY_COMPONENT_EXPORTS = ["ServerComponent"];
|
|
5012
|
+
var SERVER_ONLY_ROUTE_EXPORTS2 = [
|
|
5013
|
+
...SERVER_ONLY_COMPONENT_EXPORTS,
|
|
5014
|
+
"loader",
|
|
5015
|
+
"action",
|
|
5016
|
+
"middleware",
|
|
5017
|
+
"headers"
|
|
5018
|
+
];
|
|
5019
|
+
var SERVER_ONLY_ROUTE_EXPORTS_SET = new Set(SERVER_ONLY_ROUTE_EXPORTS2);
|
|
5020
|
+
function isServerOnlyRouteExport(name) {
|
|
5021
|
+
return SERVER_ONLY_ROUTE_EXPORTS_SET.has(name);
|
|
5022
|
+
}
|
|
5023
|
+
var COMMON_COMPONENT_EXPORTS = [
|
|
5024
|
+
"ErrorBoundary",
|
|
5025
|
+
"HydrateFallback",
|
|
5026
|
+
"Layout"
|
|
5027
|
+
];
|
|
5028
|
+
var SERVER_FIRST_COMPONENT_EXPORTS = [
|
|
5029
|
+
...COMMON_COMPONENT_EXPORTS,
|
|
5030
|
+
...SERVER_ONLY_COMPONENT_EXPORTS
|
|
5031
|
+
];
|
|
5032
|
+
var SERVER_FIRST_COMPONENT_EXPORTS_SET = new Set(
|
|
5033
|
+
SERVER_FIRST_COMPONENT_EXPORTS
|
|
5034
|
+
);
|
|
5035
|
+
function isServerFirstComponentExport(name) {
|
|
5036
|
+
return SERVER_FIRST_COMPONENT_EXPORTS_SET.has(
|
|
5037
|
+
name
|
|
5038
|
+
);
|
|
5039
|
+
}
|
|
5040
|
+
var CLIENT_COMPONENT_EXPORTS = [
|
|
5041
|
+
...COMMON_COMPONENT_EXPORTS,
|
|
5042
|
+
"default"
|
|
5043
|
+
];
|
|
5044
|
+
var CLIENT_NON_COMPONENT_EXPORTS2 = [
|
|
5045
|
+
"clientAction",
|
|
5046
|
+
"clientLoader",
|
|
5047
|
+
"clientMiddleware",
|
|
5048
|
+
"handle",
|
|
5049
|
+
"meta",
|
|
5050
|
+
"links",
|
|
5051
|
+
"shouldRevalidate"
|
|
5052
|
+
];
|
|
5053
|
+
var CLIENT_NON_COMPONENT_EXPORTS_SET = new Set(CLIENT_NON_COMPONENT_EXPORTS2);
|
|
5054
|
+
function isClientNonComponentExport(name) {
|
|
5055
|
+
return CLIENT_NON_COMPONENT_EXPORTS_SET.has(name);
|
|
5056
|
+
}
|
|
5057
|
+
var CLIENT_ROUTE_EXPORTS2 = [
|
|
5058
|
+
...CLIENT_NON_COMPONENT_EXPORTS2,
|
|
5059
|
+
...CLIENT_COMPONENT_EXPORTS
|
|
5060
|
+
];
|
|
5061
|
+
var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS2);
|
|
5062
|
+
function isClientRouteExport(name) {
|
|
5063
|
+
return CLIENT_ROUTE_EXPORTS_SET.has(name);
|
|
5064
|
+
}
|
|
5065
|
+
var ROUTE_EXPORTS = [
|
|
5066
|
+
...SERVER_ONLY_ROUTE_EXPORTS2,
|
|
5067
|
+
...CLIENT_ROUTE_EXPORTS2
|
|
5068
|
+
];
|
|
5069
|
+
var ROUTE_EXPORTS_SET = new Set(ROUTE_EXPORTS);
|
|
5070
|
+
function isRouteExport(name) {
|
|
5071
|
+
return ROUTE_EXPORTS_SET.has(name);
|
|
5072
|
+
}
|
|
5073
|
+
function isCustomRouteExport(name) {
|
|
5074
|
+
return !isRouteExport(name);
|
|
5075
|
+
}
|
|
5076
|
+
function hasReactServerCondition(viteEnvironment) {
|
|
5077
|
+
return viteEnvironment.config.resolve.conditions.includes("react-server");
|
|
5078
|
+
}
|
|
5079
|
+
function transformVirtualRouteModules({
|
|
5080
|
+
id,
|
|
5081
|
+
code,
|
|
5082
|
+
viteCommand,
|
|
5083
|
+
routeIdByFile,
|
|
5084
|
+
rootRouteFile,
|
|
5085
|
+
viteEnvironment
|
|
5086
|
+
}) {
|
|
5087
|
+
if (isVirtualRouteModuleId(id) || routeIdByFile.has(id)) {
|
|
5088
|
+
return createVirtualRouteModuleCode({
|
|
5089
|
+
id,
|
|
5090
|
+
code,
|
|
5091
|
+
rootRouteFile,
|
|
5092
|
+
viteCommand,
|
|
5093
|
+
viteEnvironment
|
|
5094
|
+
});
|
|
5095
|
+
}
|
|
5096
|
+
if (isVirtualServerRouteModuleId(id)) {
|
|
5097
|
+
return createVirtualServerRouteModuleCode({
|
|
5098
|
+
id,
|
|
5099
|
+
code,
|
|
5100
|
+
viteEnvironment
|
|
5101
|
+
});
|
|
5102
|
+
}
|
|
5103
|
+
if (isVirtualClientRouteModuleId(id)) {
|
|
5104
|
+
return createVirtualClientRouteModuleCode({
|
|
5105
|
+
id,
|
|
5106
|
+
code,
|
|
5107
|
+
rootRouteFile,
|
|
5108
|
+
viteCommand
|
|
5109
|
+
});
|
|
5110
|
+
}
|
|
5111
|
+
}
|
|
5112
|
+
async function createVirtualRouteModuleCode({
|
|
5113
|
+
id,
|
|
5114
|
+
code: routeSource,
|
|
5115
|
+
rootRouteFile,
|
|
5116
|
+
viteCommand,
|
|
5117
|
+
viteEnvironment
|
|
5118
|
+
}) {
|
|
5119
|
+
const isReactServer = hasReactServerCondition(viteEnvironment);
|
|
5120
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
5121
|
+
const clientModuleId = getVirtualClientModuleId(id);
|
|
5122
|
+
const serverModuleId = getVirtualServerModuleId(id);
|
|
5123
|
+
let code = "";
|
|
5124
|
+
if (isServerFirstRoute) {
|
|
5125
|
+
if (staticExports.some(isServerFirstComponentExport)) {
|
|
5126
|
+
code += `import React from "react";
|
|
5127
|
+
`;
|
|
5128
|
+
}
|
|
5129
|
+
for (const staticExport of staticExports) {
|
|
5130
|
+
if (isClientNonComponentExport(staticExport)) {
|
|
5131
|
+
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5132
|
+
`;
|
|
5133
|
+
} else if (isReactServer && isServerFirstComponentExport(staticExport) && // Layout wraps all other component exports so doesn't need CSS injected
|
|
5134
|
+
staticExport !== "Layout") {
|
|
5135
|
+
code += `import { ${staticExport} as ${staticExport}WithoutCss } from "${serverModuleId}";
|
|
5136
|
+
`;
|
|
5137
|
+
code += `export ${staticExport === "ServerComponent" ? "default " : " "}function ${staticExport}(props) {
|
|
5138
|
+
`;
|
|
5139
|
+
code += ` return React.createElement(React.Fragment, null,
|
|
5140
|
+
`;
|
|
5141
|
+
code += ` import.meta.viteRsc.loadCss(),
|
|
5142
|
+
`;
|
|
5143
|
+
code += ` React.createElement(${staticExport}WithoutCss, props),
|
|
5144
|
+
`;
|
|
5145
|
+
code += ` );
|
|
5146
|
+
`;
|
|
5147
|
+
code += `}
|
|
5148
|
+
`;
|
|
5149
|
+
} else if (isReactServer && isRouteExport(staticExport)) {
|
|
5150
|
+
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5151
|
+
`;
|
|
5152
|
+
} else if (isCustomRouteExport(staticExport)) {
|
|
5153
|
+
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5154
|
+
`;
|
|
5155
|
+
}
|
|
5156
|
+
}
|
|
5157
|
+
if (viteCommand === "serve" && !hasClientExports) {
|
|
5158
|
+
code += `export { __ensureClientRouteModuleForHMR } from "${clientModuleId}";
|
|
5159
|
+
`;
|
|
5160
|
+
}
|
|
5161
|
+
} else {
|
|
5162
|
+
for (const staticExport of staticExports) {
|
|
5163
|
+
if (isClientRouteExport(staticExport)) {
|
|
5164
|
+
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5165
|
+
`;
|
|
5166
|
+
} else if (isReactServer && isServerOnlyRouteExport(staticExport)) {
|
|
5167
|
+
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5168
|
+
`;
|
|
5169
|
+
} else if (isCustomRouteExport(staticExport)) {
|
|
5170
|
+
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5171
|
+
`;
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
}
|
|
5175
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5176
|
+
code += `export { ErrorBoundary } from "${clientModuleId}";
|
|
5177
|
+
`;
|
|
5178
|
+
}
|
|
5179
|
+
return code;
|
|
5180
|
+
}
|
|
5181
|
+
function createVirtualServerRouteModuleCode({
|
|
5182
|
+
id,
|
|
5183
|
+
code: routeSource,
|
|
5184
|
+
viteEnvironment
|
|
5185
|
+
}) {
|
|
5186
|
+
if (!hasReactServerCondition(viteEnvironment)) {
|
|
5187
|
+
throw new Error(
|
|
5188
|
+
[
|
|
5189
|
+
"Virtual server route module was loaded outside of the RSC environment.",
|
|
5190
|
+
`Environment Name: ${viteEnvironment.name}`,
|
|
5191
|
+
`Module ID: ${id}`
|
|
5192
|
+
].join("\n")
|
|
5193
|
+
);
|
|
5194
|
+
}
|
|
5195
|
+
const { staticExports, isServerFirstRoute } = parseRouteExports(routeSource);
|
|
5196
|
+
const clientModuleId = getVirtualClientModuleId(id);
|
|
5197
|
+
const serverRouteModuleAst = import_parser.parse(routeSource, {
|
|
5198
|
+
sourceType: "module"
|
|
5199
|
+
});
|
|
5200
|
+
removeExports(
|
|
5201
|
+
serverRouteModuleAst,
|
|
5202
|
+
isServerFirstRoute ? CLIENT_NON_COMPONENT_EXPORTS2 : CLIENT_ROUTE_EXPORTS2
|
|
5203
|
+
);
|
|
5204
|
+
const generatorResult = generate(serverRouteModuleAst);
|
|
5205
|
+
if (!isServerFirstRoute) {
|
|
5206
|
+
for (const staticExport of staticExports) {
|
|
5207
|
+
if (isClientRouteExport(staticExport)) {
|
|
5208
|
+
generatorResult.code += "\n";
|
|
5209
|
+
generatorResult.code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5210
|
+
`;
|
|
5211
|
+
}
|
|
5212
|
+
}
|
|
5213
|
+
}
|
|
5214
|
+
return generatorResult;
|
|
5215
|
+
}
|
|
5216
|
+
function createVirtualClientRouteModuleCode({
|
|
5217
|
+
id,
|
|
5218
|
+
code: routeSource,
|
|
5219
|
+
rootRouteFile,
|
|
5220
|
+
viteCommand
|
|
5221
|
+
}) {
|
|
5222
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
5223
|
+
const exportsToRemove = isServerFirstRoute ? [...SERVER_ONLY_ROUTE_EXPORTS2, ...CLIENT_COMPONENT_EXPORTS] : SERVER_ONLY_ROUTE_EXPORTS2;
|
|
5224
|
+
const clientRouteModuleAst = import_parser.parse(routeSource, {
|
|
5225
|
+
sourceType: "module"
|
|
5226
|
+
});
|
|
5227
|
+
removeExports(clientRouteModuleAst, exportsToRemove);
|
|
5228
|
+
const generatorResult = generate(clientRouteModuleAst);
|
|
5229
|
+
generatorResult.code = '"use client";' + generatorResult.code;
|
|
5230
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5231
|
+
const hasRootLayout = staticExports.includes("Layout");
|
|
5232
|
+
generatorResult.code += `
|
|
5233
|
+
import { createElement as __rr_createElement } from "react";
|
|
5234
|
+
`;
|
|
5235
|
+
generatorResult.code += `import { UNSAFE_RSCDefaultRootErrorBoundary } from "react-router";
|
|
5236
|
+
`;
|
|
5237
|
+
generatorResult.code += `export function ErrorBoundary() {
|
|
5238
|
+
`;
|
|
5239
|
+
generatorResult.code += ` return __rr_createElement(UNSAFE_RSCDefaultRootErrorBoundary, { hasRootLayout: ${hasRootLayout} });
|
|
5240
|
+
`;
|
|
5241
|
+
generatorResult.code += `}
|
|
5242
|
+
`;
|
|
5243
|
+
}
|
|
5244
|
+
if (viteCommand === "serve" && isServerFirstRoute && !hasClientExports) {
|
|
5245
|
+
generatorResult.code += `
|
|
5246
|
+
export const __ensureClientRouteModuleForHMR = true;`;
|
|
5247
|
+
}
|
|
5248
|
+
return generatorResult;
|
|
5249
|
+
}
|
|
5250
|
+
function parseRouteExports(code) {
|
|
5251
|
+
const [, exportSpecifiers] = (0, import_es_module_lexer2.parse)(code);
|
|
5252
|
+
const staticExports = exportSpecifiers.map(({ n: name }) => name);
|
|
5253
|
+
const isServerFirstRoute = staticExports.some(
|
|
5254
|
+
(staticExport) => staticExport === "ServerComponent"
|
|
5255
|
+
);
|
|
5256
|
+
return {
|
|
5257
|
+
staticExports,
|
|
5258
|
+
isServerFirstRoute,
|
|
5259
|
+
hasClientExports: staticExports.some(
|
|
5260
|
+
isServerFirstRoute ? isClientNonComponentExport : isClientRouteExport
|
|
5261
|
+
)
|
|
5262
|
+
};
|
|
5263
|
+
}
|
|
5264
|
+
function getVirtualClientModuleId(id) {
|
|
5265
|
+
return `${id.split("?")[0]}?client-route-module`;
|
|
5266
|
+
}
|
|
5267
|
+
function getVirtualServerModuleId(id) {
|
|
5268
|
+
return `${id.split("?")[0]}?server-route-module`;
|
|
5269
|
+
}
|
|
5270
|
+
function isVirtualRouteModuleId(id) {
|
|
5271
|
+
return /(\?|&)route-module(&|$)/.test(id);
|
|
5272
|
+
}
|
|
5273
|
+
function isVirtualClientRouteModuleId(id) {
|
|
5274
|
+
return /(\?|&)client-route-module(&|$)/.test(id);
|
|
5275
|
+
}
|
|
5276
|
+
function isVirtualServerRouteModuleId(id) {
|
|
5277
|
+
return /(\?|&)server-route-module(&|$)/.test(id);
|
|
5278
|
+
}
|
|
5279
|
+
function isRootRouteFile({
|
|
5280
|
+
id,
|
|
5281
|
+
rootRouteFile
|
|
5282
|
+
}) {
|
|
5283
|
+
const filePath = id.split("?")[0];
|
|
5284
|
+
return filePath === rootRouteFile;
|
|
5285
|
+
}
|
|
5286
|
+
|
|
5287
|
+
// vite/rsc/plugin.ts
|
|
5288
|
+
function reactRouterRSCVitePlugin() {
|
|
5289
|
+
let configLoader;
|
|
5290
|
+
let typegenWatcherPromise;
|
|
5291
|
+
let viteCommand;
|
|
5292
|
+
let routeIdByFile;
|
|
5293
|
+
let logger;
|
|
5294
|
+
const defaultEntries2 = getDefaultEntries();
|
|
5295
|
+
let config;
|
|
5296
|
+
let rootRouteFile;
|
|
5297
|
+
function updateConfig(newConfig) {
|
|
5298
|
+
config = newConfig;
|
|
5299
|
+
rootRouteFile = Path5.resolve(
|
|
5300
|
+
newConfig.appDirectory,
|
|
5301
|
+
newConfig.routes.root.file
|
|
5302
|
+
);
|
|
5303
|
+
}
|
|
5304
|
+
return [
|
|
5305
|
+
{
|
|
5306
|
+
name: "react-router/rsc",
|
|
5307
|
+
async config(viteUserConfig, { command, mode }) {
|
|
5308
|
+
await import_es_module_lexer3.init;
|
|
5309
|
+
await preloadVite();
|
|
5310
|
+
viteCommand = command;
|
|
5311
|
+
const rootDirectory = getRootDirectory(viteUserConfig);
|
|
5312
|
+
const watch2 = command === "serve";
|
|
5313
|
+
configLoader = await createConfigLoader({
|
|
5314
|
+
rootDirectory,
|
|
5315
|
+
mode,
|
|
5316
|
+
watch: watch2,
|
|
5317
|
+
validateConfig: (userConfig) => {
|
|
5318
|
+
let errors = [];
|
|
5319
|
+
if (userConfig.buildEnd) errors.push("buildEnd");
|
|
5320
|
+
if (userConfig.prerender) errors.push("prerender");
|
|
5321
|
+
if (userConfig.presets?.length) errors.push("presets");
|
|
5322
|
+
if (userConfig.routeDiscovery) errors.push("routeDiscovery");
|
|
5323
|
+
if (userConfig.serverBundles) errors.push("serverBundles");
|
|
5324
|
+
if (userConfig.ssr === false) errors.push("ssr: false");
|
|
5325
|
+
if (userConfig.future?.unstable_splitRouteModules)
|
|
5326
|
+
errors.push("future.unstable_splitRouteModules");
|
|
5327
|
+
if (userConfig.future?.unstable_viteEnvironmentApi === false)
|
|
5328
|
+
errors.push("future.unstable_viteEnvironmentApi: false");
|
|
5329
|
+
if (userConfig.future?.v8_middleware === false)
|
|
5330
|
+
errors.push("future.v8_middleware: false");
|
|
5331
|
+
if (userConfig.future?.unstable_subResourceIntegrity)
|
|
5332
|
+
errors.push("future.unstable_subResourceIntegrity");
|
|
5333
|
+
if (errors.length) {
|
|
5334
|
+
return `RSC Framework Mode does not currently support the following React Router config:
|
|
5335
|
+
${errors.map((x) => ` - ${x}`).join("\n")}
|
|
5336
|
+
`;
|
|
5337
|
+
}
|
|
5338
|
+
}
|
|
5339
|
+
});
|
|
5340
|
+
const configResult = await configLoader.getConfig();
|
|
5341
|
+
if (!configResult.ok) throw new Error(configResult.error);
|
|
5342
|
+
updateConfig(configResult.value);
|
|
5343
|
+
if (viteUserConfig.base && config.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !config.basename.startsWith(viteUserConfig.base)) {
|
|
5344
|
+
throw new Error(
|
|
5345
|
+
"When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
|
|
5346
|
+
);
|
|
5347
|
+
}
|
|
5348
|
+
await loadDotenv({
|
|
5349
|
+
rootDirectory,
|
|
5350
|
+
viteUserConfig,
|
|
5351
|
+
mode
|
|
5352
|
+
});
|
|
5353
|
+
const vite2 = await import("vite");
|
|
5354
|
+
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
5355
|
+
prefix: "[react-router]"
|
|
5356
|
+
});
|
|
5357
|
+
return {
|
|
5358
|
+
resolve: {
|
|
5359
|
+
dedupe: [
|
|
5360
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
5361
|
+
"react",
|
|
5362
|
+
"react-dom",
|
|
5363
|
+
// Avoid router duplicates since mismatching routers cause `Error:
|
|
5364
|
+
// You must render this element inside a <Remix> element`.
|
|
5365
|
+
"react-router",
|
|
5366
|
+
"react-router/dom",
|
|
5367
|
+
...hasDependency({ name: "react-router-dom", rootDirectory }) ? ["react-router-dom"] : []
|
|
5368
|
+
]
|
|
5369
|
+
},
|
|
5370
|
+
optimizeDeps: {
|
|
5371
|
+
entries: getOptimizeDepsEntries({
|
|
5372
|
+
entryClientFilePath: defaultEntries2.client,
|
|
5373
|
+
reactRouterConfig: config
|
|
5374
|
+
}),
|
|
5375
|
+
esbuildOptions: {
|
|
5376
|
+
jsx: "automatic"
|
|
5377
|
+
},
|
|
5378
|
+
include: [
|
|
5379
|
+
// Pre-bundle React dependencies to avoid React duplicates,
|
|
5380
|
+
// even if React dependencies are not direct dependencies.
|
|
5381
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
5382
|
+
"react",
|
|
5383
|
+
"react/jsx-runtime",
|
|
5384
|
+
"react/jsx-dev-runtime",
|
|
5385
|
+
"react-dom",
|
|
5386
|
+
"react-dom/client",
|
|
5387
|
+
"react-router/internal/react-server-client"
|
|
5388
|
+
]
|
|
5389
|
+
},
|
|
5390
|
+
esbuild: {
|
|
5391
|
+
jsx: "automatic",
|
|
5392
|
+
jsxDev: viteCommand !== "build"
|
|
5393
|
+
},
|
|
5394
|
+
environments: {
|
|
5395
|
+
client: {
|
|
5396
|
+
build: {
|
|
5397
|
+
rollupOptions: {
|
|
5398
|
+
input: {
|
|
5399
|
+
index: defaultEntries2.client
|
|
5400
|
+
}
|
|
5401
|
+
},
|
|
5402
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "client")
|
|
5403
|
+
}
|
|
5404
|
+
},
|
|
5405
|
+
rsc: {
|
|
5406
|
+
build: {
|
|
5407
|
+
rollupOptions: {
|
|
5408
|
+
input: {
|
|
5409
|
+
// We use a virtual entry here so that consumers can import
|
|
5410
|
+
// it as `virtual:react-router/unstable_rsc/rsc-entry`
|
|
5411
|
+
// without needing to know the actual file path, which is
|
|
5412
|
+
// important when using the default entries.
|
|
5413
|
+
index: defaultEntries2.rsc
|
|
5414
|
+
},
|
|
5415
|
+
output: {
|
|
5416
|
+
entryFileNames: config.serverBuildFile,
|
|
5417
|
+
format: config.serverModuleFormat
|
|
5418
|
+
}
|
|
5419
|
+
},
|
|
5420
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "server")
|
|
5421
|
+
}
|
|
5422
|
+
},
|
|
5423
|
+
ssr: {
|
|
5424
|
+
build: {
|
|
5425
|
+
rollupOptions: {
|
|
5426
|
+
input: {
|
|
5427
|
+
index: defaultEntries2.ssr
|
|
5428
|
+
},
|
|
5429
|
+
output: {
|
|
5430
|
+
// Note: We don't set `entryFileNames` here because it's
|
|
5431
|
+
// considered private to the RSC environment build, and
|
|
5432
|
+
// @vitejs/plugin-rsc currently breaks if it's set to
|
|
5433
|
+
// something other than `index.js`.
|
|
5434
|
+
format: config.serverModuleFormat
|
|
5435
|
+
}
|
|
5436
|
+
},
|
|
5437
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "server/__ssr_build")
|
|
5438
|
+
}
|
|
5439
|
+
}
|
|
5440
|
+
},
|
|
5441
|
+
build: {
|
|
5442
|
+
rollupOptions: {
|
|
5443
|
+
// Copied from https://github.com/vitejs/vite-plugin-react/blob/c602225271d4acf462ba00f8d6d8a2e42492c5cd/packages/common/warning.ts
|
|
5444
|
+
onwarn(warning, defaultHandler) {
|
|
5445
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
|
|
5446
|
+
return;
|
|
5447
|
+
}
|
|
5448
|
+
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
|
5449
|
+
return;
|
|
5450
|
+
}
|
|
5451
|
+
if (viteUserConfig.build?.rollupOptions?.onwarn) {
|
|
5452
|
+
viteUserConfig.build.rollupOptions.onwarn(
|
|
5453
|
+
warning,
|
|
5454
|
+
defaultHandler
|
|
5455
|
+
);
|
|
5456
|
+
} else {
|
|
5457
|
+
defaultHandler(warning);
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
}
|
|
5461
|
+
}
|
|
5462
|
+
};
|
|
5463
|
+
},
|
|
5464
|
+
async configureServer(viteDevServer) {
|
|
5465
|
+
configLoader.onChange(
|
|
5466
|
+
async ({
|
|
5467
|
+
result,
|
|
5468
|
+
configCodeChanged,
|
|
5469
|
+
routeConfigCodeChanged,
|
|
5470
|
+
configChanged,
|
|
5471
|
+
routeConfigChanged
|
|
5472
|
+
}) => {
|
|
5473
|
+
if (!result.ok) {
|
|
5474
|
+
invalidateVirtualModules2(viteDevServer);
|
|
5475
|
+
logger.error(result.error, {
|
|
5476
|
+
clear: true,
|
|
5477
|
+
timestamp: true
|
|
5478
|
+
});
|
|
5479
|
+
return;
|
|
5480
|
+
}
|
|
5481
|
+
let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
|
|
5482
|
+
logger.info(import_picocolors5.default.green(message), {
|
|
5483
|
+
clear: true,
|
|
5484
|
+
timestamp: true
|
|
5485
|
+
});
|
|
5486
|
+
updateConfig(result.value);
|
|
5487
|
+
if (configChanged || routeConfigChanged) {
|
|
5488
|
+
invalidateVirtualModules2(viteDevServer);
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
);
|
|
5492
|
+
},
|
|
5493
|
+
async buildEnd() {
|
|
5494
|
+
await configLoader.close();
|
|
5495
|
+
}
|
|
5496
|
+
},
|
|
5497
|
+
{
|
|
5498
|
+
name: "react-router/rsc/typegen",
|
|
5499
|
+
async config(viteUserConfig, { command, mode }) {
|
|
5500
|
+
if (command === "serve") {
|
|
5501
|
+
const vite2 = await import("vite");
|
|
5502
|
+
typegenWatcherPromise = watch(
|
|
5503
|
+
getRootDirectory(viteUserConfig),
|
|
5504
|
+
{
|
|
5505
|
+
mode,
|
|
5506
|
+
rsc: true,
|
|
5507
|
+
// ignore `info` logs from typegen since they are
|
|
5508
|
+
// redundant when Vite plugin logs are active
|
|
5509
|
+
logger: vite2.createLogger("warn", {
|
|
5510
|
+
prefix: "[react-router]"
|
|
5511
|
+
})
|
|
5512
|
+
}
|
|
5513
|
+
);
|
|
5514
|
+
}
|
|
5515
|
+
},
|
|
5516
|
+
async buildEnd() {
|
|
5517
|
+
(await typegenWatcherPromise)?.close();
|
|
5518
|
+
}
|
|
5519
|
+
},
|
|
5520
|
+
{
|
|
5521
|
+
name: "react-router/rsc/virtual-rsc-entry",
|
|
5522
|
+
resolveId(id) {
|
|
5523
|
+
if (id === virtual2.rscEntry.id) return defaultEntries2.rsc;
|
|
5524
|
+
}
|
|
5525
|
+
},
|
|
5526
|
+
{
|
|
5527
|
+
name: "react-router/rsc/virtual-route-config",
|
|
5528
|
+
resolveId(id) {
|
|
5529
|
+
if (id === virtual2.routeConfig.id) {
|
|
5530
|
+
return virtual2.routeConfig.resolvedId;
|
|
5531
|
+
}
|
|
5532
|
+
},
|
|
5533
|
+
load(id) {
|
|
5534
|
+
if (id === virtual2.routeConfig.resolvedId) {
|
|
5535
|
+
const result = createVirtualRouteConfig({
|
|
5536
|
+
appDirectory: config.appDirectory,
|
|
5537
|
+
routeConfig: config.unstable_routeConfig
|
|
5538
|
+
});
|
|
5539
|
+
routeIdByFile = result.routeIdByFile;
|
|
5540
|
+
return result.code;
|
|
5541
|
+
}
|
|
5542
|
+
}
|
|
5543
|
+
},
|
|
5544
|
+
{
|
|
5545
|
+
name: "react-router/rsc/virtual-route-modules",
|
|
5546
|
+
transform(code, id) {
|
|
5547
|
+
if (!routeIdByFile) return;
|
|
5548
|
+
return transformVirtualRouteModules({
|
|
5549
|
+
code,
|
|
5550
|
+
id,
|
|
5551
|
+
viteCommand,
|
|
5552
|
+
routeIdByFile,
|
|
5553
|
+
rootRouteFile,
|
|
5554
|
+
viteEnvironment: this.environment
|
|
5555
|
+
});
|
|
5556
|
+
}
|
|
5557
|
+
},
|
|
5558
|
+
{
|
|
5559
|
+
name: "react-router/rsc/virtual-basename",
|
|
5560
|
+
resolveId(id) {
|
|
5561
|
+
if (id === virtual2.basename.id) {
|
|
5562
|
+
return virtual2.basename.resolvedId;
|
|
5563
|
+
}
|
|
5564
|
+
},
|
|
5565
|
+
load(id) {
|
|
5566
|
+
if (id === virtual2.basename.resolvedId) {
|
|
5567
|
+
return `export default ${JSON.stringify(config.basename)};`;
|
|
5568
|
+
}
|
|
5569
|
+
}
|
|
5570
|
+
},
|
|
5571
|
+
{
|
|
5572
|
+
name: "react-router/rsc/hmr/inject-runtime",
|
|
5573
|
+
enforce: "pre",
|
|
5574
|
+
resolveId(id) {
|
|
5575
|
+
if (id === virtual2.injectHmrRuntime.id) {
|
|
5576
|
+
return virtual2.injectHmrRuntime.resolvedId;
|
|
5577
|
+
}
|
|
5578
|
+
},
|
|
5579
|
+
async load(id) {
|
|
5580
|
+
if (id !== virtual2.injectHmrRuntime.resolvedId) return;
|
|
5581
|
+
return viteCommand === "serve" ? [
|
|
5582
|
+
`import RefreshRuntime from "${virtual2.hmrRuntime.id}"`,
|
|
5583
|
+
"RefreshRuntime.injectIntoGlobalHook(window)",
|
|
5584
|
+
"window.$RefreshReg$ = () => {}",
|
|
5585
|
+
"window.$RefreshSig$ = () => (type) => type",
|
|
5586
|
+
"window.__vite_plugin_react_preamble_installed__ = true"
|
|
5587
|
+
].join("\n") : "";
|
|
5588
|
+
}
|
|
5589
|
+
},
|
|
5590
|
+
{
|
|
5591
|
+
name: "react-router/rsc/hmr/runtime",
|
|
5592
|
+
enforce: "pre",
|
|
5593
|
+
resolveId(id) {
|
|
5594
|
+
if (id === virtual2.hmrRuntime.id) return virtual2.hmrRuntime.resolvedId;
|
|
5595
|
+
},
|
|
5596
|
+
async load(id) {
|
|
5597
|
+
if (id !== virtual2.hmrRuntime.resolvedId) return;
|
|
5598
|
+
const reactRefreshDir = import_pathe6.default.dirname(
|
|
5599
|
+
require.resolve("react-refresh/package.json")
|
|
5600
|
+
);
|
|
5601
|
+
const reactRefreshRuntimePath = import_pathe6.default.join(
|
|
5602
|
+
reactRefreshDir,
|
|
5603
|
+
"cjs/react-refresh-runtime.development.js"
|
|
5604
|
+
);
|
|
5605
|
+
return [
|
|
5606
|
+
"const exports = {}",
|
|
5607
|
+
await (0, import_promises3.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
5608
|
+
await (0, import_promises3.readFile)(
|
|
5609
|
+
require.resolve("./static/rsc-refresh-utils.mjs"),
|
|
5610
|
+
"utf8"
|
|
5611
|
+
),
|
|
5612
|
+
"export default exports"
|
|
5613
|
+
].join("\n");
|
|
5614
|
+
}
|
|
5615
|
+
},
|
|
5616
|
+
{
|
|
5617
|
+
name: "react-router/rsc/hmr/react-refresh",
|
|
5618
|
+
async transform(code, id, options) {
|
|
5619
|
+
if (viteCommand !== "serve") return;
|
|
5620
|
+
if (id.includes("/node_modules/")) return;
|
|
5621
|
+
const filepath = id.split("?")[0];
|
|
5622
|
+
const extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
|
|
5623
|
+
if (!extensionsRE.test(filepath)) return;
|
|
5624
|
+
const devRuntime = "react/jsx-dev-runtime";
|
|
5625
|
+
const ssr = options?.ssr === true;
|
|
5626
|
+
const isJSX = filepath.endsWith("x");
|
|
5627
|
+
const useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
5628
|
+
if (!useFastRefresh) return;
|
|
5629
|
+
if (isVirtualClientRouteModuleId(id)) {
|
|
5630
|
+
const routeId = routeIdByFile?.get(filepath);
|
|
5631
|
+
return { code: addRefreshWrapper2({ routeId, code, id }) };
|
|
5632
|
+
}
|
|
5633
|
+
const result = await babel2.transformAsync(code, {
|
|
5634
|
+
babelrc: false,
|
|
5635
|
+
configFile: false,
|
|
5636
|
+
filename: id,
|
|
5637
|
+
sourceFileName: filepath,
|
|
5638
|
+
parserOpts: {
|
|
5639
|
+
sourceType: "module",
|
|
5640
|
+
allowAwaitOutsideFunction: true
|
|
5641
|
+
},
|
|
5642
|
+
plugins: [[require("react-refresh/babel"), { skipEnvCheck: true }]],
|
|
5643
|
+
sourceMaps: true
|
|
5644
|
+
});
|
|
5645
|
+
if (result === null) return;
|
|
5646
|
+
code = result.code;
|
|
5647
|
+
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
5648
|
+
if (refreshContentRE.test(code)) {
|
|
5649
|
+
code = addRefreshWrapper2({ code, id });
|
|
5650
|
+
}
|
|
5651
|
+
return { code, map: result.map };
|
|
5652
|
+
}
|
|
5653
|
+
},
|
|
5654
|
+
{
|
|
5655
|
+
name: "react-router/rsc/hmr/updates",
|
|
5656
|
+
async hotUpdate({ server, file, modules }) {
|
|
5657
|
+
if (this.environment.name !== "rsc") return;
|
|
5658
|
+
const clientModules = server.environments.client.moduleGraph.getModulesByFile(file);
|
|
5659
|
+
const vite2 = await import("vite");
|
|
5660
|
+
const isServerOnlyChange = !clientModules || clientModules.size === 0 || // Handle CSS injected from server-first routes (with ?direct query
|
|
5661
|
+
// string) since the client graph has a reference to the CSS
|
|
5662
|
+
vite2.isCSSRequest(file) && Array.from(clientModules).some(
|
|
5663
|
+
(mod) => mod.id?.includes("?direct")
|
|
5664
|
+
);
|
|
5665
|
+
for (const mod of getModulesWithImporters(modules)) {
|
|
5666
|
+
if (!mod.file) continue;
|
|
5667
|
+
const normalizedPath = import_pathe6.default.normalize(mod.file);
|
|
5668
|
+
const routeId = routeIdByFile?.get(normalizedPath);
|
|
5669
|
+
if (routeId !== void 0) {
|
|
5670
|
+
const routeSource = await (0, import_promises3.readFile)(normalizedPath, "utf8");
|
|
5671
|
+
const virtualRouteModuleCode = (await server.environments.rsc.pluginContainer.transform(
|
|
5672
|
+
routeSource,
|
|
5673
|
+
`${normalizedPath}?route-module`
|
|
5674
|
+
)).code;
|
|
5675
|
+
const { staticExports } = parseRouteExports(virtualRouteModuleCode);
|
|
5676
|
+
const hasAction = staticExports.includes("action");
|
|
5677
|
+
const hasComponent = staticExports.includes("default");
|
|
5678
|
+
const hasErrorBoundary = staticExports.includes("ErrorBoundary");
|
|
5679
|
+
const hasLoader = staticExports.includes("loader");
|
|
5680
|
+
server.hot.send({
|
|
5681
|
+
type: "custom",
|
|
5682
|
+
event: "react-router:hmr",
|
|
5683
|
+
data: {
|
|
5684
|
+
routeId,
|
|
5685
|
+
isServerOnlyChange,
|
|
5686
|
+
hasAction,
|
|
5687
|
+
hasComponent,
|
|
5688
|
+
hasErrorBoundary,
|
|
5689
|
+
hasLoader
|
|
5690
|
+
}
|
|
5691
|
+
});
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
return modules;
|
|
5695
|
+
}
|
|
5696
|
+
},
|
|
5697
|
+
validatePluginOrder(),
|
|
5698
|
+
warnOnClientSourceMaps()
|
|
5699
|
+
];
|
|
5700
|
+
}
|
|
5701
|
+
var virtual2 = {
|
|
5702
|
+
routeConfig: create("unstable_rsc/routes"),
|
|
5703
|
+
injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
|
|
5704
|
+
hmrRuntime: create("unstable_rsc/runtime"),
|
|
5705
|
+
basename: create("unstable_rsc/basename"),
|
|
5706
|
+
rscEntry: create("unstable_rsc/rsc-entry")
|
|
5707
|
+
};
|
|
5708
|
+
function invalidateVirtualModules2(viteDevServer) {
|
|
5709
|
+
for (const vmod of Object.values(virtual2)) {
|
|
5710
|
+
for (const env of Object.values(viteDevServer.environments)) {
|
|
5711
|
+
const mod = env.moduleGraph.getModuleById(vmod.resolvedId);
|
|
5712
|
+
if (mod) {
|
|
5713
|
+
env.moduleGraph.invalidateModule(mod);
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5716
|
+
}
|
|
5717
|
+
}
|
|
5718
|
+
function getRootDirectory(viteUserConfig) {
|
|
5719
|
+
return viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
5720
|
+
}
|
|
5721
|
+
function getDevPackageRoot() {
|
|
5722
|
+
const currentDir = (0, import_pathe6.dirname)(__dirname);
|
|
5723
|
+
let dir = currentDir;
|
|
5724
|
+
while (dir !== (0, import_pathe6.dirname)(dir)) {
|
|
5725
|
+
try {
|
|
5726
|
+
const packageJsonPath = (0, import_pathe6.join)(dir, "package.json");
|
|
5727
|
+
(0, import_fs.readFileSync)(packageJsonPath, "utf-8");
|
|
5728
|
+
return dir;
|
|
5729
|
+
} catch {
|
|
5730
|
+
dir = (0, import_pathe6.dirname)(dir);
|
|
5731
|
+
}
|
|
5732
|
+
}
|
|
5733
|
+
throw new Error("Could not find package.json");
|
|
5734
|
+
}
|
|
5735
|
+
function getDefaultEntries() {
|
|
5736
|
+
const defaultEntriesDir2 = (0, import_pathe6.join)(
|
|
5737
|
+
getDevPackageRoot(),
|
|
5738
|
+
"dist",
|
|
5739
|
+
"config",
|
|
5740
|
+
"default-rsc-entries"
|
|
5741
|
+
);
|
|
5742
|
+
return {
|
|
5743
|
+
rsc: (0, import_pathe6.join)(defaultEntriesDir2, "entry.rsc.tsx"),
|
|
5744
|
+
ssr: (0, import_pathe6.join)(defaultEntriesDir2, "entry.ssr.tsx"),
|
|
5745
|
+
client: (0, import_pathe6.join)(defaultEntriesDir2, "entry.client.tsx")
|
|
5746
|
+
};
|
|
5747
|
+
}
|
|
5748
|
+
function getModulesWithImporters(modules) {
|
|
5749
|
+
const visited = /* @__PURE__ */ new Set();
|
|
5750
|
+
const result = /* @__PURE__ */ new Set();
|
|
5751
|
+
function walk(module2) {
|
|
5752
|
+
if (visited.has(module2)) return;
|
|
5753
|
+
visited.add(module2);
|
|
5754
|
+
result.add(module2);
|
|
5755
|
+
for (const importer of module2.importers) {
|
|
5756
|
+
walk(importer);
|
|
5757
|
+
}
|
|
5758
|
+
}
|
|
5759
|
+
for (const module2 of modules) {
|
|
5760
|
+
walk(module2);
|
|
5761
|
+
}
|
|
5762
|
+
return result;
|
|
5763
|
+
}
|
|
5764
|
+
function addRefreshWrapper2({
|
|
5765
|
+
routeId,
|
|
5766
|
+
code,
|
|
5767
|
+
id
|
|
5768
|
+
}) {
|
|
5769
|
+
const acceptExports = routeId !== void 0 ? CLIENT_NON_COMPONENT_EXPORTS2 : [];
|
|
5770
|
+
return REACT_REFRESH_HEADER2.replaceAll("__SOURCE__", JSON.stringify(id)) + code + REACT_REFRESH_FOOTER2.replaceAll("__SOURCE__", JSON.stringify(id)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(routeId));
|
|
5771
|
+
}
|
|
5772
|
+
var REACT_REFRESH_HEADER2 = `
|
|
5773
|
+
import RefreshRuntime from "${virtual2.hmrRuntime.id}";
|
|
5774
|
+
|
|
5775
|
+
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
5776
|
+
let prevRefreshReg;
|
|
5777
|
+
let prevRefreshSig;
|
|
5778
|
+
|
|
5779
|
+
if (import.meta.hot && !inWebWorker) {
|
|
5780
|
+
if (!window.__vite_plugin_react_preamble_installed__) {
|
|
5781
|
+
throw new Error(
|
|
5782
|
+
"React Router Vite plugin can't detect preamble. Something is wrong."
|
|
5783
|
+
);
|
|
5784
|
+
}
|
|
5785
|
+
|
|
5786
|
+
prevRefreshReg = window.$RefreshReg$;
|
|
5787
|
+
prevRefreshSig = window.$RefreshSig$;
|
|
5788
|
+
window.$RefreshReg$ = (type, id) => {
|
|
5789
|
+
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
5790
|
+
};
|
|
5791
|
+
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
5792
|
+
}`.replaceAll("\n", "");
|
|
5793
|
+
var REACT_REFRESH_FOOTER2 = `
|
|
5794
|
+
if (import.meta.hot && !inWebWorker) {
|
|
5795
|
+
window.$RefreshReg$ = prevRefreshReg;
|
|
5796
|
+
window.$RefreshSig$ = prevRefreshSig;
|
|
5797
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
5798
|
+
RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
|
|
5799
|
+
import.meta.hot.accept((nextExports) => {
|
|
5800
|
+
if (!nextExports) return;
|
|
5801
|
+
__ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
|
|
5802
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
|
|
5803
|
+
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
5804
|
+
});
|
|
5805
|
+
});
|
|
5806
|
+
}`;
|
|
4934
5807
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4935
5808
|
0 && (module.exports = {
|
|
4936
|
-
reactRouter
|
|
5809
|
+
reactRouter,
|
|
5810
|
+
unstable_reactRouterRSC
|
|
4937
5811
|
});
|