@react-router/dev 0.0.0-experimental-89dc2043e → 0.0.0-experimental-1ebb6d403

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-89dc2043e
2
+ * @react-router/dev v0.0.0-experimental-1ebb6d403
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -46,8 +46,8 @@ module.exports = __toCommonJS(vite_exports);
46
46
 
47
47
  // vite/plugin.ts
48
48
  var import_node_crypto = require("crypto");
49
- var path4 = __toESM(require("path"));
50
- var url2 = __toESM(require("url"));
49
+ var path6 = __toESM(require("path"));
50
+ var url = __toESM(require("url"));
51
51
  var fse = __toESM(require("fs-extra"));
52
52
  var babel = __toESM(require("@babel/core"));
53
53
  var import_react_router2 = require("react-router");
@@ -70,6 +70,9 @@ var import_server = require("vite-node/server");
70
70
  var import_client = require("vite-node/client");
71
71
  var import_source_map = require("vite-node/source-map");
72
72
 
73
+ // vite/vite.ts
74
+ var import_pathe2 = __toESM(require("pathe"));
75
+
73
76
  // invariant.ts
74
77
  function invariant(value, message) {
75
78
  if (value === false || value === null || typeof value === "undefined") {
@@ -80,20 +83,41 @@ function invariant(value, message) {
80
83
  }
81
84
  }
82
85
 
83
- // vite/import-vite-esm-sync.ts
86
+ // config/is-react-router-repo.ts
87
+ var import_pathe = __toESM(require("pathe"));
88
+ function isReactRouterRepo() {
89
+ let serverRuntimePath = import_pathe.default.dirname(
90
+ require.resolve("@react-router/node/package.json")
91
+ );
92
+ let serverRuntimeParentDir = import_pathe.default.basename(
93
+ import_pathe.default.resolve(serverRuntimePath, "..")
94
+ );
95
+ return serverRuntimeParentDir === "packages";
96
+ }
97
+
98
+ // vite/vite.ts
84
99
  var vite;
85
- async function preloadViteEsm() {
86
- vite = await import("vite");
100
+ var viteImportSpecifier = isReactRouterRepo() ? (
101
+ // Support testing against different versions of Vite by ensuring that Vite
102
+ // is resolved from the current working directory when running within this
103
+ // repo. If we don't do this, Vite will always be imported relative to this
104
+ // file, which means that it will always resolve to Vite 6.
105
+ `file:///${import_pathe2.default.normalize(
106
+ require.resolve("vite/package.json", { paths: [process.cwd()] })
107
+ ).replace("package.json", "dist/node/index.js")}`
108
+ ) : "vite";
109
+ async function preloadVite() {
110
+ vite = await import(viteImportSpecifier);
87
111
  }
88
- function importViteEsmSync() {
89
- invariant(vite, "importViteEsmSync() called before preloadViteEsm()");
112
+ function getVite() {
113
+ invariant(vite, "getVite() called before preloadVite()");
90
114
  return vite;
91
115
  }
92
116
 
93
117
  // vite/vite-node.ts
94
118
  async function createContext(viteConfig = {}) {
95
- await preloadViteEsm();
96
- const vite2 = importViteEsmSync();
119
+ await preloadVite();
120
+ const vite2 = getVite();
97
121
  const devServer = await vite2.createServer(
98
122
  vite2.mergeConfig(
99
123
  {
@@ -119,18 +143,18 @@ async function createContext(viteConfig = {}) {
119
143
  const runner = new import_client.ViteNodeRunner({
120
144
  root: devServer.config.root,
121
145
  base: devServer.config.base,
122
- fetchModule(id2) {
123
- return server.fetchModule(id2);
146
+ fetchModule(id) {
147
+ return server.fetchModule(id);
124
148
  },
125
- resolveId(id2, importer) {
126
- return server.resolveId(id2, importer);
149
+ resolveId(id, importer) {
150
+ return server.resolveId(id, importer);
127
151
  }
128
152
  });
129
153
  return { devServer, server, runner };
130
154
  }
131
155
 
132
156
  // config/config.ts
133
- var import_pathe = __toESM(require("pathe"));
157
+ var import_pathe3 = __toESM(require("pathe"));
134
158
  var import_chokidar = __toESM(require("chokidar"));
135
159
  var import_picocolors = __toESM(require("picocolors"));
136
160
  var import_pick2 = __toESM(require("lodash/pick"));
@@ -184,7 +208,7 @@ function validateRouteConfig({
184
208
  `Route config in "${routeConfigFile}" is invalid.`,
185
209
  root ? `${root}` : [],
186
210
  nested ? Object.entries(nested).map(
187
- ([path5, message]) => `Path: routes.${path5}
211
+ ([path7, message]) => `Path: routes.${path7}
188
212
  ${message}`
189
213
  ) : []
190
214
  ].flat().join("\n\n")
@@ -195,24 +219,24 @@ ${message}`
195
219
  function configRoutesToRouteManifest(appDirectory, routes, rootId = "root") {
196
220
  let routeManifest = {};
197
221
  function walk(route, parentId) {
198
- let id2 = route.id || createRouteId(route.file);
222
+ let id = route.id || createRouteId(route.file);
199
223
  let manifestItem = {
200
- id: id2,
224
+ id,
201
225
  parentId,
202
226
  file: Path.isAbsolute(route.file) ? Path.relative(appDirectory, route.file) : route.file,
203
227
  path: route.path,
204
228
  index: route.index,
205
229
  caseSensitive: route.caseSensitive
206
230
  };
207
- if (routeManifest.hasOwnProperty(id2)) {
231
+ if (routeManifest.hasOwnProperty(id)) {
208
232
  throw new Error(
209
- `Unable to define routes with duplicate route id: "${id2}"`
233
+ `Unable to define routes with duplicate route id: "${id}"`
210
234
  );
211
235
  }
212
- routeManifest[id2] = manifestItem;
236
+ routeManifest[id] = manifestItem;
213
237
  if (route.children) {
214
238
  for (let child of route.children) {
215
- walk(child, id2);
239
+ walk(child, id);
216
240
  }
217
241
  }
218
242
  }
@@ -366,13 +390,13 @@ async function resolveConfig({
366
390
  "The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
367
391
  );
368
392
  }
369
- let appDirectory = import_pathe.default.resolve(root, userAppDirectory || "app");
370
- let buildDirectory = import_pathe.default.resolve(root, userBuildDirectory);
393
+ let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
394
+ let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
371
395
  let rootRouteFile = findEntry(appDirectory, "root");
372
396
  if (!rootRouteFile) {
373
- let rootRouteDisplayPath = import_pathe.default.relative(
397
+ let rootRouteDisplayPath = import_pathe3.default.relative(
374
398
  root,
375
- import_pathe.default.join(appDirectory, "root.tsx")
399
+ import_pathe3.default.join(appDirectory, "root.tsx")
376
400
  );
377
401
  return err(
378
402
  `Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
@@ -384,15 +408,15 @@ async function resolveConfig({
384
408
  let routeConfigFile = findEntry(appDirectory, "routes");
385
409
  try {
386
410
  if (!routeConfigFile) {
387
- let routeConfigDisplayPath = import_pathe.default.relative(
411
+ let routeConfigDisplayPath = import_pathe3.default.relative(
388
412
  root,
389
- import_pathe.default.join(appDirectory, "routes.ts")
413
+ import_pathe3.default.join(appDirectory, "routes.ts")
390
414
  );
391
415
  return err(`Route config file not found at "${routeConfigDisplayPath}".`);
392
416
  }
393
417
  setAppDirectory(appDirectory);
394
418
  let routeConfigExport = (await viteNodeContext.runner.executeFile(
395
- import_pathe.default.join(appDirectory, routeConfigFile)
419
+ import_pathe3.default.join(appDirectory, routeConfigFile)
396
420
  )).default;
397
421
  let routeConfig = await routeConfigExport;
398
422
  let result = validateRouteConfig({
@@ -412,7 +436,7 @@ async function resolveConfig({
412
436
  import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
413
437
  "",
414
438
  error.loc?.file && error.loc?.column && error.frame ? [
415
- import_pathe.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
439
+ import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
416
440
  error.frame.trim?.()
417
441
  ] : error.stack
418
442
  ].flat().join("\n")
@@ -484,8 +508,8 @@ async function createConfigLoader({
484
508
  );
485
509
  fsWatcher.on("all", async (...args) => {
486
510
  let [event, rawFilepath] = args;
487
- let filepath = import_pathe.default.normalize(rawFilepath);
488
- let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe.default.normalize(appDirectory));
511
+ let filepath = import_pathe3.default.normalize(rawFilepath);
512
+ let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
489
513
  let configCodeUpdated = Boolean(
490
514
  viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
491
515
  );
@@ -531,8 +555,8 @@ async function resolveEntryFiles({
531
555
  reactRouterConfig
532
556
  }) {
533
557
  let { appDirectory } = reactRouterConfig;
534
- let defaultsDirectory = import_pathe.default.resolve(
535
- import_pathe.default.dirname(require.resolve("@react-router/dev/package.json")),
558
+ let defaultsDirectory = import_pathe3.default.resolve(
559
+ import_pathe3.default.dirname(require.resolve("@react-router/dev/package.json")),
536
560
  "dist",
537
561
  "config",
538
562
  "defaults"
@@ -570,11 +594,11 @@ async function resolveEntryFiles({
570
594
  }
571
595
  entryServerFile = `entry.server.node.tsx`;
572
596
  }
573
- let entryClientFilePath = userEntryClientFile ? import_pathe.default.resolve(reactRouterConfig.appDirectory, userEntryClientFile) : import_pathe.default.resolve(defaultsDirectory, entryClientFile);
574
- let entryServerFilePath = userEntryServerFile ? import_pathe.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe.default.resolve(defaultsDirectory, entryServerFile);
597
+ let entryClientFilePath = userEntryClientFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryClientFile) : import_pathe3.default.resolve(defaultsDirectory, entryClientFile);
598
+ let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
575
599
  return { entryClientFilePath, entryServerFilePath };
576
600
  }
577
- var ssrExternals = isInReactRouterMonorepo() ? [
601
+ var ssrExternals = isReactRouterRepo() ? [
578
602
  // This is only needed within this repo because these packages
579
603
  // are linked to a directory outside of node_modules so Vite
580
604
  // treats them as internal code by default.
@@ -587,21 +611,12 @@ var ssrExternals = isInReactRouterMonorepo() ? [
587
611
  "@react-router/node",
588
612
  "@react-router/serve"
589
613
  ] : void 0;
590
- function isInReactRouterMonorepo() {
591
- let serverRuntimePath = import_pathe.default.dirname(
592
- require.resolve("@react-router/node/package.json")
593
- );
594
- let serverRuntimeParentDir = import_pathe.default.basename(
595
- import_pathe.default.resolve(serverRuntimePath, "..")
596
- );
597
- return serverRuntimeParentDir === "packages";
598
- }
599
614
  var entryExts = [".js", ".jsx", ".ts", ".tsx"];
600
615
  function findEntry(dir, basename2, options) {
601
616
  for (let ext of entryExts) {
602
- let file = import_pathe.default.resolve(dir, basename2 + ext);
617
+ let file = import_pathe3.default.resolve(dir, basename2 + ext);
603
618
  if (import_node_fs.default.existsSync(file)) {
604
- return options?.absolute ?? false ? file : import_pathe.default.relative(dir, file);
619
+ return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
605
620
  }
606
621
  }
607
622
  return void 0;
@@ -641,7 +656,7 @@ function generate(ctx, route) {
641
656
  const indent = i === 0 ? "" : " ".repeat(2);
642
657
  let source = noExtension(rel);
643
658
  if (!source.startsWith("../")) source = "./" + source;
644
- return `${indent}import type { Info as Parent${i} } from "${source}"`;
659
+ return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
645
660
  }).join("\n");
646
661
  return import_dedent.default`
647
662
  // React Router generated types for route:
@@ -651,14 +666,16 @@ function generate(ctx, route) {
651
666
 
652
667
  ${parentTypeImports}
653
668
 
654
- type Module = typeof import("../${Pathe2.filename(route.file)}")
669
+ type Module = typeof import("../${Pathe2.filename(route.file)}.js")
655
670
 
656
671
  export type Info = {
657
672
  parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
658
673
  id: "${route.id}"
659
674
  file: "${route.file}"
660
675
  path: "${route.path}"
661
- params: {${formatParamProperties(urlpath)}}
676
+ params: {${formatParamProperties(
677
+ urlpath
678
+ )}} & { [key: string]: string | undefined }
662
679
  module: Module
663
680
  loaderData: T.CreateLoaderData<Module>
664
681
  actionData: T.CreateActionData<Module>
@@ -686,7 +703,7 @@ function generate(ctx, route) {
686
703
  }
687
704
  `;
688
705
  }
689
- var noExtension = (path5) => Path3.join(Path3.dirname(path5), Pathe2.filename(path5));
706
+ var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
690
707
  function getRouteLineage(routes, route) {
691
708
  const result = [];
692
709
  while (route) {
@@ -810,7 +827,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
810
827
  nodeReq.originalUrl,
811
828
  "Expected `nodeReq.originalUrl` to be defined"
812
829
  );
813
- let url3 = new URL(nodeReq.originalUrl, origin);
830
+ let url2 = new URL(nodeReq.originalUrl, origin);
814
831
  let controller = new AbortController();
815
832
  let init = {
816
833
  method: nodeReq.method,
@@ -823,7 +840,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
823
840
  init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
824
841
  init.duplex = "half";
825
842
  }
826
- return new Request(url3.href, init);
843
+ return new Request(url2.href, init);
827
844
  }
828
845
  async function toNodeRequest(res, nodeRes) {
829
846
  nodeRes.statusCode = res.status;
@@ -848,17 +865,17 @@ async function toNodeRequest(res, nodeRes) {
848
865
  }
849
866
 
850
867
  // vite/styles.ts
851
- var path3 = __toESM(require("path"));
868
+ var path5 = __toESM(require("path"));
852
869
  var import_react_router = require("react-router");
853
870
 
854
871
  // vite/resolve-file-url.ts
855
- var path2 = __toESM(require("path"));
872
+ var path4 = __toESM(require("path"));
856
873
  var resolveFileUrl = ({ rootDirectory }, filePath) => {
857
- let vite2 = importViteEsmSync();
858
- let relativePath = path2.relative(rootDirectory, filePath);
859
- let isWithinRoot = !relativePath.startsWith("..") && !path2.isAbsolute(relativePath);
874
+ let vite2 = getVite();
875
+ let relativePath = path4.relative(rootDirectory, filePath);
876
+ let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
860
877
  if (!isWithinRoot) {
861
- return path2.posix.join("/@fs", vite2.normalizePath(filePath));
878
+ return path4.posix.join("/@fs", vite2.normalizePath(filePath));
862
879
  }
863
880
  return "/" + vite2.normalizePath(relativePath);
864
881
  };
@@ -869,8 +886,8 @@ var cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
869
886
  var isCssFile = (file) => cssFileRegExp.test(file);
870
887
  var isCssModulesFile = (file) => cssModulesRegExp.test(file);
871
888
  var cssUrlParamsWithoutSideEffects = ["url", "inline", "raw", "inline-css"];
872
- var isCssUrlWithoutSideEffects = (url3) => {
873
- let queryString = url3.split("?")[1];
889
+ var isCssUrlWithoutSideEffects = (url2) => {
890
+ let queryString = url2.split("?")[1];
874
891
  if (!queryString) {
875
892
  return false;
876
893
  }
@@ -878,24 +895,27 @@ var isCssUrlWithoutSideEffects = (url3) => {
878
895
  for (let paramWithoutSideEffects of cssUrlParamsWithoutSideEffects) {
879
896
  if (
880
897
  // Parameter is blank and not explicitly set, i.e. "?url", not "?url="
881
- params.get(paramWithoutSideEffects) === "" && !url3.includes(`?${paramWithoutSideEffects}=`) && !url3.includes(`&${paramWithoutSideEffects}=`)
898
+ params.get(paramWithoutSideEffects) === "" && !url2.includes(`?${paramWithoutSideEffects}=`) && !url2.includes(`&${paramWithoutSideEffects}=`)
882
899
  ) {
883
900
  return true;
884
901
  }
885
902
  }
886
903
  return false;
887
904
  };
905
+ var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
888
906
  var getStylesForFiles = async ({
889
907
  viteDevServer,
890
908
  rootDirectory,
891
909
  cssModulesManifest,
892
910
  files
893
911
  }) => {
912
+ let vite2 = getVite();
913
+ let viteMajor = parseInt(vite2.version.split(".")[0], 10);
894
914
  let styles = {};
895
915
  let deps = /* @__PURE__ */ new Set();
896
916
  try {
897
917
  for (let file of files) {
898
- let normalizedPath = path3.resolve(rootDirectory, file).replace(/\\/g, "/");
918
+ let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
899
919
  let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
900
920
  if (!node) {
901
921
  try {
@@ -919,7 +939,15 @@ var getStylesForFiles = async ({
919
939
  for (let dep of deps) {
920
940
  if (dep.file && isCssFile(dep.file) && !isCssUrlWithoutSideEffects(dep.url)) {
921
941
  try {
922
- let css = isCssModulesFile(dep.file) ? cssModulesManifest[dep.file] : (await viteDevServer.ssrLoadModule(dep.url)).default;
942
+ let css = isCssModulesFile(dep.file) ? cssModulesManifest[dep.file] : (await viteDevServer.ssrLoadModule(
943
+ // We need the ?inline query in Vite v6 when loading CSS in SSR
944
+ // since it does not expose the default export for CSS in a
945
+ // server environment. This is to align with non-SSR
946
+ // environments. For backwards compatibility with v5 we keep
947
+ // using the URL without ?inline query because the HMR code was
948
+ // relying on the implicit SSR-client module graph relationship.
949
+ viteMajor >= 6 ? injectQuery(dep.url, "inline") : dep.url
950
+ )).default;
923
951
  if (css === void 0) {
924
952
  throw new Error();
925
953
  }
@@ -943,8 +971,8 @@ var findDeps = async (vite2, node, deps) => {
943
971
  await findDeps(vite2, node2, deps);
944
972
  }
945
973
  }
946
- async function addFromUrl(url3) {
947
- let node2 = await vite2.moduleGraph.getModuleByUrl(url3);
974
+ async function addFromUrl(url2) {
975
+ let node2 = await vite2.moduleGraph.getModuleByUrl(url2);
948
976
  if (node2) {
949
977
  await addFromNode(node2);
950
978
  }
@@ -952,7 +980,7 @@ var findDeps = async (vite2, node, deps) => {
952
980
  if (node.ssrTransformResult) {
953
981
  if (node.ssrTransformResult.deps) {
954
982
  node.ssrTransformResult.deps.forEach(
955
- (url3) => branches.push(addFromUrl(url3))
983
+ (url2) => branches.push(addFromUrl(url2))
956
984
  );
957
985
  }
958
986
  } else {
@@ -986,15 +1014,15 @@ var getStylesForUrl = async ({
986
1014
  entryClientFilePath,
987
1015
  cssModulesManifest,
988
1016
  build,
989
- url: url3
1017
+ url: url2
990
1018
  }) => {
991
- if (url3 === void 0 || url3.includes("?_data=")) {
1019
+ if (url2 === void 0 || url2.includes("?_data=")) {
992
1020
  return void 0;
993
1021
  }
994
1022
  let routes = createRoutes(build.routes);
995
- let appPath = path3.relative(process.cwd(), reactRouterConfig.appDirectory);
996
- let documentRouteFiles = (0, import_react_router.matchRoutes)(routes, url3, build.basename)?.map(
997
- (match) => path3.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1023
+ let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
1024
+ let documentRouteFiles = (0, import_react_router.matchRoutes)(routes, url2, build.basename)?.map(
1025
+ (match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
998
1026
  ) ?? [];
999
1027
  let styles = await getStylesForFiles({
1000
1028
  viteDevServer,
@@ -1002,7 +1030,7 @@ var getStylesForUrl = async ({
1002
1030
  cssModulesManifest,
1003
1031
  files: [
1004
1032
  // Always include the client entry file when crawling the module graph for CSS
1005
- path3.relative(rootDirectory, entryClientFilePath),
1033
+ path5.relative(rootDirectory, entryClientFilePath),
1006
1034
  // Then include any styles from the matched routes
1007
1035
  ...documentRouteFiles
1008
1036
  ]
@@ -1010,10 +1038,15 @@ var getStylesForUrl = async ({
1010
1038
  return styles;
1011
1039
  };
1012
1040
 
1013
- // vite/vmod.ts
1014
- var id = (name) => `virtual:react-router/${name}`;
1015
- var resolve3 = (id2) => `\0${id2}`;
1016
- var url = (id2) => `/@id/__x00__${id2}`;
1041
+ // vite/virtual-module.ts
1042
+ function create(name) {
1043
+ let id = `virtual:react-router/${name}`;
1044
+ return {
1045
+ id,
1046
+ resolvedId: `\0${id}`,
1047
+ url: `/@id/__x00__${id}`
1048
+ };
1049
+ }
1017
1050
 
1018
1051
  // vite/combine-urls.ts
1019
1052
  function combineURLs(baseURL, relativeURL) {
@@ -1027,10 +1060,10 @@ var removeExports = (ast, exportsToRemove) => {
1027
1060
  let exportsFiltered = false;
1028
1061
  let markedForRemoval = /* @__PURE__ */ new Set();
1029
1062
  traverse(ast, {
1030
- ExportDeclaration(path5) {
1031
- if (path5.node.type === "ExportNamedDeclaration") {
1032
- if (path5.node.specifiers.length) {
1033
- path5.node.specifiers = path5.node.specifiers.filter((specifier) => {
1063
+ ExportDeclaration(path7) {
1064
+ if (path7.node.type === "ExportNamedDeclaration") {
1065
+ if (path7.node.specifiers.length) {
1066
+ path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
1034
1067
  if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
1035
1068
  if (exportsToRemove.includes(specifier.exported.name)) {
1036
1069
  exportsFiltered = true;
@@ -1039,12 +1072,12 @@ var removeExports = (ast, exportsToRemove) => {
1039
1072
  }
1040
1073
  return true;
1041
1074
  });
1042
- if (path5.node.specifiers.length === 0) {
1043
- markedForRemoval.add(path5);
1075
+ if (path7.node.specifiers.length === 0) {
1076
+ markedForRemoval.add(path7);
1044
1077
  }
1045
1078
  }
1046
- if (path5.node.declaration?.type === "VariableDeclaration") {
1047
- let declaration = path5.node.declaration;
1079
+ if (path7.node.declaration?.type === "VariableDeclaration") {
1080
+ let declaration = path7.node.declaration;
1048
1081
  declaration.declarations = declaration.declarations.filter(
1049
1082
  (declaration2) => {
1050
1083
  if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
@@ -1058,37 +1091,37 @@ var removeExports = (ast, exportsToRemove) => {
1058
1091
  }
1059
1092
  );
1060
1093
  if (declaration.declarations.length === 0) {
1061
- markedForRemoval.add(path5);
1094
+ markedForRemoval.add(path7);
1062
1095
  }
1063
1096
  }
1064
- if (path5.node.declaration?.type === "FunctionDeclaration") {
1065
- let id2 = path5.node.declaration.id;
1066
- if (id2 && exportsToRemove.includes(id2.name)) {
1067
- markedForRemoval.add(path5);
1097
+ if (path7.node.declaration?.type === "FunctionDeclaration") {
1098
+ let id = path7.node.declaration.id;
1099
+ if (id && exportsToRemove.includes(id.name)) {
1100
+ markedForRemoval.add(path7);
1068
1101
  }
1069
1102
  }
1070
- if (path5.node.declaration?.type === "ClassDeclaration") {
1071
- let id2 = path5.node.declaration.id;
1072
- if (id2 && exportsToRemove.includes(id2.name)) {
1073
- markedForRemoval.add(path5);
1103
+ if (path7.node.declaration?.type === "ClassDeclaration") {
1104
+ let id = path7.node.declaration.id;
1105
+ if (id && exportsToRemove.includes(id.name)) {
1106
+ markedForRemoval.add(path7);
1074
1107
  }
1075
1108
  }
1076
1109
  }
1077
- if (path5.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1078
- markedForRemoval.add(path5);
1110
+ if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1111
+ markedForRemoval.add(path7);
1079
1112
  }
1080
1113
  }
1081
1114
  });
1082
1115
  if (markedForRemoval.size > 0 || exportsFiltered) {
1083
- for (let path5 of markedForRemoval) {
1084
- path5.remove();
1116
+ for (let path7 of markedForRemoval) {
1117
+ path7.remove();
1085
1118
  }
1086
1119
  (0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
1087
1120
  }
1088
1121
  };
1089
- function validateDestructuredExports(id2, exportsToRemove) {
1090
- if (id2.type === "ArrayPattern") {
1091
- for (let element of id2.elements) {
1122
+ function validateDestructuredExports(id, exportsToRemove) {
1123
+ if (id.type === "ArrayPattern") {
1124
+ for (let element of id.elements) {
1092
1125
  if (!element) {
1093
1126
  continue;
1094
1127
  }
@@ -1103,8 +1136,8 @@ function validateDestructuredExports(id2, exportsToRemove) {
1103
1136
  }
1104
1137
  }
1105
1138
  }
1106
- if (id2.type === "ObjectPattern") {
1107
- for (let property of id2.properties) {
1139
+ if (id.type === "ObjectPattern") {
1140
+ for (let property of id.properties) {
1108
1141
  if (!property) {
1109
1142
  continue;
1110
1143
  }
@@ -1128,16 +1161,16 @@ function invalidDestructureError(name) {
1128
1161
 
1129
1162
  // vite/with-props.ts
1130
1163
  var import_dedent2 = __toESM(require("dedent"));
1131
- var vmodId = id("with-props");
1164
+ var vmod = create("with-props");
1132
1165
  var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
1133
1166
  var plugin = {
1134
1167
  name: "react-router-with-props",
1135
1168
  enforce: "pre",
1136
- resolveId(id2) {
1137
- if (id2 === vmodId) return resolve3(vmodId);
1169
+ resolveId(id) {
1170
+ if (id === vmod.id) return vmod.resolvedId;
1138
1171
  },
1139
- async load(id2) {
1140
- if (id2 !== resolve3(vmodId)) return;
1172
+ async load(id) {
1173
+ if (id !== vmod.resolvedId) return;
1141
1174
  return import_dedent2.default`
1142
1175
  import { createElement as h } from "react";
1143
1176
  import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
@@ -1179,44 +1212,44 @@ var plugin = {
1179
1212
  };
1180
1213
  var transform = (ast) => {
1181
1214
  const hocs = [];
1182
- function getHocUid(path5, hocName) {
1183
- const uid = path5.scope.generateUidIdentifier(hocName);
1215
+ function getHocUid(path7, hocName) {
1216
+ const uid = path7.scope.generateUidIdentifier(hocName);
1184
1217
  hocs.push([hocName, uid]);
1185
1218
  return uid;
1186
1219
  }
1187
1220
  traverse(ast, {
1188
- ExportDeclaration(path5) {
1189
- if (path5.isExportDefaultDeclaration()) {
1190
- const declaration = path5.get("declaration");
1221
+ ExportDeclaration(path7) {
1222
+ if (path7.isExportDefaultDeclaration()) {
1223
+ const declaration = path7.get("declaration");
1191
1224
  const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
1192
1225
  if (expr) {
1193
- const uid = getHocUid(path5, "withComponentProps");
1226
+ const uid = getHocUid(path7, "withComponentProps");
1194
1227
  declaration.replaceWith(t.callExpression(uid, [expr]));
1195
1228
  }
1196
1229
  return;
1197
1230
  }
1198
- if (path5.isExportNamedDeclaration()) {
1199
- const decl = path5.get("declaration");
1231
+ if (path7.isExportNamedDeclaration()) {
1232
+ const decl = path7.get("declaration");
1200
1233
  if (decl.isVariableDeclaration()) {
1201
1234
  decl.get("declarations").forEach((varDeclarator) => {
1202
- const id2 = varDeclarator.get("id");
1235
+ const id = varDeclarator.get("id");
1203
1236
  const init = varDeclarator.get("init");
1204
1237
  const expr = init.node;
1205
1238
  if (!expr) return;
1206
- if (!id2.isIdentifier()) return;
1207
- const { name } = id2.node;
1239
+ if (!id.isIdentifier()) return;
1240
+ const { name } = id.node;
1208
1241
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1209
- const uid = getHocUid(path5, `with${name}Props`);
1242
+ const uid = getHocUid(path7, `with${name}Props`);
1210
1243
  init.replaceWith(t.callExpression(uid, [expr]));
1211
1244
  });
1212
1245
  return;
1213
1246
  }
1214
1247
  if (decl.isFunctionDeclaration()) {
1215
- const { id: id2 } = decl.node;
1216
- if (!id2) return;
1217
- const { name } = id2;
1248
+ const { id } = decl.node;
1249
+ if (!id) return;
1250
+ const { name } = id;
1218
1251
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1219
- const uid = getHocUid(path5, `with${name}Props`);
1252
+ const uid = getHocUid(path7, `with${name}Props`);
1220
1253
  decl.replaceWith(
1221
1254
  t.variableDeclaration("const", [
1222
1255
  t.variableDeclarator(
@@ -1235,7 +1268,7 @@ var transform = (ast) => {
1235
1268
  hocs.map(
1236
1269
  ([name, identifier]) => t.importSpecifier(identifier, t.identifier(name))
1237
1270
  ),
1238
- t.stringLiteral(vmodId)
1271
+ t.stringLiteral(vmod.id)
1239
1272
  )
1240
1273
  );
1241
1274
  }
@@ -1264,27 +1297,23 @@ var CLIENT_ROUTE_EXPORTS = [
1264
1297
  "meta",
1265
1298
  "shouldRevalidate"
1266
1299
  ];
1267
- var ROUTE_ENTRY_QUERY_STRING = "?route-entry=1";
1268
- var isRouteEntry = (id2) => {
1269
- return id2.endsWith(ROUTE_ENTRY_QUERY_STRING);
1270
- };
1271
- var serverBuildId = id("server-build");
1272
- var serverManifestId = id("server-manifest");
1273
- var browserManifestId = id("browser-manifest");
1274
- var hmrRuntimeId = id("hmr-runtime");
1275
- var injectHmrRuntimeId = id("inject-hmr-runtime");
1300
+ var BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route";
1301
+ var virtualHmrRuntime = create("hmr-runtime");
1302
+ var virtualInjectHmrRuntime = create("inject-hmr-runtime");
1276
1303
  var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
1277
- let vite2 = importViteEsmSync();
1304
+ let vite2 = getVite();
1278
1305
  let file = route.file;
1279
- let fullPath = path4.resolve(reactRouterConfig.appDirectory, file);
1306
+ let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
1280
1307
  return vite2.normalizePath(fullPath);
1281
1308
  };
1282
- var vmods = [serverBuildId, serverManifestId, browserManifestId];
1309
+ var virtual = {
1310
+ serverBuild: create("server-build"),
1311
+ serverManifest: create("server-manifest"),
1312
+ browserManifest: create("browser-manifest")
1313
+ };
1283
1314
  var invalidateVirtualModules = (viteDevServer) => {
1284
- vmods.forEach((vmod) => {
1285
- let mod = viteDevServer.moduleGraph.getModuleById(
1286
- resolve3(vmod)
1287
- );
1315
+ Object.values(virtual).forEach((vmod2) => {
1316
+ let mod = viteDevServer.moduleGraph.getModuleById(vmod2.resolvedId);
1288
1317
  if (mod) {
1289
1318
  viteDevServer.moduleGraph.invalidateModule(mod);
1290
1319
  }
@@ -1295,11 +1324,11 @@ var getHash = (source, maxLength) => {
1295
1324
  return typeof maxLength === "number" ? hash.slice(0, maxLength) : hash;
1296
1325
  };
1297
1326
  var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
1298
- let vite2 = importViteEsmSync();
1327
+ let vite2 = getVite();
1299
1328
  let rootRelativeFilePath = vite2.normalizePath(
1300
- path4.relative(ctx.rootDirectory, absoluteFilePath)
1329
+ path6.relative(ctx.rootDirectory, absoluteFilePath)
1301
1330
  );
1302
- let entryChunk = viteManifest[rootRelativeFilePath + ROUTE_ENTRY_QUERY_STRING] ?? viteManifest[rootRelativeFilePath];
1331
+ let entryChunk = viteManifest[rootRelativeFilePath + BUILD_CLIENT_ROUTE_QUERY_STRING] ?? viteManifest[rootRelativeFilePath];
1303
1332
  if (!entryChunk) {
1304
1333
  let knownManifestKeys = Object.keys(viteManifest).map((key) => '"' + key + '"').join(", ");
1305
1334
  throw new Error(
@@ -1349,7 +1378,7 @@ function dedupe(array2) {
1349
1378
  return [...new Set(array2)];
1350
1379
  }
1351
1380
  var writeFileSafe = async (file, contents) => {
1352
- await fse.ensureDir(path4.dirname(file));
1381
+ await fse.ensureDir(path6.dirname(file));
1353
1382
  await fse.writeFile(file, contents);
1354
1383
  };
1355
1384
  var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
@@ -1371,20 +1400,20 @@ var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteF
1371
1400
  }
1372
1401
  let ssr = true;
1373
1402
  let { pluginContainer, moduleGraph } = viteChildCompiler;
1374
- let routePath = path4.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
1375
- let url3 = resolveFileUrl(ctx, routePath);
1403
+ let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
1404
+ let url2 = resolveFileUrl(ctx, routePath);
1376
1405
  let resolveId = async () => {
1377
- let result = await pluginContainer.resolveId(url3, void 0, { ssr });
1378
- if (!result) throw new Error(`Could not resolve module ID for ${url3}`);
1406
+ let result = await pluginContainer.resolveId(url2, void 0, { ssr });
1407
+ if (!result) throw new Error(`Could not resolve module ID for ${url2}`);
1379
1408
  return result.id;
1380
1409
  };
1381
- let [id2, code] = await Promise.all([
1410
+ let [id, code] = await Promise.all([
1382
1411
  resolveId(),
1383
1412
  readRouteFile?.() ?? fse.readFile(routePath, "utf-8"),
1384
1413
  // pluginContainer.transform(...) fails if we don't do this first:
1385
- moduleGraph.ensureEntryFromUrl(url3, ssr)
1414
+ moduleGraph.ensureEntryFromUrl(url2, ssr)
1386
1415
  ]);
1387
- let transformed = await pluginContainer.transform(code, id2, { ssr });
1416
+ let transformed = await pluginContainer.transform(code, id, { ssr });
1388
1417
  let [, exports2] = (0, import_es_module_lexer.parse)(transformed.code);
1389
1418
  let exportNames = exports2.map((e) => e.n);
1390
1419
  return exportNames;
@@ -1395,19 +1424,19 @@ var getServerBundleBuildConfig = (viteUserConfig) => {
1395
1424
  }
1396
1425
  return viteUserConfig.__reactRouterServerBundleBuildConfig;
1397
1426
  };
1398
- var getServerBuildDirectory = (ctx) => path4.join(
1427
+ var getServerBuildDirectory = (ctx) => path6.join(
1399
1428
  ctx.reactRouterConfig.buildDirectory,
1400
1429
  "server",
1401
1430
  ...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
1402
1431
  );
1403
- var getClientBuildDirectory = (reactRouterConfig) => path4.join(reactRouterConfig.buildDirectory, "client");
1404
- var defaultEntriesDir = path4.resolve(
1405
- path4.dirname(require.resolve("@react-router/dev/package.json")),
1432
+ var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
1433
+ var defaultEntriesDir = path6.resolve(
1434
+ path6.dirname(require.resolve("@react-router/dev/package.json")),
1406
1435
  "dist",
1407
1436
  "config",
1408
1437
  "defaults"
1409
1438
  );
1410
- var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path4.join(defaultEntriesDir, filename3));
1439
+ var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
1411
1440
  invariant(defaultEntries.length > 0, "No default entries found");
1412
1441
  var reactRouterDevLoadContext = () => ({});
1413
1442
  var reactRouterVitePlugin = () => {
@@ -1489,12 +1518,14 @@ var reactRouterVitePlugin = () => {
1489
1518
  resolveFileUrl(
1490
1519
  ctx,
1491
1520
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
1492
- ) + ROUTE_ENTRY_QUERY_STRING
1521
+ )
1493
1522
  )};`;
1494
1523
  }).join("\n")}
1495
- export { default as assets } from ${JSON.stringify(serverManifestId)};
1524
+ export { default as assets } from ${JSON.stringify(
1525
+ virtual.serverManifest.id
1526
+ )};
1496
1527
  export const assetsBuildDirectory = ${JSON.stringify(
1497
- path4.relative(
1528
+ path6.relative(
1498
1529
  ctx.rootDirectory,
1499
1530
  getClientBuildDirectory(ctx.reactRouterConfig)
1500
1531
  )
@@ -1520,7 +1551,7 @@ var reactRouterVitePlugin = () => {
1520
1551
  };
1521
1552
  let loadViteManifest = async (directory) => {
1522
1553
  let manifestContents = await fse.readFile(
1523
- path4.resolve(directory, ".vite", "manifest.json"),
1554
+ path6.resolve(directory, ".vite", "manifest.json"),
1524
1555
  "utf-8"
1525
1556
  );
1526
1557
  return JSON.parse(manifestContents);
@@ -1556,7 +1587,7 @@ var reactRouterVitePlugin = () => {
1556
1587
  ctx
1557
1588
  );
1558
1589
  for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
1559
- let routeFilePath = path4.join(
1590
+ let routeFilePath = path6.join(
1560
1591
  ctx.reactRouterConfig.appDirectory,
1561
1592
  route.file
1562
1593
  );
@@ -1591,18 +1622,18 @@ var reactRouterVitePlugin = () => {
1591
1622
  }
1592
1623
  let fingerprintedValues = { entry, routes: browserRoutes };
1593
1624
  let version = getHash(JSON.stringify(fingerprintedValues), 8);
1594
- let manifestPath = path4.posix.join(
1625
+ let manifestPath = path6.posix.join(
1595
1626
  viteConfig.build.assetsDir,
1596
1627
  `manifest-${version}.js`
1597
1628
  );
1598
- let url3 = `${ctx.publicPath}${manifestPath}`;
1599
- let nonFingerprintedValues = { url: url3, version };
1629
+ let url2 = `${ctx.publicPath}${manifestPath}`;
1630
+ let nonFingerprintedValues = { url: url2, version };
1600
1631
  let reactRouterBrowserManifest = {
1601
1632
  ...fingerprintedValues,
1602
1633
  ...nonFingerprintedValues
1603
1634
  };
1604
1635
  await writeFileSafe(
1605
- path4.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
1636
+ path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
1606
1637
  `window.__reactRouterManifest=${JSON.stringify(
1607
1638
  reactRouterBrowserManifest
1608
1639
  )};`
@@ -1632,10 +1663,10 @@ var reactRouterVitePlugin = () => {
1632
1663
  caseSensitive: route.caseSensitive,
1633
1664
  module: combineURLs(
1634
1665
  ctx.publicPath,
1635
- `${resolveFileUrl(
1666
+ resolveFileUrl(
1636
1667
  ctx,
1637
1668
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
1638
- )}${ROUTE_ENTRY_QUERY_STRING}`
1669
+ )
1639
1670
  ),
1640
1671
  hasAction: sourceExports.includes("action"),
1641
1672
  hasLoader: sourceExports.includes("loader"),
@@ -1647,12 +1678,9 @@ var reactRouterVitePlugin = () => {
1647
1678
  }
1648
1679
  return {
1649
1680
  version: String(Math.random()),
1650
- url: combineURLs(ctx.publicPath, url(browserManifestId)),
1681
+ url: combineURLs(ctx.publicPath, virtual.browserManifest.url),
1651
1682
  hmr: {
1652
- runtime: combineURLs(
1653
- ctx.publicPath,
1654
- url(injectHmrRuntimeId)
1655
- )
1683
+ runtime: combineURLs(ctx.publicPath, virtualInjectHmrRuntime.url)
1656
1684
  },
1657
1685
  entry: {
1658
1686
  module: combineURLs(
@@ -1668,11 +1696,17 @@ var reactRouterVitePlugin = () => {
1668
1696
  {
1669
1697
  name: "react-router",
1670
1698
  config: async (_viteUserConfig, _viteConfigEnv) => {
1671
- await preloadViteEsm();
1672
- let vite2 = importViteEsmSync();
1699
+ await preloadVite();
1700
+ let vite2 = getVite();
1673
1701
  viteUserConfig = _viteUserConfig;
1674
1702
  viteConfigEnv = _viteConfigEnv;
1675
1703
  viteCommand = viteConfigEnv.command;
1704
+ let viteClientConditions = [
1705
+ ...vite2.defaultClientConditions ?? []
1706
+ ];
1707
+ let viteServerConditions = [
1708
+ ...vite2.defaultServerConditions ?? []
1709
+ ];
1676
1710
  logger = vite2.createLogger(viteUserConfig.logLevel, {
1677
1711
  prefix: "[react-router]"
1678
1712
  });
@@ -1722,15 +1756,15 @@ var reactRouterVitePlugin = () => {
1722
1756
  ssr: {
1723
1757
  external: ssrExternals,
1724
1758
  resolve: {
1725
- conditions: viteCommand === "build" ? [] : ["development"],
1726
- externalConditions: viteCommand === "build" ? [] : ["development"]
1759
+ conditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions],
1760
+ externalConditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions]
1727
1761
  }
1728
1762
  },
1729
1763
  optimizeDeps: {
1730
1764
  entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
1731
1765
  ctx.entryClientFilePath,
1732
1766
  ...Object.values(ctx.reactRouterConfig.routes).map(
1733
- (route) => path4.join(ctx.reactRouterConfig.appDirectory, route.file)
1767
+ (route) => path6.join(ctx.reactRouterConfig.appDirectory, route.file)
1734
1768
  )
1735
1769
  ] : [],
1736
1770
  include: [
@@ -1764,7 +1798,7 @@ var reactRouterVitePlugin = () => {
1764
1798
  "react-router/dom",
1765
1799
  "react-router-dom"
1766
1800
  ],
1767
- conditions: viteCommand === "build" ? [] : ["development"]
1801
+ conditions: viteCommand === "build" ? viteClientConditions : ["development", ...viteClientConditions]
1768
1802
  },
1769
1803
  base: viteUserConfig.base,
1770
1804
  // When consumer provides an allow list for files that can be read by
@@ -1786,10 +1820,10 @@ var reactRouterVitePlugin = () => {
1786
1820
  input: [
1787
1821
  ctx.entryClientFilePath,
1788
1822
  ...Object.values(ctx.reactRouterConfig.routes).map(
1789
- (route) => `${path4.resolve(
1823
+ (route) => `${path6.resolve(
1790
1824
  ctx.reactRouterConfig.appDirectory,
1791
1825
  route.file
1792
- )}${ROUTE_ENTRY_QUERY_STRING}`
1826
+ )}${BUILD_CLIENT_ROUTE_QUERY_STRING}`
1793
1827
  )
1794
1828
  ]
1795
1829
  }
@@ -1808,7 +1842,7 @@ var reactRouterVitePlugin = () => {
1808
1842
  rollupOptions: {
1809
1843
  ...baseRollupOptions,
1810
1844
  preserveEntrySignatures: "exports-only",
1811
- input: viteUserConfig.build?.rollupOptions?.input ?? serverBuildId,
1845
+ input: viteUserConfig.build?.rollupOptions?.input ?? virtual.serverBuild.id,
1812
1846
  output: {
1813
1847
  entryFileNames: ctx.reactRouterConfig.serverBuildFile,
1814
1848
  format: ctx.reactRouterConfig.serverModuleFormat
@@ -1835,7 +1869,7 @@ var reactRouterVitePlugin = () => {
1835
1869
  "The React Router Vite plugin requires the use of a Vite config file"
1836
1870
  );
1837
1871
  }
1838
- let vite2 = importViteEsmSync();
1872
+ let vite2 = getVite();
1839
1873
  let childCompilerConfigFile = await vite2.loadConfigFromFile(
1840
1874
  {
1841
1875
  command: viteConfig.command,
@@ -1871,15 +1905,15 @@ var reactRouterVitePlugin = () => {
1871
1905
  envFile: false,
1872
1906
  plugins: [
1873
1907
  ...(childCompilerConfigFile.config.plugins ?? []).flat().filter(
1874
- (plugin2) => typeof plugin2 === "object" && plugin2 !== null && "name" in plugin2 && plugin2.name !== "react-router" && plugin2.name !== "react-router-route-exports" && plugin2.name !== "react-router-hmr-updates"
1908
+ (plugin2) => typeof plugin2 === "object" && plugin2 !== null && "name" in plugin2 && plugin2.name !== "react-router" && plugin2.name !== "react-router:route-exports" && plugin2.name !== "react-router:hmr-updates"
1875
1909
  )
1876
1910
  ]
1877
1911
  });
1878
1912
  await viteChildCompiler.pluginContainer.buildStart({});
1879
1913
  },
1880
- async transform(code, id2) {
1881
- if (isCssModulesFile(id2)) {
1882
- cssModulesManifest[id2] = code;
1914
+ async transform(code, id) {
1915
+ if (isCssModulesFile(id)) {
1916
+ cssModulesManifest[id] = code;
1883
1917
  }
1884
1918
  },
1885
1919
  buildStart() {
@@ -1903,7 +1937,7 @@ var reactRouterVitePlugin = () => {
1903
1937
  (0, import_react_router2.unstable_setDevServerHooks)({
1904
1938
  // Give the request handler access to the critical CSS in dev to avoid a
1905
1939
  // flash of unstyled content since Vite injects CSS file contents via JS
1906
- getCriticalCss: async (build, url3) => {
1940
+ getCriticalCss: async (build, url2) => {
1907
1941
  return getStylesForUrl({
1908
1942
  rootDirectory: ctx.rootDirectory,
1909
1943
  entryClientFilePath: ctx.entryClientFilePath,
@@ -1911,7 +1945,7 @@ var reactRouterVitePlugin = () => {
1911
1945
  viteDevServer,
1912
1946
  cssModulesManifest,
1913
1947
  build,
1914
- url: url3
1948
+ url: url2
1915
1949
  });
1916
1950
  },
1917
1951
  // If an error is caught within the request handler, let Vite fix the
@@ -1959,7 +1993,7 @@ var reactRouterVitePlugin = () => {
1959
1993
  viteDevServer.middlewares.use(async (req, res, next) => {
1960
1994
  try {
1961
1995
  let build = await viteDevServer.ssrLoadModule(
1962
- serverBuildId
1996
+ virtual.serverBuild.id
1963
1997
  );
1964
1998
  let handler = (0, import_react_router2.createRequestHandler)(build, "development");
1965
1999
  let nodeHandler = async (nodeReq, nodeRes) => {
@@ -1994,8 +2028,8 @@ var reactRouterVitePlugin = () => {
1994
2028
  let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
1995
2029
  let movedAssetPaths = [];
1996
2030
  for (let ssrAssetPath of ssrAssetPaths) {
1997
- let src = path4.join(serverBuildDirectory, ssrAssetPath);
1998
- let dest = path4.join(clientBuildDirectory, ssrAssetPath);
2031
+ let src = path6.join(serverBuildDirectory, ssrAssetPath);
2032
+ let dest = path6.join(clientBuildDirectory, ssrAssetPath);
1999
2033
  if (!fse.existsSync(dest)) {
2000
2034
  await fse.move(src, dest);
2001
2035
  movedAssetPaths.push(dest);
@@ -2008,7 +2042,7 @@ var reactRouterVitePlugin = () => {
2008
2042
  );
2009
2043
  await Promise.all(
2010
2044
  ssrCssPaths.map(
2011
- (cssPath) => fse.remove(path4.join(serverBuildDirectory, cssPath))
2045
+ (cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
2012
2046
  )
2013
2047
  );
2014
2048
  if (movedAssetPaths.length) {
@@ -2017,7 +2051,7 @@ var reactRouterVitePlugin = () => {
2017
2051
  "",
2018
2052
  `${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
2019
2053
  ...movedAssetPaths.map(
2020
- (movedAssetPath) => import_picocolors3.default.dim(path4.relative(ctx.rootDirectory, movedAssetPath))
2054
+ (movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
2021
2055
  ),
2022
2056
  ""
2023
2057
  ].join("\n")
@@ -2059,12 +2093,12 @@ var reactRouterVitePlugin = () => {
2059
2093
  }
2060
2094
  },
2061
2095
  {
2062
- name: "react-router-route-entry",
2096
+ name: "react-router:build-client-route",
2063
2097
  enforce: "pre",
2064
- async transform(_code, id2, options) {
2065
- if (!isRouteEntry(id2)) return;
2066
- let routeModuleId = id2.replace(ROUTE_ENTRY_QUERY_STRING, "");
2067
- let routeFileName = path4.basename(routeModuleId);
2098
+ async transform(_code, id, options) {
2099
+ if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
2100
+ let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
2101
+ let routeFileName = path6.basename(routeModuleId);
2068
2102
  let sourceExports = await getRouteModuleExports(
2069
2103
  viteChildCompiler,
2070
2104
  ctx,
@@ -2077,23 +2111,24 @@ var reactRouterVitePlugin = () => {
2077
2111
  }
2078
2112
  },
2079
2113
  {
2080
- name: "react-router-virtual-modules",
2114
+ name: "react-router:virtual-modules",
2081
2115
  enforce: "pre",
2082
- resolveId(id2) {
2083
- if (vmods.includes(id2)) return resolve3(id2);
2116
+ resolveId(id) {
2117
+ const vmod2 = Object.values(virtual).find((vmod3) => vmod3.id === id);
2118
+ if (vmod2) return vmod2.resolvedId;
2084
2119
  },
2085
- async load(id2) {
2086
- switch (id2) {
2087
- case resolve3(serverBuildId): {
2120
+ async load(id) {
2121
+ switch (id) {
2122
+ case virtual.serverBuild.resolvedId: {
2088
2123
  return await getServerEntry();
2089
2124
  }
2090
- case resolve3(serverManifestId): {
2125
+ case virtual.serverManifest.resolvedId: {
2091
2126
  let reactRouterManifest = ctx.isSsrBuild ? await ctx.getReactRouterServerManifest() : await getReactRouterManifestForDev();
2092
2127
  return `export default ${(0, import_jsesc.default)(reactRouterManifest, {
2093
2128
  es6: true
2094
2129
  })};`;
2095
2130
  }
2096
- case resolve3(browserManifestId): {
2131
+ case virtual.browserManifest.resolvedId: {
2097
2132
  if (viteCommand === "build") {
2098
2133
  throw new Error("This module only exists in development");
2099
2134
  }
@@ -2107,15 +2142,15 @@ var reactRouterVitePlugin = () => {
2107
2142
  }
2108
2143
  },
2109
2144
  {
2110
- name: "react-router-dot-server",
2145
+ name: "react-router:dot-server",
2111
2146
  enforce: "pre",
2112
- async resolveId(id2, importer, options) {
2147
+ async resolveId(id, importer, options) {
2113
2148
  let isOptimizeDeps = viteCommand === "serve" && options?.scan === true;
2114
2149
  if (isOptimizeDeps || options?.ssr) return;
2115
- let isResolving = options?.custom?.["react-router-dot-server"] ?? false;
2150
+ let isResolving = options?.custom?.["react-router:dot-server"] ?? false;
2116
2151
  if (isResolving) return;
2117
- options.custom = { ...options.custom, "react-router-dot-server": true };
2118
- let resolved = await this.resolve(id2, importer, options);
2152
+ options.custom = { ...options.custom, "react-router:dot-server": true };
2153
+ let resolved = await this.resolve(id, importer, options);
2119
2154
  if (!resolved) return;
2120
2155
  let serverFileRE = /\.server(\.[cm]?[jt]sx?)?$/;
2121
2156
  let serverDirRE = /\/\.server\//;
@@ -2125,9 +2160,9 @@ var reactRouterVitePlugin = () => {
2125
2160
  if (viteCommand !== "build" && importer.endsWith(".html")) {
2126
2161
  return;
2127
2162
  }
2128
- let vite2 = importViteEsmSync();
2163
+ let vite2 = getVite();
2129
2164
  let importerShort = vite2.normalizePath(
2130
- path4.relative(ctx.rootDirectory, importer)
2165
+ path6.relative(ctx.rootDirectory, importer)
2131
2166
  );
2132
2167
  let isRoute = getRoute(ctx.reactRouterConfig, importer);
2133
2168
  if (isRoute) {
@@ -2138,12 +2173,12 @@ var reactRouterVitePlugin = () => {
2138
2173
  [
2139
2174
  import_picocolors3.default.red(`Server-only module referenced by client`),
2140
2175
  "",
2141
- ` '${id2}' imported by route '${importerShort}'`,
2176
+ ` '${id}' imported by route '${importerShort}'`,
2142
2177
  "",
2143
2178
  ` React Router automatically removes server-code from these exports:`,
2144
2179
  ` ${serverOnlyExports}`,
2145
2180
  "",
2146
- ` But other route exports in '${importerShort}' depend on '${id2}'.`,
2181
+ ` But other route exports in '${importerShort}' depend on '${id}'.`,
2147
2182
  "",
2148
2183
  " See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
2149
2184
  ""
@@ -2154,7 +2189,7 @@ var reactRouterVitePlugin = () => {
2154
2189
  [
2155
2190
  import_picocolors3.default.red(`Server-only module referenced by client`),
2156
2191
  "",
2157
- ` '${id2}' imported by '${importerShort}'`,
2192
+ ` '${id}' imported by '${importerShort}'`,
2158
2193
  "",
2159
2194
  " See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
2160
2195
  ""
@@ -2163,12 +2198,12 @@ var reactRouterVitePlugin = () => {
2163
2198
  }
2164
2199
  },
2165
2200
  {
2166
- name: "react-router-dot-client",
2167
- async transform(code, id2, options) {
2201
+ name: "react-router:dot-client",
2202
+ async transform(code, id, options) {
2168
2203
  if (!options?.ssr) return;
2169
2204
  let clientFileRE = /\.client(\.[cm]?[jt]sx?)?$/;
2170
2205
  let clientDirRE = /\/\.client\//;
2171
- if (clientFileRE.test(id2) || clientDirRE.test(id2)) {
2206
+ if (clientFileRE.test(id) || clientDirRE.test(id)) {
2172
2207
  let exports2 = (0, import_es_module_lexer.parse)(code)[1];
2173
2208
  return {
2174
2209
  code: exports2.map(
@@ -2181,9 +2216,9 @@ var reactRouterVitePlugin = () => {
2181
2216
  },
2182
2217
  plugin,
2183
2218
  {
2184
- name: "react-router-route-exports",
2185
- async transform(code, id2, options) {
2186
- let route = getRoute(ctx.reactRouterConfig, id2);
2219
+ name: "react-router:route-exports",
2220
+ async transform(code, id, options) {
2221
+ let route = getRoute(ctx.reactRouterConfig, id);
2187
2222
  if (!route) return;
2188
2223
  if (!options?.ssr && !ctx.reactRouterConfig.ssr) {
2189
2224
  let serverOnlyExports = (0, import_es_module_lexer.parse)(code)[1].map((exp) => exp.n).filter((exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp));
@@ -2200,7 +2235,7 @@ var reactRouterVitePlugin = () => {
2200
2235
  }
2201
2236
  }
2202
2237
  }
2203
- let [filepath] = id2.split("?");
2238
+ let [filepath] = id.split("?");
2204
2239
  let ast = (0, import_parser.parse)(code, { sourceType: "module" });
2205
2240
  if (!options?.ssr) {
2206
2241
  removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS);
@@ -2208,22 +2243,23 @@ var reactRouterVitePlugin = () => {
2208
2243
  transform(ast);
2209
2244
  return generate2(ast, {
2210
2245
  sourceMaps: true,
2211
- filename: id2,
2246
+ filename: id,
2212
2247
  sourceFileName: filepath
2213
2248
  });
2214
2249
  }
2215
2250
  },
2216
2251
  {
2217
- name: "react-router-inject-hmr-runtime",
2252
+ name: "react-router:inject-hmr-runtime",
2218
2253
  enforce: "pre",
2219
- resolveId(id2) {
2220
- if (id2 === injectHmrRuntimeId)
2221
- return resolve3(injectHmrRuntimeId);
2254
+ resolveId(id) {
2255
+ if (id === virtualInjectHmrRuntime.id) {
2256
+ return virtualInjectHmrRuntime.resolvedId;
2257
+ }
2222
2258
  },
2223
- async load(id2) {
2224
- if (id2 !== resolve3(injectHmrRuntimeId)) return;
2259
+ async load(id) {
2260
+ if (id !== virtualInjectHmrRuntime.resolvedId) return;
2225
2261
  return [
2226
- `import RefreshRuntime from "${hmrRuntimeId}"`,
2262
+ `import RefreshRuntime from "${virtualHmrRuntime.id}"`,
2227
2263
  "RefreshRuntime.injectIntoGlobalHook(window)",
2228
2264
  "window.$RefreshReg$ = () => {}",
2229
2265
  "window.$RefreshSig$ = () => (type) => type",
@@ -2232,17 +2268,17 @@ var reactRouterVitePlugin = () => {
2232
2268
  }
2233
2269
  },
2234
2270
  {
2235
- name: "react-router-hmr-runtime",
2271
+ name: "react-router:hmr-runtime",
2236
2272
  enforce: "pre",
2237
- resolveId(id2) {
2238
- if (id2 === hmrRuntimeId) return resolve3(hmrRuntimeId);
2273
+ resolveId(id) {
2274
+ if (id === virtualHmrRuntime.id) return virtualHmrRuntime.resolvedId;
2239
2275
  },
2240
- async load(id2) {
2241
- if (id2 !== resolve3(hmrRuntimeId)) return;
2242
- let reactRefreshDir = path4.dirname(
2276
+ async load(id) {
2277
+ if (id !== virtualHmrRuntime.resolvedId) return;
2278
+ let reactRefreshDir = path6.dirname(
2243
2279
  require.resolve("react-refresh/package.json")
2244
2280
  );
2245
- let reactRefreshRuntimePath = path4.join(
2281
+ let reactRefreshRuntimePath = path6.join(
2246
2282
  reactRefreshDir,
2247
2283
  "cjs/react-refresh-runtime.development.js"
2248
2284
  );
@@ -2258,11 +2294,11 @@ var reactRouterVitePlugin = () => {
2258
2294
  }
2259
2295
  },
2260
2296
  {
2261
- name: "react-router-react-refresh-babel",
2262
- async transform(code, id2, options) {
2297
+ name: "react-router:react-refresh-babel",
2298
+ async transform(code, id, options) {
2263
2299
  if (viteCommand !== "serve") return;
2264
- if (id2.includes("/node_modules/")) return;
2265
- let [filepath] = id2.split("?");
2300
+ if (id.includes("/node_modules/")) return;
2301
+ let [filepath] = id.split("?");
2266
2302
  let extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
2267
2303
  if (!extensionsRE.test(filepath)) return;
2268
2304
  let devRuntime = "react/jsx-dev-runtime";
@@ -2270,13 +2306,10 @@ var reactRouterVitePlugin = () => {
2270
2306
  let isJSX = filepath.endsWith("x");
2271
2307
  let useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
2272
2308
  if (!useFastRefresh) return;
2273
- if (isRouteEntry(id2)) {
2274
- return { code: addRefreshWrapper(ctx.reactRouterConfig, code, id2) };
2275
- }
2276
2309
  let result = await babel.transformAsync(code, {
2277
2310
  babelrc: false,
2278
2311
  configFile: false,
2279
- filename: id2,
2312
+ filename: id,
2280
2313
  sourceFileName: filepath,
2281
2314
  parserOpts: {
2282
2315
  sourceType: "module",
@@ -2289,18 +2322,18 @@ var reactRouterVitePlugin = () => {
2289
2322
  code = result.code;
2290
2323
  let refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
2291
2324
  if (refreshContentRE.test(code)) {
2292
- code = addRefreshWrapper(ctx.reactRouterConfig, code, id2);
2325
+ code = addRefreshWrapper(ctx.reactRouterConfig, code, id);
2293
2326
  }
2294
2327
  return { code, map: result.map };
2295
2328
  }
2296
2329
  },
2297
2330
  {
2298
- name: "react-router-hmr-updates",
2331
+ name: "react-router:hmr-updates",
2299
2332
  async handleHotUpdate({ server, file, modules, read }) {
2300
2333
  let route = getRoute(ctx.reactRouterConfig, file);
2301
2334
  let hmrEventData = { route: null };
2302
2335
  if (route) {
2303
- let serverManifest = (await server.ssrLoadModule(serverManifestId)).default;
2336
+ let serverManifest = (await server.ssrLoadModule(virtual.serverManifest.id)).default;
2304
2337
  let oldRouteMetadata = serverManifest.routes[route.id];
2305
2338
  let newRouteMetadata = await getRouteMetadata(
2306
2339
  ctx,
@@ -2326,12 +2359,58 @@ var reactRouterVitePlugin = () => {
2326
2359
  });
2327
2360
  return modules;
2328
2361
  }
2362
+ },
2363
+ {
2364
+ name: "react-router-server-change-trigger-client-hmr",
2365
+ // This hook is only available in Vite v6+ so this is a no-op in v5.
2366
+ // Previously the server and client modules were shared in a single module
2367
+ // graph. This meant that changes to server code automatically resulted in
2368
+ // client HMR updates. In Vite v6+ these module graphs are separate from
2369
+ // each other so we need to manually trigger client HMR updates if server
2370
+ // code has changed.
2371
+ hotUpdate({ server, modules }) {
2372
+ if (this.environment.name !== "ssr" && modules.length <= 0) {
2373
+ return;
2374
+ }
2375
+ let clientModules = uniqueNodes(
2376
+ modules.flatMap(
2377
+ (mod) => getParentClientNodes(server.environments.client.moduleGraph, mod)
2378
+ )
2379
+ );
2380
+ for (let clientModule of clientModules) {
2381
+ server.environments.client.reloadModule(clientModule);
2382
+ }
2383
+ }
2329
2384
  }
2330
2385
  ];
2331
2386
  };
2332
- function addRefreshWrapper(reactRouterConfig, code, id2) {
2333
- let route = getRoute(reactRouterConfig, id2);
2334
- let acceptExports = route || isRouteEntry(id2) ? [
2387
+ function getParentClientNodes(clientModuleGraph, module2) {
2388
+ if (!module2.id) {
2389
+ return [];
2390
+ }
2391
+ let clientModule = clientModuleGraph.getModuleById(module2.id);
2392
+ if (clientModule) {
2393
+ return [clientModule];
2394
+ }
2395
+ return [...module2.importers].flatMap(
2396
+ (importer) => getParentClientNodes(clientModuleGraph, importer)
2397
+ );
2398
+ }
2399
+ function uniqueNodes(nodes) {
2400
+ let nodeUrls = /* @__PURE__ */ new Set();
2401
+ let unique = [];
2402
+ for (let node of nodes) {
2403
+ if (nodeUrls.has(node.url)) {
2404
+ continue;
2405
+ }
2406
+ nodeUrls.add(node.url);
2407
+ unique.push(node);
2408
+ }
2409
+ return unique;
2410
+ }
2411
+ function addRefreshWrapper(reactRouterConfig, code, id) {
2412
+ let route = getRoute(reactRouterConfig, id);
2413
+ let acceptExports = route ? [
2335
2414
  "clientAction",
2336
2415
  "clientLoader",
2337
2416
  "handle",
@@ -2339,25 +2418,10 @@ function addRefreshWrapper(reactRouterConfig, code, id2) {
2339
2418
  "links",
2340
2419
  "shouldRevalidate"
2341
2420
  ] : [];
2342
- return "\n\n" + withCommentBoundaries(
2343
- "REACT REFRESH HEADER",
2344
- REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id2))
2345
- ) + "\n\n" + withCommentBoundaries("REACT REFRESH BODY", code) + "\n\n" + withCommentBoundaries(
2346
- "REACT REFRESH FOOTER",
2347
- REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id2)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(route?.id))
2348
- ) + "\n";
2349
- }
2350
- function withCommentBoundaries(label, text) {
2351
- let begin = `// [BEGIN] ${label} `;
2352
- begin += "-".repeat(80 - begin.length);
2353
- let end = `// [END] ${label} `;
2354
- end += "-".repeat(80 - end.length);
2355
- return `${begin}
2356
- ${text}
2357
- ${end}`;
2421
+ return REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id)) + code + REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(route?.id));
2358
2422
  }
2359
2423
  var REACT_REFRESH_HEADER = `
2360
- import RefreshRuntime from "${hmrRuntimeId}";
2424
+ import RefreshRuntime from "${virtualHmrRuntime.id}";
2361
2425
 
2362
2426
  const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
2363
2427
  let prevRefreshReg;
@@ -2376,7 +2440,7 @@ if (import.meta.hot && !inWebWorker) {
2376
2440
  RefreshRuntime.register(type, __SOURCE__ + " " + id)
2377
2441
  };
2378
2442
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
2379
- }`.trim();
2443
+ }`.replaceAll("\n", "");
2380
2444
  var REACT_REFRESH_FOOTER = `
2381
2445
  if (import.meta.hot && !inWebWorker) {
2382
2446
  window.$RefreshReg$ = prevRefreshReg;
@@ -2390,11 +2454,11 @@ if (import.meta.hot && !inWebWorker) {
2390
2454
  if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
2391
2455
  });
2392
2456
  });
2393
- }`.trim();
2457
+ }`;
2394
2458
  function getRoute(pluginConfig, file) {
2395
- let vite2 = importViteEsmSync();
2459
+ let vite2 = getVite();
2396
2460
  let routePath = vite2.normalizePath(
2397
- path4.relative(pluginConfig.appDirectory, file)
2461
+ path6.relative(pluginConfig.appDirectory, file)
2398
2462
  );
2399
2463
  let route = Object.values(pluginConfig.routes).find(
2400
2464
  (r) => vite2.normalizePath(r.file) === routePath
@@ -2416,7 +2480,7 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
2416
2480
  caseSensitive: route.caseSensitive,
2417
2481
  url: combineURLs(
2418
2482
  ctx.publicPath,
2419
- "/" + path4.relative(
2483
+ "/" + path6.relative(
2420
2484
  ctx.rootDirectory,
2421
2485
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
2422
2486
  )
@@ -2439,11 +2503,11 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
2439
2503
  return info;
2440
2504
  }
2441
2505
  async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, serverBuildDirectory) {
2442
- let serverBuildPath = path4.join(
2506
+ let serverBuildPath = path6.join(
2443
2507
  serverBuildDirectory,
2444
2508
  reactRouterConfig.serverBuildFile
2445
2509
  );
2446
- let build = await import(url2.pathToFileURL(serverBuildPath).toString());
2510
+ let build = await import(url.pathToFileURL(serverBuildPath).toString());
2447
2511
  let { createRequestHandler: createHandler } = await import("react-router");
2448
2512
  return {
2449
2513
  build,
@@ -2461,9 +2525,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
2461
2525
  let html = await response.text();
2462
2526
  validatePrerenderedResponse(response, html, "SPA Mode", "/");
2463
2527
  validatePrerenderedHtml(html, "SPA Mode");
2464
- await fse.writeFile(path4.join(clientBuildDirectory, "index.html"), html);
2528
+ await fse.writeFile(path6.join(clientBuildDirectory, "index.html"), html);
2465
2529
  viteConfig.logger.info(
2466
- "SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(path4.relative(process.cwd(), clientBuildDirectory)) + " directory"
2530
+ "SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(path6.relative(process.cwd(), clientBuildDirectory)) + " directory"
2467
2531
  );
2468
2532
  }
2469
2533
  async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
@@ -2493,14 +2557,14 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2493
2557
  // build time or runtime
2494
2558
  "X-React-Router-Prerender": "yes"
2495
2559
  };
2496
- for (let path5 of routesToPrerender) {
2497
- let matches = (0, import_react_router2.matchRoutes)(routes, path5);
2560
+ for (let path7 of routesToPrerender) {
2561
+ let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
2498
2562
  let hasLoaders = matches?.some((m) => m.route.loader);
2499
2563
  let data;
2500
2564
  if (hasLoaders) {
2501
2565
  data = await prerenderData(
2502
2566
  handler,
2503
- path5,
2567
+ path7,
2504
2568
  clientBuildDirectory,
2505
2569
  reactRouterConfig,
2506
2570
  viteConfig,
@@ -2513,7 +2577,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2513
2577
  if (isResourceRoute) {
2514
2578
  await prerenderResourceRoute(
2515
2579
  handler,
2516
- path5,
2580
+ path7,
2517
2581
  clientBuildDirectory,
2518
2582
  reactRouterConfig,
2519
2583
  viteConfig,
@@ -2522,7 +2586,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2522
2586
  } else {
2523
2587
  await prerenderRoute(
2524
2588
  handler,
2525
- path5,
2589
+ path7,
2526
2590
  clientBuildDirectory,
2527
2591
  reactRouterConfig,
2528
2592
  viteConfig,
@@ -2579,9 +2643,9 @@ async function prerenderData(handler, prerenderPath, clientBuildDirectory, react
2579
2643
  let response = await handler(request);
2580
2644
  let data = await response.text();
2581
2645
  validatePrerenderedResponse(response, data, "Prerender", normalizedPath);
2582
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2583
- let outfile = path4.join(outdir, ...normalizedPath.split("/"));
2584
- await fse.ensureDir(path4.dirname(outfile));
2646
+ let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2647
+ let outfile = path6.join(outdir, ...normalizedPath.split("/"));
2648
+ await fse.ensureDir(path6.dirname(outfile));
2585
2649
  await fse.outputFile(outfile, data);
2586
2650
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2587
2651
  return data;
@@ -2598,9 +2662,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
2598
2662
  if (!reactRouterConfig.ssr) {
2599
2663
  validatePrerenderedHtml(html, "Prerender");
2600
2664
  }
2601
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2602
- let outfile = path4.join(outdir, ...normalizedPath.split("/"), "index.html");
2603
- await fse.ensureDir(path4.dirname(outfile));
2665
+ let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2666
+ let outfile = path6.join(outdir, ...normalizedPath.split("/"), "index.html");
2667
+ await fse.ensureDir(path6.dirname(outfile));
2604
2668
  await fse.outputFile(outfile, html);
2605
2669
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2606
2670
  }
@@ -2610,9 +2674,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
2610
2674
  let response = await handler(request);
2611
2675
  let text = await response.text();
2612
2676
  validatePrerenderedResponse(response, text, "Prerender", normalizedPath);
2613
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2614
- let outfile = path4.join(outdir, ...normalizedPath.split("/"));
2615
- await fse.ensureDir(path4.dirname(outfile));
2677
+ let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2678
+ let outfile = path6.join(outdir, ...normalizedPath.split("/"));
2679
+ await fse.ensureDir(path6.dirname(outfile));
2616
2680
  await fse.outputFile(outfile, text);
2617
2681
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2618
2682
  }
@@ -2621,17 +2685,17 @@ async function prerenderManifest(build, clientBuildDirectory, reactRouterConfig,
2621
2685
  /\/\/+/g,
2622
2686
  "/"
2623
2687
  );
2624
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2625
- let outfile = path4.join(outdir, ...normalizedPath.split("/"));
2626
- await fse.ensureDir(path4.dirname(outfile));
2688
+ let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2689
+ let outfile = path6.join(outdir, ...normalizedPath.split("/"));
2690
+ await fse.ensureDir(path6.dirname(outfile));
2627
2691
  let manifestData = JSON.stringify(build.assets.routes);
2628
2692
  await fse.outputFile(outfile, manifestData);
2629
2693
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2630
2694
  }
2631
- function validatePrerenderedResponse(response, html, prefix, path5) {
2695
+ function validatePrerenderedResponse(response, html, prefix, path7) {
2632
2696
  if (response.status !== 200) {
2633
2697
  throw new Error(
2634
- `${prefix}: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${path5}\` path.
2698
+ `${prefix}: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${path7}\` path.
2635
2699
  ${html}`
2636
2700
  );
2637
2701
  }