@react-router/dev 7.9.1 → 7.9.2-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 +11 -8
- package/dist/cli/index.js +5 -8
- package/dist/config/default-rsc-entries/entry.rsc.tsx +3 -0
- package/dist/config/default-rsc-entries/entry.ssr.tsx +2 -4
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +6 -72
- package/dist/vite.d.ts +3 -1
- package/dist/vite.js +1021 -175
- package/package.json +9 -14
- package/dist/internal.d.ts +0 -9
- package/dist/internal.js +0 -2307
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v7.9.
|
|
2
|
+
* @react-router/dev v7.9.2-pre.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -40,7 +40,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
40
40
|
// vite.ts
|
|
41
41
|
var vite_exports = {};
|
|
42
42
|
__export(vite_exports, {
|
|
43
|
-
reactRouter: () => reactRouterVitePlugin
|
|
43
|
+
reactRouter: () => reactRouterVitePlugin,
|
|
44
|
+
unstable_reactRouterRSC: () => reactRouterRSCVitePlugin
|
|
44
45
|
});
|
|
45
46
|
module.exports = __toCommonJS(vite_exports);
|
|
46
47
|
|
|
@@ -51,6 +52,7 @@ var import_promises2 = require("fs/promises");
|
|
|
51
52
|
var path6 = __toESM(require("path"));
|
|
52
53
|
var url = __toESM(require("url"));
|
|
53
54
|
var babel = __toESM(require("@babel/core"));
|
|
55
|
+
var import_node_fetch_server2 = require("@remix-run/node-fetch-server");
|
|
54
56
|
var import_react_router2 = require("react-router");
|
|
55
57
|
var import_es_module_lexer = require("es-module-lexer");
|
|
56
58
|
var import_pick3 = __toESM(require("lodash/pick"));
|
|
@@ -246,7 +248,7 @@ function validateRouteConfig({
|
|
|
246
248
|
`Route config in "${routeConfigFile}" is invalid.`,
|
|
247
249
|
root ? `${root}` : [],
|
|
248
250
|
nested ? Object.entries(nested).map(
|
|
249
|
-
([
|
|
251
|
+
([path9, message]) => `Path: routes.${path9}
|
|
250
252
|
${message}`
|
|
251
253
|
) : []
|
|
252
254
|
].flat().join("\n\n")
|
|
@@ -617,12 +619,12 @@ async function createConfigLoader({
|
|
|
617
619
|
if (!fsWatcher) {
|
|
618
620
|
fsWatcher = import_chokidar.default.watch([root, appDirectory], {
|
|
619
621
|
ignoreInitial: true,
|
|
620
|
-
ignored: (
|
|
621
|
-
let
|
|
622
|
-
return !
|
|
622
|
+
ignored: (path9) => {
|
|
623
|
+
let dirname5 = import_pathe3.default.dirname(path9);
|
|
624
|
+
return !dirname5.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
|
|
623
625
|
// that are at the root level, not nested in subdirectories
|
|
624
|
-
|
|
625
|
-
|
|
626
|
+
path9 !== root && // Watch the root directory itself
|
|
627
|
+
dirname5 !== root;
|
|
626
628
|
}
|
|
627
629
|
});
|
|
628
630
|
fsWatcher.on("all", async (...args) => {
|
|
@@ -882,7 +884,7 @@ function fullpath(lineage2) {
|
|
|
882
884
|
if (lineage2.length === 1 && route?.id === "root") return "/";
|
|
883
885
|
const isLayout = route && route.index !== true && route.path === void 0;
|
|
884
886
|
if (isLayout) return void 0;
|
|
885
|
-
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((
|
|
887
|
+
return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path9) => path9 !== void 0 && path9 !== "").join("/");
|
|
886
888
|
}
|
|
887
889
|
|
|
888
890
|
// typegen/generate.ts
|
|
@@ -1038,8 +1040,8 @@ function routeFilesType({
|
|
|
1038
1040
|
);
|
|
1039
1041
|
}
|
|
1040
1042
|
function isInAppDirectory(ctx, routeFile) {
|
|
1041
|
-
const
|
|
1042
|
-
return
|
|
1043
|
+
const path9 = Path3.resolve(ctx.config.appDirectory, routeFile);
|
|
1044
|
+
return path9.startsWith(ctx.config.appDirectory);
|
|
1043
1045
|
}
|
|
1044
1046
|
function getRouteAnnotations({
|
|
1045
1047
|
ctx,
|
|
@@ -1151,21 +1153,21 @@ function getRouteAnnotations({
|
|
|
1151
1153
|
return { filename: filename2, content };
|
|
1152
1154
|
}
|
|
1153
1155
|
function relativeImportSource(from, to) {
|
|
1154
|
-
let
|
|
1155
|
-
let extension = Path3.extname(
|
|
1156
|
-
|
|
1157
|
-
if (!
|
|
1156
|
+
let path9 = Path3.relative(Path3.dirname(from), to);
|
|
1157
|
+
let extension = Path3.extname(path9);
|
|
1158
|
+
path9 = Path3.join(Path3.dirname(path9), Pathe.filename(path9));
|
|
1159
|
+
if (!path9.startsWith("../")) path9 = "./" + path9;
|
|
1158
1160
|
if (!extension || /\.(js|ts)x?$/.test(extension)) {
|
|
1159
1161
|
extension = ".js";
|
|
1160
1162
|
}
|
|
1161
|
-
return
|
|
1163
|
+
return path9 + extension;
|
|
1162
1164
|
}
|
|
1163
1165
|
function rootDirsPath(ctx, typesPath) {
|
|
1164
1166
|
const rel = Path3.relative(typesDirectory(ctx), typesPath);
|
|
1165
1167
|
return Path3.join(ctx.rootDirectory, rel);
|
|
1166
1168
|
}
|
|
1167
|
-
function paramsType(
|
|
1168
|
-
const params = parse2(
|
|
1169
|
+
function paramsType(path9) {
|
|
1170
|
+
const params = parse2(path9);
|
|
1169
1171
|
return t2.tsTypeLiteral(
|
|
1170
1172
|
Object.entries(params).map(([param, isRequired]) => {
|
|
1171
1173
|
const property = t2.tsPropertySignature(
|
|
@@ -1254,81 +1256,14 @@ async function watch(rootDirectory, { mode, logger, rsc }) {
|
|
|
1254
1256
|
}
|
|
1255
1257
|
|
|
1256
1258
|
// vite/node-adapter.ts
|
|
1257
|
-
var
|
|
1258
|
-
var import_node_tls = require("tls");
|
|
1259
|
-
var import_node_stream = require("stream");
|
|
1260
|
-
var import_set_cookie_parser = require("set-cookie-parser");
|
|
1261
|
-
var import_node = require("@react-router/node");
|
|
1262
|
-
function fromNodeHeaders(nodeReq) {
|
|
1263
|
-
let nodeHeaders = nodeReq.headers;
|
|
1264
|
-
if (nodeReq.httpVersionMajor >= 2) {
|
|
1265
|
-
nodeHeaders = { ...nodeHeaders };
|
|
1266
|
-
if (nodeHeaders[":authority"]) {
|
|
1267
|
-
nodeHeaders.host = nodeHeaders[":authority"];
|
|
1268
|
-
}
|
|
1269
|
-
delete nodeHeaders[":authority"];
|
|
1270
|
-
delete nodeHeaders[":method"];
|
|
1271
|
-
delete nodeHeaders[":path"];
|
|
1272
|
-
delete nodeHeaders[":scheme"];
|
|
1273
|
-
}
|
|
1274
|
-
let headers = new Headers();
|
|
1275
|
-
for (let [key, values] of Object.entries(nodeHeaders)) {
|
|
1276
|
-
if (values) {
|
|
1277
|
-
if (Array.isArray(values)) {
|
|
1278
|
-
for (let value of values) {
|
|
1279
|
-
headers.append(key, value);
|
|
1280
|
-
}
|
|
1281
|
-
} else {
|
|
1282
|
-
headers.set(key, values);
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
return headers;
|
|
1287
|
-
}
|
|
1259
|
+
var import_node_fetch_server = require("@remix-run/node-fetch-server");
|
|
1288
1260
|
function fromNodeRequest(nodeReq, nodeRes) {
|
|
1289
|
-
let protocol = nodeReq.socket instanceof import_node_tls.TLSSocket && nodeReq.socket.encrypted ? "https" : "http";
|
|
1290
|
-
let origin = nodeReq.headers.origin && "null" !== nodeReq.headers.origin ? nodeReq.headers.origin : `${protocol}://${nodeReq.headers.host}`;
|
|
1291
1261
|
invariant(
|
|
1292
1262
|
nodeReq.originalUrl,
|
|
1293
1263
|
"Expected `nodeReq.originalUrl` to be defined"
|
|
1294
1264
|
);
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
let init = {
|
|
1298
|
-
method: nodeReq.method,
|
|
1299
|
-
headers: fromNodeHeaders(nodeReq),
|
|
1300
|
-
signal: controller.signal
|
|
1301
|
-
};
|
|
1302
|
-
nodeRes.on("finish", () => controller = null);
|
|
1303
|
-
nodeRes.on("close", () => controller?.abort());
|
|
1304
|
-
if (nodeReq.method !== "GET" && nodeReq.method !== "HEAD") {
|
|
1305
|
-
init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
|
|
1306
|
-
init.duplex = "half";
|
|
1307
|
-
}
|
|
1308
|
-
return new Request(url2.href, init);
|
|
1309
|
-
}
|
|
1310
|
-
async function toNodeRequest(res, nodeRes) {
|
|
1311
|
-
nodeRes.statusCode = res.status;
|
|
1312
|
-
if (!nodeRes.req || nodeRes.req.httpVersionMajor < 2) {
|
|
1313
|
-
nodeRes.statusMessage = res.statusText;
|
|
1314
|
-
}
|
|
1315
|
-
let cookiesStrings = [];
|
|
1316
|
-
for (let [name, value] of res.headers) {
|
|
1317
|
-
if (name === "set-cookie") {
|
|
1318
|
-
cookiesStrings.push(...(0, import_set_cookie_parser.splitCookiesString)(value));
|
|
1319
|
-
} else nodeRes.setHeader(name, value);
|
|
1320
|
-
}
|
|
1321
|
-
if (cookiesStrings.length) {
|
|
1322
|
-
nodeRes.setHeader("set-cookie", cookiesStrings);
|
|
1323
|
-
}
|
|
1324
|
-
if (res.body) {
|
|
1325
|
-
let responseBody = res.body;
|
|
1326
|
-
let readable = import_node_stream.Readable.from(responseBody);
|
|
1327
|
-
readable.pipe(nodeRes);
|
|
1328
|
-
await (0, import_node_events.once)(readable, "end");
|
|
1329
|
-
} else {
|
|
1330
|
-
nodeRes.end();
|
|
1331
|
-
}
|
|
1265
|
+
nodeReq.url = nodeReq.originalUrl;
|
|
1266
|
+
return (0, import_node_fetch_server.createRequest)(nodeReq, nodeRes);
|
|
1332
1267
|
}
|
|
1333
1268
|
|
|
1334
1269
|
// vite/styles.ts
|
|
@@ -1501,11 +1436,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
|
|
|
1501
1436
|
let cssContent = void 0;
|
|
1502
1437
|
const ast = import_parser.parse(code, { sourceType: "module" });
|
|
1503
1438
|
traverse(ast, {
|
|
1504
|
-
VariableDeclaration(
|
|
1505
|
-
const declaration =
|
|
1439
|
+
VariableDeclaration(path9) {
|
|
1440
|
+
const declaration = path9.node.declarations[0];
|
|
1506
1441
|
if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
|
|
1507
1442
|
cssContent = declaration.init.value;
|
|
1508
|
-
|
|
1443
|
+
path9.stop();
|
|
1509
1444
|
}
|
|
1510
1445
|
}
|
|
1511
1446
|
});
|
|
@@ -1544,10 +1479,10 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1544
1479
|
let markedForRemoval = /* @__PURE__ */ new Set();
|
|
1545
1480
|
let removedExportLocalNames = /* @__PURE__ */ new Set();
|
|
1546
1481
|
traverse(ast, {
|
|
1547
|
-
ExportDeclaration(
|
|
1548
|
-
if (
|
|
1549
|
-
if (
|
|
1550
|
-
|
|
1482
|
+
ExportDeclaration(path9) {
|
|
1483
|
+
if (path9.node.type === "ExportNamedDeclaration") {
|
|
1484
|
+
if (path9.node.specifiers.length) {
|
|
1485
|
+
path9.node.specifiers = path9.node.specifiers.filter((specifier) => {
|
|
1551
1486
|
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
1552
1487
|
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
1553
1488
|
exportsFiltered = true;
|
|
@@ -1559,12 +1494,12 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1559
1494
|
}
|
|
1560
1495
|
return true;
|
|
1561
1496
|
});
|
|
1562
|
-
if (
|
|
1563
|
-
markedForRemoval.add(
|
|
1497
|
+
if (path9.node.specifiers.length === 0) {
|
|
1498
|
+
markedForRemoval.add(path9);
|
|
1564
1499
|
}
|
|
1565
1500
|
}
|
|
1566
|
-
if (
|
|
1567
|
-
let declaration =
|
|
1501
|
+
if (path9.node.declaration?.type === "VariableDeclaration") {
|
|
1502
|
+
let declaration = path9.node.declaration;
|
|
1568
1503
|
declaration.declarations = declaration.declarations.filter(
|
|
1569
1504
|
(declaration2) => {
|
|
1570
1505
|
if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
|
|
@@ -1578,30 +1513,30 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1578
1513
|
}
|
|
1579
1514
|
);
|
|
1580
1515
|
if (declaration.declarations.length === 0) {
|
|
1581
|
-
markedForRemoval.add(
|
|
1516
|
+
markedForRemoval.add(path9);
|
|
1582
1517
|
}
|
|
1583
1518
|
}
|
|
1584
|
-
if (
|
|
1585
|
-
let id =
|
|
1519
|
+
if (path9.node.declaration?.type === "FunctionDeclaration") {
|
|
1520
|
+
let id = path9.node.declaration.id;
|
|
1586
1521
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1587
|
-
markedForRemoval.add(
|
|
1522
|
+
markedForRemoval.add(path9);
|
|
1588
1523
|
}
|
|
1589
1524
|
}
|
|
1590
|
-
if (
|
|
1591
|
-
let id =
|
|
1525
|
+
if (path9.node.declaration?.type === "ClassDeclaration") {
|
|
1526
|
+
let id = path9.node.declaration.id;
|
|
1592
1527
|
if (id && exportsToRemove.includes(id.name)) {
|
|
1593
|
-
markedForRemoval.add(
|
|
1528
|
+
markedForRemoval.add(path9);
|
|
1594
1529
|
}
|
|
1595
1530
|
}
|
|
1596
1531
|
}
|
|
1597
|
-
if (
|
|
1532
|
+
if (path9.node.type === "ExportDefaultDeclaration") {
|
|
1598
1533
|
if (exportsToRemove.includes("default")) {
|
|
1599
|
-
markedForRemoval.add(
|
|
1600
|
-
if (
|
|
1601
|
-
if (
|
|
1602
|
-
removedExportLocalNames.add(
|
|
1603
|
-
} else if ((
|
|
1604
|
-
removedExportLocalNames.add(
|
|
1534
|
+
markedForRemoval.add(path9);
|
|
1535
|
+
if (path9.node.declaration) {
|
|
1536
|
+
if (path9.node.declaration.type === "Identifier") {
|
|
1537
|
+
removedExportLocalNames.add(path9.node.declaration.name);
|
|
1538
|
+
} else if ((path9.node.declaration.type === "FunctionDeclaration" || path9.node.declaration.type === "ClassDeclaration") && path9.node.declaration.id) {
|
|
1539
|
+
removedExportLocalNames.add(path9.node.declaration.id.name);
|
|
1605
1540
|
}
|
|
1606
1541
|
}
|
|
1607
1542
|
}
|
|
@@ -1609,21 +1544,21 @@ var removeExports = (ast, exportsToRemove) => {
|
|
|
1609
1544
|
}
|
|
1610
1545
|
});
|
|
1611
1546
|
traverse(ast, {
|
|
1612
|
-
ExpressionStatement(
|
|
1613
|
-
if (!
|
|
1547
|
+
ExpressionStatement(path9) {
|
|
1548
|
+
if (!path9.parentPath.isProgram()) {
|
|
1614
1549
|
return;
|
|
1615
1550
|
}
|
|
1616
|
-
if (
|
|
1617
|
-
const left =
|
|
1551
|
+
if (path9.node.expression.type === "AssignmentExpression") {
|
|
1552
|
+
const left = path9.node.expression.left;
|
|
1618
1553
|
if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
|
|
1619
|
-
markedForRemoval.add(
|
|
1554
|
+
markedForRemoval.add(path9);
|
|
1620
1555
|
}
|
|
1621
1556
|
}
|
|
1622
1557
|
}
|
|
1623
1558
|
});
|
|
1624
1559
|
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
1625
|
-
for (let
|
|
1626
|
-
|
|
1560
|
+
for (let path9 of markedForRemoval) {
|
|
1561
|
+
path9.remove();
|
|
1627
1562
|
}
|
|
1628
1563
|
(0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
|
|
1629
1564
|
}
|
|
@@ -1706,28 +1641,28 @@ function codeToAst(code, cache, cacheKey) {
|
|
|
1706
1641
|
)
|
|
1707
1642
|
);
|
|
1708
1643
|
}
|
|
1709
|
-
function assertNodePath(
|
|
1644
|
+
function assertNodePath(path9) {
|
|
1710
1645
|
invariant(
|
|
1711
|
-
|
|
1712
|
-
`Expected a Path, but got ${Array.isArray(
|
|
1646
|
+
path9 && !Array.isArray(path9),
|
|
1647
|
+
`Expected a Path, but got ${Array.isArray(path9) ? "an array" : path9}`
|
|
1713
1648
|
);
|
|
1714
1649
|
}
|
|
1715
|
-
function assertNodePathIsStatement(
|
|
1650
|
+
function assertNodePathIsStatement(path9) {
|
|
1716
1651
|
invariant(
|
|
1717
|
-
|
|
1718
|
-
`Expected a Statement path, but got ${Array.isArray(
|
|
1652
|
+
path9 && !Array.isArray(path9) && t.isStatement(path9.node),
|
|
1653
|
+
`Expected a Statement path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1719
1654
|
);
|
|
1720
1655
|
}
|
|
1721
|
-
function assertNodePathIsVariableDeclarator(
|
|
1656
|
+
function assertNodePathIsVariableDeclarator(path9) {
|
|
1722
1657
|
invariant(
|
|
1723
|
-
|
|
1724
|
-
`Expected an Identifier path, but got ${Array.isArray(
|
|
1658
|
+
path9 && !Array.isArray(path9) && t.isVariableDeclarator(path9.node),
|
|
1659
|
+
`Expected an Identifier path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1725
1660
|
);
|
|
1726
1661
|
}
|
|
1727
|
-
function assertNodePathIsPattern(
|
|
1662
|
+
function assertNodePathIsPattern(path9) {
|
|
1728
1663
|
invariant(
|
|
1729
|
-
|
|
1730
|
-
`Expected a Pattern path, but got ${Array.isArray(
|
|
1664
|
+
path9 && !Array.isArray(path9) && t.isPattern(path9.node),
|
|
1665
|
+
`Expected a Pattern path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
|
|
1731
1666
|
);
|
|
1732
1667
|
}
|
|
1733
1668
|
function getExportDependencies(code, cache, cacheKey) {
|
|
@@ -1763,8 +1698,8 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1763
1698
|
}
|
|
1764
1699
|
let isWithinExportDestructuring = Boolean(
|
|
1765
1700
|
identifier.findParent(
|
|
1766
|
-
(
|
|
1767
|
-
|
|
1701
|
+
(path9) => Boolean(
|
|
1702
|
+
path9.isPattern() && path9.parentPath?.isVariableDeclarator() && path9.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
|
|
1768
1703
|
)
|
|
1769
1704
|
)
|
|
1770
1705
|
);
|
|
@@ -1842,7 +1777,7 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1842
1777
|
for (let specifier of node.specifiers) {
|
|
1843
1778
|
if (t.isIdentifier(specifier.exported)) {
|
|
1844
1779
|
let name = specifier.exported.name;
|
|
1845
|
-
let specifierPath = exportPath.get("specifiers").find((
|
|
1780
|
+
let specifierPath = exportPath.get("specifiers").find((path9) => path9.node === specifier);
|
|
1846
1781
|
invariant(
|
|
1847
1782
|
specifierPath,
|
|
1848
1783
|
`Expected to find specifier path for ${name}`
|
|
@@ -1859,22 +1794,22 @@ function getExportDependencies(code, cache, cacheKey) {
|
|
|
1859
1794
|
}
|
|
1860
1795
|
);
|
|
1861
1796
|
}
|
|
1862
|
-
function getDependentIdentifiersForPath(
|
|
1797
|
+
function getDependentIdentifiersForPath(path9, state) {
|
|
1863
1798
|
let { visited, identifiers } = state ?? {
|
|
1864
1799
|
visited: /* @__PURE__ */ new Set(),
|
|
1865
1800
|
identifiers: /* @__PURE__ */ new Set()
|
|
1866
1801
|
};
|
|
1867
|
-
if (visited.has(
|
|
1802
|
+
if (visited.has(path9)) {
|
|
1868
1803
|
return identifiers;
|
|
1869
1804
|
}
|
|
1870
|
-
visited.add(
|
|
1871
|
-
|
|
1872
|
-
Identifier(
|
|
1873
|
-
if (identifiers.has(
|
|
1805
|
+
visited.add(path9);
|
|
1806
|
+
path9.traverse({
|
|
1807
|
+
Identifier(path10) {
|
|
1808
|
+
if (identifiers.has(path10)) {
|
|
1874
1809
|
return;
|
|
1875
1810
|
}
|
|
1876
|
-
identifiers.add(
|
|
1877
|
-
let binding =
|
|
1811
|
+
identifiers.add(path10);
|
|
1812
|
+
let binding = path10.scope.getBinding(path10.node.name);
|
|
1878
1813
|
if (!binding) {
|
|
1879
1814
|
return;
|
|
1880
1815
|
}
|
|
@@ -1896,7 +1831,7 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1896
1831
|
}
|
|
1897
1832
|
}
|
|
1898
1833
|
});
|
|
1899
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1834
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path9);
|
|
1900
1835
|
let withinImportStatement = topLevelStatement.isImportDeclaration();
|
|
1901
1836
|
let withinExportStatement = topLevelStatement.isExportDeclaration();
|
|
1902
1837
|
if (!withinImportStatement && !withinExportStatement) {
|
|
@@ -1905,9 +1840,9 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1905
1840
|
identifiers
|
|
1906
1841
|
});
|
|
1907
1842
|
}
|
|
1908
|
-
if (withinExportStatement &&
|
|
1909
|
-
t.isPattern(
|
|
1910
|
-
let variableDeclarator =
|
|
1843
|
+
if (withinExportStatement && path9.isIdentifier() && (t.isPattern(path9.parentPath.node) || // [foo]
|
|
1844
|
+
t.isPattern(path9.parentPath.parentPath?.node))) {
|
|
1845
|
+
let variableDeclarator = path9.findParent((p) => p.isVariableDeclarator());
|
|
1911
1846
|
assertNodePath(variableDeclarator);
|
|
1912
1847
|
getDependentIdentifiersForPath(variableDeclarator, {
|
|
1913
1848
|
visited,
|
|
@@ -1916,16 +1851,16 @@ function getDependentIdentifiersForPath(path7, state) {
|
|
|
1916
1851
|
}
|
|
1917
1852
|
return identifiers;
|
|
1918
1853
|
}
|
|
1919
|
-
function getTopLevelStatementPathForPath(
|
|
1920
|
-
let ancestry =
|
|
1854
|
+
function getTopLevelStatementPathForPath(path9) {
|
|
1855
|
+
let ancestry = path9.getAncestry();
|
|
1921
1856
|
let topLevelStatement = ancestry[ancestry.length - 2];
|
|
1922
1857
|
assertNodePathIsStatement(topLevelStatement);
|
|
1923
1858
|
return topLevelStatement;
|
|
1924
1859
|
}
|
|
1925
1860
|
function getTopLevelStatementsForPaths(paths) {
|
|
1926
1861
|
let topLevelStatements = /* @__PURE__ */ new Set();
|
|
1927
|
-
for (let
|
|
1928
|
-
let topLevelStatement = getTopLevelStatementPathForPath(
|
|
1862
|
+
for (let path9 of paths) {
|
|
1863
|
+
let topLevelStatement = getTopLevelStatementPathForPath(path9);
|
|
1929
1864
|
topLevelStatements.add(topLevelStatement.node);
|
|
1930
1865
|
}
|
|
1931
1866
|
return topLevelStatements;
|
|
@@ -2319,24 +2254,24 @@ function isNamedComponentExport(name) {
|
|
|
2319
2254
|
}
|
|
2320
2255
|
var decorateComponentExportsWithProps = (ast) => {
|
|
2321
2256
|
const hocs = [];
|
|
2322
|
-
function getHocUid(
|
|
2323
|
-
const uid =
|
|
2257
|
+
function getHocUid(path9, hocName) {
|
|
2258
|
+
const uid = path9.scope.generateUidIdentifier(hocName);
|
|
2324
2259
|
hocs.push([hocName, uid]);
|
|
2325
2260
|
return uid;
|
|
2326
2261
|
}
|
|
2327
2262
|
traverse(ast, {
|
|
2328
|
-
ExportDeclaration(
|
|
2329
|
-
if (
|
|
2330
|
-
const declaration =
|
|
2263
|
+
ExportDeclaration(path9) {
|
|
2264
|
+
if (path9.isExportDefaultDeclaration()) {
|
|
2265
|
+
const declaration = path9.get("declaration");
|
|
2331
2266
|
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
|
|
2332
2267
|
if (expr) {
|
|
2333
|
-
const uid = getHocUid(
|
|
2268
|
+
const uid = getHocUid(path9, "UNSAFE_withComponentProps");
|
|
2334
2269
|
declaration.replaceWith(t.callExpression(uid, [expr]));
|
|
2335
2270
|
}
|
|
2336
2271
|
return;
|
|
2337
2272
|
}
|
|
2338
|
-
if (
|
|
2339
|
-
const decl =
|
|
2273
|
+
if (path9.isExportNamedDeclaration()) {
|
|
2274
|
+
const decl = path9.get("declaration");
|
|
2340
2275
|
if (decl.isVariableDeclaration()) {
|
|
2341
2276
|
decl.get("declarations").forEach((varDeclarator) => {
|
|
2342
2277
|
const id = varDeclarator.get("id");
|
|
@@ -2346,7 +2281,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2346
2281
|
if (!id.isIdentifier()) return;
|
|
2347
2282
|
const { name } = id.node;
|
|
2348
2283
|
if (!isNamedComponentExport(name)) return;
|
|
2349
|
-
const uid = getHocUid(
|
|
2284
|
+
const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
|
|
2350
2285
|
init.replaceWith(t.callExpression(uid, [expr]));
|
|
2351
2286
|
});
|
|
2352
2287
|
return;
|
|
@@ -2356,7 +2291,7 @@ var decorateComponentExportsWithProps = (ast) => {
|
|
|
2356
2291
|
if (!id) return;
|
|
2357
2292
|
const { name } = id;
|
|
2358
2293
|
if (!isNamedComponentExport(name)) return;
|
|
2359
|
-
const uid = getHocUid(
|
|
2294
|
+
const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
|
|
2360
2295
|
decl.replaceWith(
|
|
2361
2296
|
t.variableDeclaration("const", [
|
|
2362
2297
|
t.variableDeclarator(
|
|
@@ -3480,7 +3415,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3480
3415
|
req2,
|
|
3481
3416
|
await reactRouterDevLoadContext(req2)
|
|
3482
3417
|
);
|
|
3483
|
-
await
|
|
3418
|
+
await (0, import_node_fetch_server2.sendResponse)(nodeRes, res2);
|
|
3484
3419
|
};
|
|
3485
3420
|
await nodeHandler(req, res);
|
|
3486
3421
|
} catch (error) {
|
|
@@ -4235,17 +4170,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4235
4170
|
serverBuildPath
|
|
4236
4171
|
);
|
|
4237
4172
|
let routes = createPrerenderRoutes(reactRouterConfig.routes);
|
|
4238
|
-
for (let
|
|
4239
|
-
let matches = (0, import_react_router2.matchRoutes)(routes, `/${
|
|
4173
|
+
for (let path9 of build.prerender) {
|
|
4174
|
+
let matches = (0, import_react_router2.matchRoutes)(routes, `/${path9}/`.replace(/^\/\/+/, "/"));
|
|
4240
4175
|
if (!matches) {
|
|
4241
4176
|
throw new Error(
|
|
4242
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4177
|
+
`Unable to prerender path because it does not match any routes: ${path9}`
|
|
4243
4178
|
);
|
|
4244
4179
|
}
|
|
4245
4180
|
}
|
|
4246
4181
|
let buildRoutes = createPrerenderRoutes(build.routes);
|
|
4247
|
-
for (let
|
|
4248
|
-
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${
|
|
4182
|
+
for (let path9 of build.prerender) {
|
|
4183
|
+
let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path9}/`.replace(/^\/\/+/, "/"));
|
|
4249
4184
|
if (!matches) {
|
|
4250
4185
|
continue;
|
|
4251
4186
|
}
|
|
@@ -4258,7 +4193,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4258
4193
|
if (manifestRoute.loader) {
|
|
4259
4194
|
await prerenderData(
|
|
4260
4195
|
handler,
|
|
4261
|
-
|
|
4196
|
+
path9,
|
|
4262
4197
|
[leafRoute.id],
|
|
4263
4198
|
clientBuildDirectory,
|
|
4264
4199
|
reactRouterConfig,
|
|
@@ -4266,7 +4201,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4266
4201
|
);
|
|
4267
4202
|
await prerenderResourceRoute(
|
|
4268
4203
|
handler,
|
|
4269
|
-
|
|
4204
|
+
path9,
|
|
4270
4205
|
clientBuildDirectory,
|
|
4271
4206
|
reactRouterConfig,
|
|
4272
4207
|
viteConfig
|
|
@@ -4284,7 +4219,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4284
4219
|
if (!isResourceRoute && hasLoaders) {
|
|
4285
4220
|
data = await prerenderData(
|
|
4286
4221
|
handler,
|
|
4287
|
-
|
|
4222
|
+
path9,
|
|
4288
4223
|
null,
|
|
4289
4224
|
clientBuildDirectory,
|
|
4290
4225
|
reactRouterConfig,
|
|
@@ -4293,7 +4228,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4293
4228
|
}
|
|
4294
4229
|
await prerenderRoute(
|
|
4295
4230
|
handler,
|
|
4296
|
-
|
|
4231
|
+
path9,
|
|
4297
4232
|
clientBuildDirectory,
|
|
4298
4233
|
reactRouterConfig,
|
|
4299
4234
|
viteConfig,
|
|
@@ -4489,14 +4424,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
|
|
|
4489
4424
|
}
|
|
4490
4425
|
let prerenderRoutes = createPrerenderRoutes(manifest.routes);
|
|
4491
4426
|
let prerenderedRoutes = /* @__PURE__ */ new Set();
|
|
4492
|
-
for (let
|
|
4427
|
+
for (let path9 of prerenderPaths) {
|
|
4493
4428
|
let matches = (0, import_react_router2.matchRoutes)(
|
|
4494
4429
|
prerenderRoutes,
|
|
4495
|
-
`/${
|
|
4430
|
+
`/${path9}/`.replace(/^\/\/+/, "/")
|
|
4496
4431
|
);
|
|
4497
4432
|
invariant(
|
|
4498
4433
|
matches,
|
|
4499
|
-
`Unable to prerender path because it does not match any routes: ${
|
|
4434
|
+
`Unable to prerender path because it does not match any routes: ${path9}`
|
|
4500
4435
|
);
|
|
4501
4436
|
matches.forEach((m) => prerenderedRoutes.add(m.route.id));
|
|
4502
4437
|
}
|
|
@@ -4944,7 +4879,918 @@ async function asyncFlatten(arr) {
|
|
|
4944
4879
|
} while (arr.some((v2) => v2?.then));
|
|
4945
4880
|
return arr;
|
|
4946
4881
|
}
|
|
4882
|
+
|
|
4883
|
+
// vite/rsc/plugin.ts
|
|
4884
|
+
var import_es_module_lexer3 = require("es-module-lexer");
|
|
4885
|
+
var Path5 = __toESM(require("pathe"));
|
|
4886
|
+
var babel2 = __toESM(require("@babel/core"));
|
|
4887
|
+
var import_picocolors5 = __toESM(require("picocolors"));
|
|
4888
|
+
var import_fs = require("fs");
|
|
4889
|
+
var import_promises3 = require("fs/promises");
|
|
4890
|
+
var import_pathe6 = __toESM(require("pathe"));
|
|
4891
|
+
|
|
4892
|
+
// vite/rsc/virtual-route-config.ts
|
|
4893
|
+
var import_pathe5 = __toESM(require("pathe"));
|
|
4894
|
+
function createVirtualRouteConfig({
|
|
4895
|
+
appDirectory,
|
|
4896
|
+
routeConfig
|
|
4897
|
+
}) {
|
|
4898
|
+
let routeIdByFile = /* @__PURE__ */ new Map();
|
|
4899
|
+
let code = "export default [";
|
|
4900
|
+
const closeRouteSymbol = Symbol("CLOSE_ROUTE");
|
|
4901
|
+
let stack = [
|
|
4902
|
+
...routeConfig
|
|
4903
|
+
];
|
|
4904
|
+
while (stack.length > 0) {
|
|
4905
|
+
const route = stack.pop();
|
|
4906
|
+
if (!route) break;
|
|
4907
|
+
if (route === closeRouteSymbol) {
|
|
4908
|
+
code += "]},";
|
|
4909
|
+
continue;
|
|
4910
|
+
}
|
|
4911
|
+
code += "{";
|
|
4912
|
+
const routeFile = import_pathe5.default.resolve(appDirectory, route.file);
|
|
4913
|
+
const routeId = route.id || createRouteId2(route.file, appDirectory);
|
|
4914
|
+
routeIdByFile.set(routeFile, routeId);
|
|
4915
|
+
code += `lazy: () => import(${JSON.stringify(
|
|
4916
|
+
`${routeFile}?route-module`
|
|
4917
|
+
)}),`;
|
|
4918
|
+
code += `id: ${JSON.stringify(routeId)},`;
|
|
4919
|
+
if (typeof route.path === "string") {
|
|
4920
|
+
code += `path: ${JSON.stringify(route.path)},`;
|
|
4921
|
+
}
|
|
4922
|
+
if (route.index) {
|
|
4923
|
+
code += `index: true,`;
|
|
4924
|
+
}
|
|
4925
|
+
if (route.caseSensitive) {
|
|
4926
|
+
code += `caseSensitive: true,`;
|
|
4927
|
+
}
|
|
4928
|
+
if (route.children) {
|
|
4929
|
+
code += ["children:["];
|
|
4930
|
+
stack.push(closeRouteSymbol);
|
|
4931
|
+
stack.push(...[...route.children].reverse());
|
|
4932
|
+
} else {
|
|
4933
|
+
code += "},";
|
|
4934
|
+
}
|
|
4935
|
+
}
|
|
4936
|
+
code += "];\n";
|
|
4937
|
+
return { code, routeIdByFile };
|
|
4938
|
+
}
|
|
4939
|
+
function createRouteId2(file, appDirectory) {
|
|
4940
|
+
return import_pathe5.default.relative(appDirectory, file).replace(/\\+/, "/").slice(0, -import_pathe5.default.extname(file).length);
|
|
4941
|
+
}
|
|
4942
|
+
|
|
4943
|
+
// vite/rsc/virtual-route-modules.ts
|
|
4944
|
+
var import_es_module_lexer2 = require("es-module-lexer");
|
|
4945
|
+
var SERVER_ONLY_COMPONENT_EXPORTS = ["ServerComponent"];
|
|
4946
|
+
var SERVER_ONLY_ROUTE_EXPORTS2 = [
|
|
4947
|
+
...SERVER_ONLY_COMPONENT_EXPORTS,
|
|
4948
|
+
"loader",
|
|
4949
|
+
"action",
|
|
4950
|
+
"middleware",
|
|
4951
|
+
"headers"
|
|
4952
|
+
];
|
|
4953
|
+
var SERVER_ONLY_ROUTE_EXPORTS_SET = new Set(SERVER_ONLY_ROUTE_EXPORTS2);
|
|
4954
|
+
function isServerOnlyRouteExport(name) {
|
|
4955
|
+
return SERVER_ONLY_ROUTE_EXPORTS_SET.has(name);
|
|
4956
|
+
}
|
|
4957
|
+
var COMMON_COMPONENT_EXPORTS = [
|
|
4958
|
+
"ErrorBoundary",
|
|
4959
|
+
"HydrateFallback",
|
|
4960
|
+
"Layout"
|
|
4961
|
+
];
|
|
4962
|
+
var SERVER_FIRST_COMPONENT_EXPORTS = [
|
|
4963
|
+
...COMMON_COMPONENT_EXPORTS,
|
|
4964
|
+
...SERVER_ONLY_COMPONENT_EXPORTS
|
|
4965
|
+
];
|
|
4966
|
+
var SERVER_FIRST_COMPONENT_EXPORTS_SET = new Set(
|
|
4967
|
+
SERVER_FIRST_COMPONENT_EXPORTS
|
|
4968
|
+
);
|
|
4969
|
+
function isServerFirstComponentExport(name) {
|
|
4970
|
+
return SERVER_FIRST_COMPONENT_EXPORTS_SET.has(
|
|
4971
|
+
name
|
|
4972
|
+
);
|
|
4973
|
+
}
|
|
4974
|
+
var CLIENT_COMPONENT_EXPORTS = [
|
|
4975
|
+
...COMMON_COMPONENT_EXPORTS,
|
|
4976
|
+
"default"
|
|
4977
|
+
];
|
|
4978
|
+
var CLIENT_NON_COMPONENT_EXPORTS2 = [
|
|
4979
|
+
"clientAction",
|
|
4980
|
+
"clientLoader",
|
|
4981
|
+
"clientMiddleware",
|
|
4982
|
+
"handle",
|
|
4983
|
+
"meta",
|
|
4984
|
+
"links",
|
|
4985
|
+
"shouldRevalidate"
|
|
4986
|
+
];
|
|
4987
|
+
var CLIENT_NON_COMPONENT_EXPORTS_SET = new Set(CLIENT_NON_COMPONENT_EXPORTS2);
|
|
4988
|
+
function isClientNonComponentExport(name) {
|
|
4989
|
+
return CLIENT_NON_COMPONENT_EXPORTS_SET.has(name);
|
|
4990
|
+
}
|
|
4991
|
+
var CLIENT_ROUTE_EXPORTS2 = [
|
|
4992
|
+
...CLIENT_NON_COMPONENT_EXPORTS2,
|
|
4993
|
+
...CLIENT_COMPONENT_EXPORTS
|
|
4994
|
+
];
|
|
4995
|
+
var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS2);
|
|
4996
|
+
function isClientRouteExport(name) {
|
|
4997
|
+
return CLIENT_ROUTE_EXPORTS_SET.has(name);
|
|
4998
|
+
}
|
|
4999
|
+
var ROUTE_EXPORTS = [
|
|
5000
|
+
...SERVER_ONLY_ROUTE_EXPORTS2,
|
|
5001
|
+
...CLIENT_ROUTE_EXPORTS2
|
|
5002
|
+
];
|
|
5003
|
+
var ROUTE_EXPORTS_SET = new Set(ROUTE_EXPORTS);
|
|
5004
|
+
function isRouteExport(name) {
|
|
5005
|
+
return ROUTE_EXPORTS_SET.has(name);
|
|
5006
|
+
}
|
|
5007
|
+
function isCustomRouteExport(name) {
|
|
5008
|
+
return !isRouteExport(name);
|
|
5009
|
+
}
|
|
5010
|
+
function hasReactServerCondition(viteEnvironment) {
|
|
5011
|
+
return viteEnvironment.config.resolve.conditions.includes("react-server");
|
|
5012
|
+
}
|
|
5013
|
+
function transformVirtualRouteModules({
|
|
5014
|
+
id,
|
|
5015
|
+
code,
|
|
5016
|
+
viteCommand,
|
|
5017
|
+
routeIdByFile,
|
|
5018
|
+
rootRouteFile,
|
|
5019
|
+
viteEnvironment
|
|
5020
|
+
}) {
|
|
5021
|
+
if (isVirtualRouteModuleId(id) || routeIdByFile.has(id)) {
|
|
5022
|
+
return createVirtualRouteModuleCode({
|
|
5023
|
+
id,
|
|
5024
|
+
code,
|
|
5025
|
+
rootRouteFile,
|
|
5026
|
+
viteCommand,
|
|
5027
|
+
viteEnvironment
|
|
5028
|
+
});
|
|
5029
|
+
}
|
|
5030
|
+
if (isVirtualServerRouteModuleId(id)) {
|
|
5031
|
+
return createVirtualServerRouteModuleCode({
|
|
5032
|
+
id,
|
|
5033
|
+
code,
|
|
5034
|
+
viteEnvironment
|
|
5035
|
+
});
|
|
5036
|
+
}
|
|
5037
|
+
if (isVirtualClientRouteModuleId(id)) {
|
|
5038
|
+
return createVirtualClientRouteModuleCode({
|
|
5039
|
+
id,
|
|
5040
|
+
code,
|
|
5041
|
+
rootRouteFile,
|
|
5042
|
+
viteCommand
|
|
5043
|
+
});
|
|
5044
|
+
}
|
|
5045
|
+
}
|
|
5046
|
+
async function createVirtualRouteModuleCode({
|
|
5047
|
+
id,
|
|
5048
|
+
code: routeSource,
|
|
5049
|
+
rootRouteFile,
|
|
5050
|
+
viteCommand,
|
|
5051
|
+
viteEnvironment
|
|
5052
|
+
}) {
|
|
5053
|
+
const isReactServer = hasReactServerCondition(viteEnvironment);
|
|
5054
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
5055
|
+
const clientModuleId = getVirtualClientModuleId(id);
|
|
5056
|
+
const serverModuleId = getVirtualServerModuleId(id);
|
|
5057
|
+
let code = "";
|
|
5058
|
+
if (isServerFirstRoute) {
|
|
5059
|
+
if (staticExports.some(isServerFirstComponentExport)) {
|
|
5060
|
+
code += `import React from "react";
|
|
5061
|
+
`;
|
|
5062
|
+
}
|
|
5063
|
+
for (const staticExport of staticExports) {
|
|
5064
|
+
if (isClientNonComponentExport(staticExport)) {
|
|
5065
|
+
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5066
|
+
`;
|
|
5067
|
+
} else if (isReactServer && isServerFirstComponentExport(staticExport) && // Layout wraps all other component exports so doesn't need CSS injected
|
|
5068
|
+
staticExport !== "Layout") {
|
|
5069
|
+
code += `import { ${staticExport} as ${staticExport}WithoutCss } from "${serverModuleId}";
|
|
5070
|
+
`;
|
|
5071
|
+
code += `export ${staticExport === "ServerComponent" ? "default " : " "}function ${staticExport}(props) {
|
|
5072
|
+
`;
|
|
5073
|
+
code += ` return React.createElement(React.Fragment, null,
|
|
5074
|
+
`;
|
|
5075
|
+
code += ` import.meta.viteRsc.loadCss(),
|
|
5076
|
+
`;
|
|
5077
|
+
code += ` React.createElement(${staticExport}WithoutCss, props),
|
|
5078
|
+
`;
|
|
5079
|
+
code += ` );
|
|
5080
|
+
`;
|
|
5081
|
+
code += `}
|
|
5082
|
+
`;
|
|
5083
|
+
} else if (isReactServer && isRouteExport(staticExport)) {
|
|
5084
|
+
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5085
|
+
`;
|
|
5086
|
+
} else if (isCustomRouteExport(staticExport)) {
|
|
5087
|
+
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5088
|
+
`;
|
|
5089
|
+
}
|
|
5090
|
+
}
|
|
5091
|
+
if (viteCommand === "serve" && !hasClientExports) {
|
|
5092
|
+
code += `export { __ensureClientRouteModuleForHMR } from "${clientModuleId}";
|
|
5093
|
+
`;
|
|
5094
|
+
}
|
|
5095
|
+
} else {
|
|
5096
|
+
for (const staticExport of staticExports) {
|
|
5097
|
+
if (isClientRouteExport(staticExport)) {
|
|
5098
|
+
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5099
|
+
`;
|
|
5100
|
+
} else if (isReactServer && isServerOnlyRouteExport(staticExport)) {
|
|
5101
|
+
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5102
|
+
`;
|
|
5103
|
+
} else if (isCustomRouteExport(staticExport)) {
|
|
5104
|
+
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5105
|
+
`;
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
}
|
|
5109
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5110
|
+
code += `export { ErrorBoundary } from "${clientModuleId}";
|
|
5111
|
+
`;
|
|
5112
|
+
}
|
|
5113
|
+
return code;
|
|
5114
|
+
}
|
|
5115
|
+
function createVirtualServerRouteModuleCode({
|
|
5116
|
+
id,
|
|
5117
|
+
code: routeSource,
|
|
5118
|
+
viteEnvironment
|
|
5119
|
+
}) {
|
|
5120
|
+
if (!hasReactServerCondition(viteEnvironment)) {
|
|
5121
|
+
throw new Error(
|
|
5122
|
+
[
|
|
5123
|
+
"Virtual server route module was loaded outside of the RSC environment.",
|
|
5124
|
+
`Environment Name: ${viteEnvironment.name}`,
|
|
5125
|
+
`Module ID: ${id}`
|
|
5126
|
+
].join("\n")
|
|
5127
|
+
);
|
|
5128
|
+
}
|
|
5129
|
+
const { staticExports, isServerFirstRoute } = parseRouteExports(routeSource);
|
|
5130
|
+
const clientModuleId = getVirtualClientModuleId(id);
|
|
5131
|
+
const serverRouteModuleAst = import_parser.parse(routeSource, {
|
|
5132
|
+
sourceType: "module"
|
|
5133
|
+
});
|
|
5134
|
+
removeExports(
|
|
5135
|
+
serverRouteModuleAst,
|
|
5136
|
+
isServerFirstRoute ? CLIENT_NON_COMPONENT_EXPORTS2 : CLIENT_ROUTE_EXPORTS2
|
|
5137
|
+
);
|
|
5138
|
+
const generatorResult = generate(serverRouteModuleAst);
|
|
5139
|
+
if (!isServerFirstRoute) {
|
|
5140
|
+
for (const staticExport of staticExports) {
|
|
5141
|
+
if (isClientRouteExport(staticExport)) {
|
|
5142
|
+
generatorResult.code += "\n";
|
|
5143
|
+
generatorResult.code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5144
|
+
`;
|
|
5145
|
+
}
|
|
5146
|
+
}
|
|
5147
|
+
}
|
|
5148
|
+
return generatorResult;
|
|
5149
|
+
}
|
|
5150
|
+
function createVirtualClientRouteModuleCode({
|
|
5151
|
+
id,
|
|
5152
|
+
code: routeSource,
|
|
5153
|
+
rootRouteFile,
|
|
5154
|
+
viteCommand
|
|
5155
|
+
}) {
|
|
5156
|
+
const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
|
|
5157
|
+
const exportsToRemove = isServerFirstRoute ? [...SERVER_ONLY_ROUTE_EXPORTS2, ...CLIENT_COMPONENT_EXPORTS] : SERVER_ONLY_ROUTE_EXPORTS2;
|
|
5158
|
+
const clientRouteModuleAst = import_parser.parse(routeSource, {
|
|
5159
|
+
sourceType: "module"
|
|
5160
|
+
});
|
|
5161
|
+
removeExports(clientRouteModuleAst, exportsToRemove);
|
|
5162
|
+
const generatorResult = generate(clientRouteModuleAst);
|
|
5163
|
+
generatorResult.code = '"use client";' + generatorResult.code;
|
|
5164
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5165
|
+
const hasRootLayout = staticExports.includes("Layout");
|
|
5166
|
+
generatorResult.code += `
|
|
5167
|
+
import { createElement as __rr_createElement } from "react";
|
|
5168
|
+
`;
|
|
5169
|
+
generatorResult.code += `import { UNSAFE_RSCDefaultRootErrorBoundary } from "react-router";
|
|
5170
|
+
`;
|
|
5171
|
+
generatorResult.code += `export function ErrorBoundary() {
|
|
5172
|
+
`;
|
|
5173
|
+
generatorResult.code += ` return __rr_createElement(UNSAFE_RSCDefaultRootErrorBoundary, { hasRootLayout: ${hasRootLayout} });
|
|
5174
|
+
`;
|
|
5175
|
+
generatorResult.code += `}
|
|
5176
|
+
`;
|
|
5177
|
+
}
|
|
5178
|
+
if (viteCommand === "serve" && isServerFirstRoute && !hasClientExports) {
|
|
5179
|
+
generatorResult.code += `
|
|
5180
|
+
export const __ensureClientRouteModuleForHMR = true;`;
|
|
5181
|
+
}
|
|
5182
|
+
return generatorResult;
|
|
5183
|
+
}
|
|
5184
|
+
function parseRouteExports(code) {
|
|
5185
|
+
const [, exportSpecifiers] = (0, import_es_module_lexer2.parse)(code);
|
|
5186
|
+
const staticExports = exportSpecifiers.map(({ n: name }) => name);
|
|
5187
|
+
const isServerFirstRoute = staticExports.some(
|
|
5188
|
+
(staticExport) => staticExport === "ServerComponent"
|
|
5189
|
+
);
|
|
5190
|
+
return {
|
|
5191
|
+
staticExports,
|
|
5192
|
+
isServerFirstRoute,
|
|
5193
|
+
hasClientExports: staticExports.some(
|
|
5194
|
+
isServerFirstRoute ? isClientNonComponentExport : isClientRouteExport
|
|
5195
|
+
)
|
|
5196
|
+
};
|
|
5197
|
+
}
|
|
5198
|
+
function getVirtualClientModuleId(id) {
|
|
5199
|
+
return `${id.split("?")[0]}?client-route-module`;
|
|
5200
|
+
}
|
|
5201
|
+
function getVirtualServerModuleId(id) {
|
|
5202
|
+
return `${id.split("?")[0]}?server-route-module`;
|
|
5203
|
+
}
|
|
5204
|
+
function isVirtualRouteModuleId(id) {
|
|
5205
|
+
return /(\?|&)route-module(&|$)/.test(id);
|
|
5206
|
+
}
|
|
5207
|
+
function isVirtualClientRouteModuleId(id) {
|
|
5208
|
+
return /(\?|&)client-route-module(&|$)/.test(id);
|
|
5209
|
+
}
|
|
5210
|
+
function isVirtualServerRouteModuleId(id) {
|
|
5211
|
+
return /(\?|&)server-route-module(&|$)/.test(id);
|
|
5212
|
+
}
|
|
5213
|
+
function isRootRouteFile({
|
|
5214
|
+
id,
|
|
5215
|
+
rootRouteFile
|
|
5216
|
+
}) {
|
|
5217
|
+
const filePath = id.split("?")[0];
|
|
5218
|
+
return filePath === rootRouteFile;
|
|
5219
|
+
}
|
|
5220
|
+
|
|
5221
|
+
// vite/rsc/plugin.ts
|
|
5222
|
+
function reactRouterRSCVitePlugin() {
|
|
5223
|
+
let configLoader;
|
|
5224
|
+
let typegenWatcherPromise;
|
|
5225
|
+
let viteCommand;
|
|
5226
|
+
let resolvedViteConfig;
|
|
5227
|
+
let routeIdByFile;
|
|
5228
|
+
let logger;
|
|
5229
|
+
const defaultEntries2 = getDefaultEntries();
|
|
5230
|
+
let config;
|
|
5231
|
+
let rootRouteFile;
|
|
5232
|
+
function updateConfig(newConfig) {
|
|
5233
|
+
config = newConfig;
|
|
5234
|
+
rootRouteFile = Path5.resolve(
|
|
5235
|
+
newConfig.appDirectory,
|
|
5236
|
+
newConfig.routes.root.file
|
|
5237
|
+
);
|
|
5238
|
+
}
|
|
5239
|
+
return [
|
|
5240
|
+
{
|
|
5241
|
+
name: "react-router/rsc",
|
|
5242
|
+
async config(viteUserConfig, { command, mode }) {
|
|
5243
|
+
await import_es_module_lexer3.init;
|
|
5244
|
+
await preloadVite();
|
|
5245
|
+
viteCommand = command;
|
|
5246
|
+
const rootDirectory = getRootDirectory(viteUserConfig);
|
|
5247
|
+
const watch2 = command === "serve";
|
|
5248
|
+
configLoader = await createConfigLoader({
|
|
5249
|
+
rootDirectory,
|
|
5250
|
+
mode,
|
|
5251
|
+
watch: watch2,
|
|
5252
|
+
validateConfig: (userConfig) => {
|
|
5253
|
+
let errors = [];
|
|
5254
|
+
if (userConfig.buildEnd) errors.push("buildEnd");
|
|
5255
|
+
if (userConfig.prerender) errors.push("prerender");
|
|
5256
|
+
if (userConfig.presets?.length) errors.push("presets");
|
|
5257
|
+
if (userConfig.routeDiscovery) errors.push("routeDiscovery");
|
|
5258
|
+
if (userConfig.serverBundles) errors.push("serverBundles");
|
|
5259
|
+
if (userConfig.ssr === false) errors.push("ssr: false");
|
|
5260
|
+
if (userConfig.future?.unstable_splitRouteModules)
|
|
5261
|
+
errors.push("future.unstable_splitRouteModules");
|
|
5262
|
+
if (userConfig.future?.unstable_viteEnvironmentApi === false)
|
|
5263
|
+
errors.push("future.unstable_viteEnvironmentApi: false");
|
|
5264
|
+
if (userConfig.future?.v8_middleware === false)
|
|
5265
|
+
errors.push("future.v8_middleware: false");
|
|
5266
|
+
if (userConfig.future?.unstable_subResourceIntegrity)
|
|
5267
|
+
errors.push("future.unstable_subResourceIntegrity");
|
|
5268
|
+
if (errors.length) {
|
|
5269
|
+
return `RSC Framework Mode does not currently support the following React Router config:
|
|
5270
|
+
${errors.map((x) => ` - ${x}`).join("\n")}
|
|
5271
|
+
`;
|
|
5272
|
+
}
|
|
5273
|
+
}
|
|
5274
|
+
});
|
|
5275
|
+
const configResult = await configLoader.getConfig();
|
|
5276
|
+
if (!configResult.ok) throw new Error(configResult.error);
|
|
5277
|
+
updateConfig(configResult.value);
|
|
5278
|
+
if (viteUserConfig.base && config.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !config.basename.startsWith(viteUserConfig.base)) {
|
|
5279
|
+
throw new Error(
|
|
5280
|
+
"When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
|
|
5281
|
+
);
|
|
5282
|
+
}
|
|
5283
|
+
await loadDotenv({
|
|
5284
|
+
rootDirectory,
|
|
5285
|
+
viteUserConfig,
|
|
5286
|
+
mode
|
|
5287
|
+
});
|
|
5288
|
+
const vite2 = await import("vite");
|
|
5289
|
+
logger = vite2.createLogger(viteUserConfig.logLevel, {
|
|
5290
|
+
prefix: "[react-router]"
|
|
5291
|
+
});
|
|
5292
|
+
return {
|
|
5293
|
+
resolve: {
|
|
5294
|
+
dedupe: [
|
|
5295
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
5296
|
+
"react",
|
|
5297
|
+
"react-dom",
|
|
5298
|
+
// Avoid router duplicates since mismatching routers cause `Error:
|
|
5299
|
+
// You must render this element inside a <Remix> element`.
|
|
5300
|
+
"react-router",
|
|
5301
|
+
"react-router/dom",
|
|
5302
|
+
...hasDependency({ name: "react-router-dom", rootDirectory }) ? ["react-router-dom"] : []
|
|
5303
|
+
]
|
|
5304
|
+
},
|
|
5305
|
+
optimizeDeps: {
|
|
5306
|
+
entries: getOptimizeDepsEntries({
|
|
5307
|
+
entryClientFilePath: defaultEntries2.client,
|
|
5308
|
+
reactRouterConfig: config
|
|
5309
|
+
}),
|
|
5310
|
+
esbuildOptions: {
|
|
5311
|
+
jsx: "automatic"
|
|
5312
|
+
},
|
|
5313
|
+
include: [
|
|
5314
|
+
// Pre-bundle React dependencies to avoid React duplicates,
|
|
5315
|
+
// even if React dependencies are not direct dependencies.
|
|
5316
|
+
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
5317
|
+
"react",
|
|
5318
|
+
"react/jsx-runtime",
|
|
5319
|
+
"react/jsx-dev-runtime",
|
|
5320
|
+
"react-dom",
|
|
5321
|
+
"react-dom/client",
|
|
5322
|
+
"react-router/internal/react-server-client"
|
|
5323
|
+
]
|
|
5324
|
+
},
|
|
5325
|
+
esbuild: {
|
|
5326
|
+
jsx: "automatic",
|
|
5327
|
+
jsxDev: viteCommand !== "build"
|
|
5328
|
+
},
|
|
5329
|
+
environments: {
|
|
5330
|
+
client: {
|
|
5331
|
+
build: {
|
|
5332
|
+
rollupOptions: {
|
|
5333
|
+
input: {
|
|
5334
|
+
index: defaultEntries2.client
|
|
5335
|
+
}
|
|
5336
|
+
},
|
|
5337
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "client")
|
|
5338
|
+
},
|
|
5339
|
+
optimizeDeps: {
|
|
5340
|
+
include: [
|
|
5341
|
+
"react-router > cookie",
|
|
5342
|
+
"react-router > set-cookie-parser"
|
|
5343
|
+
]
|
|
5344
|
+
}
|
|
5345
|
+
},
|
|
5346
|
+
rsc: {
|
|
5347
|
+
build: {
|
|
5348
|
+
rollupOptions: {
|
|
5349
|
+
input: {
|
|
5350
|
+
// We use a virtual entry here so that consumers can import
|
|
5351
|
+
// it as `virtual:react-router/unstable_rsc/rsc-entry`
|
|
5352
|
+
// without needing to know the actual file path, which is
|
|
5353
|
+
// important when using the default entries.
|
|
5354
|
+
index: defaultEntries2.rsc
|
|
5355
|
+
},
|
|
5356
|
+
output: {
|
|
5357
|
+
entryFileNames: config.serverBuildFile,
|
|
5358
|
+
format: config.serverModuleFormat
|
|
5359
|
+
}
|
|
5360
|
+
},
|
|
5361
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "server")
|
|
5362
|
+
}
|
|
5363
|
+
},
|
|
5364
|
+
ssr: {
|
|
5365
|
+
build: {
|
|
5366
|
+
rollupOptions: {
|
|
5367
|
+
input: {
|
|
5368
|
+
index: defaultEntries2.ssr
|
|
5369
|
+
},
|
|
5370
|
+
output: {
|
|
5371
|
+
// Note: We don't set `entryFileNames` here because it's
|
|
5372
|
+
// considered private to the RSC environment build, and
|
|
5373
|
+
// @vitejs/plugin-rsc currently breaks if it's set to
|
|
5374
|
+
// something other than `index.js`.
|
|
5375
|
+
format: config.serverModuleFormat
|
|
5376
|
+
}
|
|
5377
|
+
},
|
|
5378
|
+
outDir: (0, import_pathe6.join)(config.buildDirectory, "server/__ssr_build")
|
|
5379
|
+
}
|
|
5380
|
+
}
|
|
5381
|
+
},
|
|
5382
|
+
build: {
|
|
5383
|
+
rollupOptions: {
|
|
5384
|
+
// Copied from https://github.com/vitejs/vite-plugin-react/blob/c602225271d4acf462ba00f8d6d8a2e42492c5cd/packages/common/warning.ts
|
|
5385
|
+
onwarn(warning, defaultHandler) {
|
|
5386
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
|
|
5387
|
+
return;
|
|
5388
|
+
}
|
|
5389
|
+
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
|
5390
|
+
return;
|
|
5391
|
+
}
|
|
5392
|
+
if (viteUserConfig.build?.rollupOptions?.onwarn) {
|
|
5393
|
+
viteUserConfig.build.rollupOptions.onwarn(
|
|
5394
|
+
warning,
|
|
5395
|
+
defaultHandler
|
|
5396
|
+
);
|
|
5397
|
+
} else {
|
|
5398
|
+
defaultHandler(warning);
|
|
5399
|
+
}
|
|
5400
|
+
}
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5403
|
+
};
|
|
5404
|
+
},
|
|
5405
|
+
configResolved(viteConfig) {
|
|
5406
|
+
resolvedViteConfig = viteConfig;
|
|
5407
|
+
},
|
|
5408
|
+
async configureServer(viteDevServer) {
|
|
5409
|
+
configLoader.onChange(
|
|
5410
|
+
async ({
|
|
5411
|
+
result,
|
|
5412
|
+
configCodeChanged,
|
|
5413
|
+
routeConfigCodeChanged,
|
|
5414
|
+
configChanged,
|
|
5415
|
+
routeConfigChanged
|
|
5416
|
+
}) => {
|
|
5417
|
+
if (!result.ok) {
|
|
5418
|
+
invalidateVirtualModules2(viteDevServer);
|
|
5419
|
+
logger.error(result.error, {
|
|
5420
|
+
clear: true,
|
|
5421
|
+
timestamp: true
|
|
5422
|
+
});
|
|
5423
|
+
return;
|
|
5424
|
+
}
|
|
5425
|
+
let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
|
|
5426
|
+
logger.info(import_picocolors5.default.green(message), {
|
|
5427
|
+
clear: true,
|
|
5428
|
+
timestamp: true
|
|
5429
|
+
});
|
|
5430
|
+
updateConfig(result.value);
|
|
5431
|
+
if (configChanged || routeConfigChanged) {
|
|
5432
|
+
invalidateVirtualModules2(viteDevServer);
|
|
5433
|
+
}
|
|
5434
|
+
}
|
|
5435
|
+
);
|
|
5436
|
+
},
|
|
5437
|
+
async buildEnd() {
|
|
5438
|
+
await configLoader.close();
|
|
5439
|
+
}
|
|
5440
|
+
},
|
|
5441
|
+
/* @__PURE__ */ (() => {
|
|
5442
|
+
let logged = false;
|
|
5443
|
+
function logExperimentalNotice() {
|
|
5444
|
+
if (logged) return;
|
|
5445
|
+
logged = true;
|
|
5446
|
+
logger.info(
|
|
5447
|
+
import_picocolors5.default.yellow(
|
|
5448
|
+
`${viteCommand === "serve" ? " " : ""}\u{1F9EA} Using React Router's RSC Framework Mode (experimental)`
|
|
5449
|
+
)
|
|
5450
|
+
);
|
|
5451
|
+
}
|
|
5452
|
+
return {
|
|
5453
|
+
name: "react-router/rsc/log-experimental-notice",
|
|
5454
|
+
sharedDuringBuild: true,
|
|
5455
|
+
buildStart: logExperimentalNotice,
|
|
5456
|
+
configureServer: logExperimentalNotice
|
|
5457
|
+
};
|
|
5458
|
+
})(),
|
|
5459
|
+
{
|
|
5460
|
+
name: "react-router/rsc/typegen",
|
|
5461
|
+
async config(viteUserConfig, { command, mode }) {
|
|
5462
|
+
if (command === "serve") {
|
|
5463
|
+
const vite2 = await import("vite");
|
|
5464
|
+
typegenWatcherPromise = watch(
|
|
5465
|
+
getRootDirectory(viteUserConfig),
|
|
5466
|
+
{
|
|
5467
|
+
mode,
|
|
5468
|
+
rsc: true,
|
|
5469
|
+
// ignore `info` logs from typegen since they are
|
|
5470
|
+
// redundant when Vite plugin logs are active
|
|
5471
|
+
logger: vite2.createLogger("warn", {
|
|
5472
|
+
prefix: "[react-router]"
|
|
5473
|
+
})
|
|
5474
|
+
}
|
|
5475
|
+
);
|
|
5476
|
+
}
|
|
5477
|
+
},
|
|
5478
|
+
async buildEnd() {
|
|
5479
|
+
(await typegenWatcherPromise)?.close();
|
|
5480
|
+
}
|
|
5481
|
+
},
|
|
5482
|
+
{
|
|
5483
|
+
name: "react-router/rsc/virtual-rsc-entry",
|
|
5484
|
+
resolveId(id) {
|
|
5485
|
+
if (id === virtual2.rscEntry.id) return defaultEntries2.rsc;
|
|
5486
|
+
}
|
|
5487
|
+
},
|
|
5488
|
+
{
|
|
5489
|
+
name: "react-router/rsc/virtual-route-config",
|
|
5490
|
+
resolveId(id) {
|
|
5491
|
+
if (id === virtual2.routeConfig.id) {
|
|
5492
|
+
return virtual2.routeConfig.resolvedId;
|
|
5493
|
+
}
|
|
5494
|
+
},
|
|
5495
|
+
load(id) {
|
|
5496
|
+
if (id === virtual2.routeConfig.resolvedId) {
|
|
5497
|
+
const result = createVirtualRouteConfig({
|
|
5498
|
+
appDirectory: config.appDirectory,
|
|
5499
|
+
routeConfig: config.unstable_routeConfig
|
|
5500
|
+
});
|
|
5501
|
+
routeIdByFile = result.routeIdByFile;
|
|
5502
|
+
return result.code;
|
|
5503
|
+
}
|
|
5504
|
+
}
|
|
5505
|
+
},
|
|
5506
|
+
{
|
|
5507
|
+
name: "react-router/rsc/virtual-route-modules",
|
|
5508
|
+
transform(code, id) {
|
|
5509
|
+
if (!routeIdByFile) return;
|
|
5510
|
+
return transformVirtualRouteModules({
|
|
5511
|
+
code,
|
|
5512
|
+
id,
|
|
5513
|
+
viteCommand,
|
|
5514
|
+
routeIdByFile,
|
|
5515
|
+
rootRouteFile,
|
|
5516
|
+
viteEnvironment: this.environment
|
|
5517
|
+
});
|
|
5518
|
+
}
|
|
5519
|
+
},
|
|
5520
|
+
{
|
|
5521
|
+
name: "react-router/rsc/virtual-basename",
|
|
5522
|
+
resolveId(id) {
|
|
5523
|
+
if (id === virtual2.basename.id) {
|
|
5524
|
+
return virtual2.basename.resolvedId;
|
|
5525
|
+
}
|
|
5526
|
+
},
|
|
5527
|
+
load(id) {
|
|
5528
|
+
if (id === virtual2.basename.resolvedId) {
|
|
5529
|
+
return `export default ${JSON.stringify(config.basename)};`;
|
|
5530
|
+
}
|
|
5531
|
+
}
|
|
5532
|
+
},
|
|
5533
|
+
{
|
|
5534
|
+
name: "react-router/rsc/hmr/inject-runtime",
|
|
5535
|
+
enforce: "pre",
|
|
5536
|
+
resolveId(id) {
|
|
5537
|
+
if (id === virtual2.injectHmrRuntime.id) {
|
|
5538
|
+
return virtual2.injectHmrRuntime.resolvedId;
|
|
5539
|
+
}
|
|
5540
|
+
},
|
|
5541
|
+
async load(id) {
|
|
5542
|
+
if (id !== virtual2.injectHmrRuntime.resolvedId) return;
|
|
5543
|
+
return viteCommand === "serve" ? [
|
|
5544
|
+
`import RefreshRuntime from "${virtual2.hmrRuntime.id}"`,
|
|
5545
|
+
"RefreshRuntime.injectIntoGlobalHook(window)",
|
|
5546
|
+
"window.$RefreshReg$ = () => {}",
|
|
5547
|
+
"window.$RefreshSig$ = () => (type) => type",
|
|
5548
|
+
"window.__vite_plugin_react_preamble_installed__ = true"
|
|
5549
|
+
].join("\n") : "";
|
|
5550
|
+
}
|
|
5551
|
+
},
|
|
5552
|
+
{
|
|
5553
|
+
name: "react-router/rsc/hmr/runtime",
|
|
5554
|
+
enforce: "pre",
|
|
5555
|
+
resolveId(id) {
|
|
5556
|
+
if (id === virtual2.hmrRuntime.id) return virtual2.hmrRuntime.resolvedId;
|
|
5557
|
+
},
|
|
5558
|
+
async load(id) {
|
|
5559
|
+
if (id !== virtual2.hmrRuntime.resolvedId) return;
|
|
5560
|
+
const reactRefreshDir = import_pathe6.default.dirname(
|
|
5561
|
+
require.resolve("react-refresh/package.json")
|
|
5562
|
+
);
|
|
5563
|
+
const reactRefreshRuntimePath = import_pathe6.default.join(
|
|
5564
|
+
reactRefreshDir,
|
|
5565
|
+
"cjs/react-refresh-runtime.development.js"
|
|
5566
|
+
);
|
|
5567
|
+
return [
|
|
5568
|
+
"const exports = {}",
|
|
5569
|
+
await (0, import_promises3.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
5570
|
+
await (0, import_promises3.readFile)(
|
|
5571
|
+
require.resolve("./static/rsc-refresh-utils.mjs"),
|
|
5572
|
+
"utf8"
|
|
5573
|
+
),
|
|
5574
|
+
"export default exports"
|
|
5575
|
+
].join("\n");
|
|
5576
|
+
}
|
|
5577
|
+
},
|
|
5578
|
+
{
|
|
5579
|
+
name: "react-router/rsc/hmr/react-refresh",
|
|
5580
|
+
async transform(code, id, options) {
|
|
5581
|
+
if (viteCommand !== "serve") return;
|
|
5582
|
+
if (id.includes("/node_modules/")) return;
|
|
5583
|
+
const filepath = id.split("?")[0];
|
|
5584
|
+
const extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
|
|
5585
|
+
if (!extensionsRE.test(filepath)) return;
|
|
5586
|
+
const devRuntime = "react/jsx-dev-runtime";
|
|
5587
|
+
const ssr = options?.ssr === true;
|
|
5588
|
+
const isJSX = filepath.endsWith("x");
|
|
5589
|
+
const useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
5590
|
+
if (!useFastRefresh) return;
|
|
5591
|
+
if (isVirtualClientRouteModuleId(id)) {
|
|
5592
|
+
const routeId = routeIdByFile?.get(filepath);
|
|
5593
|
+
return { code: addRefreshWrapper2({ routeId, code, id }) };
|
|
5594
|
+
}
|
|
5595
|
+
const result = await babel2.transformAsync(code, {
|
|
5596
|
+
babelrc: false,
|
|
5597
|
+
configFile: false,
|
|
5598
|
+
filename: id,
|
|
5599
|
+
sourceFileName: filepath,
|
|
5600
|
+
parserOpts: {
|
|
5601
|
+
sourceType: "module",
|
|
5602
|
+
allowAwaitOutsideFunction: true
|
|
5603
|
+
},
|
|
5604
|
+
plugins: [[require("react-refresh/babel"), { skipEnvCheck: true }]],
|
|
5605
|
+
sourceMaps: true
|
|
5606
|
+
});
|
|
5607
|
+
if (result === null) return;
|
|
5608
|
+
code = result.code;
|
|
5609
|
+
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
5610
|
+
if (refreshContentRE.test(code)) {
|
|
5611
|
+
code = addRefreshWrapper2({ code, id });
|
|
5612
|
+
}
|
|
5613
|
+
return { code, map: result.map };
|
|
5614
|
+
}
|
|
5615
|
+
},
|
|
5616
|
+
{
|
|
5617
|
+
name: "react-router/rsc/hmr/updates",
|
|
5618
|
+
async hotUpdate({ server, file, modules }) {
|
|
5619
|
+
if (this.environment.name !== "rsc") return;
|
|
5620
|
+
const clientModules = server.environments.client.moduleGraph.getModulesByFile(file);
|
|
5621
|
+
const vite2 = await import("vite");
|
|
5622
|
+
const isServerOnlyChange = !clientModules || clientModules.size === 0 || // Handle CSS injected from server-first routes (with ?direct query
|
|
5623
|
+
// string) since the client graph has a reference to the CSS
|
|
5624
|
+
vite2.isCSSRequest(file) && Array.from(clientModules).some(
|
|
5625
|
+
(mod) => mod.id?.includes("?direct")
|
|
5626
|
+
);
|
|
5627
|
+
for (const mod of getModulesWithImporters(modules)) {
|
|
5628
|
+
if (!mod.file) continue;
|
|
5629
|
+
const normalizedPath = import_pathe6.default.normalize(mod.file);
|
|
5630
|
+
const routeId = routeIdByFile?.get(normalizedPath);
|
|
5631
|
+
if (routeId !== void 0) {
|
|
5632
|
+
const routeSource = await (0, import_promises3.readFile)(normalizedPath, "utf8");
|
|
5633
|
+
const virtualRouteModuleCode = (await server.environments.rsc.pluginContainer.transform(
|
|
5634
|
+
routeSource,
|
|
5635
|
+
`${normalizedPath}?route-module`
|
|
5636
|
+
)).code;
|
|
5637
|
+
const { staticExports } = parseRouteExports(virtualRouteModuleCode);
|
|
5638
|
+
const hasAction = staticExports.includes("action");
|
|
5639
|
+
const hasComponent = staticExports.includes("default");
|
|
5640
|
+
const hasErrorBoundary = staticExports.includes("ErrorBoundary");
|
|
5641
|
+
const hasLoader = staticExports.includes("loader");
|
|
5642
|
+
server.hot.send({
|
|
5643
|
+
type: "custom",
|
|
5644
|
+
event: "react-router:hmr",
|
|
5645
|
+
data: {
|
|
5646
|
+
routeId,
|
|
5647
|
+
isServerOnlyChange,
|
|
5648
|
+
hasAction,
|
|
5649
|
+
hasComponent,
|
|
5650
|
+
hasErrorBoundary,
|
|
5651
|
+
hasLoader
|
|
5652
|
+
}
|
|
5653
|
+
});
|
|
5654
|
+
}
|
|
5655
|
+
}
|
|
5656
|
+
return modules;
|
|
5657
|
+
}
|
|
5658
|
+
},
|
|
5659
|
+
{
|
|
5660
|
+
name: "react-router/rsc/virtual-react-router-serve-config",
|
|
5661
|
+
resolveId(id) {
|
|
5662
|
+
if (id === virtual2.reactRouterServeConfig.id) {
|
|
5663
|
+
return virtual2.reactRouterServeConfig.resolvedId;
|
|
5664
|
+
}
|
|
5665
|
+
},
|
|
5666
|
+
load(id) {
|
|
5667
|
+
if (id === virtual2.reactRouterServeConfig.resolvedId) {
|
|
5668
|
+
const rscOutDir = resolvedViteConfig.environments.rsc?.build?.outDir;
|
|
5669
|
+
invariant(rscOutDir, "RSC build directory config not found");
|
|
5670
|
+
const clientOutDir = resolvedViteConfig.environments.client?.build?.outDir;
|
|
5671
|
+
invariant(clientOutDir, "Client build directory config not found");
|
|
5672
|
+
const assetsBuildDirectory = Path5.relative(rscOutDir, clientOutDir);
|
|
5673
|
+
const publicPath = resolvedViteConfig.base;
|
|
5674
|
+
return `export default ${JSON.stringify({
|
|
5675
|
+
assetsBuildDirectory,
|
|
5676
|
+
publicPath
|
|
5677
|
+
})};`;
|
|
5678
|
+
}
|
|
5679
|
+
}
|
|
5680
|
+
},
|
|
5681
|
+
validatePluginOrder(),
|
|
5682
|
+
warnOnClientSourceMaps()
|
|
5683
|
+
];
|
|
5684
|
+
}
|
|
5685
|
+
var virtual2 = {
|
|
5686
|
+
routeConfig: create("unstable_rsc/routes"),
|
|
5687
|
+
injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
|
|
5688
|
+
hmrRuntime: create("unstable_rsc/runtime"),
|
|
5689
|
+
basename: create("unstable_rsc/basename"),
|
|
5690
|
+
rscEntry: create("unstable_rsc/rsc-entry"),
|
|
5691
|
+
reactRouterServeConfig: create("unstable_rsc/react-router-serve-config")
|
|
5692
|
+
};
|
|
5693
|
+
function invalidateVirtualModules2(viteDevServer) {
|
|
5694
|
+
for (const vmod of Object.values(virtual2)) {
|
|
5695
|
+
for (const env of Object.values(viteDevServer.environments)) {
|
|
5696
|
+
const mod = env.moduleGraph.getModuleById(vmod.resolvedId);
|
|
5697
|
+
if (mod) {
|
|
5698
|
+
env.moduleGraph.invalidateModule(mod);
|
|
5699
|
+
}
|
|
5700
|
+
}
|
|
5701
|
+
}
|
|
5702
|
+
}
|
|
5703
|
+
function getRootDirectory(viteUserConfig) {
|
|
5704
|
+
return viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
5705
|
+
}
|
|
5706
|
+
function getDevPackageRoot() {
|
|
5707
|
+
const currentDir = (0, import_pathe6.dirname)(__dirname);
|
|
5708
|
+
let dir = currentDir;
|
|
5709
|
+
while (dir !== (0, import_pathe6.dirname)(dir)) {
|
|
5710
|
+
try {
|
|
5711
|
+
const packageJsonPath = (0, import_pathe6.join)(dir, "package.json");
|
|
5712
|
+
(0, import_fs.readFileSync)(packageJsonPath, "utf-8");
|
|
5713
|
+
return dir;
|
|
5714
|
+
} catch {
|
|
5715
|
+
dir = (0, import_pathe6.dirname)(dir);
|
|
5716
|
+
}
|
|
5717
|
+
}
|
|
5718
|
+
throw new Error("Could not find package.json");
|
|
5719
|
+
}
|
|
5720
|
+
function getDefaultEntries() {
|
|
5721
|
+
const defaultEntriesDir2 = (0, import_pathe6.join)(
|
|
5722
|
+
getDevPackageRoot(),
|
|
5723
|
+
"dist",
|
|
5724
|
+
"config",
|
|
5725
|
+
"default-rsc-entries"
|
|
5726
|
+
);
|
|
5727
|
+
return {
|
|
5728
|
+
rsc: (0, import_pathe6.join)(defaultEntriesDir2, "entry.rsc.tsx"),
|
|
5729
|
+
ssr: (0, import_pathe6.join)(defaultEntriesDir2, "entry.ssr.tsx"),
|
|
5730
|
+
client: (0, import_pathe6.join)(defaultEntriesDir2, "entry.client.tsx")
|
|
5731
|
+
};
|
|
5732
|
+
}
|
|
5733
|
+
function getModulesWithImporters(modules) {
|
|
5734
|
+
const visited = /* @__PURE__ */ new Set();
|
|
5735
|
+
const result = /* @__PURE__ */ new Set();
|
|
5736
|
+
function walk(module2) {
|
|
5737
|
+
if (visited.has(module2)) return;
|
|
5738
|
+
visited.add(module2);
|
|
5739
|
+
result.add(module2);
|
|
5740
|
+
for (const importer of module2.importers) {
|
|
5741
|
+
walk(importer);
|
|
5742
|
+
}
|
|
5743
|
+
}
|
|
5744
|
+
for (const module2 of modules) {
|
|
5745
|
+
walk(module2);
|
|
5746
|
+
}
|
|
5747
|
+
return result;
|
|
5748
|
+
}
|
|
5749
|
+
function addRefreshWrapper2({
|
|
5750
|
+
routeId,
|
|
5751
|
+
code,
|
|
5752
|
+
id
|
|
5753
|
+
}) {
|
|
5754
|
+
const acceptExports = routeId !== void 0 ? CLIENT_NON_COMPONENT_EXPORTS2 : [];
|
|
5755
|
+
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));
|
|
5756
|
+
}
|
|
5757
|
+
var REACT_REFRESH_HEADER2 = `
|
|
5758
|
+
import RefreshRuntime from "${virtual2.hmrRuntime.id}";
|
|
5759
|
+
|
|
5760
|
+
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
5761
|
+
let prevRefreshReg;
|
|
5762
|
+
let prevRefreshSig;
|
|
5763
|
+
|
|
5764
|
+
if (import.meta.hot && !inWebWorker) {
|
|
5765
|
+
if (!window.__vite_plugin_react_preamble_installed__) {
|
|
5766
|
+
throw new Error(
|
|
5767
|
+
"React Router Vite plugin can't detect preamble. Something is wrong."
|
|
5768
|
+
);
|
|
5769
|
+
}
|
|
5770
|
+
|
|
5771
|
+
prevRefreshReg = window.$RefreshReg$;
|
|
5772
|
+
prevRefreshSig = window.$RefreshSig$;
|
|
5773
|
+
window.$RefreshReg$ = (type, id) => {
|
|
5774
|
+
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
5775
|
+
};
|
|
5776
|
+
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
5777
|
+
}`.replaceAll("\n", "");
|
|
5778
|
+
var REACT_REFRESH_FOOTER2 = `
|
|
5779
|
+
if (import.meta.hot && !inWebWorker) {
|
|
5780
|
+
window.$RefreshReg$ = prevRefreshReg;
|
|
5781
|
+
window.$RefreshSig$ = prevRefreshSig;
|
|
5782
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
5783
|
+
RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
|
|
5784
|
+
import.meta.hot.accept((nextExports) => {
|
|
5785
|
+
if (!nextExports) return;
|
|
5786
|
+
__ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
|
|
5787
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
|
|
5788
|
+
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
5789
|
+
});
|
|
5790
|
+
});
|
|
5791
|
+
}`;
|
|
4947
5792
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4948
5793
|
0 && (module.exports = {
|
|
4949
|
-
reactRouter
|
|
5794
|
+
reactRouter,
|
|
5795
|
+
unstable_reactRouterRSC
|
|
4950
5796
|
});
|