@react-router/dev 0.0.0-experimental-1ebb6d403 → 0.0.0-experimental-e41ede670

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