@c0va23/react-router-dev 7.8.3-alpha.2 → 7.9.4-patch.2

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
- * @c0va23/react-router-dev v7.8.3-alpha.2
2
+ * @c0va23/react-router-dev v7.9.4-patch.1
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
 
@@ -48,15 +49,15 @@ module.exports = __toCommonJS(vite_exports);
48
49
  var import_node_crypto = require("crypto");
49
50
  var import_node_fs2 = require("fs");
50
51
  var import_promises2 = require("fs/promises");
51
- var path5 = __toESM(require("path"));
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
- var import_tinyglobby = require("tinyglobby");
57
58
  var import_pick3 = __toESM(require("lodash/pick"));
58
59
  var import_jsesc = __toESM(require("jsesc"));
59
- var import_picocolors3 = __toESM(require("picocolors"));
60
+ var import_picocolors4 = __toESM(require("picocolors"));
60
61
  var import_kebabCase = __toESM(require("lodash/kebabCase"));
61
62
 
62
63
  // typegen/index.ts
@@ -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
- ([path6, message]) => `Path: routes.${path6}
251
+ ([path9, message]) => `Path: routes.${path9}
251
252
  ${message}`
252
253
  ) : []
253
254
  ].flat().join("\n\n")
@@ -367,7 +368,8 @@ async function resolveConfig({
367
368
  root,
368
369
  viteNodeContext,
369
370
  reactRouterConfigFile,
370
- skipRoutes
371
+ skipRoutes,
372
+ validateConfig
371
373
  }) {
372
374
  let reactRouterUserConfig = {};
373
375
  if (reactRouterConfigFile) {
@@ -385,6 +387,12 @@ async function resolveConfig({
385
387
  return err(`${reactRouterConfigFile} must export a config`);
386
388
  }
387
389
  reactRouterUserConfig = configModule.default;
390
+ if (validateConfig) {
391
+ const error = validateConfig(reactRouterUserConfig);
392
+ if (error) {
393
+ return err(error);
394
+ }
395
+ }
388
396
  } catch (error) {
389
397
  return err(`Error loading ${reactRouterConfigFile}: ${error}`);
390
398
  }
@@ -473,7 +481,7 @@ async function resolveConfig({
473
481
  }
474
482
  let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
475
483
  let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
476
- let rootRouteFile = findEntry(appDirectory, "root");
484
+ let rootRouteFile = findEntry(appDirectory, "root", { absolute: true });
477
485
  if (!rootRouteFile) {
478
486
  let rootRouteDisplayPath = import_pathe3.default.relative(
479
487
  root,
@@ -514,7 +522,7 @@ async function resolveConfig({
514
522
  {
515
523
  id: "root",
516
524
  path: "",
517
- file: rootRouteFile,
525
+ file: import_pathe3.default.relative(appDirectory, rootRouteFile),
518
526
  children: result.routeConfig
519
527
  }
520
528
  ];
@@ -533,11 +541,11 @@ async function resolveConfig({
533
541
  }
534
542
  }
535
543
  let future = {
536
- unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
537
- unstable_optimizeDeps: reactRouterUserConfig.future?.unstable_optimizeDeps ?? false,
538
- unstable_splitRouteModules: reactRouterUserConfig.future?.unstable_splitRouteModules ?? false,
539
- unstable_subResourceIntegrity: reactRouterUserConfig.future?.unstable_subResourceIntegrity ?? false,
540
- unstable_viteEnvironmentApi: reactRouterUserConfig.future?.unstable_viteEnvironmentApi ?? false
544
+ v8_middleware: userAndPresetConfigs.future?.v8_middleware ?? false,
545
+ unstable_optimizeDeps: userAndPresetConfigs.future?.unstable_optimizeDeps ?? false,
546
+ unstable_splitRouteModules: userAndPresetConfigs.future?.unstable_splitRouteModules ?? false,
547
+ unstable_subResourceIntegrity: userAndPresetConfigs.future?.unstable_subResourceIntegrity ?? false,
548
+ unstable_viteEnvironmentApi: userAndPresetConfigs.future?.unstable_viteEnvironmentApi ?? false
541
549
  };
542
550
  let reactRouterConfig = deepFreeze({
543
551
  appDirectory,
@@ -563,7 +571,8 @@ async function createConfigLoader({
563
571
  rootDirectory: root,
564
572
  watch: watch2,
565
573
  mode,
566
- skipRoutes
574
+ skipRoutes,
575
+ validateConfig
567
576
  }) {
568
577
  root = import_pathe3.default.normalize(root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd());
569
578
  let vite2 = await import("vite");
@@ -582,7 +591,13 @@ async function createConfigLoader({
582
591
  });
583
592
  };
584
593
  updateReactRouterConfigFile();
585
- let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile, skipRoutes });
594
+ let getConfig = () => resolveConfig({
595
+ root,
596
+ viteNodeContext,
597
+ reactRouterConfigFile,
598
+ skipRoutes,
599
+ validateConfig
600
+ });
586
601
  let appDirectory;
587
602
  let initialConfigResult = await getConfig();
588
603
  if (!initialConfigResult.ok) {
@@ -604,12 +619,12 @@ async function createConfigLoader({
604
619
  if (!fsWatcher) {
605
620
  fsWatcher = import_chokidar.default.watch([root, appDirectory], {
606
621
  ignoreInitial: true,
607
- ignored: (path6) => {
608
- let dirname4 = import_pathe3.default.dirname(path6);
609
- 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
610
625
  // that are at the root level, not nested in subdirectories
611
- path6 !== root && // Watch the root directory itself
612
- dirname4 !== root;
626
+ path9 !== root && // Watch the root directory itself
627
+ dirname5 !== root;
613
628
  }
614
629
  });
615
630
  fsWatcher.on("all", async (...args) => {
@@ -801,7 +816,8 @@ function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /
801
816
  async function createContext2({
802
817
  rootDirectory,
803
818
  watch: watch2,
804
- mode
819
+ mode,
820
+ rsc
805
821
  }) {
806
822
  const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
807
823
  const configResult = await configLoader.getConfig();
@@ -812,7 +828,8 @@ async function createContext2({
812
828
  return {
813
829
  configLoader,
814
830
  rootDirectory,
815
- config
831
+ config,
832
+ rsc
816
833
  };
817
834
  }
818
835
 
@@ -867,7 +884,7 @@ function fullpath(lineage2) {
867
884
  if (lineage2.length === 1 && route?.id === "root") return "/";
868
885
  const isLayout = route && route.index !== true && route.path === void 0;
869
886
  if (isLayout) return void 0;
870
- return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path6) => path6 !== void 0 && path6 !== "").join("/");
887
+ return "/" + lineage2.map((route2) => route2.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path9) => path9 !== void 0 && path9 !== "").join("/");
871
888
  }
872
889
 
873
890
  // typegen/generate.ts
@@ -883,7 +900,7 @@ function generateFuture(ctx) {
883
900
 
884
901
  declare module "react-router" {
885
902
  interface Future {
886
- unstable_middleware: ${ctx.config.future.unstable_middleware}
903
+ v8_middleware: ${ctx.config.future.v8_middleware}
887
904
  }
888
905
  }
889
906
  `;
@@ -951,9 +968,10 @@ function generateRoutes(ctx) {
951
968
  interface Register {
952
969
  pages: Pages
953
970
  routeFiles: RouteFiles
971
+ routeModules: RouteModules
954
972
  }
955
973
  }
956
- ` + "\n\n" + generate(pagesType(allPages)).code + "\n\n" + generate(routeFilesType({ fileToRoutes, routeToPages })).code
974
+ ` + "\n\n" + generate(pagesType(allPages)).code + "\n\n" + generate(routeFilesType({ fileToRoutes, routeToPages })).code + "\n\n" + generate(routeModulesType(ctx)).code
957
975
  };
958
976
  const allAnnotations = Array.from(fileToRoutes.entries()).filter(([file]) => isInAppDirectory(ctx, file)).map(
959
977
  ([file, routeIds]) => getRouteAnnotations({ ctx, file, routeIds, lineages })
@@ -1022,9 +1040,31 @@ function routeFilesType({
1022
1040
  )
1023
1041
  );
1024
1042
  }
1043
+ function routeModulesType(ctx) {
1044
+ return t2.tsTypeAliasDeclaration(
1045
+ t2.identifier("RouteModules"),
1046
+ null,
1047
+ t2.tsTypeLiteral(
1048
+ Object.values(ctx.config.routes).map(
1049
+ (route) => t2.tsPropertySignature(
1050
+ t2.stringLiteral(route.id),
1051
+ t2.tsTypeAnnotation(
1052
+ t2.tsTypeQuery(
1053
+ t2.tsImportType(
1054
+ t2.stringLiteral(
1055
+ `./${Path3.relative(ctx.rootDirectory, ctx.config.appDirectory)}/${route.file}`
1056
+ )
1057
+ )
1058
+ )
1059
+ )
1060
+ )
1061
+ )
1062
+ )
1063
+ );
1064
+ }
1025
1065
  function isInAppDirectory(ctx, routeFile) {
1026
- const path6 = Path3.resolve(ctx.config.appDirectory, routeFile);
1027
- return path6.startsWith(ctx.config.appDirectory);
1066
+ const path9 = Path3.resolve(ctx.config.appDirectory, routeFile);
1067
+ return path9.startsWith(ctx.config.appDirectory);
1028
1068
  }
1029
1069
  function getRouteAnnotations({
1030
1070
  ctx,
@@ -1089,7 +1129,7 @@ function getRouteAnnotations({
1089
1129
  module: Module
1090
1130
  }>
1091
1131
  ` + "\n\n" + generate(matchesType).code + "\n\n" + import_dedent.default`
1092
- type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }>;
1132
+ type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }, ${ctx.rsc}>;
1093
1133
 
1094
1134
  export namespace Route {
1095
1135
  // links
@@ -1105,11 +1145,11 @@ function getRouteAnnotations({
1105
1145
  export type HeadersArgs = Annotations["HeadersArgs"];
1106
1146
  export type HeadersFunction = Annotations["HeadersFunction"];
1107
1147
 
1108
- // unstable_middleware
1109
- export type unstable_MiddlewareFunction = Annotations["unstable_MiddlewareFunction"];
1148
+ // middleware
1149
+ export type MiddlewareFunction = Annotations["MiddlewareFunction"];
1110
1150
 
1111
- // unstable_clientMiddleware
1112
- export type unstable_ClientMiddlewareFunction = Annotations["unstable_ClientMiddlewareFunction"];
1151
+ // clientMiddleware
1152
+ export type ClientMiddlewareFunction = Annotations["ClientMiddlewareFunction"];
1113
1153
 
1114
1154
  // loader
1115
1155
  export type LoaderArgs = Annotations["LoaderArgs"];
@@ -1136,21 +1176,21 @@ function getRouteAnnotations({
1136
1176
  return { filename: filename2, content };
1137
1177
  }
1138
1178
  function relativeImportSource(from, to) {
1139
- let path6 = Path3.relative(Path3.dirname(from), to);
1140
- let extension = Path3.extname(path6);
1141
- path6 = Path3.join(Path3.dirname(path6), Pathe.filename(path6));
1142
- if (!path6.startsWith("../")) path6 = "./" + path6;
1179
+ let path9 = Path3.relative(Path3.dirname(from), to);
1180
+ let extension = Path3.extname(path9);
1181
+ path9 = Path3.join(Path3.dirname(path9), Pathe.filename(path9));
1182
+ if (!path9.startsWith("../")) path9 = "./" + path9;
1143
1183
  if (!extension || /\.(js|ts)x?$/.test(extension)) {
1144
1184
  extension = ".js";
1145
1185
  }
1146
- return path6 + extension;
1186
+ return path9 + extension;
1147
1187
  }
1148
1188
  function rootDirsPath(ctx, typesPath) {
1149
1189
  const rel = Path3.relative(typesDirectory(ctx), typesPath);
1150
1190
  return Path3.join(ctx.rootDirectory, rel);
1151
1191
  }
1152
- function paramsType(path6) {
1153
- const params = parse2(path6);
1192
+ function paramsType(path9) {
1193
+ const params = parse2(path9);
1154
1194
  return t2.tsTypeLiteral(
1155
1195
  Object.entries(params).map(([param, isRequired]) => {
1156
1196
  const property = t2.tsPropertySignature(
@@ -1200,8 +1240,8 @@ async function write(...files) {
1200
1240
  })
1201
1241
  );
1202
1242
  }
1203
- async function watch(rootDirectory, { mode, logger }) {
1204
- const ctx = await createContext2({ rootDirectory, mode, watch: true });
1243
+ async function watch(rootDirectory, { mode, logger, rsc }) {
1244
+ const ctx = await createContext2({ rootDirectory, mode, rsc, watch: true });
1205
1245
  await import_promises.default.rm(typesDirectory(ctx), { recursive: true, force: true });
1206
1246
  await write(
1207
1247
  generateFuture(ctx),
@@ -1239,81 +1279,14 @@ async function watch(rootDirectory, { mode, logger }) {
1239
1279
  }
1240
1280
 
1241
1281
  // vite/node-adapter.ts
1242
- var import_node_events = require("events");
1243
- var import_node_tls = require("tls");
1244
- var import_node_stream = require("stream");
1245
- var import_set_cookie_parser = require("set-cookie-parser");
1246
- var import_node = require("@react-router/node");
1247
- function fromNodeHeaders(nodeReq) {
1248
- let nodeHeaders = nodeReq.headers;
1249
- if (nodeReq.httpVersionMajor >= 2) {
1250
- nodeHeaders = { ...nodeHeaders };
1251
- if (nodeHeaders[":authority"]) {
1252
- nodeHeaders.host = nodeHeaders[":authority"];
1253
- }
1254
- delete nodeHeaders[":authority"];
1255
- delete nodeHeaders[":method"];
1256
- delete nodeHeaders[":path"];
1257
- delete nodeHeaders[":scheme"];
1258
- }
1259
- let headers = new Headers();
1260
- for (let [key, values] of Object.entries(nodeHeaders)) {
1261
- if (values) {
1262
- if (Array.isArray(values)) {
1263
- for (let value of values) {
1264
- headers.append(key, value);
1265
- }
1266
- } else {
1267
- headers.set(key, values);
1268
- }
1269
- }
1270
- }
1271
- return headers;
1272
- }
1282
+ var import_node_fetch_server = require("@remix-run/node-fetch-server");
1273
1283
  function fromNodeRequest(nodeReq, nodeRes) {
1274
- let protocol = nodeReq.socket instanceof import_node_tls.TLSSocket && nodeReq.socket.encrypted ? "https" : "http";
1275
- let origin = nodeReq.headers.origin && "null" !== nodeReq.headers.origin ? nodeReq.headers.origin : `${protocol}://${nodeReq.headers.host}`;
1276
1284
  invariant(
1277
1285
  nodeReq.originalUrl,
1278
1286
  "Expected `nodeReq.originalUrl` to be defined"
1279
1287
  );
1280
- let url2 = new URL(nodeReq.originalUrl, origin);
1281
- let controller = new AbortController();
1282
- let init = {
1283
- method: nodeReq.method,
1284
- headers: fromNodeHeaders(nodeReq),
1285
- signal: controller.signal
1286
- };
1287
- nodeRes.on("finish", () => controller = null);
1288
- nodeRes.on("close", () => controller?.abort());
1289
- if (nodeReq.method !== "GET" && nodeReq.method !== "HEAD") {
1290
- init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
1291
- init.duplex = "half";
1292
- }
1293
- return new Request(url2.href, init);
1294
- }
1295
- async function toNodeRequest(res, nodeRes) {
1296
- nodeRes.statusCode = res.status;
1297
- if (!nodeRes.req || nodeRes.req.httpVersionMajor < 2) {
1298
- nodeRes.statusMessage = res.statusText;
1299
- }
1300
- let cookiesStrings = [];
1301
- for (let [name, value] of res.headers) {
1302
- if (name === "set-cookie") {
1303
- cookiesStrings.push(...(0, import_set_cookie_parser.splitCookiesString)(value));
1304
- } else nodeRes.setHeader(name, value);
1305
- }
1306
- if (cookiesStrings.length) {
1307
- nodeRes.setHeader("set-cookie", cookiesStrings);
1308
- }
1309
- if (res.body) {
1310
- let responseBody = res.body;
1311
- let readable = import_node_stream.Readable.from(responseBody);
1312
- readable.pipe(nodeRes);
1313
- await (0, import_node_events.once)(readable, "end");
1314
- } else {
1315
- nodeRes.end();
1316
- }
1288
+ nodeReq.url = nodeReq.originalUrl;
1289
+ return (0, import_node_fetch_server.createRequest)(nodeReq, nodeRes);
1317
1290
  }
1318
1291
 
1319
1292
  // vite/styles.ts
@@ -1486,11 +1459,11 @@ var getCssStringFromViteDevModuleCode = (code) => {
1486
1459
  let cssContent = void 0;
1487
1460
  const ast = import_parser.parse(code, { sourceType: "module" });
1488
1461
  traverse(ast, {
1489
- VariableDeclaration(path6) {
1490
- const declaration = path6.node.declarations[0];
1462
+ VariableDeclaration(path9) {
1463
+ const declaration = path9.node.declarations[0];
1491
1464
  if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
1492
1465
  cssContent = declaration.init.value;
1493
- path6.stop();
1466
+ path9.stop();
1494
1467
  }
1495
1468
  }
1496
1469
  });
@@ -1507,6 +1480,15 @@ function create(name) {
1507
1480
  };
1508
1481
  }
1509
1482
 
1483
+ // vite/resolve-relative-route-file-path.ts
1484
+ var import_pathe4 = __toESM(require("pathe"));
1485
+ function resolveRelativeRouteFilePath(route, reactRouterConfig) {
1486
+ let vite2 = getVite();
1487
+ let file = route.file;
1488
+ let fullPath = import_pathe4.default.resolve(reactRouterConfig.appDirectory, file);
1489
+ return vite2.normalizePath(fullPath);
1490
+ }
1491
+
1510
1492
  // vite/combine-urls.ts
1511
1493
  function combineURLs(baseURL, relativeURL) {
1512
1494
  return relativeURL ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
@@ -1520,10 +1502,10 @@ var removeExports = (ast, exportsToRemove) => {
1520
1502
  let markedForRemoval = /* @__PURE__ */ new Set();
1521
1503
  let removedExportLocalNames = /* @__PURE__ */ new Set();
1522
1504
  traverse(ast, {
1523
- ExportDeclaration(path6) {
1524
- if (path6.node.type === "ExportNamedDeclaration") {
1525
- if (path6.node.specifiers.length) {
1526
- path6.node.specifiers = path6.node.specifiers.filter((specifier) => {
1505
+ ExportDeclaration(path9) {
1506
+ if (path9.node.type === "ExportNamedDeclaration") {
1507
+ if (path9.node.specifiers.length) {
1508
+ path9.node.specifiers = path9.node.specifiers.filter((specifier) => {
1527
1509
  if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
1528
1510
  if (exportsToRemove.includes(specifier.exported.name)) {
1529
1511
  exportsFiltered = true;
@@ -1535,12 +1517,12 @@ var removeExports = (ast, exportsToRemove) => {
1535
1517
  }
1536
1518
  return true;
1537
1519
  });
1538
- if (path6.node.specifiers.length === 0) {
1539
- markedForRemoval.add(path6);
1520
+ if (path9.node.specifiers.length === 0) {
1521
+ markedForRemoval.add(path9);
1540
1522
  }
1541
1523
  }
1542
- if (path6.node.declaration?.type === "VariableDeclaration") {
1543
- let declaration = path6.node.declaration;
1524
+ if (path9.node.declaration?.type === "VariableDeclaration") {
1525
+ let declaration = path9.node.declaration;
1544
1526
  declaration.declarations = declaration.declarations.filter(
1545
1527
  (declaration2) => {
1546
1528
  if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
@@ -1554,30 +1536,30 @@ var removeExports = (ast, exportsToRemove) => {
1554
1536
  }
1555
1537
  );
1556
1538
  if (declaration.declarations.length === 0) {
1557
- markedForRemoval.add(path6);
1539
+ markedForRemoval.add(path9);
1558
1540
  }
1559
1541
  }
1560
- if (path6.node.declaration?.type === "FunctionDeclaration") {
1561
- let id = path6.node.declaration.id;
1542
+ if (path9.node.declaration?.type === "FunctionDeclaration") {
1543
+ let id = path9.node.declaration.id;
1562
1544
  if (id && exportsToRemove.includes(id.name)) {
1563
- markedForRemoval.add(path6);
1545
+ markedForRemoval.add(path9);
1564
1546
  }
1565
1547
  }
1566
- if (path6.node.declaration?.type === "ClassDeclaration") {
1567
- let id = path6.node.declaration.id;
1548
+ if (path9.node.declaration?.type === "ClassDeclaration") {
1549
+ let id = path9.node.declaration.id;
1568
1550
  if (id && exportsToRemove.includes(id.name)) {
1569
- markedForRemoval.add(path6);
1551
+ markedForRemoval.add(path9);
1570
1552
  }
1571
1553
  }
1572
1554
  }
1573
- if (path6.node.type === "ExportDefaultDeclaration") {
1555
+ if (path9.node.type === "ExportDefaultDeclaration") {
1574
1556
  if (exportsToRemove.includes("default")) {
1575
- markedForRemoval.add(path6);
1576
- if (path6.node.declaration) {
1577
- if (path6.node.declaration.type === "Identifier") {
1578
- removedExportLocalNames.add(path6.node.declaration.name);
1579
- } else if ((path6.node.declaration.type === "FunctionDeclaration" || path6.node.declaration.type === "ClassDeclaration") && path6.node.declaration.id) {
1580
- removedExportLocalNames.add(path6.node.declaration.id.name);
1557
+ markedForRemoval.add(path9);
1558
+ if (path9.node.declaration) {
1559
+ if (path9.node.declaration.type === "Identifier") {
1560
+ removedExportLocalNames.add(path9.node.declaration.name);
1561
+ } else if ((path9.node.declaration.type === "FunctionDeclaration" || path9.node.declaration.type === "ClassDeclaration") && path9.node.declaration.id) {
1562
+ removedExportLocalNames.add(path9.node.declaration.id.name);
1581
1563
  }
1582
1564
  }
1583
1565
  }
@@ -1585,21 +1567,21 @@ var removeExports = (ast, exportsToRemove) => {
1585
1567
  }
1586
1568
  });
1587
1569
  traverse(ast, {
1588
- ExpressionStatement(path6) {
1589
- if (!path6.parentPath.isProgram()) {
1570
+ ExpressionStatement(path9) {
1571
+ if (!path9.parentPath.isProgram()) {
1590
1572
  return;
1591
1573
  }
1592
- if (path6.node.expression.type === "AssignmentExpression") {
1593
- const left = path6.node.expression.left;
1574
+ if (path9.node.expression.type === "AssignmentExpression") {
1575
+ const left = path9.node.expression.left;
1594
1576
  if (left.type === "MemberExpression" && left.object.type === "Identifier" && (exportsToRemove.includes(left.object.name) || removedExportLocalNames.has(left.object.name))) {
1595
- markedForRemoval.add(path6);
1577
+ markedForRemoval.add(path9);
1596
1578
  }
1597
1579
  }
1598
1580
  }
1599
1581
  });
1600
1582
  if (markedForRemoval.size > 0 || exportsFiltered) {
1601
- for (let path6 of markedForRemoval) {
1602
- path6.remove();
1583
+ for (let path9 of markedForRemoval) {
1584
+ path9.remove();
1603
1585
  }
1604
1586
  (0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
1605
1587
  }
@@ -1644,6 +1626,18 @@ function invalidDestructureError(name) {
1644
1626
  return new Error(`Cannot remove destructured export "${name}"`);
1645
1627
  }
1646
1628
 
1629
+ // vite/has-dependency.ts
1630
+ function hasDependency({
1631
+ name,
1632
+ rootDirectory
1633
+ }) {
1634
+ try {
1635
+ return Boolean(require.resolve(name, { paths: [rootDirectory] }));
1636
+ } catch (err2) {
1637
+ return false;
1638
+ }
1639
+ }
1640
+
1647
1641
  // vite/cache.ts
1648
1642
  function getOrSetFromCache(cache, key, version, getValue) {
1649
1643
  if (!cache) {
@@ -1670,28 +1664,28 @@ function codeToAst(code, cache, cacheKey) {
1670
1664
  )
1671
1665
  );
1672
1666
  }
1673
- function assertNodePath(path6) {
1667
+ function assertNodePath(path9) {
1674
1668
  invariant(
1675
- path6 && !Array.isArray(path6),
1676
- `Expected a Path, but got ${Array.isArray(path6) ? "an array" : path6}`
1669
+ path9 && !Array.isArray(path9),
1670
+ `Expected a Path, but got ${Array.isArray(path9) ? "an array" : path9}`
1677
1671
  );
1678
1672
  }
1679
- function assertNodePathIsStatement(path6) {
1673
+ function assertNodePathIsStatement(path9) {
1680
1674
  invariant(
1681
- path6 && !Array.isArray(path6) && t.isStatement(path6.node),
1682
- `Expected a Statement path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1675
+ path9 && !Array.isArray(path9) && t.isStatement(path9.node),
1676
+ `Expected a Statement path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
1683
1677
  );
1684
1678
  }
1685
- function assertNodePathIsVariableDeclarator(path6) {
1679
+ function assertNodePathIsVariableDeclarator(path9) {
1686
1680
  invariant(
1687
- path6 && !Array.isArray(path6) && t.isVariableDeclarator(path6.node),
1688
- `Expected an Identifier path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1681
+ path9 && !Array.isArray(path9) && t.isVariableDeclarator(path9.node),
1682
+ `Expected an Identifier path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
1689
1683
  );
1690
1684
  }
1691
- function assertNodePathIsPattern(path6) {
1685
+ function assertNodePathIsPattern(path9) {
1692
1686
  invariant(
1693
- path6 && !Array.isArray(path6) && t.isPattern(path6.node),
1694
- `Expected a Pattern path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1687
+ path9 && !Array.isArray(path9) && t.isPattern(path9.node),
1688
+ `Expected a Pattern path, but got ${Array.isArray(path9) ? "an array" : path9?.node?.type}`
1695
1689
  );
1696
1690
  }
1697
1691
  function getExportDependencies(code, cache, cacheKey) {
@@ -1727,8 +1721,8 @@ function getExportDependencies(code, cache, cacheKey) {
1727
1721
  }
1728
1722
  let isWithinExportDestructuring = Boolean(
1729
1723
  identifier.findParent(
1730
- (path6) => Boolean(
1731
- path6.isPattern() && path6.parentPath?.isVariableDeclarator() && path6.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1724
+ (path9) => Boolean(
1725
+ path9.isPattern() && path9.parentPath?.isVariableDeclarator() && path9.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1732
1726
  )
1733
1727
  )
1734
1728
  );
@@ -1806,7 +1800,7 @@ function getExportDependencies(code, cache, cacheKey) {
1806
1800
  for (let specifier of node.specifiers) {
1807
1801
  if (t.isIdentifier(specifier.exported)) {
1808
1802
  let name = specifier.exported.name;
1809
- let specifierPath = exportPath.get("specifiers").find((path6) => path6.node === specifier);
1803
+ let specifierPath = exportPath.get("specifiers").find((path9) => path9.node === specifier);
1810
1804
  invariant(
1811
1805
  specifierPath,
1812
1806
  `Expected to find specifier path for ${name}`
@@ -1823,22 +1817,22 @@ function getExportDependencies(code, cache, cacheKey) {
1823
1817
  }
1824
1818
  );
1825
1819
  }
1826
- function getDependentIdentifiersForPath(path6, state) {
1820
+ function getDependentIdentifiersForPath(path9, state) {
1827
1821
  let { visited, identifiers } = state ?? {
1828
1822
  visited: /* @__PURE__ */ new Set(),
1829
1823
  identifiers: /* @__PURE__ */ new Set()
1830
1824
  };
1831
- if (visited.has(path6)) {
1825
+ if (visited.has(path9)) {
1832
1826
  return identifiers;
1833
1827
  }
1834
- visited.add(path6);
1835
- path6.traverse({
1836
- Identifier(path7) {
1837
- if (identifiers.has(path7)) {
1828
+ visited.add(path9);
1829
+ path9.traverse({
1830
+ Identifier(path10) {
1831
+ if (identifiers.has(path10)) {
1838
1832
  return;
1839
1833
  }
1840
- identifiers.add(path7);
1841
- let binding = path7.scope.getBinding(path7.node.name);
1834
+ identifiers.add(path10);
1835
+ let binding = path10.scope.getBinding(path10.node.name);
1842
1836
  if (!binding) {
1843
1837
  return;
1844
1838
  }
@@ -1860,7 +1854,7 @@ function getDependentIdentifiersForPath(path6, state) {
1860
1854
  }
1861
1855
  }
1862
1856
  });
1863
- let topLevelStatement = getTopLevelStatementPathForPath(path6);
1857
+ let topLevelStatement = getTopLevelStatementPathForPath(path9);
1864
1858
  let withinImportStatement = topLevelStatement.isImportDeclaration();
1865
1859
  let withinExportStatement = topLevelStatement.isExportDeclaration();
1866
1860
  if (!withinImportStatement && !withinExportStatement) {
@@ -1869,9 +1863,9 @@ function getDependentIdentifiersForPath(path6, state) {
1869
1863
  identifiers
1870
1864
  });
1871
1865
  }
1872
- if (withinExportStatement && path6.isIdentifier() && (t.isPattern(path6.parentPath.node) || // [foo]
1873
- t.isPattern(path6.parentPath.parentPath?.node))) {
1874
- let variableDeclarator = path6.findParent((p) => p.isVariableDeclarator());
1866
+ if (withinExportStatement && path9.isIdentifier() && (t.isPattern(path9.parentPath.node) || // [foo]
1867
+ t.isPattern(path9.parentPath.parentPath?.node))) {
1868
+ let variableDeclarator = path9.findParent((p) => p.isVariableDeclarator());
1875
1869
  assertNodePath(variableDeclarator);
1876
1870
  getDependentIdentifiersForPath(variableDeclarator, {
1877
1871
  visited,
@@ -1880,16 +1874,16 @@ function getDependentIdentifiersForPath(path6, state) {
1880
1874
  }
1881
1875
  return identifiers;
1882
1876
  }
1883
- function getTopLevelStatementPathForPath(path6) {
1884
- let ancestry = path6.getAncestry();
1877
+ function getTopLevelStatementPathForPath(path9) {
1878
+ let ancestry = path9.getAncestry();
1885
1879
  let topLevelStatement = ancestry[ancestry.length - 2];
1886
1880
  assertNodePathIsStatement(topLevelStatement);
1887
1881
  return topLevelStatement;
1888
1882
  }
1889
1883
  function getTopLevelStatementsForPaths(paths) {
1890
1884
  let topLevelStatements = /* @__PURE__ */ new Set();
1891
- for (let path6 of paths) {
1892
- let topLevelStatement = getTopLevelStatementPathForPath(path6);
1885
+ for (let path9 of paths) {
1886
+ let topLevelStatement = getTopLevelStatementPathForPath(path9);
1893
1887
  topLevelStatements.add(topLevelStatement.node);
1894
1888
  }
1895
1889
  return topLevelStatements;
@@ -2210,7 +2204,7 @@ function detectRouteChunks(code, cache, cacheKey) {
2210
2204
  var routeChunkExportNames = [
2211
2205
  "clientAction",
2212
2206
  "clientLoader",
2213
- "unstable_clientMiddleware",
2207
+ "clientMiddleware",
2214
2208
  "HydrateFallback"
2215
2209
  ];
2216
2210
  var mainChunkName = "main";
@@ -2226,7 +2220,7 @@ var routeChunkQueryStrings = {
2226
2220
  main: `${routeChunkQueryStringPrefix}main`,
2227
2221
  clientAction: `${routeChunkQueryStringPrefix}clientAction`,
2228
2222
  clientLoader: `${routeChunkQueryStringPrefix}clientLoader`,
2229
- unstable_clientMiddleware: `${routeChunkQueryStringPrefix}unstable_clientMiddleware`,
2223
+ clientMiddleware: `${routeChunkQueryStringPrefix}clientMiddleware`,
2230
2224
  HydrateFallback: `${routeChunkQueryStringPrefix}HydrateFallback`
2231
2225
  };
2232
2226
  function getRouteChunkModuleId(filePath, chunkName) {
@@ -2251,6 +2245,31 @@ function getRouteChunkNameFromModuleId(id) {
2251
2245
  return chunkName;
2252
2246
  }
2253
2247
 
2248
+ // vite/optimize-deps-entries.ts
2249
+ var import_tinyglobby = require("tinyglobby");
2250
+ function getOptimizeDepsEntries({
2251
+ entryClientFilePath,
2252
+ reactRouterConfig
2253
+ }) {
2254
+ if (!reactRouterConfig.future.unstable_optimizeDeps) {
2255
+ return [];
2256
+ }
2257
+ const vite2 = getVite();
2258
+ const viteMajorVersion = parseInt(vite2.version.split(".")[0], 10);
2259
+ return [
2260
+ vite2.normalizePath(entryClientFilePath),
2261
+ ...Object.values(reactRouterConfig.routes).map(
2262
+ (route) => resolveRelativeRouteFilePath(route, reactRouterConfig)
2263
+ )
2264
+ ].map(
2265
+ (entry) => (
2266
+ // In Vite 7, the `optimizeDeps.entries` option only accepts glob patterns.
2267
+ // In prior versions, absolute file paths were treated differently.
2268
+ viteMajorVersion >= 7 ? (0, import_tinyglobby.escapePath)(entry) : entry
2269
+ )
2270
+ );
2271
+ }
2272
+
2254
2273
  // vite/with-props.ts
2255
2274
  var namedComponentExports = ["HydrateFallback", "ErrorBoundary"];
2256
2275
  function isNamedComponentExport(name) {
@@ -2258,24 +2277,24 @@ function isNamedComponentExport(name) {
2258
2277
  }
2259
2278
  var decorateComponentExportsWithProps = (ast) => {
2260
2279
  const hocs = [];
2261
- function getHocUid(path6, hocName) {
2262
- const uid = path6.scope.generateUidIdentifier(hocName);
2280
+ function getHocUid(path9, hocName) {
2281
+ const uid = path9.scope.generateUidIdentifier(hocName);
2263
2282
  hocs.push([hocName, uid]);
2264
2283
  return uid;
2265
2284
  }
2266
2285
  traverse(ast, {
2267
- ExportDeclaration(path6) {
2268
- if (path6.isExportDefaultDeclaration()) {
2269
- const declaration = path6.get("declaration");
2286
+ ExportDeclaration(path9) {
2287
+ if (path9.isExportDefaultDeclaration()) {
2288
+ const declaration = path9.get("declaration");
2270
2289
  const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
2271
2290
  if (expr) {
2272
- const uid = getHocUid(path6, "UNSAFE_withComponentProps");
2291
+ const uid = getHocUid(path9, "UNSAFE_withComponentProps");
2273
2292
  declaration.replaceWith(t.callExpression(uid, [expr]));
2274
2293
  }
2275
2294
  return;
2276
2295
  }
2277
- if (path6.isExportNamedDeclaration()) {
2278
- const decl = path6.get("declaration");
2296
+ if (path9.isExportNamedDeclaration()) {
2297
+ const decl = path9.get("declaration");
2279
2298
  if (decl.isVariableDeclaration()) {
2280
2299
  decl.get("declarations").forEach((varDeclarator) => {
2281
2300
  const id = varDeclarator.get("id");
@@ -2285,7 +2304,7 @@ var decorateComponentExportsWithProps = (ast) => {
2285
2304
  if (!id.isIdentifier()) return;
2286
2305
  const { name } = id.node;
2287
2306
  if (!isNamedComponentExport(name)) return;
2288
- const uid = getHocUid(path6, `UNSAFE_with${name}Props`);
2307
+ const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
2289
2308
  init.replaceWith(t.callExpression(uid, [expr]));
2290
2309
  });
2291
2310
  return;
@@ -2295,7 +2314,7 @@ var decorateComponentExportsWithProps = (ast) => {
2295
2314
  if (!id) return;
2296
2315
  const { name } = id;
2297
2316
  if (!isNamedComponentExport(name)) return;
2298
- const uid = getHocUid(path6, `UNSAFE_with${name}Props`);
2317
+ const uid = getHocUid(path9, `UNSAFE_with${name}Props`);
2299
2318
  decl.replaceWith(
2300
2319
  t.variableDeclaration("const", [
2301
2320
  t.variableDeclarator(
@@ -2329,6 +2348,26 @@ function toFunctionExpression(decl) {
2329
2348
  );
2330
2349
  }
2331
2350
 
2351
+ // vite/load-dotenv.ts
2352
+ async function loadDotenv({
2353
+ rootDirectory,
2354
+ viteUserConfig,
2355
+ mode
2356
+ }) {
2357
+ const vite2 = await import("vite");
2358
+ Object.assign(
2359
+ process.env,
2360
+ vite2.loadEnv(
2361
+ mode,
2362
+ viteUserConfig.envDir ?? rootDirectory,
2363
+ // We override the default prefix of "VITE_" with a blank string since
2364
+ // we're targeting the server, so we want to load all environment
2365
+ // variables, not just those explicitly marked for the client
2366
+ ""
2367
+ )
2368
+ );
2369
+ }
2370
+
2332
2371
  // vite/plugins/validate-plugin-order.ts
2333
2372
  function validatePluginOrder() {
2334
2373
  return {
@@ -2340,16 +2379,57 @@ function validatePluginOrder() {
2340
2379
  (plugin) => pluginName.includes(plugin.name)
2341
2380
  );
2342
2381
  };
2343
- let rollupPrePlugins = [
2344
- { pluginName: "@mdx-js/rollup", displayName: "@mdx-js/rollup" }
2345
- ];
2346
- for (let prePlugin of rollupPrePlugins) {
2347
- let prePluginIndex = pluginIndex(prePlugin.pluginName);
2348
- if (prePluginIndex >= 0 && prePluginIndex > pluginIndex(["react-router", "react-router/rsc"])) {
2349
- throw new Error(
2350
- `The "${prePlugin.displayName}" plugin should be placed before the React Router plugin in your Vite config file`
2351
- );
2352
- }
2382
+ let reactRouterRscPluginIndex = pluginIndex("react-router/rsc");
2383
+ let viteRscPluginIndex = pluginIndex("rsc");
2384
+ if (reactRouterRscPluginIndex >= 0 && viteRscPluginIndex >= 0 && reactRouterRscPluginIndex > viteRscPluginIndex) {
2385
+ throw new Error(
2386
+ `The "@vitejs/plugin-rsc" plugin should be placed after the React Router RSC plugin in your Vite config`
2387
+ );
2388
+ }
2389
+ let reactRouterPluginIndex = pluginIndex([
2390
+ "react-router",
2391
+ "react-router/rsc"
2392
+ ]);
2393
+ let mdxPluginIndex = pluginIndex("@mdx-js/rollup");
2394
+ if (mdxPluginIndex >= 0 && mdxPluginIndex > reactRouterPluginIndex) {
2395
+ throw new Error(
2396
+ `The "@mdx-js/rollup" plugin should be placed before the React Router plugin in your Vite config`
2397
+ );
2398
+ }
2399
+ }
2400
+ };
2401
+ }
2402
+
2403
+ // vite/plugins/warn-on-client-source-maps.ts
2404
+ var import_picocolors3 = __toESM(require("picocolors"));
2405
+ function warnOnClientSourceMaps() {
2406
+ let viteConfig;
2407
+ let viteCommand;
2408
+ let logged = false;
2409
+ return {
2410
+ name: "react-router:warn-on-client-source-maps",
2411
+ config(_, configEnv) {
2412
+ viteCommand = configEnv.command;
2413
+ },
2414
+ configResolved(config) {
2415
+ viteConfig = config;
2416
+ },
2417
+ buildStart() {
2418
+ invariant(viteConfig);
2419
+ if (!logged && viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && (viteConfig.build.sourcemap || viteConfig.environments?.client?.build.sourcemap)) {
2420
+ viteConfig.logger.warn(
2421
+ import_picocolors3.default.yellow(
2422
+ "\n" + import_picocolors3.default.bold(" \u26A0\uFE0F Source maps are enabled in production\n") + [
2423
+ "This makes your server code publicly",
2424
+ "visible in the browser. This is highly",
2425
+ "discouraged! If you insist, ensure that",
2426
+ "you are using environment variables for",
2427
+ "secrets and not hard-coding them in",
2428
+ "your source code."
2429
+ ].map((line) => " " + line).join("\n") + "\n"
2430
+ )
2431
+ );
2432
+ logged = true;
2353
2433
  }
2354
2434
  }
2355
2435
  };
@@ -2359,16 +2439,11 @@ function validatePluginOrder() {
2359
2439
  function extractPluginContext(viteConfig) {
2360
2440
  return viteConfig["__reactRouterPluginContext"];
2361
2441
  }
2362
- var SERVER_ONLY_ROUTE_EXPORTS = [
2363
- "loader",
2364
- "action",
2365
- "unstable_middleware",
2366
- "headers"
2367
- ];
2442
+ var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "middleware", "headers"];
2368
2443
  var CLIENT_NON_COMPONENT_EXPORTS = [
2369
2444
  "clientAction",
2370
2445
  "clientLoader",
2371
- "unstable_clientMiddleware",
2446
+ "clientMiddleware",
2372
2447
  "handle",
2373
2448
  "meta",
2374
2449
  "links",
@@ -2421,16 +2496,10 @@ var virtualHmrRuntime = create("hmr-runtime");
2421
2496
  var virtualInjectHmrRuntime = create("inject-hmr-runtime");
2422
2497
  var normalizeRelativeFilePath = (file, reactRouterConfig) => {
2423
2498
  let vite2 = getVite();
2424
- let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2425
- let relativePath = path5.relative(reactRouterConfig.appDirectory, fullPath);
2499
+ let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
2500
+ let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
2426
2501
  return vite2.normalizePath(relativePath).split("?")[0];
2427
2502
  };
2428
- var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
2429
- let vite2 = getVite();
2430
- let file = route.file;
2431
- let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2432
- return vite2.normalizePath(fullPath);
2433
- };
2434
2503
  var virtual = {
2435
2504
  serverBuild: create("server-build"),
2436
2505
  serverManifest: create("server-manifest"),
@@ -2451,7 +2520,7 @@ var getHash = (source, maxLength) => {
2451
2520
  var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
2452
2521
  let vite2 = getVite();
2453
2522
  let rootRelativeFilePath = vite2.normalizePath(
2454
- path5.relative(ctx.rootDirectory, absoluteFilePath)
2523
+ path6.relative(ctx.rootDirectory, absoluteFilePath)
2455
2524
  );
2456
2525
  let entryChunk = viteManifest[rootRelativeFilePath];
2457
2526
  if (!entryChunk) {
@@ -2540,7 +2609,7 @@ function dedupe(array2) {
2540
2609
  return [...new Set(array2)];
2541
2610
  }
2542
2611
  var writeFileSafe = async (file, contents) => {
2543
- await (0, import_promises2.mkdir)(path5.dirname(file), { recursive: true });
2612
+ await (0, import_promises2.mkdir)(path6.dirname(file), { recursive: true });
2544
2613
  await (0, import_promises2.writeFile)(file, contents);
2545
2614
  };
2546
2615
  var getExportNames = (code) => {
@@ -2566,7 +2635,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
2566
2635
  }
2567
2636
  let ssr = true;
2568
2637
  let { pluginContainer, moduleGraph } = viteChildCompiler;
2569
- let routePath = path5.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2638
+ let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2570
2639
  let url2 = resolveFileUrl(ctx, routePath);
2571
2640
  let resolveId = async () => {
2572
2641
  let result = await pluginContainer.resolveId(url2, void 0, { ssr });
@@ -2608,12 +2677,12 @@ var resolveEnvironmentBuildContext = ({
2608
2677
  };
2609
2678
  return resolvedBuildContext;
2610
2679
  };
2611
- var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path5.join(
2680
+ var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
2612
2681
  reactRouterConfig.buildDirectory,
2613
2682
  "server",
2614
2683
  ...serverBundleId ? [serverBundleId] : []
2615
2684
  );
2616
- var getClientBuildDirectory = (reactRouterConfig) => path5.join(reactRouterConfig.buildDirectory, "client");
2685
+ var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
2617
2686
  var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2618
2687
  if (!ctx.buildManifest) {
2619
2688
  return void 0;
@@ -2631,14 +2700,14 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2631
2700
  );
2632
2701
  return Object.keys(serverBundleRoutes);
2633
2702
  };
2634
- var defaultEntriesDir = path5.resolve(
2635
- path5.dirname(require.resolve("@react-router/dev/package.json")),
2703
+ var defaultEntriesDir = path6.resolve(
2704
+ path6.dirname(require.resolve("@react-router/dev/package.json")),
2636
2705
  "dist",
2637
2706
  "config",
2638
2707
  "defaults"
2639
2708
  );
2640
2709
  var defaultEntries = (0, import_node_fs2.readdirSync)(defaultEntriesDir).map(
2641
- (filename2) => path5.join(defaultEntriesDir, filename2)
2710
+ (filename2) => path6.join(defaultEntriesDir, filename2)
2642
2711
  );
2643
2712
  invariant(defaultEntries.length > 0, "No default entries found");
2644
2713
  var reactRouterDevLoadContext = () => void 0;
@@ -2676,7 +2745,7 @@ var reactRouterVitePlugin = () => {
2676
2745
  let publicPath = viteUserConfig.base ?? "/";
2677
2746
  if (reactRouterConfig.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !reactRouterConfig.basename.startsWith(publicPath)) {
2678
2747
  logger.error(
2679
- import_picocolors3.default.red(
2748
+ import_picocolors4.default.red(
2680
2749
  "When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
2681
2750
  )
2682
2751
  );
@@ -2734,7 +2803,7 @@ var reactRouterVitePlugin = () => {
2734
2803
  virtual.serverManifest.id
2735
2804
  )};
2736
2805
  export const assetsBuildDirectory = ${JSON.stringify(
2737
- path5.relative(
2806
+ path6.relative(
2738
2807
  ctx.rootDirectory,
2739
2808
  getClientBuildDirectory(ctx.reactRouterConfig)
2740
2809
  )
@@ -2773,18 +2842,11 @@ var reactRouterVitePlugin = () => {
2773
2842
  };
2774
2843
  let loadViteManifest = async (directory) => {
2775
2844
  let manifestContents = await (0, import_promises2.readFile)(
2776
- path5.resolve(directory, ".vite", "manifest.json"),
2845
+ path6.resolve(directory, ".vite", "manifest.json"),
2777
2846
  "utf-8"
2778
2847
  );
2779
2848
  return JSON.parse(manifestContents);
2780
2849
  };
2781
- let hasDependency = (name) => {
2782
- try {
2783
- return Boolean(require.resolve(name, { paths: [ctx.rootDirectory] }));
2784
- } catch (err2) {
2785
- return false;
2786
- }
2787
- };
2788
2850
  let getViteManifestAssetPaths = (viteManifest) => {
2789
2851
  let cssUrlPaths = Object.values(viteManifest).filter((chunk) => chunk.file.endsWith(".css")).map((chunk) => chunk.file);
2790
2852
  let chunkAssetPaths = Object.values(viteManifest).flatMap(
@@ -2805,7 +2867,7 @@ var reactRouterVitePlugin = () => {
2805
2867
  let contents;
2806
2868
  try {
2807
2869
  contents = await (0, import_promises2.readFile)(
2808
- path5.join(entryNormalizedPath, entry.name),
2870
+ path6.join(entryNormalizedPath, entry.name),
2809
2871
  "utf-8"
2810
2872
  );
2811
2873
  } catch (e) {
@@ -2814,9 +2876,9 @@ var reactRouterVitePlugin = () => {
2814
2876
  }
2815
2877
  let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
2816
2878
  let filepath = getVite().normalizePath(
2817
- path5.relative(
2879
+ path6.relative(
2818
2880
  clientBuildDirectory,
2819
- path5.join(entryNormalizedPath, entry.name)
2881
+ path6.join(entryNormalizedPath, entry.name)
2820
2882
  )
2821
2883
  );
2822
2884
  sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
@@ -2847,13 +2909,11 @@ var reactRouterVitePlugin = () => {
2847
2909
  );
2848
2910
  let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
2849
2911
  for (let route of Object.values(ctx.reactRouterConfig.routes)) {
2850
- let routeFile = path5.join(ctx.reactRouterConfig.appDirectory, route.file);
2912
+ let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
2851
2913
  let sourceExports = routeManifestExports[route.id];
2852
2914
  let hasClientAction = sourceExports.includes("clientAction");
2853
2915
  let hasClientLoader = sourceExports.includes("clientLoader");
2854
- let hasClientMiddleware = sourceExports.includes(
2855
- "unstable_clientMiddleware"
2856
- );
2916
+ let hasClientMiddleware = sourceExports.includes("clientMiddleware");
2857
2917
  let hasHydrateFallback = sourceExports.includes("HydrateFallback");
2858
2918
  let { hasRouteChunkByExportName } = await detectRouteChunksIfEnabled(
2859
2919
  cache,
@@ -2868,7 +2928,7 @@ var reactRouterVitePlugin = () => {
2868
2928
  valid: {
2869
2929
  clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
2870
2930
  clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
2871
- unstable_clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.unstable_clientMiddleware,
2931
+ clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.clientMiddleware,
2872
2932
  HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
2873
2933
  }
2874
2934
  });
@@ -2902,10 +2962,10 @@ var reactRouterVitePlugin = () => {
2902
2962
  viteManifest,
2903
2963
  getRouteChunkModuleId(routeFile, "clientLoader")
2904
2964
  ) : void 0,
2905
- clientMiddlewareModule: hasRouteChunkByExportName.unstable_clientMiddleware ? getPublicModulePathForEntry(
2965
+ clientMiddlewareModule: hasRouteChunkByExportName.clientMiddleware ? getPublicModulePathForEntry(
2906
2966
  ctx,
2907
2967
  viteManifest,
2908
- getRouteChunkModuleId(routeFile, "unstable_clientMiddleware")
2968
+ getRouteChunkModuleId(routeFile, "clientMiddleware")
2909
2969
  ) : void 0,
2910
2970
  hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? getPublicModulePathForEntry(
2911
2971
  ctx,
@@ -2920,7 +2980,7 @@ var reactRouterVitePlugin = () => {
2920
2980
  }
2921
2981
  let fingerprintedValues = { entry, routes: browserRoutes };
2922
2982
  let version = getHash(JSON.stringify(fingerprintedValues), 8);
2923
- let manifestPath = path5.posix.join(
2983
+ let manifestPath = path6.posix.join(
2924
2984
  viteConfig2.build.assetsDir,
2925
2985
  `manifest-${version}.js`
2926
2986
  );
@@ -2932,7 +2992,7 @@ var reactRouterVitePlugin = () => {
2932
2992
  sri: void 0
2933
2993
  };
2934
2994
  await writeFileSafe(
2935
- path5.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2995
+ path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2936
2996
  `window.__reactRouterManifest=${JSON.stringify(
2937
2997
  reactRouterBrowserManifest
2938
2998
  )};`
@@ -2964,9 +3024,7 @@ var reactRouterVitePlugin = () => {
2964
3024
  let sourceExports = routeManifestExports[key];
2965
3025
  let hasClientAction = sourceExports.includes("clientAction");
2966
3026
  let hasClientLoader = sourceExports.includes("clientLoader");
2967
- let hasClientMiddleware = sourceExports.includes(
2968
- "unstable_clientMiddleware"
2969
- );
3027
+ let hasClientMiddleware = sourceExports.includes("clientMiddleware");
2970
3028
  let hasHydrateFallback = sourceExports.includes("HydrateFallback");
2971
3029
  let routeModulePath = combineURLs(
2972
3030
  ctx.publicPath,
@@ -2988,7 +3046,7 @@ var reactRouterVitePlugin = () => {
2988
3046
  valid: {
2989
3047
  clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
2990
3048
  clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
2991
- unstable_clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.unstable_clientMiddleware,
3049
+ clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.clientMiddleware,
2992
3050
  HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
2993
3051
  }
2994
3052
  });
@@ -3060,7 +3118,6 @@ var reactRouterVitePlugin = () => {
3060
3118
  config: async (_viteUserConfig, _viteConfigEnv) => {
3061
3119
  await preloadVite();
3062
3120
  let vite2 = getVite();
3063
- let viteMajorVersion = parseInt(vite2.version.split(".")[0], 10);
3064
3121
  viteUserConfig = _viteUserConfig;
3065
3122
  viteConfigEnv = _viteConfigEnv;
3066
3123
  viteCommand = viteConfigEnv.command;
@@ -3075,6 +3132,7 @@ var reactRouterVitePlugin = () => {
3075
3132
  if (viteCommand === "serve") {
3076
3133
  typegenWatcherPromise = watch(rootDirectory, {
3077
3134
  mode,
3135
+ rsc: false,
3078
3136
  // ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
3079
3137
  logger: vite2.createLogger("warn", { prefix: "[react-router]" })
3080
3138
  });
@@ -3085,17 +3143,11 @@ var reactRouterVitePlugin = () => {
3085
3143
  watch: viteCommand === "serve"
3086
3144
  });
3087
3145
  await updatePluginContext();
3088
- Object.assign(
3089
- process.env,
3090
- vite2.loadEnv(
3091
- viteConfigEnv.mode,
3092
- viteUserConfig.envDir ?? ctx.rootDirectory,
3093
- // We override the default prefix of "VITE_" with a blank string since
3094
- // we're targeting the server, so we want to load all environment
3095
- // variables, not just those explicitly marked for the client
3096
- ""
3097
- )
3098
- );
3146
+ await loadDotenv({
3147
+ rootDirectory,
3148
+ viteUserConfig,
3149
+ mode
3150
+ });
3099
3151
  let environments = await getEnvironmentsOptions(ctx, viteCommand, {
3100
3152
  viteUserConfig
3101
3153
  });
@@ -3114,18 +3166,10 @@ var reactRouterVitePlugin = () => {
3114
3166
  resolve: serverEnvironment.resolve
3115
3167
  },
3116
3168
  optimizeDeps: {
3117
- entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
3118
- vite2.normalizePath(ctx.entryClientFilePath),
3119
- ...Object.values(ctx.reactRouterConfig.routes).map(
3120
- (route) => resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
3121
- )
3122
- ].map(
3123
- (entry) => (
3124
- // In Vite 7, the `optimizeDeps.entries` option only accepts glob patterns.
3125
- // In prior versions, absolute file paths were treated differently.
3126
- viteMajorVersion >= 7 ? (0, import_tinyglobby.escapePath)(entry) : entry
3127
- )
3128
- ) : [],
3169
+ entries: getOptimizeDepsEntries({
3170
+ entryClientFilePath: ctx.entryClientFilePath,
3171
+ reactRouterConfig: ctx.reactRouterConfig
3172
+ }),
3129
3173
  include: [
3130
3174
  // Pre-bundle React dependencies to avoid React duplicates,
3131
3175
  // even if React dependencies are not direct dependencies.
@@ -3140,7 +3184,10 @@ var reactRouterVitePlugin = () => {
3140
3184
  "react-router",
3141
3185
  "react-router/dom",
3142
3186
  // Check to avoid "Failed to resolve dependency: react-router-dom, present in 'optimizeDeps.include'"
3143
- ...hasDependency("react-router-dom") ? ["react-router-dom"] : []
3187
+ ...hasDependency({
3188
+ name: "react-router-dom",
3189
+ rootDirectory: ctx.rootDirectory
3190
+ }) ? ["react-router-dom"] : []
3144
3191
  ]
3145
3192
  },
3146
3193
  esbuild: {
@@ -3292,23 +3339,6 @@ var reactRouterVitePlugin = () => {
3292
3339
  cssModulesManifest[id] = code;
3293
3340
  }
3294
3341
  },
3295
- buildStart() {
3296
- invariant(viteConfig);
3297
- if (viteCommand === "build" && viteConfig.mode === "production" && !viteConfig.build.ssr && viteConfig.build.sourcemap) {
3298
- viteConfig.logger.warn(
3299
- import_picocolors3.default.yellow(
3300
- "\n" + import_picocolors3.default.bold(" \u26A0\uFE0F Source maps are enabled in production\n") + [
3301
- "This makes your server code publicly",
3302
- "visible in the browser. This is highly",
3303
- "discouraged! If you insist, ensure that",
3304
- "you are using environment variables for",
3305
- "secrets and not hard-coding them in",
3306
- "your source code."
3307
- ].map((line) => " " + line).join("\n") + "\n"
3308
- )
3309
- );
3310
- }
3311
- },
3312
3342
  async configureServer(viteDevServer) {
3313
3343
  (0, import_react_router2.unstable_setDevServerHooks)({
3314
3344
  // Give the request handler access to the critical CSS in dev to avoid a
@@ -3348,7 +3378,7 @@ var reactRouterVitePlugin = () => {
3348
3378
  return;
3349
3379
  }
3350
3380
  let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
3351
- logger.info(import_picocolors3.default.green(message), {
3381
+ logger.info(import_picocolors4.default.green(message), {
3352
3382
  clear: true,
3353
3383
  timestamp: true
3354
3384
  });
@@ -3408,7 +3438,7 @@ var reactRouterVitePlugin = () => {
3408
3438
  req2,
3409
3439
  await reactRouterDevLoadContext(req2)
3410
3440
  );
3411
- await toNodeRequest(res2, nodeRes);
3441
+ await (0, import_node_fetch_server2.sendResponse)(nodeRes, res2);
3412
3442
  };
3413
3443
  await nodeHandler(req, res);
3414
3444
  } catch (error) {
@@ -3438,11 +3468,11 @@ var reactRouterVitePlugin = () => {
3438
3468
  let removedAssetPaths = [];
3439
3469
  let copiedAssetPaths = [];
3440
3470
  for (let ssrAssetPath of ssrAssetPaths) {
3441
- let src = path5.join(serverBuildDirectory, ssrAssetPath);
3442
- let dest = path5.join(clientBuildDirectory, ssrAssetPath);
3471
+ let src = path6.join(serverBuildDirectory, ssrAssetPath);
3472
+ let dest = path6.join(clientBuildDirectory, ssrAssetPath);
3443
3473
  if (!userSsrEmitAssets) {
3444
3474
  if (!(0, import_node_fs2.existsSync)(dest)) {
3445
- await (0, import_promises2.mkdir)(path5.dirname(dest), { recursive: true });
3475
+ await (0, import_promises2.mkdir)(path6.dirname(dest), { recursive: true });
3446
3476
  await (0, import_promises2.rename)(src, dest);
3447
3477
  movedAssetPaths.push(dest);
3448
3478
  } else {
@@ -3460,7 +3490,7 @@ var reactRouterVitePlugin = () => {
3460
3490
  );
3461
3491
  await Promise.all(
3462
3492
  ssrCssPaths.map(async (cssPath) => {
3463
- let src = path5.join(serverBuildDirectory, cssPath);
3493
+ let src = path6.join(serverBuildDirectory, cssPath);
3464
3494
  await (0, import_promises2.rm)(src, { force: true, recursive: true });
3465
3495
  removedAssetPaths.push(src);
3466
3496
  })
@@ -3468,7 +3498,7 @@ var reactRouterVitePlugin = () => {
3468
3498
  }
3469
3499
  let cleanedAssetPaths = [...removedAssetPaths, ...movedAssetPaths];
3470
3500
  let handledAssetPaths = [...cleanedAssetPaths, ...copiedAssetPaths];
3471
- let cleanedAssetDirs = new Set(cleanedAssetPaths.map(path5.dirname));
3501
+ let cleanedAssetDirs = new Set(cleanedAssetPaths.map(path6.dirname));
3472
3502
  await Promise.all(
3473
3503
  Array.from(cleanedAssetDirs).map(async (dir) => {
3474
3504
  try {
@@ -3488,9 +3518,9 @@ var reactRouterVitePlugin = () => {
3488
3518
  if (paths.length) {
3489
3519
  viteConfig.logger.info(
3490
3520
  [
3491
- `${import_picocolors3.default.green("\u2713")} ${message}`,
3521
+ `${import_picocolors4.default.green("\u2713")} ${message}`,
3492
3522
  ...paths.map(
3493
- (assetPath) => import_picocolors3.default.dim(path5.relative(ctx.rootDirectory, assetPath))
3523
+ (assetPath) => import_picocolors4.default.dim(path6.relative(ctx.rootDirectory, assetPath))
3494
3524
  )
3495
3525
  ].join("\n")
3496
3526
  );
@@ -3534,7 +3564,7 @@ var reactRouterVitePlugin = () => {
3534
3564
  viteConfig.logger.info(
3535
3565
  [
3536
3566
  "Removing the server build in",
3537
- import_picocolors3.default.green(serverBuildDirectory),
3567
+ import_picocolors4.default.green(serverBuildDirectory),
3538
3568
  "due to ssr:false"
3539
3569
  ].join(" ")
3540
3570
  );
@@ -3584,7 +3614,7 @@ var reactRouterVitePlugin = () => {
3584
3614
  );
3585
3615
  let isMainChunkExport = (name) => !chunkedExports.includes(name);
3586
3616
  let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
3587
- let chunkBasePath = `./${path5.basename(id)}`;
3617
+ let chunkBasePath = `./${path6.basename(id)}`;
3588
3618
  return [
3589
3619
  `export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
3590
3620
  chunkBasePath,
@@ -3604,7 +3634,7 @@ var reactRouterVitePlugin = () => {
3604
3634
  async transform(code, id, options) {
3605
3635
  if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
3606
3636
  let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
3607
- let routeFileName = path5.basename(routeModuleId);
3637
+ let routeFileName = path6.basename(routeModuleId);
3608
3638
  let sourceExports = await getRouteModuleExports(
3609
3639
  viteChildCompiler,
3610
3640
  ctx,
@@ -3656,9 +3686,7 @@ var reactRouterVitePlugin = () => {
3656
3686
  valid: {
3657
3687
  clientAction: !exportNames.includes("clientAction"),
3658
3688
  clientLoader: !exportNames.includes("clientLoader"),
3659
- unstable_clientMiddleware: !exportNames.includes(
3660
- "unstable_clientMiddleware"
3661
- ),
3689
+ clientMiddleware: !exportNames.includes("clientMiddleware"),
3662
3690
  HydrateFallback: !exportNames.includes("HydrateFallback")
3663
3691
  }
3664
3692
  });
@@ -3733,7 +3761,7 @@ var reactRouterVitePlugin = () => {
3733
3761
  }
3734
3762
  let vite2 = getVite();
3735
3763
  let importerShort = vite2.normalizePath(
3736
- path5.relative(ctx.rootDirectory, importer)
3764
+ path6.relative(ctx.rootDirectory, importer)
3737
3765
  );
3738
3766
  if (isRoute(ctx.reactRouterConfig, importer)) {
3739
3767
  let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
@@ -3741,7 +3769,7 @@ var reactRouterVitePlugin = () => {
3741
3769
  ).join(", ");
3742
3770
  throw Error(
3743
3771
  [
3744
- import_picocolors3.default.red(`Server-only module referenced by client`),
3772
+ import_picocolors4.default.red(`Server-only module referenced by client`),
3745
3773
  "",
3746
3774
  ` '${id}' imported by route '${importerShort}'`,
3747
3775
  "",
@@ -3750,18 +3778,18 @@ var reactRouterVitePlugin = () => {
3750
3778
  "",
3751
3779
  ` But other route exports in '${importerShort}' depend on '${id}'.`,
3752
3780
  "",
3753
- " See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
3781
+ " See https://reactrouter.com/explanation/code-splitting#removal-of-server-code",
3754
3782
  ""
3755
3783
  ].join("\n")
3756
3784
  );
3757
3785
  }
3758
3786
  throw Error(
3759
3787
  [
3760
- import_picocolors3.default.red(`Server-only module referenced by client`),
3788
+ import_picocolors4.default.red(`Server-only module referenced by client`),
3761
3789
  "",
3762
3790
  ` '${id}' imported by '${importerShort}'`,
3763
3791
  "",
3764
- " See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
3792
+ " See https://reactrouter.com/explanation/code-splitting#removal-of-server-code",
3765
3793
  ""
3766
3794
  ].join("\n")
3767
3795
  );
@@ -3855,10 +3883,10 @@ var reactRouterVitePlugin = () => {
3855
3883
  },
3856
3884
  async load(id) {
3857
3885
  if (id !== virtualHmrRuntime.resolvedId) return;
3858
- let reactRefreshDir = path5.dirname(
3886
+ let reactRefreshDir = path6.dirname(
3859
3887
  require.resolve("react-refresh/package.json")
3860
3888
  );
3861
- let reactRefreshRuntimePath = path5.join(
3889
+ let reactRefreshRuntimePath = path6.join(
3862
3890
  reactRefreshDir,
3863
3891
  "cjs/react-refresh-runtime.development.js"
3864
3892
  );
@@ -3967,7 +3995,8 @@ var reactRouterVitePlugin = () => {
3967
3995
  }
3968
3996
  }
3969
3997
  },
3970
- validatePluginOrder()
3998
+ validatePluginOrder(),
3999
+ warnOnClientSourceMaps()
3971
4000
  ];
3972
4001
  };
3973
4002
  function getParentClientNodes(clientModuleGraph, module2) {
@@ -4037,7 +4066,7 @@ if (import.meta.hot && !inWebWorker) {
4037
4066
  function getRoute(pluginConfig, file) {
4038
4067
  let vite2 = getVite();
4039
4068
  let routePath = vite2.normalizePath(
4040
- path5.relative(pluginConfig.appDirectory, file)
4069
+ path6.relative(pluginConfig.appDirectory, file)
4041
4070
  );
4042
4071
  let route = Object.values(pluginConfig.routes).find(
4043
4072
  (r) => vite2.normalizePath(r.file) === routePath
@@ -4076,7 +4105,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
4076
4105
  caseSensitive: route.caseSensitive,
4077
4106
  url: combineURLs(
4078
4107
  ctx.publicPath,
4079
- "/" + path5.relative(
4108
+ "/" + path6.relative(
4080
4109
  ctx.rootDirectory,
4081
4110
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
4082
4111
  )
@@ -4085,13 +4114,13 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
4085
4114
  // Ensure the Vite dev server responds with a JS module
4086
4115
  clientActionModule: hasRouteChunkByExportName.clientAction ? `${getRouteChunkModuleId(moduleUrl, "clientAction")}` : void 0,
4087
4116
  clientLoaderModule: hasRouteChunkByExportName.clientLoader ? `${getRouteChunkModuleId(moduleUrl, "clientLoader")}` : void 0,
4088
- clientMiddlewareModule: hasRouteChunkByExportName.unstable_clientMiddleware ? `${getRouteChunkModuleId(moduleUrl, "unstable_clientMiddleware")}` : void 0,
4117
+ clientMiddlewareModule: hasRouteChunkByExportName.clientMiddleware ? `${getRouteChunkModuleId(moduleUrl, "clientMiddleware")}` : void 0,
4089
4118
  hydrateFallbackModule: hasRouteChunkByExportName.HydrateFallback ? `${getRouteChunkModuleId(moduleUrl, "HydrateFallback")}` : void 0,
4090
4119
  hasAction: sourceExports.includes("action"),
4091
4120
  hasClientAction: sourceExports.includes("clientAction"),
4092
4121
  hasLoader: sourceExports.includes("loader"),
4093
4122
  hasClientLoader: sourceExports.includes("clientLoader"),
4094
- hasClientMiddleware: sourceExports.includes("unstable_clientMiddleware"),
4123
+ hasClientMiddleware: sourceExports.includes("clientMiddleware"),
4095
4124
  hasErrorBoundary: sourceExports.includes("ErrorBoundary"),
4096
4125
  imports: []
4097
4126
  };
@@ -4104,7 +4133,7 @@ function isSpaModeEnabled(reactRouterConfig) {
4104
4133
  return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
4105
4134
  }
4106
4135
  async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
4107
- let serverBuildPath = path5.join(serverBuildDirectory, serverBuildFile);
4136
+ let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
4108
4137
  let build = await import(url.pathToFileURL(serverBuildPath).toString());
4109
4138
  let { createRequestHandler: createHandler } = await import("react-router");
4110
4139
  return {
@@ -4146,15 +4175,15 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
4146
4175
  "SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
4147
4176
  );
4148
4177
  }
4149
- await (0, import_promises2.writeFile)(path5.join(clientBuildDirectory, filename2), html);
4150
- let prettyDir = path5.relative(viteConfig.root, clientBuildDirectory);
4151
- let prettyPath = path5.join(prettyDir, filename2);
4178
+ await (0, import_promises2.writeFile)(path6.join(clientBuildDirectory, filename2), html);
4179
+ let prettyDir = path6.relative(viteConfig.root, clientBuildDirectory);
4180
+ let prettyPath = path6.join(prettyDir, filename2);
4152
4181
  if (build.prerender.length > 0) {
4153
4182
  viteConfig.logger.info(
4154
- `Prerender (html): SPA Fallback -> ${import_picocolors3.default.bold(prettyPath)}`
4183
+ `Prerender (html): SPA Fallback -> ${import_picocolors4.default.bold(prettyPath)}`
4155
4184
  );
4156
4185
  } else {
4157
- viteConfig.logger.info(`SPA Mode: Generated ${import_picocolors3.default.bold(prettyPath)}`);
4186
+ viteConfig.logger.info(`SPA Mode: Generated ${import_picocolors4.default.bold(prettyPath)}`);
4158
4187
  }
4159
4188
  }
4160
4189
  async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, serverBuildPath, clientBuildDirectory) {
@@ -4164,17 +4193,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4164
4193
  serverBuildPath
4165
4194
  );
4166
4195
  let routes = createPrerenderRoutes(reactRouterConfig.routes);
4167
- for (let path6 of build.prerender) {
4168
- let matches = (0, import_react_router2.matchRoutes)(routes, `/${path6}/`.replace(/^\/\/+/, "/"));
4196
+ for (let path9 of build.prerender) {
4197
+ let matches = (0, import_react_router2.matchRoutes)(routes, `/${path9}/`.replace(/^\/\/+/, "/"));
4169
4198
  if (!matches) {
4170
4199
  throw new Error(
4171
- `Unable to prerender path because it does not match any routes: ${path6}`
4200
+ `Unable to prerender path because it does not match any routes: ${path9}`
4172
4201
  );
4173
4202
  }
4174
4203
  }
4175
4204
  let buildRoutes = createPrerenderRoutes(build.routes);
4176
- for (let path6 of build.prerender) {
4177
- let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path6}/`.replace(/^\/\/+/, "/"));
4205
+ for (let path9 of build.prerender) {
4206
+ let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path9}/`.replace(/^\/\/+/, "/"));
4178
4207
  if (!matches) {
4179
4208
  continue;
4180
4209
  }
@@ -4187,7 +4216,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4187
4216
  if (manifestRoute.loader) {
4188
4217
  await prerenderData(
4189
4218
  handler,
4190
- path6,
4219
+ path9,
4191
4220
  [leafRoute.id],
4192
4221
  clientBuildDirectory,
4193
4222
  reactRouterConfig,
@@ -4195,7 +4224,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4195
4224
  );
4196
4225
  await prerenderResourceRoute(
4197
4226
  handler,
4198
- path6,
4227
+ path9,
4199
4228
  clientBuildDirectory,
4200
4229
  reactRouterConfig,
4201
4230
  viteConfig
@@ -4213,7 +4242,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4213
4242
  if (!isResourceRoute && hasLoaders) {
4214
4243
  data = await prerenderData(
4215
4244
  handler,
4216
- path6,
4245
+ path9,
4217
4246
  null,
4218
4247
  clientBuildDirectory,
4219
4248
  reactRouterConfig,
@@ -4222,7 +4251,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
4222
4251
  }
4223
4252
  await prerenderRoute(
4224
4253
  handler,
4225
- path6,
4254
+ path9,
4226
4255
  clientBuildDirectory,
4227
4256
  reactRouterConfig,
4228
4257
  viteConfig,
@@ -4275,12 +4304,12 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
4275
4304
  ${normalizedPath}`
4276
4305
  );
4277
4306
  }
4278
- let outfile = path5.join(clientBuildDirectory, ...normalizedPath.split("/"));
4279
- await (0, import_promises2.mkdir)(path5.dirname(outfile), { recursive: true });
4307
+ let outfile = path6.join(clientBuildDirectory, ...normalizedPath.split("/"));
4308
+ await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
4280
4309
  await (0, import_promises2.writeFile)(outfile, data);
4281
4310
  viteConfig.logger.info(
4282
- `Prerender (data): ${prerenderPath} -> ${import_picocolors3.default.bold(
4283
- path5.relative(viteConfig.root, outfile)
4311
+ `Prerender (data): ${prerenderPath} -> ${import_picocolors4.default.bold(
4312
+ path6.relative(viteConfig.root, outfile)
4284
4313
  )}`
4285
4314
  );
4286
4315
  return data;
@@ -4315,16 +4344,16 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
4315
4344
  ${html}`
4316
4345
  );
4317
4346
  }
4318
- let outfile = path5.join(
4347
+ let outfile = path6.join(
4319
4348
  clientBuildDirectory,
4320
4349
  ...normalizedPath.split("/"),
4321
4350
  "index.html"
4322
4351
  );
4323
- await (0, import_promises2.mkdir)(path5.dirname(outfile), { recursive: true });
4352
+ await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
4324
4353
  await (0, import_promises2.writeFile)(outfile, html);
4325
4354
  viteConfig.logger.info(
4326
- `Prerender (html): ${prerenderPath} -> ${import_picocolors3.default.bold(
4327
- path5.relative(viteConfig.root, outfile)
4355
+ `Prerender (html): ${prerenderPath} -> ${import_picocolors4.default.bold(
4356
+ path6.relative(viteConfig.root, outfile)
4328
4357
  )}`
4329
4358
  );
4330
4359
  }
@@ -4339,12 +4368,12 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
4339
4368
  ${content.toString("utf8")}`
4340
4369
  );
4341
4370
  }
4342
- let outfile = path5.join(clientBuildDirectory, ...normalizedPath.split("/"));
4343
- await (0, import_promises2.mkdir)(path5.dirname(outfile), { recursive: true });
4371
+ let outfile = path6.join(clientBuildDirectory, ...normalizedPath.split("/"));
4372
+ await (0, import_promises2.mkdir)(path6.dirname(outfile), { recursive: true });
4344
4373
  await (0, import_promises2.writeFile)(outfile, content);
4345
4374
  viteConfig.logger.info(
4346
- `Prerender (resource): ${prerenderPath} -> ${import_picocolors3.default.bold(
4347
- path5.relative(viteConfig.root, outfile)
4375
+ `Prerender (resource): ${prerenderPath} -> ${import_picocolors4.default.bold(
4376
+ path6.relative(viteConfig.root, outfile)
4348
4377
  )}`
4349
4378
  );
4350
4379
  }
@@ -4356,7 +4385,7 @@ async function getPrerenderPaths(prerender, ssr, routes, logWarning = false) {
4356
4385
  let { paths, paramRoutes } = getStaticPrerenderPaths(prerenderRoutes);
4357
4386
  if (logWarning && !ssr && paramRoutes.length > 0) {
4358
4387
  console.warn(
4359
- import_picocolors3.default.yellow(
4388
+ import_picocolors4.default.yellow(
4360
4389
  [
4361
4390
  "\u26A0\uFE0F Paths with dynamic/splat params cannot be prerendered when using `prerender: true`. You may want to use the `prerender()` API to prerender the following paths:",
4362
4391
  ...paramRoutes.map((p) => " - " + p)
@@ -4418,14 +4447,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
4418
4447
  }
4419
4448
  let prerenderRoutes = createPrerenderRoutes(manifest.routes);
4420
4449
  let prerenderedRoutes = /* @__PURE__ */ new Set();
4421
- for (let path6 of prerenderPaths) {
4450
+ for (let path9 of prerenderPaths) {
4422
4451
  let matches = (0, import_react_router2.matchRoutes)(
4423
4452
  prerenderRoutes,
4424
- `/${path6}/`.replace(/^\/\/+/, "/")
4453
+ `/${path9}/`.replace(/^\/\/+/, "/")
4425
4454
  );
4426
4455
  invariant(
4427
4456
  matches,
4428
- `Unable to prerender path because it does not match any routes: ${path6}`
4457
+ `Unable to prerender path because it does not match any routes: ${path9}`
4429
4458
  );
4430
4459
  matches.forEach((m) => prerenderedRoutes.add(m.route.id));
4431
4460
  }
@@ -4463,7 +4492,7 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
4463
4492
  }
4464
4493
  }
4465
4494
  if (errors.length > 0) {
4466
- viteConfig.logger.error(import_picocolors3.default.red(errors.join("\n")));
4495
+ viteConfig.logger.error(import_picocolors4.default.red(errors.join("\n")));
4467
4496
  throw new Error(
4468
4497
  "Invalid route exports found when prerendering with `ssr:false`"
4469
4498
  );
@@ -4539,7 +4568,7 @@ async function detectRouteChunksIfEnabled(cache, ctx, id, input) {
4539
4568
  hasRouteChunkByExportName: {
4540
4569
  clientAction: false,
4541
4570
  clientLoader: false,
4542
- unstable_clientMiddleware: false,
4571
+ clientMiddleware: false,
4543
4572
  HydrateFallback: false
4544
4573
  }
4545
4574
  };
@@ -4592,8 +4621,8 @@ function validateRouteChunks({
4592
4621
  async function cleanBuildDirectory(viteConfig, ctx) {
4593
4622
  let buildDirectory = ctx.reactRouterConfig.buildDirectory;
4594
4623
  let isWithinRoot = () => {
4595
- let relativePath = path5.relative(ctx.rootDirectory, buildDirectory);
4596
- return !relativePath.startsWith("..") && !path5.isAbsolute(relativePath);
4624
+ let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
4625
+ return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
4597
4626
  };
4598
4627
  if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
4599
4628
  await (0, import_promises2.rm)(buildDirectory, { force: true, recursive: true });
@@ -4604,7 +4633,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4604
4633
  ([environmentName, options]) => {
4605
4634
  let outDir = options.build?.outDir;
4606
4635
  invariant(outDir, `Expected build.outDir for ${environmentName}`);
4607
- return path5.join(outDir, ".vite/manifest.json");
4636
+ return path6.join(outDir, ".vite/manifest.json");
4608
4637
  }
4609
4638
  );
4610
4639
  await Promise.all(
@@ -4614,7 +4643,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4614
4643
  if (!ctx.viteManifestEnabled) {
4615
4644
  await (0, import_promises2.rm)(viteManifestPath, { force: true, recursive: true });
4616
4645
  }
4617
- let viteDir = path5.dirname(viteManifestPath);
4646
+ let viteDir = path6.dirname(viteManifestPath);
4618
4647
  let viteDirFiles = await (0, import_promises2.readdir)(viteDir, { recursive: true });
4619
4648
  if (viteDirFiles.length === 0) {
4620
4649
  await (0, import_promises2.rm)(viteDir, { force: true, recursive: true });
@@ -4632,12 +4661,12 @@ async function getBuildManifest({
4632
4661
  }
4633
4662
  let { normalizePath } = await import("vite");
4634
4663
  let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
4635
- let resolvedAppDirectory = path5.resolve(rootDirectory, appDirectory);
4664
+ let resolvedAppDirectory = path6.resolve(rootDirectory, appDirectory);
4636
4665
  let rootRelativeRoutes = Object.fromEntries(
4637
4666
  Object.entries(routes).map(([id, route]) => {
4638
- let filePath = path5.join(resolvedAppDirectory, route.file);
4667
+ let filePath = path6.join(resolvedAppDirectory, route.file);
4639
4668
  let rootRelativeFilePath = normalizePath(
4640
- path5.relative(rootDirectory, filePath)
4669
+ path6.relative(rootDirectory, filePath)
4641
4670
  );
4642
4671
  return [id, { ...route, file: rootRelativeFilePath }];
4643
4672
  })
@@ -4655,7 +4684,7 @@ async function getBuildManifest({
4655
4684
  (route2) => configRouteToBranchRoute({
4656
4685
  ...route2,
4657
4686
  // Ensure absolute paths are passed to the serverBundles function
4658
- file: path5.join(resolvedAppDirectory, route2.file)
4687
+ file: path6.join(resolvedAppDirectory, route2.file)
4659
4688
  })
4660
4689
  )
4661
4690
  });
@@ -4679,10 +4708,10 @@ async function getBuildManifest({
4679
4708
  buildManifest.serverBundles[serverBundleId] ??= {
4680
4709
  id: serverBundleId,
4681
4710
  file: normalizePath(
4682
- path5.join(
4683
- path5.relative(
4711
+ path6.join(
4712
+ path6.relative(
4684
4713
  rootDirectory,
4685
- path5.join(serverBuildDirectory, serverBundleId)
4714
+ path6.join(serverBuildDirectory, serverBundleId)
4686
4715
  ),
4687
4716
  reactRouterConfig.serverBuildFile
4688
4717
  )
@@ -4701,10 +4730,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
4701
4730
  }
4702
4731
  async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4703
4732
  let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
4704
- let packageRoot = path5.dirname(
4733
+ let packageRoot = path6.dirname(
4705
4734
  require.resolve("@react-router/dev/package.json")
4706
4735
  );
4707
- let { moduleSyncEnabled } = await import(`file:///${path5.join(packageRoot, "module-sync-enabled/index.mjs")}`);
4736
+ let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
4708
4737
  let vite2 = getVite();
4709
4738
  function getBaseOptions({
4710
4739
  viteUserConfig
@@ -4783,7 +4812,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4783
4812
  ctx.entryClientFilePath,
4784
4813
  ...Object.values(ctx.reactRouterConfig.routes).flatMap(
4785
4814
  (route) => {
4786
- let routeFilePath = path5.resolve(
4815
+ let routeFilePath = path6.resolve(
4787
4816
  ctx.reactRouterConfig.appDirectory,
4788
4817
  route.file
4789
4818
  );
@@ -4807,7 +4836,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4807
4836
  ) : null;
4808
4837
  let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
4809
4838
  let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
4810
- return path5.posix.join(
4839
+ return path6.posix.join(
4811
4840
  assetsDir,
4812
4841
  `[name]${routeChunkSuffix}-[hash].js`
4813
4842
  );
@@ -4873,7 +4902,918 @@ async function asyncFlatten(arr) {
4873
4902
  } while (arr.some((v2) => v2?.then));
4874
4903
  return arr;
4875
4904
  }
4905
+
4906
+ // vite/rsc/plugin.ts
4907
+ var import_es_module_lexer3 = require("es-module-lexer");
4908
+ var Path5 = __toESM(require("pathe"));
4909
+ var babel2 = __toESM(require("@babel/core"));
4910
+ var import_picocolors5 = __toESM(require("picocolors"));
4911
+ var import_fs = require("fs");
4912
+ var import_promises3 = require("fs/promises");
4913
+ var import_pathe6 = __toESM(require("pathe"));
4914
+
4915
+ // vite/rsc/virtual-route-config.ts
4916
+ var import_pathe5 = __toESM(require("pathe"));
4917
+ function createVirtualRouteConfig({
4918
+ appDirectory,
4919
+ routeConfig
4920
+ }) {
4921
+ let routeIdByFile = /* @__PURE__ */ new Map();
4922
+ let code = "export default [";
4923
+ const closeRouteSymbol = Symbol("CLOSE_ROUTE");
4924
+ let stack = [
4925
+ ...routeConfig
4926
+ ];
4927
+ while (stack.length > 0) {
4928
+ const route = stack.pop();
4929
+ if (!route) break;
4930
+ if (route === closeRouteSymbol) {
4931
+ code += "]},";
4932
+ continue;
4933
+ }
4934
+ code += "{";
4935
+ const routeFile = import_pathe5.default.resolve(appDirectory, route.file);
4936
+ const routeId = route.id || createRouteId2(route.file, appDirectory);
4937
+ routeIdByFile.set(routeFile, routeId);
4938
+ code += `lazy: () => import(${JSON.stringify(
4939
+ `${routeFile}?route-module`
4940
+ )}),`;
4941
+ code += `id: ${JSON.stringify(routeId)},`;
4942
+ if (typeof route.path === "string") {
4943
+ code += `path: ${JSON.stringify(route.path)},`;
4944
+ }
4945
+ if (route.index) {
4946
+ code += `index: true,`;
4947
+ }
4948
+ if (route.caseSensitive) {
4949
+ code += `caseSensitive: true,`;
4950
+ }
4951
+ if (route.children) {
4952
+ code += ["children:["];
4953
+ stack.push(closeRouteSymbol);
4954
+ stack.push(...[...route.children].reverse());
4955
+ } else {
4956
+ code += "},";
4957
+ }
4958
+ }
4959
+ code += "];\n";
4960
+ return { code, routeIdByFile };
4961
+ }
4962
+ function createRouteId2(file, appDirectory) {
4963
+ return import_pathe5.default.relative(appDirectory, file).replace(/\\+/, "/").slice(0, -import_pathe5.default.extname(file).length);
4964
+ }
4965
+
4966
+ // vite/rsc/virtual-route-modules.ts
4967
+ var import_es_module_lexer2 = require("es-module-lexer");
4968
+ var SERVER_ONLY_COMPONENT_EXPORTS = ["ServerComponent"];
4969
+ var SERVER_ONLY_ROUTE_EXPORTS2 = [
4970
+ ...SERVER_ONLY_COMPONENT_EXPORTS,
4971
+ "loader",
4972
+ "action",
4973
+ "middleware",
4974
+ "headers"
4975
+ ];
4976
+ var SERVER_ONLY_ROUTE_EXPORTS_SET = new Set(SERVER_ONLY_ROUTE_EXPORTS2);
4977
+ function isServerOnlyRouteExport(name) {
4978
+ return SERVER_ONLY_ROUTE_EXPORTS_SET.has(name);
4979
+ }
4980
+ var COMMON_COMPONENT_EXPORTS = [
4981
+ "ErrorBoundary",
4982
+ "HydrateFallback",
4983
+ "Layout"
4984
+ ];
4985
+ var SERVER_FIRST_COMPONENT_EXPORTS = [
4986
+ ...COMMON_COMPONENT_EXPORTS,
4987
+ ...SERVER_ONLY_COMPONENT_EXPORTS
4988
+ ];
4989
+ var SERVER_FIRST_COMPONENT_EXPORTS_SET = new Set(
4990
+ SERVER_FIRST_COMPONENT_EXPORTS
4991
+ );
4992
+ function isServerFirstComponentExport(name) {
4993
+ return SERVER_FIRST_COMPONENT_EXPORTS_SET.has(
4994
+ name
4995
+ );
4996
+ }
4997
+ var CLIENT_COMPONENT_EXPORTS = [
4998
+ ...COMMON_COMPONENT_EXPORTS,
4999
+ "default"
5000
+ ];
5001
+ var CLIENT_NON_COMPONENT_EXPORTS2 = [
5002
+ "clientAction",
5003
+ "clientLoader",
5004
+ "clientMiddleware",
5005
+ "handle",
5006
+ "meta",
5007
+ "links",
5008
+ "shouldRevalidate"
5009
+ ];
5010
+ var CLIENT_NON_COMPONENT_EXPORTS_SET = new Set(CLIENT_NON_COMPONENT_EXPORTS2);
5011
+ function isClientNonComponentExport(name) {
5012
+ return CLIENT_NON_COMPONENT_EXPORTS_SET.has(name);
5013
+ }
5014
+ var CLIENT_ROUTE_EXPORTS2 = [
5015
+ ...CLIENT_NON_COMPONENT_EXPORTS2,
5016
+ ...CLIENT_COMPONENT_EXPORTS
5017
+ ];
5018
+ var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS2);
5019
+ function isClientRouteExport(name) {
5020
+ return CLIENT_ROUTE_EXPORTS_SET.has(name);
5021
+ }
5022
+ var ROUTE_EXPORTS = [
5023
+ ...SERVER_ONLY_ROUTE_EXPORTS2,
5024
+ ...CLIENT_ROUTE_EXPORTS2
5025
+ ];
5026
+ var ROUTE_EXPORTS_SET = new Set(ROUTE_EXPORTS);
5027
+ function isRouteExport(name) {
5028
+ return ROUTE_EXPORTS_SET.has(name);
5029
+ }
5030
+ function isCustomRouteExport(name) {
5031
+ return !isRouteExport(name);
5032
+ }
5033
+ function hasReactServerCondition(viteEnvironment) {
5034
+ return viteEnvironment.config.resolve.conditions.includes("react-server");
5035
+ }
5036
+ function transformVirtualRouteModules({
5037
+ id,
5038
+ code,
5039
+ viteCommand,
5040
+ routeIdByFile,
5041
+ rootRouteFile,
5042
+ viteEnvironment
5043
+ }) {
5044
+ if (isVirtualRouteModuleId(id) || routeIdByFile.has(id)) {
5045
+ return createVirtualRouteModuleCode({
5046
+ id,
5047
+ code,
5048
+ rootRouteFile,
5049
+ viteCommand,
5050
+ viteEnvironment
5051
+ });
5052
+ }
5053
+ if (isVirtualServerRouteModuleId(id)) {
5054
+ return createVirtualServerRouteModuleCode({
5055
+ id,
5056
+ code,
5057
+ viteEnvironment
5058
+ });
5059
+ }
5060
+ if (isVirtualClientRouteModuleId(id)) {
5061
+ return createVirtualClientRouteModuleCode({
5062
+ id,
5063
+ code,
5064
+ rootRouteFile,
5065
+ viteCommand
5066
+ });
5067
+ }
5068
+ }
5069
+ async function createVirtualRouteModuleCode({
5070
+ id,
5071
+ code: routeSource,
5072
+ rootRouteFile,
5073
+ viteCommand,
5074
+ viteEnvironment
5075
+ }) {
5076
+ const isReactServer = hasReactServerCondition(viteEnvironment);
5077
+ const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
5078
+ const clientModuleId = getVirtualClientModuleId(id);
5079
+ const serverModuleId = getVirtualServerModuleId(id);
5080
+ let code = "";
5081
+ if (isServerFirstRoute) {
5082
+ if (staticExports.some(isServerFirstComponentExport)) {
5083
+ code += `import React from "react";
5084
+ `;
5085
+ }
5086
+ for (const staticExport of staticExports) {
5087
+ if (isClientNonComponentExport(staticExport)) {
5088
+ code += `export { ${staticExport} } from "${clientModuleId}";
5089
+ `;
5090
+ } else if (isReactServer && isServerFirstComponentExport(staticExport) && // Layout wraps all other component exports so doesn't need CSS injected
5091
+ staticExport !== "Layout") {
5092
+ code += `import { ${staticExport} as ${staticExport}WithoutCss } from "${serverModuleId}";
5093
+ `;
5094
+ code += `export ${staticExport === "ServerComponent" ? "default " : " "}function ${staticExport}(props) {
5095
+ `;
5096
+ code += ` return React.createElement(React.Fragment, null,
5097
+ `;
5098
+ code += ` import.meta.viteRsc.loadCss(),
5099
+ `;
5100
+ code += ` React.createElement(${staticExport}WithoutCss, props),
5101
+ `;
5102
+ code += ` );
5103
+ `;
5104
+ code += `}
5105
+ `;
5106
+ } else if (isReactServer && isRouteExport(staticExport)) {
5107
+ code += `export { ${staticExport} } from "${serverModuleId}";
5108
+ `;
5109
+ } else if (isCustomRouteExport(staticExport)) {
5110
+ code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
5111
+ `;
5112
+ }
5113
+ }
5114
+ if (viteCommand === "serve" && !hasClientExports) {
5115
+ code += `export { __ensureClientRouteModuleForHMR } from "${clientModuleId}";
5116
+ `;
5117
+ }
5118
+ } else {
5119
+ for (const staticExport of staticExports) {
5120
+ if (isClientRouteExport(staticExport)) {
5121
+ code += `export { ${staticExport} } from "${clientModuleId}";
5122
+ `;
5123
+ } else if (isReactServer && isServerOnlyRouteExport(staticExport)) {
5124
+ code += `export { ${staticExport} } from "${serverModuleId}";
5125
+ `;
5126
+ } else if (isCustomRouteExport(staticExport)) {
5127
+ code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
5128
+ `;
5129
+ }
5130
+ }
5131
+ }
5132
+ if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
5133
+ code += `export { ErrorBoundary } from "${clientModuleId}";
5134
+ `;
5135
+ }
5136
+ return code;
5137
+ }
5138
+ function createVirtualServerRouteModuleCode({
5139
+ id,
5140
+ code: routeSource,
5141
+ viteEnvironment
5142
+ }) {
5143
+ if (!hasReactServerCondition(viteEnvironment)) {
5144
+ throw new Error(
5145
+ [
5146
+ "Virtual server route module was loaded outside of the RSC environment.",
5147
+ `Environment Name: ${viteEnvironment.name}`,
5148
+ `Module ID: ${id}`
5149
+ ].join("\n")
5150
+ );
5151
+ }
5152
+ const { staticExports, isServerFirstRoute } = parseRouteExports(routeSource);
5153
+ const clientModuleId = getVirtualClientModuleId(id);
5154
+ const serverRouteModuleAst = import_parser.parse(routeSource, {
5155
+ sourceType: "module"
5156
+ });
5157
+ removeExports(
5158
+ serverRouteModuleAst,
5159
+ isServerFirstRoute ? CLIENT_NON_COMPONENT_EXPORTS2 : CLIENT_ROUTE_EXPORTS2
5160
+ );
5161
+ const generatorResult = generate(serverRouteModuleAst);
5162
+ if (!isServerFirstRoute) {
5163
+ for (const staticExport of staticExports) {
5164
+ if (isClientRouteExport(staticExport)) {
5165
+ generatorResult.code += "\n";
5166
+ generatorResult.code += `export { ${staticExport} } from "${clientModuleId}";
5167
+ `;
5168
+ }
5169
+ }
5170
+ }
5171
+ return generatorResult;
5172
+ }
5173
+ function createVirtualClientRouteModuleCode({
5174
+ id,
5175
+ code: routeSource,
5176
+ rootRouteFile,
5177
+ viteCommand
5178
+ }) {
5179
+ const { staticExports, isServerFirstRoute, hasClientExports } = parseRouteExports(routeSource);
5180
+ const exportsToRemove = isServerFirstRoute ? [...SERVER_ONLY_ROUTE_EXPORTS2, ...CLIENT_COMPONENT_EXPORTS] : SERVER_ONLY_ROUTE_EXPORTS2;
5181
+ const clientRouteModuleAst = import_parser.parse(routeSource, {
5182
+ sourceType: "module"
5183
+ });
5184
+ removeExports(clientRouteModuleAst, exportsToRemove);
5185
+ const generatorResult = generate(clientRouteModuleAst);
5186
+ generatorResult.code = '"use client";' + generatorResult.code;
5187
+ if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
5188
+ const hasRootLayout = staticExports.includes("Layout");
5189
+ generatorResult.code += `
5190
+ import { createElement as __rr_createElement } from "react";
5191
+ `;
5192
+ generatorResult.code += `import { UNSAFE_RSCDefaultRootErrorBoundary } from "react-router";
5193
+ `;
5194
+ generatorResult.code += `export function ErrorBoundary() {
5195
+ `;
5196
+ generatorResult.code += ` return __rr_createElement(UNSAFE_RSCDefaultRootErrorBoundary, { hasRootLayout: ${hasRootLayout} });
5197
+ `;
5198
+ generatorResult.code += `}
5199
+ `;
5200
+ }
5201
+ if (viteCommand === "serve" && isServerFirstRoute && !hasClientExports) {
5202
+ generatorResult.code += `
5203
+ export const __ensureClientRouteModuleForHMR = true;`;
5204
+ }
5205
+ return generatorResult;
5206
+ }
5207
+ function parseRouteExports(code) {
5208
+ const [, exportSpecifiers] = (0, import_es_module_lexer2.parse)(code);
5209
+ const staticExports = exportSpecifiers.map(({ n: name }) => name);
5210
+ const isServerFirstRoute = staticExports.some(
5211
+ (staticExport) => staticExport === "ServerComponent"
5212
+ );
5213
+ return {
5214
+ staticExports,
5215
+ isServerFirstRoute,
5216
+ hasClientExports: staticExports.some(
5217
+ isServerFirstRoute ? isClientNonComponentExport : isClientRouteExport
5218
+ )
5219
+ };
5220
+ }
5221
+ function getVirtualClientModuleId(id) {
5222
+ return `${id.split("?")[0]}?client-route-module`;
5223
+ }
5224
+ function getVirtualServerModuleId(id) {
5225
+ return `${id.split("?")[0]}?server-route-module`;
5226
+ }
5227
+ function isVirtualRouteModuleId(id) {
5228
+ return /(\?|&)route-module(&|$)/.test(id);
5229
+ }
5230
+ function isVirtualClientRouteModuleId(id) {
5231
+ return /(\?|&)client-route-module(&|$)/.test(id);
5232
+ }
5233
+ function isVirtualServerRouteModuleId(id) {
5234
+ return /(\?|&)server-route-module(&|$)/.test(id);
5235
+ }
5236
+ function isRootRouteFile({
5237
+ id,
5238
+ rootRouteFile
5239
+ }) {
5240
+ const filePath = id.split("?")[0];
5241
+ return filePath === rootRouteFile;
5242
+ }
5243
+
5244
+ // vite/rsc/plugin.ts
5245
+ function reactRouterRSCVitePlugin() {
5246
+ let configLoader;
5247
+ let typegenWatcherPromise;
5248
+ let viteCommand;
5249
+ let resolvedViteConfig;
5250
+ let routeIdByFile;
5251
+ let logger;
5252
+ const defaultEntries2 = getDefaultEntries();
5253
+ let config;
5254
+ let rootRouteFile;
5255
+ function updateConfig(newConfig) {
5256
+ config = newConfig;
5257
+ rootRouteFile = Path5.resolve(
5258
+ newConfig.appDirectory,
5259
+ newConfig.routes.root.file
5260
+ );
5261
+ }
5262
+ return [
5263
+ {
5264
+ name: "react-router/rsc",
5265
+ async config(viteUserConfig, { command, mode }) {
5266
+ await import_es_module_lexer3.init;
5267
+ await preloadVite();
5268
+ viteCommand = command;
5269
+ const rootDirectory = getRootDirectory(viteUserConfig);
5270
+ const watch2 = command === "serve";
5271
+ configLoader = await createConfigLoader({
5272
+ rootDirectory,
5273
+ mode,
5274
+ watch: watch2,
5275
+ validateConfig: (userConfig) => {
5276
+ let errors = [];
5277
+ if (userConfig.buildEnd) errors.push("buildEnd");
5278
+ if (userConfig.prerender) errors.push("prerender");
5279
+ if (userConfig.presets?.length) errors.push("presets");
5280
+ if (userConfig.routeDiscovery) errors.push("routeDiscovery");
5281
+ if (userConfig.serverBundles) errors.push("serverBundles");
5282
+ if (userConfig.ssr === false) errors.push("ssr: false");
5283
+ if (userConfig.future?.unstable_splitRouteModules)
5284
+ errors.push("future.unstable_splitRouteModules");
5285
+ if (userConfig.future?.unstable_viteEnvironmentApi === false)
5286
+ errors.push("future.unstable_viteEnvironmentApi: false");
5287
+ if (userConfig.future?.v8_middleware === false)
5288
+ errors.push("future.v8_middleware: false");
5289
+ if (userConfig.future?.unstable_subResourceIntegrity)
5290
+ errors.push("future.unstable_subResourceIntegrity");
5291
+ if (errors.length) {
5292
+ return `RSC Framework Mode does not currently support the following React Router config:
5293
+ ${errors.map((x) => ` - ${x}`).join("\n")}
5294
+ `;
5295
+ }
5296
+ }
5297
+ });
5298
+ const configResult = await configLoader.getConfig();
5299
+ if (!configResult.ok) throw new Error(configResult.error);
5300
+ updateConfig(configResult.value);
5301
+ if (viteUserConfig.base && config.basename !== "/" && viteCommand === "serve" && !viteUserConfig.server?.middlewareMode && !config.basename.startsWith(viteUserConfig.base)) {
5302
+ throw new Error(
5303
+ "When using the React Router `basename` and the Vite `base` config, the `basename` config must begin with `base` for the default Vite dev server."
5304
+ );
5305
+ }
5306
+ await loadDotenv({
5307
+ rootDirectory,
5308
+ viteUserConfig,
5309
+ mode
5310
+ });
5311
+ const vite2 = await import("vite");
5312
+ logger = vite2.createLogger(viteUserConfig.logLevel, {
5313
+ prefix: "[react-router]"
5314
+ });
5315
+ return {
5316
+ resolve: {
5317
+ dedupe: [
5318
+ // https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
5319
+ "react",
5320
+ "react-dom",
5321
+ // Avoid router duplicates since mismatching routers cause `Error:
5322
+ // You must render this element inside a <Remix> element`.
5323
+ "react-router",
5324
+ "react-router/dom",
5325
+ ...hasDependency({ name: "react-router-dom", rootDirectory }) ? ["react-router-dom"] : []
5326
+ ]
5327
+ },
5328
+ optimizeDeps: {
5329
+ entries: getOptimizeDepsEntries({
5330
+ entryClientFilePath: defaultEntries2.client,
5331
+ reactRouterConfig: config
5332
+ }),
5333
+ esbuildOptions: {
5334
+ jsx: "automatic"
5335
+ },
5336
+ include: [
5337
+ // Pre-bundle React dependencies to avoid React duplicates,
5338
+ // even if React dependencies are not direct dependencies.
5339
+ // https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
5340
+ "react",
5341
+ "react/jsx-runtime",
5342
+ "react/jsx-dev-runtime",
5343
+ "react-dom",
5344
+ "react-dom/client",
5345
+ "react-router/internal/react-server-client"
5346
+ ]
5347
+ },
5348
+ esbuild: {
5349
+ jsx: "automatic",
5350
+ jsxDev: viteCommand !== "build"
5351
+ },
5352
+ environments: {
5353
+ client: {
5354
+ build: {
5355
+ rollupOptions: {
5356
+ input: {
5357
+ index: defaultEntries2.client
5358
+ }
5359
+ },
5360
+ outDir: (0, import_pathe6.join)(config.buildDirectory, "client")
5361
+ },
5362
+ optimizeDeps: {
5363
+ include: [
5364
+ "react-router > cookie",
5365
+ "react-router > set-cookie-parser"
5366
+ ]
5367
+ }
5368
+ },
5369
+ rsc: {
5370
+ build: {
5371
+ rollupOptions: {
5372
+ input: {
5373
+ // We use a virtual entry here so that consumers can import
5374
+ // it as `virtual:react-router/unstable_rsc/rsc-entry`
5375
+ // without needing to know the actual file path, which is
5376
+ // important when using the default entries.
5377
+ index: defaultEntries2.rsc
5378
+ },
5379
+ output: {
5380
+ entryFileNames: config.serverBuildFile,
5381
+ format: config.serverModuleFormat
5382
+ }
5383
+ },
5384
+ outDir: (0, import_pathe6.join)(config.buildDirectory, "server")
5385
+ }
5386
+ },
5387
+ ssr: {
5388
+ build: {
5389
+ rollupOptions: {
5390
+ input: {
5391
+ index: defaultEntries2.ssr
5392
+ },
5393
+ output: {
5394
+ // Note: We don't set `entryFileNames` here because it's
5395
+ // considered private to the RSC environment build, and
5396
+ // @vitejs/plugin-rsc currently breaks if it's set to
5397
+ // something other than `index.js`.
5398
+ format: config.serverModuleFormat
5399
+ }
5400
+ },
5401
+ outDir: (0, import_pathe6.join)(config.buildDirectory, "server/__ssr_build")
5402
+ }
5403
+ }
5404
+ },
5405
+ build: {
5406
+ rollupOptions: {
5407
+ // Copied from https://github.com/vitejs/vite-plugin-react/blob/c602225271d4acf462ba00f8d6d8a2e42492c5cd/packages/common/warning.ts
5408
+ onwarn(warning, defaultHandler) {
5409
+ if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
5410
+ return;
5411
+ }
5412
+ if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
5413
+ return;
5414
+ }
5415
+ if (viteUserConfig.build?.rollupOptions?.onwarn) {
5416
+ viteUserConfig.build.rollupOptions.onwarn(
5417
+ warning,
5418
+ defaultHandler
5419
+ );
5420
+ } else {
5421
+ defaultHandler(warning);
5422
+ }
5423
+ }
5424
+ }
5425
+ }
5426
+ };
5427
+ },
5428
+ configResolved(viteConfig) {
5429
+ resolvedViteConfig = viteConfig;
5430
+ },
5431
+ async configureServer(viteDevServer) {
5432
+ configLoader.onChange(
5433
+ async ({
5434
+ result,
5435
+ configCodeChanged,
5436
+ routeConfigCodeChanged,
5437
+ configChanged,
5438
+ routeConfigChanged
5439
+ }) => {
5440
+ if (!result.ok) {
5441
+ invalidateVirtualModules2(viteDevServer);
5442
+ logger.error(result.error, {
5443
+ clear: true,
5444
+ timestamp: true
5445
+ });
5446
+ return;
5447
+ }
5448
+ let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
5449
+ logger.info(import_picocolors5.default.green(message), {
5450
+ clear: true,
5451
+ timestamp: true
5452
+ });
5453
+ updateConfig(result.value);
5454
+ if (configChanged || routeConfigChanged) {
5455
+ invalidateVirtualModules2(viteDevServer);
5456
+ }
5457
+ }
5458
+ );
5459
+ },
5460
+ async buildEnd() {
5461
+ await configLoader.close();
5462
+ }
5463
+ },
5464
+ /* @__PURE__ */ (() => {
5465
+ let logged = false;
5466
+ function logExperimentalNotice() {
5467
+ if (logged) return;
5468
+ logged = true;
5469
+ logger.info(
5470
+ import_picocolors5.default.yellow(
5471
+ `${viteCommand === "serve" ? " " : ""}\u{1F9EA} Using React Router's RSC Framework Mode (experimental)`
5472
+ )
5473
+ );
5474
+ }
5475
+ return {
5476
+ name: "react-router/rsc/log-experimental-notice",
5477
+ sharedDuringBuild: true,
5478
+ buildStart: logExperimentalNotice,
5479
+ configureServer: logExperimentalNotice
5480
+ };
5481
+ })(),
5482
+ {
5483
+ name: "react-router/rsc/typegen",
5484
+ async config(viteUserConfig, { command, mode }) {
5485
+ if (command === "serve") {
5486
+ const vite2 = await import("vite");
5487
+ typegenWatcherPromise = watch(
5488
+ getRootDirectory(viteUserConfig),
5489
+ {
5490
+ mode,
5491
+ rsc: true,
5492
+ // ignore `info` logs from typegen since they are
5493
+ // redundant when Vite plugin logs are active
5494
+ logger: vite2.createLogger("warn", {
5495
+ prefix: "[react-router]"
5496
+ })
5497
+ }
5498
+ );
5499
+ }
5500
+ },
5501
+ async buildEnd() {
5502
+ (await typegenWatcherPromise)?.close();
5503
+ }
5504
+ },
5505
+ {
5506
+ name: "react-router/rsc/virtual-rsc-entry",
5507
+ resolveId(id) {
5508
+ if (id === virtual2.rscEntry.id) return defaultEntries2.rsc;
5509
+ }
5510
+ },
5511
+ {
5512
+ name: "react-router/rsc/virtual-route-config",
5513
+ resolveId(id) {
5514
+ if (id === virtual2.routeConfig.id) {
5515
+ return virtual2.routeConfig.resolvedId;
5516
+ }
5517
+ },
5518
+ load(id) {
5519
+ if (id === virtual2.routeConfig.resolvedId) {
5520
+ const result = createVirtualRouteConfig({
5521
+ appDirectory: config.appDirectory,
5522
+ routeConfig: config.unstable_routeConfig
5523
+ });
5524
+ routeIdByFile = result.routeIdByFile;
5525
+ return result.code;
5526
+ }
5527
+ }
5528
+ },
5529
+ {
5530
+ name: "react-router/rsc/virtual-route-modules",
5531
+ transform(code, id) {
5532
+ if (!routeIdByFile) return;
5533
+ return transformVirtualRouteModules({
5534
+ code,
5535
+ id,
5536
+ viteCommand,
5537
+ routeIdByFile,
5538
+ rootRouteFile,
5539
+ viteEnvironment: this.environment
5540
+ });
5541
+ }
5542
+ },
5543
+ {
5544
+ name: "react-router/rsc/virtual-basename",
5545
+ resolveId(id) {
5546
+ if (id === virtual2.basename.id) {
5547
+ return virtual2.basename.resolvedId;
5548
+ }
5549
+ },
5550
+ load(id) {
5551
+ if (id === virtual2.basename.resolvedId) {
5552
+ return `export default ${JSON.stringify(config.basename)};`;
5553
+ }
5554
+ }
5555
+ },
5556
+ {
5557
+ name: "react-router/rsc/hmr/inject-runtime",
5558
+ enforce: "pre",
5559
+ resolveId(id) {
5560
+ if (id === virtual2.injectHmrRuntime.id) {
5561
+ return virtual2.injectHmrRuntime.resolvedId;
5562
+ }
5563
+ },
5564
+ async load(id) {
5565
+ if (id !== virtual2.injectHmrRuntime.resolvedId) return;
5566
+ return viteCommand === "serve" ? [
5567
+ `import RefreshRuntime from "${virtual2.hmrRuntime.id}"`,
5568
+ "RefreshRuntime.injectIntoGlobalHook(window)",
5569
+ "window.$RefreshReg$ = () => {}",
5570
+ "window.$RefreshSig$ = () => (type) => type",
5571
+ "window.__vite_plugin_react_preamble_installed__ = true"
5572
+ ].join("\n") : "";
5573
+ }
5574
+ },
5575
+ {
5576
+ name: "react-router/rsc/hmr/runtime",
5577
+ enforce: "pre",
5578
+ resolveId(id) {
5579
+ if (id === virtual2.hmrRuntime.id) return virtual2.hmrRuntime.resolvedId;
5580
+ },
5581
+ async load(id) {
5582
+ if (id !== virtual2.hmrRuntime.resolvedId) return;
5583
+ const reactRefreshDir = import_pathe6.default.dirname(
5584
+ require.resolve("react-refresh/package.json")
5585
+ );
5586
+ const reactRefreshRuntimePath = import_pathe6.default.join(
5587
+ reactRefreshDir,
5588
+ "cjs/react-refresh-runtime.development.js"
5589
+ );
5590
+ return [
5591
+ "const exports = {}",
5592
+ await (0, import_promises3.readFile)(reactRefreshRuntimePath, "utf8"),
5593
+ await (0, import_promises3.readFile)(
5594
+ require.resolve("./static/rsc-refresh-utils.mjs"),
5595
+ "utf8"
5596
+ ),
5597
+ "export default exports"
5598
+ ].join("\n");
5599
+ }
5600
+ },
5601
+ {
5602
+ name: "react-router/rsc/hmr/react-refresh",
5603
+ async transform(code, id, options) {
5604
+ if (viteCommand !== "serve") return;
5605
+ if (id.includes("/node_modules/")) return;
5606
+ const filepath = id.split("?")[0];
5607
+ const extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
5608
+ if (!extensionsRE.test(filepath)) return;
5609
+ const devRuntime = "react/jsx-dev-runtime";
5610
+ const ssr = options?.ssr === true;
5611
+ const isJSX = filepath.endsWith("x");
5612
+ const useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
5613
+ if (!useFastRefresh) return;
5614
+ if (isVirtualClientRouteModuleId(id)) {
5615
+ const routeId = routeIdByFile?.get(filepath);
5616
+ return { code: addRefreshWrapper2({ routeId, code, id }) };
5617
+ }
5618
+ const result = await babel2.transformAsync(code, {
5619
+ babelrc: false,
5620
+ configFile: false,
5621
+ filename: id,
5622
+ sourceFileName: filepath,
5623
+ parserOpts: {
5624
+ sourceType: "module",
5625
+ allowAwaitOutsideFunction: true
5626
+ },
5627
+ plugins: [[require("react-refresh/babel"), { skipEnvCheck: true }]],
5628
+ sourceMaps: true
5629
+ });
5630
+ if (result === null) return;
5631
+ code = result.code;
5632
+ const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
5633
+ if (refreshContentRE.test(code)) {
5634
+ code = addRefreshWrapper2({ code, id });
5635
+ }
5636
+ return { code, map: result.map };
5637
+ }
5638
+ },
5639
+ {
5640
+ name: "react-router/rsc/hmr/updates",
5641
+ async hotUpdate({ server, file, modules }) {
5642
+ if (this.environment.name !== "rsc") return;
5643
+ const clientModules = server.environments.client.moduleGraph.getModulesByFile(file);
5644
+ const vite2 = await import("vite");
5645
+ const isServerOnlyChange = !clientModules || clientModules.size === 0 || // Handle CSS injected from server-first routes (with ?direct query
5646
+ // string) since the client graph has a reference to the CSS
5647
+ vite2.isCSSRequest(file) && Array.from(clientModules).some(
5648
+ (mod) => mod.id?.includes("?direct")
5649
+ );
5650
+ for (const mod of getModulesWithImporters(modules)) {
5651
+ if (!mod.file) continue;
5652
+ const normalizedPath = import_pathe6.default.normalize(mod.file);
5653
+ const routeId = routeIdByFile?.get(normalizedPath);
5654
+ if (routeId !== void 0) {
5655
+ const routeSource = await (0, import_promises3.readFile)(normalizedPath, "utf8");
5656
+ const virtualRouteModuleCode = (await server.environments.rsc.pluginContainer.transform(
5657
+ routeSource,
5658
+ `${normalizedPath}?route-module`
5659
+ )).code;
5660
+ const { staticExports } = parseRouteExports(virtualRouteModuleCode);
5661
+ const hasAction = staticExports.includes("action");
5662
+ const hasComponent = staticExports.includes("default");
5663
+ const hasErrorBoundary = staticExports.includes("ErrorBoundary");
5664
+ const hasLoader = staticExports.includes("loader");
5665
+ server.hot.send({
5666
+ type: "custom",
5667
+ event: "react-router:hmr",
5668
+ data: {
5669
+ routeId,
5670
+ isServerOnlyChange,
5671
+ hasAction,
5672
+ hasComponent,
5673
+ hasErrorBoundary,
5674
+ hasLoader
5675
+ }
5676
+ });
5677
+ }
5678
+ }
5679
+ return modules;
5680
+ }
5681
+ },
5682
+ {
5683
+ name: "react-router/rsc/virtual-react-router-serve-config",
5684
+ resolveId(id) {
5685
+ if (id === virtual2.reactRouterServeConfig.id) {
5686
+ return virtual2.reactRouterServeConfig.resolvedId;
5687
+ }
5688
+ },
5689
+ load(id) {
5690
+ if (id === virtual2.reactRouterServeConfig.resolvedId) {
5691
+ const rscOutDir = resolvedViteConfig.environments.rsc?.build?.outDir;
5692
+ invariant(rscOutDir, "RSC build directory config not found");
5693
+ const clientOutDir = resolvedViteConfig.environments.client?.build?.outDir;
5694
+ invariant(clientOutDir, "Client build directory config not found");
5695
+ const assetsBuildDirectory = Path5.relative(rscOutDir, clientOutDir);
5696
+ const publicPath = resolvedViteConfig.base;
5697
+ return `export default ${JSON.stringify({
5698
+ assetsBuildDirectory,
5699
+ publicPath
5700
+ })};`;
5701
+ }
5702
+ }
5703
+ },
5704
+ validatePluginOrder(),
5705
+ warnOnClientSourceMaps()
5706
+ ];
5707
+ }
5708
+ var virtual2 = {
5709
+ routeConfig: create("unstable_rsc/routes"),
5710
+ injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
5711
+ hmrRuntime: create("unstable_rsc/runtime"),
5712
+ basename: create("unstable_rsc/basename"),
5713
+ rscEntry: create("unstable_rsc/rsc-entry"),
5714
+ reactRouterServeConfig: create("unstable_rsc/react-router-serve-config")
5715
+ };
5716
+ function invalidateVirtualModules2(viteDevServer) {
5717
+ for (const vmod of Object.values(virtual2)) {
5718
+ for (const env of Object.values(viteDevServer.environments)) {
5719
+ const mod = env.moduleGraph.getModuleById(vmod.resolvedId);
5720
+ if (mod) {
5721
+ env.moduleGraph.invalidateModule(mod);
5722
+ }
5723
+ }
5724
+ }
5725
+ }
5726
+ function getRootDirectory(viteUserConfig) {
5727
+ return viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
5728
+ }
5729
+ function getDevPackageRoot() {
5730
+ const currentDir = (0, import_pathe6.dirname)(__dirname);
5731
+ let dir = currentDir;
5732
+ while (dir !== (0, import_pathe6.dirname)(dir)) {
5733
+ try {
5734
+ const packageJsonPath = (0, import_pathe6.join)(dir, "package.json");
5735
+ (0, import_fs.readFileSync)(packageJsonPath, "utf-8");
5736
+ return dir;
5737
+ } catch {
5738
+ dir = (0, import_pathe6.dirname)(dir);
5739
+ }
5740
+ }
5741
+ throw new Error("Could not find package.json");
5742
+ }
5743
+ function getDefaultEntries() {
5744
+ const defaultEntriesDir2 = (0, import_pathe6.join)(
5745
+ getDevPackageRoot(),
5746
+ "dist",
5747
+ "config",
5748
+ "default-rsc-entries"
5749
+ );
5750
+ return {
5751
+ rsc: (0, import_pathe6.join)(defaultEntriesDir2, "entry.rsc.tsx"),
5752
+ ssr: (0, import_pathe6.join)(defaultEntriesDir2, "entry.ssr.tsx"),
5753
+ client: (0, import_pathe6.join)(defaultEntriesDir2, "entry.client.tsx")
5754
+ };
5755
+ }
5756
+ function getModulesWithImporters(modules) {
5757
+ const visited = /* @__PURE__ */ new Set();
5758
+ const result = /* @__PURE__ */ new Set();
5759
+ function walk(module2) {
5760
+ if (visited.has(module2)) return;
5761
+ visited.add(module2);
5762
+ result.add(module2);
5763
+ for (const importer of module2.importers) {
5764
+ walk(importer);
5765
+ }
5766
+ }
5767
+ for (const module2 of modules) {
5768
+ walk(module2);
5769
+ }
5770
+ return result;
5771
+ }
5772
+ function addRefreshWrapper2({
5773
+ routeId,
5774
+ code,
5775
+ id
5776
+ }) {
5777
+ const acceptExports = routeId !== void 0 ? CLIENT_NON_COMPONENT_EXPORTS2 : [];
5778
+ 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));
5779
+ }
5780
+ var REACT_REFRESH_HEADER2 = `
5781
+ import RefreshRuntime from "${virtual2.hmrRuntime.id}";
5782
+
5783
+ const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
5784
+ let prevRefreshReg;
5785
+ let prevRefreshSig;
5786
+
5787
+ if (import.meta.hot && !inWebWorker) {
5788
+ if (!window.__vite_plugin_react_preamble_installed__) {
5789
+ throw new Error(
5790
+ "React Router Vite plugin can't detect preamble. Something is wrong."
5791
+ );
5792
+ }
5793
+
5794
+ prevRefreshReg = window.$RefreshReg$;
5795
+ prevRefreshSig = window.$RefreshSig$;
5796
+ window.$RefreshReg$ = (type, id) => {
5797
+ RefreshRuntime.register(type, __SOURCE__ + " " + id)
5798
+ };
5799
+ window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
5800
+ }`.replaceAll("\n", "");
5801
+ var REACT_REFRESH_FOOTER2 = `
5802
+ if (import.meta.hot && !inWebWorker) {
5803
+ window.$RefreshReg$ = prevRefreshReg;
5804
+ window.$RefreshSig$ = prevRefreshSig;
5805
+ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
5806
+ RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
5807
+ import.meta.hot.accept((nextExports) => {
5808
+ if (!nextExports) return;
5809
+ __ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
5810
+ const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
5811
+ if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
5812
+ });
5813
+ });
5814
+ }`;
4876
5815
  // Annotate the CommonJS export names for ESM import in node:
4877
5816
  0 && (module.exports = {
4878
- reactRouter
5817
+ reactRouter,
5818
+ unstable_reactRouterRSC
4879
5819
  });