@react-router/dev 0.0.0-experimental-e41ede670 → 0.0.0-experimental-4d16b23b6

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-e41ede670
2
+ * @react-router/dev v0.0.0-experimental-4d16b23b6
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;
@@ -677,10 +692,6 @@ function generate(ctx, route) {
677
692
  export type HeadersArgs = T.HeadersArgs
678
693
  export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
679
694
 
680
- export type MiddlewareArgs = T.CreateServerMiddlewareArgs<Info>
681
- export type MiddlewareNextFunction = T.ServerMiddlewareNextFunction
682
- export type ClientMiddlewareArgs = T.CreateClientMiddlewareArgs<Info>
683
- export type ClientMiddlewareNextFunction = T.ClientMiddlewareNextFunction
684
695
  export type LoaderArgs = T.CreateServerLoaderArgs<Info>
685
696
  export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
686
697
  export type ActionArgs = T.CreateServerActionArgs<Info>
@@ -692,7 +703,7 @@ function generate(ctx, route) {
692
703
  }
693
704
  `;
694
705
  }
695
- var noExtension = (path5) => Path3.join(Path3.dirname(path5), Pathe2.filename(path5));
706
+ var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
696
707
  function getRouteLineage(routes, route) {
697
708
  const result = [];
698
709
  while (route) {
@@ -816,7 +827,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
816
827
  nodeReq.originalUrl,
817
828
  "Expected `nodeReq.originalUrl` to be defined"
818
829
  );
819
- let url3 = new URL(nodeReq.originalUrl, origin);
830
+ let url2 = new URL(nodeReq.originalUrl, origin);
820
831
  let controller = new AbortController();
821
832
  let init = {
822
833
  method: nodeReq.method,
@@ -829,7 +840,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
829
840
  init.body = (0, import_node.createReadableStreamFromReadable)(nodeReq);
830
841
  init.duplex = "half";
831
842
  }
832
- return new Request(url3.href, init);
843
+ return new Request(url2.href, init);
833
844
  }
834
845
  async function toNodeRequest(res, nodeRes) {
835
846
  nodeRes.statusCode = res.status;
@@ -854,17 +865,17 @@ async function toNodeRequest(res, nodeRes) {
854
865
  }
855
866
 
856
867
  // vite/styles.ts
857
- var path3 = __toESM(require("path"));
868
+ var path5 = __toESM(require("path"));
858
869
  var import_react_router = require("react-router");
859
870
 
860
871
  // vite/resolve-file-url.ts
861
- var path2 = __toESM(require("path"));
872
+ var path4 = __toESM(require("path"));
862
873
  var resolveFileUrl = ({ rootDirectory }, filePath) => {
863
- let vite2 = importViteEsmSync();
864
- let relativePath = path2.relative(rootDirectory, filePath);
865
- 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);
866
877
  if (!isWithinRoot) {
867
- return path2.posix.join("/@fs", vite2.normalizePath(filePath));
878
+ return path4.posix.join("/@fs", vite2.normalizePath(filePath));
868
879
  }
869
880
  return "/" + vite2.normalizePath(relativePath);
870
881
  };
@@ -875,8 +886,8 @@ var cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
875
886
  var isCssFile = (file) => cssFileRegExp.test(file);
876
887
  var isCssModulesFile = (file) => cssModulesRegExp.test(file);
877
888
  var cssUrlParamsWithoutSideEffects = ["url", "inline", "raw", "inline-css"];
878
- var isCssUrlWithoutSideEffects = (url3) => {
879
- let queryString = url3.split("?")[1];
889
+ var isCssUrlWithoutSideEffects = (url2) => {
890
+ let queryString = url2.split("?")[1];
880
891
  if (!queryString) {
881
892
  return false;
882
893
  }
@@ -884,24 +895,27 @@ var isCssUrlWithoutSideEffects = (url3) => {
884
895
  for (let paramWithoutSideEffects of cssUrlParamsWithoutSideEffects) {
885
896
  if (
886
897
  // Parameter is blank and not explicitly set, i.e. "?url", not "?url="
887
- params.get(paramWithoutSideEffects) === "" && !url3.includes(`?${paramWithoutSideEffects}=`) && !url3.includes(`&${paramWithoutSideEffects}=`)
898
+ params.get(paramWithoutSideEffects) === "" && !url2.includes(`?${paramWithoutSideEffects}=`) && !url2.includes(`&${paramWithoutSideEffects}=`)
888
899
  ) {
889
900
  return true;
890
901
  }
891
902
  }
892
903
  return false;
893
904
  };
905
+ var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
894
906
  var getStylesForFiles = async ({
895
907
  viteDevServer,
896
908
  rootDirectory,
897
909
  cssModulesManifest,
898
910
  files
899
911
  }) => {
912
+ let vite2 = getVite();
913
+ let viteMajor = parseInt(vite2.version.split(".")[0], 10);
900
914
  let styles = {};
901
915
  let deps = /* @__PURE__ */ new Set();
902
916
  try {
903
917
  for (let file of files) {
904
- let normalizedPath = path3.resolve(rootDirectory, file).replace(/\\/g, "/");
918
+ let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
905
919
  let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
906
920
  if (!node) {
907
921
  try {
@@ -925,7 +939,15 @@ var getStylesForFiles = async ({
925
939
  for (let dep of deps) {
926
940
  if (dep.file && isCssFile(dep.file) && !isCssUrlWithoutSideEffects(dep.url)) {
927
941
  try {
928
- 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;
929
951
  if (css === void 0) {
930
952
  throw new Error();
931
953
  }
@@ -949,8 +971,8 @@ var findDeps = async (vite2, node, deps) => {
949
971
  await findDeps(vite2, node2, deps);
950
972
  }
951
973
  }
952
- async function addFromUrl(url3) {
953
- let node2 = await vite2.moduleGraph.getModuleByUrl(url3);
974
+ async function addFromUrl(url2) {
975
+ let node2 = await vite2.moduleGraph.getModuleByUrl(url2);
954
976
  if (node2) {
955
977
  await addFromNode(node2);
956
978
  }
@@ -958,7 +980,7 @@ var findDeps = async (vite2, node, deps) => {
958
980
  if (node.ssrTransformResult) {
959
981
  if (node.ssrTransformResult.deps) {
960
982
  node.ssrTransformResult.deps.forEach(
961
- (url3) => branches.push(addFromUrl(url3))
983
+ (url2) => branches.push(addFromUrl(url2))
962
984
  );
963
985
  }
964
986
  } else {
@@ -992,15 +1014,15 @@ var getStylesForUrl = async ({
992
1014
  entryClientFilePath,
993
1015
  cssModulesManifest,
994
1016
  build,
995
- url: url3
1017
+ url: url2
996
1018
  }) => {
997
- if (url3 === void 0 || url3.includes("?_data=")) {
1019
+ if (url2 === void 0 || url2.includes("?_data=")) {
998
1020
  return void 0;
999
1021
  }
1000
1022
  let routes = createRoutes(build.routes);
1001
- let appPath = path3.relative(process.cwd(), reactRouterConfig.appDirectory);
1002
- let documentRouteFiles = (0, import_react_router.matchRoutes)(routes, url3, build.basename)?.map(
1003
- (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)
1004
1026
  ) ?? [];
1005
1027
  let styles = await getStylesForFiles({
1006
1028
  viteDevServer,
@@ -1008,7 +1030,7 @@ var getStylesForUrl = async ({
1008
1030
  cssModulesManifest,
1009
1031
  files: [
1010
1032
  // Always include the client entry file when crawling the module graph for CSS
1011
- path3.relative(rootDirectory, entryClientFilePath),
1033
+ path5.relative(rootDirectory, entryClientFilePath),
1012
1034
  // Then include any styles from the matched routes
1013
1035
  ...documentRouteFiles
1014
1036
  ]
@@ -1016,10 +1038,15 @@ var getStylesForUrl = async ({
1016
1038
  return styles;
1017
1039
  };
1018
1040
 
1019
- // vite/vmod.ts
1020
- var id = (name) => `virtual:react-router/${name}`;
1021
- var resolve3 = (id2) => `\0${id2}`;
1022
- 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
+ }
1023
1050
 
1024
1051
  // vite/combine-urls.ts
1025
1052
  function combineURLs(baseURL, relativeURL) {
@@ -1033,10 +1060,10 @@ var removeExports = (ast, exportsToRemove) => {
1033
1060
  let exportsFiltered = false;
1034
1061
  let markedForRemoval = /* @__PURE__ */ new Set();
1035
1062
  traverse(ast, {
1036
- ExportDeclaration(path5) {
1037
- if (path5.node.type === "ExportNamedDeclaration") {
1038
- if (path5.node.specifiers.length) {
1039
- 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) => {
1040
1067
  if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
1041
1068
  if (exportsToRemove.includes(specifier.exported.name)) {
1042
1069
  exportsFiltered = true;
@@ -1045,12 +1072,12 @@ var removeExports = (ast, exportsToRemove) => {
1045
1072
  }
1046
1073
  return true;
1047
1074
  });
1048
- if (path5.node.specifiers.length === 0) {
1049
- markedForRemoval.add(path5);
1075
+ if (path7.node.specifiers.length === 0) {
1076
+ markedForRemoval.add(path7);
1050
1077
  }
1051
1078
  }
1052
- if (path5.node.declaration?.type === "VariableDeclaration") {
1053
- let declaration = path5.node.declaration;
1079
+ if (path7.node.declaration?.type === "VariableDeclaration") {
1080
+ let declaration = path7.node.declaration;
1054
1081
  declaration.declarations = declaration.declarations.filter(
1055
1082
  (declaration2) => {
1056
1083
  if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
@@ -1064,37 +1091,37 @@ var removeExports = (ast, exportsToRemove) => {
1064
1091
  }
1065
1092
  );
1066
1093
  if (declaration.declarations.length === 0) {
1067
- markedForRemoval.add(path5);
1094
+ markedForRemoval.add(path7);
1068
1095
  }
1069
1096
  }
1070
- if (path5.node.declaration?.type === "FunctionDeclaration") {
1071
- let id2 = path5.node.declaration.id;
1072
- if (id2 && exportsToRemove.includes(id2.name)) {
1073
- 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);
1074
1101
  }
1075
1102
  }
1076
- if (path5.node.declaration?.type === "ClassDeclaration") {
1077
- let id2 = path5.node.declaration.id;
1078
- if (id2 && exportsToRemove.includes(id2.name)) {
1079
- 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);
1080
1107
  }
1081
1108
  }
1082
1109
  }
1083
- if (path5.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1084
- markedForRemoval.add(path5);
1110
+ if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1111
+ markedForRemoval.add(path7);
1085
1112
  }
1086
1113
  }
1087
1114
  });
1088
1115
  if (markedForRemoval.size > 0 || exportsFiltered) {
1089
- for (let path5 of markedForRemoval) {
1090
- path5.remove();
1116
+ for (let path7 of markedForRemoval) {
1117
+ path7.remove();
1091
1118
  }
1092
1119
  (0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
1093
1120
  }
1094
1121
  };
1095
- function validateDestructuredExports(id2, exportsToRemove) {
1096
- if (id2.type === "ArrayPattern") {
1097
- for (let element of id2.elements) {
1122
+ function validateDestructuredExports(id, exportsToRemove) {
1123
+ if (id.type === "ArrayPattern") {
1124
+ for (let element of id.elements) {
1098
1125
  if (!element) {
1099
1126
  continue;
1100
1127
  }
@@ -1109,8 +1136,8 @@ function validateDestructuredExports(id2, exportsToRemove) {
1109
1136
  }
1110
1137
  }
1111
1138
  }
1112
- if (id2.type === "ObjectPattern") {
1113
- for (let property of id2.properties) {
1139
+ if (id.type === "ObjectPattern") {
1140
+ for (let property of id.properties) {
1114
1141
  if (!property) {
1115
1142
  continue;
1116
1143
  }
@@ -1134,16 +1161,16 @@ function invalidDestructureError(name) {
1134
1161
 
1135
1162
  // vite/with-props.ts
1136
1163
  var import_dedent2 = __toESM(require("dedent"));
1137
- var vmodId = id("with-props");
1164
+ var vmod = create("with-props");
1138
1165
  var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
1139
1166
  var plugin = {
1140
1167
  name: "react-router-with-props",
1141
1168
  enforce: "pre",
1142
- resolveId(id2) {
1143
- if (id2 === vmodId) return resolve3(vmodId);
1169
+ resolveId(id) {
1170
+ if (id === vmod.id) return vmod.resolvedId;
1144
1171
  },
1145
- async load(id2) {
1146
- if (id2 !== resolve3(vmodId)) return;
1172
+ async load(id) {
1173
+ if (id !== vmod.resolvedId) return;
1147
1174
  return import_dedent2.default`
1148
1175
  import { createElement as h } from "react";
1149
1176
  import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
@@ -1185,44 +1212,44 @@ var plugin = {
1185
1212
  };
1186
1213
  var transform = (ast) => {
1187
1214
  const hocs = [];
1188
- function getHocUid(path5, hocName) {
1189
- const uid = path5.scope.generateUidIdentifier(hocName);
1215
+ function getHocUid(path7, hocName) {
1216
+ const uid = path7.scope.generateUidIdentifier(hocName);
1190
1217
  hocs.push([hocName, uid]);
1191
1218
  return uid;
1192
1219
  }
1193
1220
  traverse(ast, {
1194
- ExportDeclaration(path5) {
1195
- if (path5.isExportDefaultDeclaration()) {
1196
- const declaration = path5.get("declaration");
1221
+ ExportDeclaration(path7) {
1222
+ if (path7.isExportDefaultDeclaration()) {
1223
+ const declaration = path7.get("declaration");
1197
1224
  const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
1198
1225
  if (expr) {
1199
- const uid = getHocUid(path5, "withComponentProps");
1226
+ const uid = getHocUid(path7, "withComponentProps");
1200
1227
  declaration.replaceWith(t.callExpression(uid, [expr]));
1201
1228
  }
1202
1229
  return;
1203
1230
  }
1204
- if (path5.isExportNamedDeclaration()) {
1205
- const decl = path5.get("declaration");
1231
+ if (path7.isExportNamedDeclaration()) {
1232
+ const decl = path7.get("declaration");
1206
1233
  if (decl.isVariableDeclaration()) {
1207
1234
  decl.get("declarations").forEach((varDeclarator) => {
1208
- const id2 = varDeclarator.get("id");
1235
+ const id = varDeclarator.get("id");
1209
1236
  const init = varDeclarator.get("init");
1210
1237
  const expr = init.node;
1211
1238
  if (!expr) return;
1212
- if (!id2.isIdentifier()) return;
1213
- const { name } = id2.node;
1239
+ if (!id.isIdentifier()) return;
1240
+ const { name } = id.node;
1214
1241
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1215
- const uid = getHocUid(path5, `with${name}Props`);
1242
+ const uid = getHocUid(path7, `with${name}Props`);
1216
1243
  init.replaceWith(t.callExpression(uid, [expr]));
1217
1244
  });
1218
1245
  return;
1219
1246
  }
1220
1247
  if (decl.isFunctionDeclaration()) {
1221
- const { id: id2 } = decl.node;
1222
- if (!id2) return;
1223
- const { name } = id2;
1248
+ const { id } = decl.node;
1249
+ if (!id) return;
1250
+ const { name } = id;
1224
1251
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1225
- const uid = getHocUid(path5, `with${name}Props`);
1252
+ const uid = getHocUid(path7, `with${name}Props`);
1226
1253
  decl.replaceWith(
1227
1254
  t.variableDeclaration("const", [
1228
1255
  t.variableDeclarator(
@@ -1241,7 +1268,7 @@ var transform = (ast) => {
1241
1268
  hocs.map(
1242
1269
  ([name, identifier]) => t.importSpecifier(identifier, t.identifier(name))
1243
1270
  ),
1244
- t.stringLiteral(vmodId)
1271
+ t.stringLiteral(vmod.id)
1245
1272
  )
1246
1273
  );
1247
1274
  }
@@ -1257,11 +1284,10 @@ function toFunctionExpression(decl) {
1257
1284
  }
1258
1285
 
1259
1286
  // vite/plugin.ts
1260
- var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "middleware", "headers"];
1287
+ var SERVER_ONLY_ROUTE_EXPORTS = ["loader", "action", "headers"];
1261
1288
  var CLIENT_ROUTE_EXPORTS = [
1262
1289
  "clientAction",
1263
1290
  "clientLoader",
1264
- "clientMiddleware",
1265
1291
  "default",
1266
1292
  "ErrorBoundary",
1267
1293
  "handle",
@@ -1271,27 +1297,23 @@ var CLIENT_ROUTE_EXPORTS = [
1271
1297
  "meta",
1272
1298
  "shouldRevalidate"
1273
1299
  ];
1274
- var ROUTE_ENTRY_QUERY_STRING = "?route-entry=1";
1275
- var isRouteEntry = (id2) => {
1276
- return id2.endsWith(ROUTE_ENTRY_QUERY_STRING);
1277
- };
1278
- var serverBuildId = id("server-build");
1279
- var serverManifestId = id("server-manifest");
1280
- var browserManifestId = id("browser-manifest");
1281
- var hmrRuntimeId = id("hmr-runtime");
1282
- 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");
1283
1303
  var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
1284
- let vite2 = importViteEsmSync();
1304
+ let vite2 = getVite();
1285
1305
  let file = route.file;
1286
- let fullPath = path4.resolve(reactRouterConfig.appDirectory, file);
1306
+ let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
1287
1307
  return vite2.normalizePath(fullPath);
1288
1308
  };
1289
- var vmods = [serverBuildId, serverManifestId, browserManifestId];
1309
+ var virtual = {
1310
+ serverBuild: create("server-build"),
1311
+ serverManifest: create("server-manifest"),
1312
+ browserManifest: create("browser-manifest")
1313
+ };
1290
1314
  var invalidateVirtualModules = (viteDevServer) => {
1291
- vmods.forEach((vmod) => {
1292
- let mod = viteDevServer.moduleGraph.getModuleById(
1293
- resolve3(vmod)
1294
- );
1315
+ Object.values(virtual).forEach((vmod2) => {
1316
+ let mod = viteDevServer.moduleGraph.getModuleById(vmod2.resolvedId);
1295
1317
  if (mod) {
1296
1318
  viteDevServer.moduleGraph.invalidateModule(mod);
1297
1319
  }
@@ -1302,11 +1324,11 @@ var getHash = (source, maxLength) => {
1302
1324
  return typeof maxLength === "number" ? hash.slice(0, maxLength) : hash;
1303
1325
  };
1304
1326
  var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
1305
- let vite2 = importViteEsmSync();
1327
+ let vite2 = getVite();
1306
1328
  let rootRelativeFilePath = vite2.normalizePath(
1307
- path4.relative(ctx.rootDirectory, absoluteFilePath)
1329
+ path6.relative(ctx.rootDirectory, absoluteFilePath)
1308
1330
  );
1309
- let entryChunk = viteManifest[rootRelativeFilePath + ROUTE_ENTRY_QUERY_STRING] ?? viteManifest[rootRelativeFilePath];
1331
+ let entryChunk = viteManifest[rootRelativeFilePath + BUILD_CLIENT_ROUTE_QUERY_STRING] ?? viteManifest[rootRelativeFilePath];
1310
1332
  if (!entryChunk) {
1311
1333
  let knownManifestKeys = Object.keys(viteManifest).map((key) => '"' + key + '"').join(", ");
1312
1334
  throw new Error(
@@ -1356,7 +1378,7 @@ function dedupe(array2) {
1356
1378
  return [...new Set(array2)];
1357
1379
  }
1358
1380
  var writeFileSafe = async (file, contents) => {
1359
- await fse.ensureDir(path4.dirname(file));
1381
+ await fse.ensureDir(path6.dirname(file));
1360
1382
  await fse.writeFile(file, contents);
1361
1383
  };
1362
1384
  var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
@@ -1378,20 +1400,20 @@ var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteF
1378
1400
  }
1379
1401
  let ssr = true;
1380
1402
  let { pluginContainer, moduleGraph } = viteChildCompiler;
1381
- let routePath = path4.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
1382
- let url3 = resolveFileUrl(ctx, routePath);
1403
+ let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
1404
+ let url2 = resolveFileUrl(ctx, routePath);
1383
1405
  let resolveId = async () => {
1384
- let result = await pluginContainer.resolveId(url3, void 0, { ssr });
1385
- 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}`);
1386
1408
  return result.id;
1387
1409
  };
1388
- let [id2, code] = await Promise.all([
1410
+ let [id, code] = await Promise.all([
1389
1411
  resolveId(),
1390
1412
  readRouteFile?.() ?? fse.readFile(routePath, "utf-8"),
1391
1413
  // pluginContainer.transform(...) fails if we don't do this first:
1392
- moduleGraph.ensureEntryFromUrl(url3, ssr)
1414
+ moduleGraph.ensureEntryFromUrl(url2, ssr)
1393
1415
  ]);
1394
- let transformed = await pluginContainer.transform(code, id2, { ssr });
1416
+ let transformed = await pluginContainer.transform(code, id, { ssr });
1395
1417
  let [, exports2] = (0, import_es_module_lexer.parse)(transformed.code);
1396
1418
  let exportNames = exports2.map((e) => e.n);
1397
1419
  return exportNames;
@@ -1402,19 +1424,19 @@ var getServerBundleBuildConfig = (viteUserConfig) => {
1402
1424
  }
1403
1425
  return viteUserConfig.__reactRouterServerBundleBuildConfig;
1404
1426
  };
1405
- var getServerBuildDirectory = (ctx) => path4.join(
1427
+ var getServerBuildDirectory = (ctx) => path6.join(
1406
1428
  ctx.reactRouterConfig.buildDirectory,
1407
1429
  "server",
1408
1430
  ...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
1409
1431
  );
1410
- var getClientBuildDirectory = (reactRouterConfig) => path4.join(reactRouterConfig.buildDirectory, "client");
1411
- var defaultEntriesDir = path4.resolve(
1412
- 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")),
1413
1435
  "dist",
1414
1436
  "config",
1415
1437
  "defaults"
1416
1438
  );
1417
- var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path4.join(defaultEntriesDir, filename3));
1439
+ var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
1418
1440
  invariant(defaultEntries.length > 0, "No default entries found");
1419
1441
  var reactRouterDevLoadContext = () => ({});
1420
1442
  var reactRouterVitePlugin = () => {
@@ -1496,12 +1518,14 @@ var reactRouterVitePlugin = () => {
1496
1518
  resolveFileUrl(
1497
1519
  ctx,
1498
1520
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
1499
- ) + ROUTE_ENTRY_QUERY_STRING
1521
+ )
1500
1522
  )};`;
1501
1523
  }).join("\n")}
1502
- export { default as assets } from ${JSON.stringify(serverManifestId)};
1524
+ export { default as assets } from ${JSON.stringify(
1525
+ virtual.serverManifest.id
1526
+ )};
1503
1527
  export const assetsBuildDirectory = ${JSON.stringify(
1504
- path4.relative(
1528
+ path6.relative(
1505
1529
  ctx.rootDirectory,
1506
1530
  getClientBuildDirectory(ctx.reactRouterConfig)
1507
1531
  )
@@ -1527,7 +1551,7 @@ var reactRouterVitePlugin = () => {
1527
1551
  };
1528
1552
  let loadViteManifest = async (directory) => {
1529
1553
  let manifestContents = await fse.readFile(
1530
- path4.resolve(directory, ".vite", "manifest.json"),
1554
+ path6.resolve(directory, ".vite", "manifest.json"),
1531
1555
  "utf-8"
1532
1556
  );
1533
1557
  return JSON.parse(manifestContents);
@@ -1563,7 +1587,7 @@ var reactRouterVitePlugin = () => {
1563
1587
  ctx
1564
1588
  );
1565
1589
  for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
1566
- let routeFilePath = path4.join(
1590
+ let routeFilePath = path6.join(
1567
1591
  ctx.reactRouterConfig.appDirectory,
1568
1592
  route.file
1569
1593
  );
@@ -1598,18 +1622,18 @@ var reactRouterVitePlugin = () => {
1598
1622
  }
1599
1623
  let fingerprintedValues = { entry, routes: browserRoutes };
1600
1624
  let version = getHash(JSON.stringify(fingerprintedValues), 8);
1601
- let manifestPath = path4.posix.join(
1625
+ let manifestPath = path6.posix.join(
1602
1626
  viteConfig.build.assetsDir,
1603
1627
  `manifest-${version}.js`
1604
1628
  );
1605
- let url3 = `${ctx.publicPath}${manifestPath}`;
1606
- let nonFingerprintedValues = { url: url3, version };
1629
+ let url2 = `${ctx.publicPath}${manifestPath}`;
1630
+ let nonFingerprintedValues = { url: url2, version };
1607
1631
  let reactRouterBrowserManifest = {
1608
1632
  ...fingerprintedValues,
1609
1633
  ...nonFingerprintedValues
1610
1634
  };
1611
1635
  await writeFileSafe(
1612
- path4.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
1636
+ path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
1613
1637
  `window.__reactRouterManifest=${JSON.stringify(
1614
1638
  reactRouterBrowserManifest
1615
1639
  )};`
@@ -1639,10 +1663,10 @@ var reactRouterVitePlugin = () => {
1639
1663
  caseSensitive: route.caseSensitive,
1640
1664
  module: combineURLs(
1641
1665
  ctx.publicPath,
1642
- `${resolveFileUrl(
1666
+ resolveFileUrl(
1643
1667
  ctx,
1644
1668
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
1645
- )}${ROUTE_ENTRY_QUERY_STRING}`
1669
+ )
1646
1670
  ),
1647
1671
  hasAction: sourceExports.includes("action"),
1648
1672
  hasLoader: sourceExports.includes("loader"),
@@ -1654,12 +1678,9 @@ var reactRouterVitePlugin = () => {
1654
1678
  }
1655
1679
  return {
1656
1680
  version: String(Math.random()),
1657
- url: combineURLs(ctx.publicPath, url(browserManifestId)),
1681
+ url: combineURLs(ctx.publicPath, virtual.browserManifest.url),
1658
1682
  hmr: {
1659
- runtime: combineURLs(
1660
- ctx.publicPath,
1661
- url(injectHmrRuntimeId)
1662
- )
1683
+ runtime: combineURLs(ctx.publicPath, virtualInjectHmrRuntime.url)
1663
1684
  },
1664
1685
  entry: {
1665
1686
  module: combineURLs(
@@ -1675,11 +1696,17 @@ var reactRouterVitePlugin = () => {
1675
1696
  {
1676
1697
  name: "react-router",
1677
1698
  config: async (_viteUserConfig, _viteConfigEnv) => {
1678
- await preloadViteEsm();
1679
- let vite2 = importViteEsmSync();
1699
+ await preloadVite();
1700
+ let vite2 = getVite();
1680
1701
  viteUserConfig = _viteUserConfig;
1681
1702
  viteConfigEnv = _viteConfigEnv;
1682
1703
  viteCommand = viteConfigEnv.command;
1704
+ let viteClientConditions = [
1705
+ ...vite2.defaultClientConditions ?? []
1706
+ ];
1707
+ let viteServerConditions = [
1708
+ ...vite2.defaultServerConditions ?? []
1709
+ ];
1683
1710
  logger = vite2.createLogger(viteUserConfig.logLevel, {
1684
1711
  prefix: "[react-router]"
1685
1712
  });
@@ -1729,15 +1756,15 @@ var reactRouterVitePlugin = () => {
1729
1756
  ssr: {
1730
1757
  external: ssrExternals,
1731
1758
  resolve: {
1732
- conditions: viteCommand === "build" ? [] : ["development"],
1733
- externalConditions: viteCommand === "build" ? [] : ["development"]
1759
+ conditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions],
1760
+ externalConditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions]
1734
1761
  }
1735
1762
  },
1736
1763
  optimizeDeps: {
1737
1764
  entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
1738
1765
  ctx.entryClientFilePath,
1739
1766
  ...Object.values(ctx.reactRouterConfig.routes).map(
1740
- (route) => path4.join(ctx.reactRouterConfig.appDirectory, route.file)
1767
+ (route) => path6.join(ctx.reactRouterConfig.appDirectory, route.file)
1741
1768
  )
1742
1769
  ] : [],
1743
1770
  include: [
@@ -1771,7 +1798,7 @@ var reactRouterVitePlugin = () => {
1771
1798
  "react-router/dom",
1772
1799
  "react-router-dom"
1773
1800
  ],
1774
- conditions: viteCommand === "build" ? [] : ["development"]
1801
+ conditions: viteCommand === "build" ? viteClientConditions : ["development", ...viteClientConditions]
1775
1802
  },
1776
1803
  base: viteUserConfig.base,
1777
1804
  // When consumer provides an allow list for files that can be read by
@@ -1793,10 +1820,10 @@ var reactRouterVitePlugin = () => {
1793
1820
  input: [
1794
1821
  ctx.entryClientFilePath,
1795
1822
  ...Object.values(ctx.reactRouterConfig.routes).map(
1796
- (route) => `${path4.resolve(
1823
+ (route) => `${path6.resolve(
1797
1824
  ctx.reactRouterConfig.appDirectory,
1798
1825
  route.file
1799
- )}${ROUTE_ENTRY_QUERY_STRING}`
1826
+ )}${BUILD_CLIENT_ROUTE_QUERY_STRING}`
1800
1827
  )
1801
1828
  ]
1802
1829
  }
@@ -1815,7 +1842,7 @@ var reactRouterVitePlugin = () => {
1815
1842
  rollupOptions: {
1816
1843
  ...baseRollupOptions,
1817
1844
  preserveEntrySignatures: "exports-only",
1818
- input: viteUserConfig.build?.rollupOptions?.input ?? serverBuildId,
1845
+ input: viteUserConfig.build?.rollupOptions?.input ?? virtual.serverBuild.id,
1819
1846
  output: {
1820
1847
  entryFileNames: ctx.reactRouterConfig.serverBuildFile,
1821
1848
  format: ctx.reactRouterConfig.serverModuleFormat
@@ -1842,7 +1869,7 @@ var reactRouterVitePlugin = () => {
1842
1869
  "The React Router Vite plugin requires the use of a Vite config file"
1843
1870
  );
1844
1871
  }
1845
- let vite2 = importViteEsmSync();
1872
+ let vite2 = getVite();
1846
1873
  let childCompilerConfigFile = await vite2.loadConfigFromFile(
1847
1874
  {
1848
1875
  command: viteConfig.command,
@@ -1878,15 +1905,15 @@ var reactRouterVitePlugin = () => {
1878
1905
  envFile: false,
1879
1906
  plugins: [
1880
1907
  ...(childCompilerConfigFile.config.plugins ?? []).flat().filter(
1881
- (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"
1882
1909
  )
1883
1910
  ]
1884
1911
  });
1885
1912
  await viteChildCompiler.pluginContainer.buildStart({});
1886
1913
  },
1887
- async transform(code, id2) {
1888
- if (isCssModulesFile(id2)) {
1889
- cssModulesManifest[id2] = code;
1914
+ async transform(code, id) {
1915
+ if (isCssModulesFile(id)) {
1916
+ cssModulesManifest[id] = code;
1890
1917
  }
1891
1918
  },
1892
1919
  buildStart() {
@@ -1910,7 +1937,7 @@ var reactRouterVitePlugin = () => {
1910
1937
  (0, import_react_router2.unstable_setDevServerHooks)({
1911
1938
  // Give the request handler access to the critical CSS in dev to avoid a
1912
1939
  // flash of unstyled content since Vite injects CSS file contents via JS
1913
- getCriticalCss: async (build, url3) => {
1940
+ getCriticalCss: async (build, url2) => {
1914
1941
  return getStylesForUrl({
1915
1942
  rootDirectory: ctx.rootDirectory,
1916
1943
  entryClientFilePath: ctx.entryClientFilePath,
@@ -1918,7 +1945,7 @@ var reactRouterVitePlugin = () => {
1918
1945
  viteDevServer,
1919
1946
  cssModulesManifest,
1920
1947
  build,
1921
- url: url3
1948
+ url: url2
1922
1949
  });
1923
1950
  },
1924
1951
  // If an error is caught within the request handler, let Vite fix the
@@ -1966,7 +1993,7 @@ var reactRouterVitePlugin = () => {
1966
1993
  viteDevServer.middlewares.use(async (req, res, next) => {
1967
1994
  try {
1968
1995
  let build = await viteDevServer.ssrLoadModule(
1969
- serverBuildId
1996
+ virtual.serverBuild.id
1970
1997
  );
1971
1998
  let handler = (0, import_react_router2.createRequestHandler)(build, "development");
1972
1999
  let nodeHandler = async (nodeReq, nodeRes) => {
@@ -2001,8 +2028,8 @@ var reactRouterVitePlugin = () => {
2001
2028
  let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
2002
2029
  let movedAssetPaths = [];
2003
2030
  for (let ssrAssetPath of ssrAssetPaths) {
2004
- let src = path4.join(serverBuildDirectory, ssrAssetPath);
2005
- let dest = path4.join(clientBuildDirectory, ssrAssetPath);
2031
+ let src = path6.join(serverBuildDirectory, ssrAssetPath);
2032
+ let dest = path6.join(clientBuildDirectory, ssrAssetPath);
2006
2033
  if (!fse.existsSync(dest)) {
2007
2034
  await fse.move(src, dest);
2008
2035
  movedAssetPaths.push(dest);
@@ -2015,7 +2042,7 @@ var reactRouterVitePlugin = () => {
2015
2042
  );
2016
2043
  await Promise.all(
2017
2044
  ssrCssPaths.map(
2018
- (cssPath) => fse.remove(path4.join(serverBuildDirectory, cssPath))
2045
+ (cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
2019
2046
  )
2020
2047
  );
2021
2048
  if (movedAssetPaths.length) {
@@ -2024,7 +2051,7 @@ var reactRouterVitePlugin = () => {
2024
2051
  "",
2025
2052
  `${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
2026
2053
  ...movedAssetPaths.map(
2027
- (movedAssetPath) => import_picocolors3.default.dim(path4.relative(ctx.rootDirectory, movedAssetPath))
2054
+ (movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
2028
2055
  ),
2029
2056
  ""
2030
2057
  ].join("\n")
@@ -2066,12 +2093,12 @@ var reactRouterVitePlugin = () => {
2066
2093
  }
2067
2094
  },
2068
2095
  {
2069
- name: "react-router-route-entry",
2096
+ name: "react-router:build-client-route",
2070
2097
  enforce: "pre",
2071
- async transform(_code, id2, options) {
2072
- if (!isRouteEntry(id2)) return;
2073
- let routeModuleId = id2.replace(ROUTE_ENTRY_QUERY_STRING, "");
2074
- 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);
2075
2102
  let sourceExports = await getRouteModuleExports(
2076
2103
  viteChildCompiler,
2077
2104
  ctx,
@@ -2084,23 +2111,24 @@ var reactRouterVitePlugin = () => {
2084
2111
  }
2085
2112
  },
2086
2113
  {
2087
- name: "react-router-virtual-modules",
2114
+ name: "react-router:virtual-modules",
2088
2115
  enforce: "pre",
2089
- resolveId(id2) {
2090
- 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;
2091
2119
  },
2092
- async load(id2) {
2093
- switch (id2) {
2094
- case resolve3(serverBuildId): {
2120
+ async load(id) {
2121
+ switch (id) {
2122
+ case virtual.serverBuild.resolvedId: {
2095
2123
  return await getServerEntry();
2096
2124
  }
2097
- case resolve3(serverManifestId): {
2125
+ case virtual.serverManifest.resolvedId: {
2098
2126
  let reactRouterManifest = ctx.isSsrBuild ? await ctx.getReactRouterServerManifest() : await getReactRouterManifestForDev();
2099
2127
  return `export default ${(0, import_jsesc.default)(reactRouterManifest, {
2100
2128
  es6: true
2101
2129
  })};`;
2102
2130
  }
2103
- case resolve3(browserManifestId): {
2131
+ case virtual.browserManifest.resolvedId: {
2104
2132
  if (viteCommand === "build") {
2105
2133
  throw new Error("This module only exists in development");
2106
2134
  }
@@ -2114,15 +2142,15 @@ var reactRouterVitePlugin = () => {
2114
2142
  }
2115
2143
  },
2116
2144
  {
2117
- name: "react-router-dot-server",
2145
+ name: "react-router:dot-server",
2118
2146
  enforce: "pre",
2119
- async resolveId(id2, importer, options) {
2147
+ async resolveId(id, importer, options) {
2120
2148
  let isOptimizeDeps = viteCommand === "serve" && options?.scan === true;
2121
2149
  if (isOptimizeDeps || options?.ssr) return;
2122
- let isResolving = options?.custom?.["react-router-dot-server"] ?? false;
2150
+ let isResolving = options?.custom?.["react-router:dot-server"] ?? false;
2123
2151
  if (isResolving) return;
2124
- options.custom = { ...options.custom, "react-router-dot-server": true };
2125
- 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);
2126
2154
  if (!resolved) return;
2127
2155
  let serverFileRE = /\.server(\.[cm]?[jt]sx?)?$/;
2128
2156
  let serverDirRE = /\/\.server\//;
@@ -2132,9 +2160,9 @@ var reactRouterVitePlugin = () => {
2132
2160
  if (viteCommand !== "build" && importer.endsWith(".html")) {
2133
2161
  return;
2134
2162
  }
2135
- let vite2 = importViteEsmSync();
2163
+ let vite2 = getVite();
2136
2164
  let importerShort = vite2.normalizePath(
2137
- path4.relative(ctx.rootDirectory, importer)
2165
+ path6.relative(ctx.rootDirectory, importer)
2138
2166
  );
2139
2167
  let isRoute = getRoute(ctx.reactRouterConfig, importer);
2140
2168
  if (isRoute) {
@@ -2145,12 +2173,12 @@ var reactRouterVitePlugin = () => {
2145
2173
  [
2146
2174
  import_picocolors3.default.red(`Server-only module referenced by client`),
2147
2175
  "",
2148
- ` '${id2}' imported by route '${importerShort}'`,
2176
+ ` '${id}' imported by route '${importerShort}'`,
2149
2177
  "",
2150
2178
  ` React Router automatically removes server-code from these exports:`,
2151
2179
  ` ${serverOnlyExports}`,
2152
2180
  "",
2153
- ` But other route exports in '${importerShort}' depend on '${id2}'.`,
2181
+ ` But other route exports in '${importerShort}' depend on '${id}'.`,
2154
2182
  "",
2155
2183
  " See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
2156
2184
  ""
@@ -2161,7 +2189,7 @@ var reactRouterVitePlugin = () => {
2161
2189
  [
2162
2190
  import_picocolors3.default.red(`Server-only module referenced by client`),
2163
2191
  "",
2164
- ` '${id2}' imported by '${importerShort}'`,
2192
+ ` '${id}' imported by '${importerShort}'`,
2165
2193
  "",
2166
2194
  " See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
2167
2195
  ""
@@ -2170,12 +2198,12 @@ var reactRouterVitePlugin = () => {
2170
2198
  }
2171
2199
  },
2172
2200
  {
2173
- name: "react-router-dot-client",
2174
- async transform(code, id2, options) {
2201
+ name: "react-router:dot-client",
2202
+ async transform(code, id, options) {
2175
2203
  if (!options?.ssr) return;
2176
2204
  let clientFileRE = /\.client(\.[cm]?[jt]sx?)?$/;
2177
2205
  let clientDirRE = /\/\.client\//;
2178
- if (clientFileRE.test(id2) || clientDirRE.test(id2)) {
2206
+ if (clientFileRE.test(id) || clientDirRE.test(id)) {
2179
2207
  let exports2 = (0, import_es_module_lexer.parse)(code)[1];
2180
2208
  return {
2181
2209
  code: exports2.map(
@@ -2188,9 +2216,9 @@ var reactRouterVitePlugin = () => {
2188
2216
  },
2189
2217
  plugin,
2190
2218
  {
2191
- name: "react-router-route-exports",
2192
- async transform(code, id2, options) {
2193
- 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);
2194
2222
  if (!route) return;
2195
2223
  if (!options?.ssr && !ctx.reactRouterConfig.ssr) {
2196
2224
  let serverOnlyExports = (0, import_es_module_lexer.parse)(code)[1].map((exp) => exp.n).filter((exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp));
@@ -2207,7 +2235,7 @@ var reactRouterVitePlugin = () => {
2207
2235
  }
2208
2236
  }
2209
2237
  }
2210
- let [filepath] = id2.split("?");
2238
+ let [filepath] = id.split("?");
2211
2239
  let ast = (0, import_parser.parse)(code, { sourceType: "module" });
2212
2240
  if (!options?.ssr) {
2213
2241
  removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS);
@@ -2215,22 +2243,23 @@ var reactRouterVitePlugin = () => {
2215
2243
  transform(ast);
2216
2244
  return generate2(ast, {
2217
2245
  sourceMaps: true,
2218
- filename: id2,
2246
+ filename: id,
2219
2247
  sourceFileName: filepath
2220
2248
  });
2221
2249
  }
2222
2250
  },
2223
2251
  {
2224
- name: "react-router-inject-hmr-runtime",
2252
+ name: "react-router:inject-hmr-runtime",
2225
2253
  enforce: "pre",
2226
- resolveId(id2) {
2227
- if (id2 === injectHmrRuntimeId)
2228
- return resolve3(injectHmrRuntimeId);
2254
+ resolveId(id) {
2255
+ if (id === virtualInjectHmrRuntime.id) {
2256
+ return virtualInjectHmrRuntime.resolvedId;
2257
+ }
2229
2258
  },
2230
- async load(id2) {
2231
- if (id2 !== resolve3(injectHmrRuntimeId)) return;
2259
+ async load(id) {
2260
+ if (id !== virtualInjectHmrRuntime.resolvedId) return;
2232
2261
  return [
2233
- `import RefreshRuntime from "${hmrRuntimeId}"`,
2262
+ `import RefreshRuntime from "${virtualHmrRuntime.id}"`,
2234
2263
  "RefreshRuntime.injectIntoGlobalHook(window)",
2235
2264
  "window.$RefreshReg$ = () => {}",
2236
2265
  "window.$RefreshSig$ = () => (type) => type",
@@ -2239,17 +2268,17 @@ var reactRouterVitePlugin = () => {
2239
2268
  }
2240
2269
  },
2241
2270
  {
2242
- name: "react-router-hmr-runtime",
2271
+ name: "react-router:hmr-runtime",
2243
2272
  enforce: "pre",
2244
- resolveId(id2) {
2245
- if (id2 === hmrRuntimeId) return resolve3(hmrRuntimeId);
2273
+ resolveId(id) {
2274
+ if (id === virtualHmrRuntime.id) return virtualHmrRuntime.resolvedId;
2246
2275
  },
2247
- async load(id2) {
2248
- if (id2 !== resolve3(hmrRuntimeId)) return;
2249
- let reactRefreshDir = path4.dirname(
2276
+ async load(id) {
2277
+ if (id !== virtualHmrRuntime.resolvedId) return;
2278
+ let reactRefreshDir = path6.dirname(
2250
2279
  require.resolve("react-refresh/package.json")
2251
2280
  );
2252
- let reactRefreshRuntimePath = path4.join(
2281
+ let reactRefreshRuntimePath = path6.join(
2253
2282
  reactRefreshDir,
2254
2283
  "cjs/react-refresh-runtime.development.js"
2255
2284
  );
@@ -2265,11 +2294,11 @@ var reactRouterVitePlugin = () => {
2265
2294
  }
2266
2295
  },
2267
2296
  {
2268
- name: "react-router-react-refresh-babel",
2269
- async transform(code, id2, options) {
2297
+ name: "react-router:react-refresh-babel",
2298
+ async transform(code, id, options) {
2270
2299
  if (viteCommand !== "serve") return;
2271
- if (id2.includes("/node_modules/")) return;
2272
- let [filepath] = id2.split("?");
2300
+ if (id.includes("/node_modules/")) return;
2301
+ let [filepath] = id.split("?");
2273
2302
  let extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
2274
2303
  if (!extensionsRE.test(filepath)) return;
2275
2304
  let devRuntime = "react/jsx-dev-runtime";
@@ -2277,13 +2306,10 @@ var reactRouterVitePlugin = () => {
2277
2306
  let isJSX = filepath.endsWith("x");
2278
2307
  let useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
2279
2308
  if (!useFastRefresh) return;
2280
- if (isRouteEntry(id2)) {
2281
- return { code: addRefreshWrapper(ctx.reactRouterConfig, code, id2) };
2282
- }
2283
2309
  let result = await babel.transformAsync(code, {
2284
2310
  babelrc: false,
2285
2311
  configFile: false,
2286
- filename: id2,
2312
+ filename: id,
2287
2313
  sourceFileName: filepath,
2288
2314
  parserOpts: {
2289
2315
  sourceType: "module",
@@ -2296,18 +2322,18 @@ var reactRouterVitePlugin = () => {
2296
2322
  code = result.code;
2297
2323
  let refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
2298
2324
  if (refreshContentRE.test(code)) {
2299
- code = addRefreshWrapper(ctx.reactRouterConfig, code, id2);
2325
+ code = addRefreshWrapper(ctx.reactRouterConfig, code, id);
2300
2326
  }
2301
2327
  return { code, map: result.map };
2302
2328
  }
2303
2329
  },
2304
2330
  {
2305
- name: "react-router-hmr-updates",
2331
+ name: "react-router:hmr-updates",
2306
2332
  async handleHotUpdate({ server, file, modules, read }) {
2307
2333
  let route = getRoute(ctx.reactRouterConfig, file);
2308
2334
  let hmrEventData = { route: null };
2309
2335
  if (route) {
2310
- let serverManifest = (await server.ssrLoadModule(serverManifestId)).default;
2336
+ let serverManifest = (await server.ssrLoadModule(virtual.serverManifest.id)).default;
2311
2337
  let oldRouteMetadata = serverManifest.routes[route.id];
2312
2338
  let newRouteMetadata = await getRouteMetadata(
2313
2339
  ctx,
@@ -2333,39 +2359,69 @@ var reactRouterVitePlugin = () => {
2333
2359
  });
2334
2360
  return modules;
2335
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
+ }
2336
2384
  }
2337
2385
  ];
2338
2386
  };
2339
- function addRefreshWrapper(reactRouterConfig, code, id2) {
2340
- let route = getRoute(reactRouterConfig, id2);
2341
- 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 ? [
2342
2414
  "clientAction",
2343
2415
  "clientLoader",
2344
- "clientMiddleware",
2345
2416
  "handle",
2346
2417
  "meta",
2347
2418
  "links",
2348
2419
  "shouldRevalidate"
2349
2420
  ] : [];
2350
- return "\n\n" + withCommentBoundaries(
2351
- "REACT REFRESH HEADER",
2352
- REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id2))
2353
- ) + "\n\n" + withCommentBoundaries("REACT REFRESH BODY", code) + "\n\n" + withCommentBoundaries(
2354
- "REACT REFRESH FOOTER",
2355
- REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id2)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(route?.id))
2356
- ) + "\n";
2357
- }
2358
- function withCommentBoundaries(label, text) {
2359
- let begin = `// [BEGIN] ${label} `;
2360
- begin += "-".repeat(80 - begin.length);
2361
- let end = `// [END] ${label} `;
2362
- end += "-".repeat(80 - end.length);
2363
- return `${begin}
2364
- ${text}
2365
- ${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));
2366
2422
  }
2367
2423
  var REACT_REFRESH_HEADER = `
2368
- import RefreshRuntime from "${hmrRuntimeId}";
2424
+ import RefreshRuntime from "${virtualHmrRuntime.id}";
2369
2425
 
2370
2426
  const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
2371
2427
  let prevRefreshReg;
@@ -2384,7 +2440,7 @@ if (import.meta.hot && !inWebWorker) {
2384
2440
  RefreshRuntime.register(type, __SOURCE__ + " " + id)
2385
2441
  };
2386
2442
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
2387
- }`.trim();
2443
+ }`.replaceAll("\n", "");
2388
2444
  var REACT_REFRESH_FOOTER = `
2389
2445
  if (import.meta.hot && !inWebWorker) {
2390
2446
  window.$RefreshReg$ = prevRefreshReg;
@@ -2398,11 +2454,11 @@ if (import.meta.hot && !inWebWorker) {
2398
2454
  if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
2399
2455
  });
2400
2456
  });
2401
- }`.trim();
2457
+ }`;
2402
2458
  function getRoute(pluginConfig, file) {
2403
- let vite2 = importViteEsmSync();
2459
+ let vite2 = getVite();
2404
2460
  let routePath = vite2.normalizePath(
2405
- path4.relative(pluginConfig.appDirectory, file)
2461
+ path6.relative(pluginConfig.appDirectory, file)
2406
2462
  );
2407
2463
  let route = Object.values(pluginConfig.routes).find(
2408
2464
  (r) => vite2.normalizePath(r.file) === routePath
@@ -2424,7 +2480,7 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
2424
2480
  caseSensitive: route.caseSensitive,
2425
2481
  url: combineURLs(
2426
2482
  ctx.publicPath,
2427
- "/" + path4.relative(
2483
+ "/" + path6.relative(
2428
2484
  ctx.rootDirectory,
2429
2485
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
2430
2486
  )
@@ -2447,11 +2503,11 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
2447
2503
  return info;
2448
2504
  }
2449
2505
  async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, serverBuildDirectory) {
2450
- let serverBuildPath = path4.join(
2506
+ let serverBuildPath = path6.join(
2451
2507
  serverBuildDirectory,
2452
2508
  reactRouterConfig.serverBuildFile
2453
2509
  );
2454
- let build = await import(url2.pathToFileURL(serverBuildPath).toString());
2510
+ let build = await import(url.pathToFileURL(serverBuildPath).toString());
2455
2511
  let { createRequestHandler: createHandler } = await import("react-router");
2456
2512
  return {
2457
2513
  build,
@@ -2469,9 +2525,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
2469
2525
  let html = await response.text();
2470
2526
  validatePrerenderedResponse(response, html, "SPA Mode", "/");
2471
2527
  validatePrerenderedHtml(html, "SPA Mode");
2472
- await fse.writeFile(path4.join(clientBuildDirectory, "index.html"), html);
2528
+ await fse.writeFile(path6.join(clientBuildDirectory, "index.html"), html);
2473
2529
  viteConfig.logger.info(
2474
- "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"
2475
2531
  );
2476
2532
  }
2477
2533
  async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
@@ -2501,14 +2557,14 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2501
2557
  // build time or runtime
2502
2558
  "X-React-Router-Prerender": "yes"
2503
2559
  };
2504
- for (let path5 of routesToPrerender) {
2505
- 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(/^\/\/+/, "/"));
2506
2562
  let hasLoaders = matches?.some((m) => m.route.loader);
2507
2563
  let data;
2508
2564
  if (hasLoaders) {
2509
2565
  data = await prerenderData(
2510
2566
  handler,
2511
- path5,
2567
+ path7,
2512
2568
  clientBuildDirectory,
2513
2569
  reactRouterConfig,
2514
2570
  viteConfig,
@@ -2521,7 +2577,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2521
2577
  if (isResourceRoute) {
2522
2578
  await prerenderResourceRoute(
2523
2579
  handler,
2524
- path5,
2580
+ path7,
2525
2581
  clientBuildDirectory,
2526
2582
  reactRouterConfig,
2527
2583
  viteConfig,
@@ -2530,7 +2586,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2530
2586
  } else {
2531
2587
  await prerenderRoute(
2532
2588
  handler,
2533
- path5,
2589
+ path7,
2534
2590
  clientBuildDirectory,
2535
2591
  reactRouterConfig,
2536
2592
  viteConfig,
@@ -2587,9 +2643,9 @@ async function prerenderData(handler, prerenderPath, clientBuildDirectory, react
2587
2643
  let response = await handler(request);
2588
2644
  let data = await response.text();
2589
2645
  validatePrerenderedResponse(response, data, "Prerender", normalizedPath);
2590
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2591
- let outfile = path4.join(outdir, ...normalizedPath.split("/"));
2592
- 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));
2593
2649
  await fse.outputFile(outfile, data);
2594
2650
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2595
2651
  return data;
@@ -2606,9 +2662,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
2606
2662
  if (!reactRouterConfig.ssr) {
2607
2663
  validatePrerenderedHtml(html, "Prerender");
2608
2664
  }
2609
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2610
- let outfile = path4.join(outdir, ...normalizedPath.split("/"), "index.html");
2611
- 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));
2612
2668
  await fse.outputFile(outfile, html);
2613
2669
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2614
2670
  }
@@ -2618,9 +2674,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
2618
2674
  let response = await handler(request);
2619
2675
  let text = await response.text();
2620
2676
  validatePrerenderedResponse(response, text, "Prerender", normalizedPath);
2621
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2622
- let outfile = path4.join(outdir, ...normalizedPath.split("/"));
2623
- 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));
2624
2680
  await fse.outputFile(outfile, text);
2625
2681
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2626
2682
  }
@@ -2629,17 +2685,17 @@ async function prerenderManifest(build, clientBuildDirectory, reactRouterConfig,
2629
2685
  /\/\/+/g,
2630
2686
  "/"
2631
2687
  );
2632
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2633
- let outfile = path4.join(outdir, ...normalizedPath.split("/"));
2634
- 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));
2635
2691
  let manifestData = JSON.stringify(build.assets.routes);
2636
2692
  await fse.outputFile(outfile, manifestData);
2637
2693
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2638
2694
  }
2639
- function validatePrerenderedResponse(response, html, prefix, path5) {
2695
+ function validatePrerenderedResponse(response, html, prefix, path7) {
2640
2696
  if (response.status !== 200) {
2641
2697
  throw new Error(
2642
- `${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.
2643
2699
  ${html}`
2644
2700
  );
2645
2701
  }
@@ -2674,8 +2730,6 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
2674
2730
  loader: route.module.loader ? () => null : void 0,
2675
2731
  action: void 0,
2676
2732
  handle: route.module.handle
2677
- // middleware is not necessary here since we just need to know which
2678
- // routes have loaders so we know what paths to prerender
2679
2733
  };
2680
2734
  return route.index ? {
2681
2735
  index: true,