@react-router/dev 0.0.0-experimental-6336d71a9 → 0.0.0-experimental-4b4fa8f64

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/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-6336d71a9
2
+ * @react-router/dev v0.0.0-experimental-4b4fa8f64
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
 
@@ -247,7 +248,7 @@ function validateRouteConfig({
247
248
  `Route config in "${routeConfigFile}" is invalid.`,
248
249
  root ? `${root}` : [],
249
250
  nested ? Object.entries(nested).map(
250
- ([path7, message]) => `Path: routes.${path7}
251
+ ([path9, message]) => `Path: routes.${path9}
251
252
  ${message}`
252
253
  ) : []
253
254
  ].flat().join("\n\n")
@@ -618,12 +619,12 @@ async function createConfigLoader({
618
619
  if (!fsWatcher) {
619
620
  fsWatcher = import_chokidar.default.watch([root, appDirectory], {
620
621
  ignoreInitial: true,
621
- ignored: (path7) => {
622
- let dirname4 = import_pathe3.default.dirname(path7);
623
- return !dirname4.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
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
624
625
  // that are at the root level, not nested in subdirectories
625
- path7 !== root && // Watch the root directory itself
626
- dirname4 !== root;
626
+ path9 !== root && // Watch the root directory itself
627
+ dirname5 !== root;
627
628
  }
628
629
  });
629
630
  fsWatcher.on("all", async (...args) => {
@@ -883,7 +884,7 @@ function fullpath(lineage2) {
883
884
  if (lineage2.length === 1 && route?.id === "root") return "/";
884
885
  const isLayout = route && route.index !== true && route.path === void 0;
885
886
  if (isLayout) return void 0;
886
- return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path7) => path7 !== void 0 && path7 !== "").join("/");
887
+ return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path9) => path9 !== void 0 && path9 !== "").join("/");
887
888
  }
888
889
 
889
890
  // typegen/generate.ts
@@ -1039,8 +1040,8 @@ function routeFilesType({
1039
1040
  );
1040
1041
  }
1041
1042
  function isInAppDirectory(ctx, routeFile) {
1042
- const path7 = Path3.resolve(ctx.config.appDirectory, routeFile);
1043
- return path7.startsWith(ctx.config.appDirectory);
1043
+ const path9 = Path3.resolve(ctx.config.appDirectory, routeFile);
1044
+ return path9.startsWith(ctx.config.appDirectory);
1044
1045
  }
1045
1046
  function getRouteAnnotations({
1046
1047
  ctx,
@@ -1152,21 +1153,21 @@ function getRouteAnnotations({
1152
1153
  return { filename: filename2, content };
1153
1154
  }
1154
1155
  function relativeImportSource(from, to) {
1155
- let path7 = Path3.relative(Path3.dirname(from), to);
1156
- let extension = Path3.extname(path7);
1157
- path7 = Path3.join(Path3.dirname(path7), Pathe.filename(path7));
1158
- if (!path7.startsWith("../")) path7 = "./" + path7;
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;
1159
1160
  if (!extension || /\.(js|ts)x?$/.test(extension)) {
1160
1161
  extension = ".js";
1161
1162
  }
1162
- return path7 + extension;
1163
+ return path9 + extension;
1163
1164
  }
1164
1165
  function rootDirsPath(ctx, typesPath) {
1165
1166
  const rel = Path3.relative(typesDirectory(ctx), typesPath);
1166
1167
  return Path3.join(ctx.rootDirectory, rel);
1167
1168
  }
1168
- function paramsType(path7) {
1169
- const params = parse2(path7);
1169
+ function paramsType(path9) {
1170
+ const params = parse2(path9);
1170
1171
  return t2.tsTypeLiteral(
1171
1172
  Object.entries(params).map(([param, isRequired]) => {
1172
1173
  const property = t2.tsPropertySignature(
@@ -1435,11 +1436,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
1435
1436
  let cssContent = void 0;
1436
1437
  const ast = import_parser.parse(code, { sourceType: "module" });
1437
1438
  traverse(ast, {
1438
- VariableDeclaration(path7) {
1439
- const declaration = path7.node.declarations[0];
1439
+ VariableDeclaration(path9) {
1440
+ const declaration = path9.node.declarations[0];
1440
1441
  if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
1441
1442
  cssContent = declaration.init.value;
1442
- path7.stop();
1443
+ path9.stop();
1443
1444
  }
1444
1445
  }
1445
1446
  });
@@ -1478,10 +1479,10 @@ var removeExports = (ast, exportsToRemove) => {
1478
1479
  let markedForRemoval = /* @__PURE__ */ new Set();
1479
1480
  let removedExportLocalNames = /* @__PURE__ */ new Set();
1480
1481
  traverse(ast, {
1481
- ExportDeclaration(path7) {
1482
- if (path7.node.type === "ExportNamedDeclaration") {
1483
- if (path7.node.specifiers.length) {
1484
- path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
1482
+ ExportDeclaration(path9) {
1483
+ if (path9.node.type === "ExportNamedDeclaration") {
1484
+ if (path9.node.specifiers.length) {
1485
+ path9.node.specifiers = path9.node.specifiers.filter((specifier) => {
1485
1486
  if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
1486
1487
  if (exportsToRemove.includes(specifier.exported.name)) {
1487
1488
  exportsFiltered = true;
@@ -1493,12 +1494,12 @@ var removeExports = (ast, exportsToRemove) => {
1493
1494
  }
1494
1495
  return true;
1495
1496
  });
1496
- if (path7.node.specifiers.length === 0) {
1497
- markedForRemoval.add(path7);
1497
+ if (path9.node.specifiers.length === 0) {
1498
+ markedForRemoval.add(path9);
1498
1499
  }
1499
1500
  }
1500
- if (path7.node.declaration?.type === "VariableDeclaration") {
1501
- let declaration = path7.node.declaration;
1501
+ if (path9.node.declaration?.type === "VariableDeclaration") {
1502
+ let declaration = path9.node.declaration;
1502
1503
  declaration.declarations = declaration.declarations.filter(
1503
1504
  (declaration2) => {
1504
1505
  if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
@@ -1512,30 +1513,30 @@ var removeExports = (ast, exportsToRemove) => {
1512
1513
  }
1513
1514
  );
1514
1515
  if (declaration.declarations.length === 0) {
1515
- markedForRemoval.add(path7);
1516
+ markedForRemoval.add(path9);
1516
1517
  }
1517
1518
  }
1518
- if (path7.node.declaration?.type === "FunctionDeclaration") {
1519
- let id = path7.node.declaration.id;
1519
+ if (path9.node.declaration?.type === "FunctionDeclaration") {
1520
+ let id = path9.node.declaration.id;
1520
1521
  if (id && exportsToRemove.includes(id.name)) {
1521
- markedForRemoval.add(path7);
1522
+ markedForRemoval.add(path9);
1522
1523
  }
1523
1524
  }
1524
- if (path7.node.declaration?.type === "ClassDeclaration") {
1525
- let id = path7.node.declaration.id;
1525
+ if (path9.node.declaration?.type === "ClassDeclaration") {
1526
+ let id = path9.node.declaration.id;
1526
1527
  if (id && exportsToRemove.includes(id.name)) {
1527
- markedForRemoval.add(path7);
1528
+ markedForRemoval.add(path9);
1528
1529
  }
1529
1530
  }
1530
1531
  }
1531
- if (path7.node.type === "ExportDefaultDeclaration") {
1532
+ if (path9.node.type === "ExportDefaultDeclaration") {
1532
1533
  if (exportsToRemove.includes("default")) {
1533
- markedForRemoval.add(path7);
1534
- if (path7.node.declaration) {
1535
- if (path7.node.declaration.type === "Identifier") {
1536
- removedExportLocalNames.add(path7.node.declaration.name);
1537
- } else if ((path7.node.declaration.type === "FunctionDeclaration" || path7.node.declaration.type === "ClassDeclaration") && path7.node.declaration.id) {
1538
- removedExportLocalNames.add(path7.node.declaration.id.name);
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);
1539
1540
  }
1540
1541
  }
1541
1542
  }
@@ -1543,21 +1544,21 @@ var removeExports = (ast, exportsToRemove) => {
1543
1544
  }
1544
1545
  });
1545
1546
  traverse(ast, {
1546
- ExpressionStatement(path7) {
1547
- if (!path7.parentPath.isProgram()) {
1547
+ ExpressionStatement(path9) {
1548
+ if (!path9.parentPath.isProgram()) {
1548
1549
  return;
1549
1550
  }
1550
- if (path7.node.expression.type === "AssignmentExpression") {
1551
- const left = path7.node.expression.left;
1551
+ if (path9.node.expression.type === "AssignmentExpression") {
1552
+ const left = path9.node.expression.left;
1552
1553
  if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
1553
- markedForRemoval.add(path7);
1554
+ markedForRemoval.add(path9);
1554
1555
  }
1555
1556
  }
1556
1557
  }
1557
1558
  });
1558
1559
  if (markedForRemoval.size > 0 || exportsFiltered) {
1559
- for (let path7 of markedForRemoval) {
1560
- path7.remove();
1560
+ for (let path9 of markedForRemoval) {
1561
+ path9.remove();
1561
1562
  }
1562
1563
  (0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
1563
1564
  }
@@ -1640,28 +1641,28 @@ function codeToAst(code, cache, cacheKey) {
1640
1641
  )
1641
1642
  );
1642
1643
  }
1643
- function assertNodePath(path7) {
1644
+ function assertNodePath(path9) {
1644
1645
  invariant(
1645
- path7 && !Array.isArray(path7),
1646
- `Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
1646
+ path9 && !Array.isArray(path9),
1647
+ `Expected a Path, but got ${Array.isArray(path9) ? "an array" : path9}`
1647
1648
  );
1648
1649
  }
1649
- function assertNodePathIsStatement(path7) {
1650
+ function assertNodePathIsStatement(path9) {
1650
1651
  invariant(
1651
- path7 && !Array.isArray(path7) && t.isStatement(path7.node),
1652
- `Expected a Statement path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1652
+ path9 && !Array.isArray(path9) && t.isStatement(path9.node),
1653
+ `Expected a Statement path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
1653
1654
  );
1654
1655
  }
1655
- function assertNodePathIsVariableDeclarator(path7) {
1656
+ function assertNodePathIsVariableDeclarator(path9) {
1656
1657
  invariant(
1657
- path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
1658
- `Expected an Identifier path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1658
+ path9 && !Array.isArray(path9) && t.isVariableDeclarator(path9.node),
1659
+ `Expected an Identifier path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
1659
1660
  );
1660
1661
  }
1661
- function assertNodePathIsPattern(path7) {
1662
+ function assertNodePathIsPattern(path9) {
1662
1663
  invariant(
1663
- path7 && !Array.isArray(path7) && t.isPattern(path7.node),
1664
- `Expected a Pattern path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1664
+ path9 && !Array.isArray(path9) && t.isPattern(path9.node),
1665
+ `Expected a Pattern path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
1665
1666
  );
1666
1667
  }
1667
1668
  function getExportDependencies(code, cache, cacheKey) {
@@ -1697,8 +1698,8 @@ function getExportDependencies(code, cache, cacheKey) {
1697
1698
  }
1698
1699
  let isWithinExportDestructuring = Boolean(
1699
1700
  identifier.findParent(
1700
- (path7) => Boolean(
1701
- path7.isPattern() && path7.parentPath?.isVariableDeclarator() && path7.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1701
+ (path9) => Boolean(
1702
+ path9.isPattern() && path9.parentPath?.isVariableDeclarator() && path9.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1702
1703
  )
1703
1704
  )
1704
1705
  );
@@ -1776,7 +1777,7 @@ function getExportDependencies(code, cache, cacheKey) {
1776
1777
  for (let specifier of node.specifiers) {
1777
1778
  if (t.isIdentifier(specifier.exported)) {
1778
1779
  let name = specifier.exported.name;
1779
- let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
1780
+ let specifierPath = exportPath.get("specifiers").find((path9) => path9.node === specifier);
1780
1781
  invariant(
1781
1782
  specifierPath,
1782
1783
  `Expected to find specifier path for ${name}`
@@ -1793,22 +1794,22 @@ function getExportDependencies(code, cache, cacheKey) {
1793
1794
  }
1794
1795
  );
1795
1796
  }
1796
- function getDependentIdentifiersForPath(path7, state) {
1797
+ function getDependentIdentifiersForPath(path9, state) {
1797
1798
  let { visited, identifiers } = state ?? {
1798
1799
  visited: /* @__PURE__ */ new Set(),
1799
1800
  identifiers: /* @__PURE__ */ new Set()
1800
1801
  };
1801
- if (visited.has(path7)) {
1802
+ if (visited.has(path9)) {
1802
1803
  return identifiers;
1803
1804
  }
1804
- visited.add(path7);
1805
- path7.traverse({
1806
- Identifier(path8) {
1807
- if (identifiers.has(path8)) {
1805
+ visited.add(path9);
1806
+ path9.traverse({
1807
+ Identifier(path10) {
1808
+ if (identifiers.has(path10)) {
1808
1809
  return;
1809
1810
  }
1810
- identifiers.add(path8);
1811
- let binding = path8.scope.getBinding(path8.node.name);
1811
+ identifiers.add(path10);
1812
+ let binding = path10.scope.getBinding(path10.node.name);
1812
1813
  if (!binding) {
1813
1814
  return;
1814
1815
  }
@@ -1830,7 +1831,7 @@ function getDependentIdentifiersForPath(path7, state) {
1830
1831
  }
1831
1832
  }
1832
1833
  });
1833
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1834
+ let topLevelStatement = getTopLevelStatementPathForPath(path9);
1834
1835
  let withinImportStatement = topLevelStatement.isImportDeclaration();
1835
1836
  let withinExportStatement = topLevelStatement.isExportDeclaration();
1836
1837
  if (!withinImportStatement && !withinExportStatement) {
@@ -1839,9 +1840,9 @@ function getDependentIdentifiersForPath(path7, state) {
1839
1840
  identifiers
1840
1841
  });
1841
1842
  }
1842
- if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
1843
- t.isPattern(path7.parentPath.parentPath?.node))) {
1844
- let variableDeclarator = path7.findParent((p) => p.isVariableDeclarator());
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());
1845
1846
  assertNodePath(variableDeclarator);
1846
1847
  getDependentIdentifiersForPath(variableDeclarator, {
1847
1848
  visited,
@@ -1850,16 +1851,16 @@ function getDependentIdentifiersForPath(path7, state) {
1850
1851
  }
1851
1852
  return identifiers;
1852
1853
  }
1853
- function getTopLevelStatementPathForPath(path7) {
1854
- let ancestry = path7.getAncestry();
1854
+ function getTopLevelStatementPathForPath(path9) {
1855
+ let ancestry = path9.getAncestry();
1855
1856
  let topLevelStatement = ancestry[ancestry.length - 2];
1856
1857
  assertNodePathIsStatement(topLevelStatement);
1857
1858
  return topLevelStatement;
1858
1859
  }
1859
1860
  function getTopLevelStatementsForPaths(paths) {
1860
1861
  let topLevelStatements = /* @__PURE__ */ new Set();
1861
- for (let path7 of paths) {
1862
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1862
+ for (let path9 of paths) {
1863
+ let topLevelStatement = getTopLevelStatementPathForPath(path9);
1863
1864
  topLevelStatements.add(topLevelStatement.node);
1864
1865
  }
1865
1866
  return topLevelStatements;
@@ -2253,24 +2254,24 @@ function isNamedComponentExport(name) {
2253
2254
  }
2254
2255
  var decorateComponentExportsWithProps = (ast) => {
2255
2256
  const hocs = [];
2256
- function getHocUid(path7, hocName) {
2257
- const uid = path7.scope.generateUidIdentifier(hocName);
2257
+ function getHocUid(path9, hocName) {
2258
+ const uid = path9.scope.generateUidIdentifier(hocName);
2258
2259
  hocs.push([hocName, uid]);
2259
2260
  return uid;
2260
2261
  }
2261
2262
  traverse(ast, {
2262
- ExportDeclaration(path7) {
2263
- if (path7.isExportDefaultDeclaration()) {
2264
- const declaration = path7.get("declaration");
2263
+ ExportDeclaration(path9) {
2264
+ if (path9.isExportDefaultDeclaration()) {
2265
+ const declaration = path9.get("declaration");
2265
2266
  const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
2266
2267
  if (expr) {
2267
- const uid = getHocUid(path7, "UNSAFE_withComponentProps");
2268
+ const uid = getHocUid(path9, "UNSAFE_withComponentProps");
2268
2269
  declaration.replaceWith(t.callExpression(uid, [expr]));
2269
2270
  }
2270
2271
  return;
2271
2272
  }
2272
- if (path7.isExportNamedDeclaration()) {
2273
- const decl = path7.get("declaration");
2273
+ if (path9.isExportNamedDeclaration()) {
2274
+ const decl = path9.get("declaration");
2274
2275
  if (decl.isVariableDeclaration()) {
2275
2276
  decl.get("declarations").forEach((varDeclarator) => {
2276
2277
  const id = varDeclarator.get("id");
@@ -2280,7 +2281,7 @@ var decorateComponentExportsWithProps = (ast) => {
2280
2281
  if (!id.isIdentifier()) return;
2281
2282
  const { name } = id.node;
2282
2283
  if (!isNamedComponentExport(name)) return;
2283
- const uid = getHocUid(path7, `UNSAFE_with${name}Props`);
2284
+ const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
2284
2285
  init.replaceWith(t.callExpression(uid, [expr]));
2285
2286
  });
2286
2287
  return;
@@ -2290,7 +2291,7 @@ var decorateComponentExportsWithProps = (ast) => {
2290
2291
  if (!id) return;
2291
2292
  const { name } = id;
2292
2293
  if (!isNamedComponentExport(name)) return;
2293
- const uid = getHocUid(path7, `UNSAFE_with${name}Props`);
2294
+ const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
2294
2295
  decl.replaceWith(
2295
2296
  t.variableDeclaration("const", [
2296
2297
  t.variableDeclarator(
@@ -4169,17 +4170,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4169
4170
  serverBuildPath
4170
4171
  );
4171
4172
  let routes = createPrerenderRoutes(reactRouterConfig.routes);
4172
- for (let path7 of build.prerender) {
4173
- let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
4173
+ for (let path9 of build.prerender) {
4174
+ let matches = (0, import_react_router2.matchRoutes)(routes, `/${path9}/`.replace(/^\/\/+/, "/"));
4174
4175
  if (!matches) {
4175
4176
  throw new Error(
4176
- `Unable to prerender path because it does not match any routes: ${path7}`
4177
+ `Unable to prerender path because it does not match any routes: ${path9}`
4177
4178
  );
4178
4179
  }
4179
4180
  }
4180
4181
  let buildRoutes = createPrerenderRoutes(build.routes);
4181
- for (let path7 of build.prerender) {
4182
- let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path7}/`.replace(/^\/\/+/, "/"));
4182
+ for (let path9 of build.prerender) {
4183
+ let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path9}/`.replace(/^\/\/+/, "/"));
4183
4184
  if (!matches) {
4184
4185
  continue;
4185
4186
  }
@@ -4192,7 +4193,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4192
4193
  if (manifestRoute.loader) {
4193
4194
  await prerenderData(
4194
4195
  handler,
4195
- path7,
4196
+ path9,
4196
4197
  [leafRoute.id],
4197
4198
  clientBuildDirectory,
4198
4199
  reactRouterConfig,
@@ -4200,7 +4201,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4200
4201
  );
4201
4202
  await prerenderResourceRoute(
4202
4203
  handler,
4203
- path7,
4204
+ path9,
4204
4205
  clientBuildDirectory,
4205
4206
  reactRouterConfig,
4206
4207
  viteConfig
@@ -4218,7 +4219,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4218
4219
  if (!isResourceRoute && hasLoaders) {
4219
4220
  data = await prerenderData(
4220
4221
  handler,
4221
- path7,
4222
+ path9,
4222
4223
  null,
4223
4224
  clientBuildDirectory,
4224
4225
  reactRouterConfig,
@@ -4227,7 +4228,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4227
4228
  }
4228
4229
  await prerenderRoute(
4229
4230
  handler,
4230
- path7,
4231
+ path9,
4231
4232
  clientBuildDirectory,
4232
4233
  reactRouterConfig,
4233
4234
  viteConfig,
@@ -4423,14 +4424,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
4423
4424
  }
4424
4425
  let prerenderRoutes = createPrerenderRoutes(manifest.routes);
4425
4426
  let prerenderedRoutes = /* @__PURE__ */ new Set();
4426
- for (let path7 of prerenderPaths) {
4427
+ for (let path9 of prerenderPaths) {
4427
4428
  let matches = (0, import_react_router2.matchRoutes)(
4428
4429
  prerenderRoutes,
4429
- `/${path7}/`.replace(/^\/\/+/, "/")
4430
+ `/${path9}/`.replace(/^\/\/+/, "/")
4430
4431
  );
4431
4432
  invariant(
4432
4433
  matches,
4433
- `Unable to prerender path because it does not match any routes: ${path7}`
4434
+ `Unable to prerender path because it does not match any routes: ${path9}`
4434
4435
  );
4435
4436
  matches.forEach((m) => prerenderedRoutes.add(m.route.id));
4436
4437
  }
@@ -4878,7 +4879,918 @@ async function asyncFlatten(arr) {
4878
4879
  } while (arr.some((v2) => v2?.then));
4879
4880
  return arr;
4880
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
+ }`;
4881
5792
  // Annotate the CommonJS export names for ESM import in node:
4882
5793
  0 && (module.exports = {
4883
- reactRouter
5794
+ reactRouter,
5795
+ unstable_reactRouterRSC
4884
5796
  });