@react-router/dev 0.0.0-experimental-a839ff7e2 → 0.0.0-experimental-6b51a129b

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-a839ff7e2
2
+ * @react-router/dev v0.0.0-experimental-6b51a129b
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,22 +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 packageRoot = path6.dirname(
1708
- require.resolve("@react-router/dev/package.json")
1709
- );
1710
- let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
1711
- let viteServerConditions = [
1712
- ...vite2.defaultServerConditions ?? [],
1713
- ...moduleSyncEnabled ? ["module-sync"] : []
1714
- ];
1715
1683
  logger = vite2.createLogger(viteUserConfig.logLevel, {
1716
1684
  prefix: "[react-router]"
1717
1685
  });
@@ -1761,15 +1729,15 @@ var reactRouterVitePlugin = () => {
1761
1729
  ssr: {
1762
1730
  external: ssrExternals,
1763
1731
  resolve: {
1764
- conditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions],
1765
- externalConditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions]
1732
+ conditions: viteCommand === "build" ? [] : ["development"],
1733
+ externalConditions: viteCommand === "build" ? [] : ["development"]
1766
1734
  }
1767
1735
  },
1768
1736
  optimizeDeps: {
1769
1737
  entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
1770
1738
  ctx.entryClientFilePath,
1771
1739
  ...Object.values(ctx.reactRouterConfig.routes).map(
1772
- (route) => path6.join(ctx.reactRouterConfig.appDirectory, route.file)
1740
+ (route) => path4.join(ctx.reactRouterConfig.appDirectory, route.file)
1773
1741
  )
1774
1742
  ] : [],
1775
1743
  include: [
@@ -1803,7 +1771,7 @@ var reactRouterVitePlugin = () => {
1803
1771
  "react-router/dom",
1804
1772
  "react-router-dom"
1805
1773
  ],
1806
- conditions: viteCommand === "build" ? viteClientConditions : ["development", ...viteClientConditions]
1774
+ conditions: viteCommand === "build" ? [] : ["development"]
1807
1775
  },
1808
1776
  base: viteUserConfig.base,
1809
1777
  // When consumer provides an allow list for files that can be read by
@@ -1825,10 +1793,10 @@ var reactRouterVitePlugin = () => {
1825
1793
  input: [
1826
1794
  ctx.entryClientFilePath,
1827
1795
  ...Object.values(ctx.reactRouterConfig.routes).map(
1828
- (route) => `${path6.resolve(
1796
+ (route) => `${path4.resolve(
1829
1797
  ctx.reactRouterConfig.appDirectory,
1830
1798
  route.file
1831
- )}${BUILD_CLIENT_ROUTE_QUERY_STRING}`
1799
+ )}${ROUTE_ENTRY_QUERY_STRING}`
1832
1800
  )
1833
1801
  ]
1834
1802
  }
@@ -1847,7 +1815,7 @@ var reactRouterVitePlugin = () => {
1847
1815
  rollupOptions: {
1848
1816
  ...baseRollupOptions,
1849
1817
  preserveEntrySignatures: "exports-only",
1850
- input: viteUserConfig.build?.rollupOptions?.input ?? virtual.serverBuild.id,
1818
+ input: viteUserConfig.build?.rollupOptions?.input ?? serverBuildId,
1851
1819
  output: {
1852
1820
  entryFileNames: ctx.reactRouterConfig.serverBuildFile,
1853
1821
  format: ctx.reactRouterConfig.serverModuleFormat
@@ -1874,7 +1842,7 @@ var reactRouterVitePlugin = () => {
1874
1842
  "The React Router Vite plugin requires the use of a Vite config file"
1875
1843
  );
1876
1844
  }
1877
- let vite2 = getVite();
1845
+ let vite2 = importViteEsmSync();
1878
1846
  let childCompilerConfigFile = await vite2.loadConfigFromFile(
1879
1847
  {
1880
1848
  command: viteConfig.command,
@@ -1910,15 +1878,15 @@ var reactRouterVitePlugin = () => {
1910
1878
  envFile: false,
1911
1879
  plugins: [
1912
1880
  ...(childCompilerConfigFile.config.plugins ?? []).flat().filter(
1913
- (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"
1914
1882
  )
1915
1883
  ]
1916
1884
  });
1917
1885
  await viteChildCompiler.pluginContainer.buildStart({});
1918
1886
  },
1919
- async transform(code, id) {
1920
- if (isCssModulesFile(id)) {
1921
- cssModulesManifest[id] = code;
1887
+ async transform(code, id2) {
1888
+ if (isCssModulesFile(id2)) {
1889
+ cssModulesManifest[id2] = code;
1922
1890
  }
1923
1891
  },
1924
1892
  buildStart() {
@@ -1942,7 +1910,7 @@ var reactRouterVitePlugin = () => {
1942
1910
  (0, import_react_router2.unstable_setDevServerHooks)({
1943
1911
  // Give the request handler access to the critical CSS in dev to avoid a
1944
1912
  // flash of unstyled content since Vite injects CSS file contents via JS
1945
- getCriticalCss: async (build, url2) => {
1913
+ getCriticalCss: async (build, url3) => {
1946
1914
  return getStylesForUrl({
1947
1915
  rootDirectory: ctx.rootDirectory,
1948
1916
  entryClientFilePath: ctx.entryClientFilePath,
@@ -1950,7 +1918,7 @@ var reactRouterVitePlugin = () => {
1950
1918
  viteDevServer,
1951
1919
  cssModulesManifest,
1952
1920
  build,
1953
- url: url2
1921
+ url: url3
1954
1922
  });
1955
1923
  },
1956
1924
  // If an error is caught within the request handler, let Vite fix the
@@ -1998,7 +1966,7 @@ var reactRouterVitePlugin = () => {
1998
1966
  viteDevServer.middlewares.use(async (req, res, next) => {
1999
1967
  try {
2000
1968
  let build = await viteDevServer.ssrLoadModule(
2001
- virtual.serverBuild.id
1969
+ serverBuildId
2002
1970
  );
2003
1971
  let handler = (0, import_react_router2.createRequestHandler)(build, "development");
2004
1972
  let nodeHandler = async (nodeReq, nodeRes) => {
@@ -2033,8 +2001,8 @@ var reactRouterVitePlugin = () => {
2033
2001
  let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
2034
2002
  let movedAssetPaths = [];
2035
2003
  for (let ssrAssetPath of ssrAssetPaths) {
2036
- let src = path6.join(serverBuildDirectory, ssrAssetPath);
2037
- let dest = path6.join(clientBuildDirectory, ssrAssetPath);
2004
+ let src = path4.join(serverBuildDirectory, ssrAssetPath);
2005
+ let dest = path4.join(clientBuildDirectory, ssrAssetPath);
2038
2006
  if (!fse.existsSync(dest)) {
2039
2007
  await fse.move(src, dest);
2040
2008
  movedAssetPaths.push(dest);
@@ -2047,7 +2015,7 @@ var reactRouterVitePlugin = () => {
2047
2015
  );
2048
2016
  await Promise.all(
2049
2017
  ssrCssPaths.map(
2050
- (cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
2018
+ (cssPath) => fse.remove(path4.join(serverBuildDirectory, cssPath))
2051
2019
  )
2052
2020
  );
2053
2021
  if (movedAssetPaths.length) {
@@ -2056,7 +2024,7 @@ var reactRouterVitePlugin = () => {
2056
2024
  "",
2057
2025
  `${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
2058
2026
  ...movedAssetPaths.map(
2059
- (movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
2027
+ (movedAssetPath) => import_picocolors3.default.dim(path4.relative(ctx.rootDirectory, movedAssetPath))
2060
2028
  ),
2061
2029
  ""
2062
2030
  ].join("\n")
@@ -2098,12 +2066,12 @@ var reactRouterVitePlugin = () => {
2098
2066
  }
2099
2067
  },
2100
2068
  {
2101
- name: "react-router:build-client-route",
2069
+ name: "react-router-route-entry",
2102
2070
  enforce: "pre",
2103
- async transform(_code, id, options) {
2104
- if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
2105
- let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
2106
- 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);
2107
2075
  let sourceExports = await getRouteModuleExports(
2108
2076
  viteChildCompiler,
2109
2077
  ctx,
@@ -2116,24 +2084,23 @@ var reactRouterVitePlugin = () => {
2116
2084
  }
2117
2085
  },
2118
2086
  {
2119
- name: "react-router:virtual-modules",
2087
+ name: "react-router-virtual-modules",
2120
2088
  enforce: "pre",
2121
- resolveId(id) {
2122
- const vmod2 = Object.values(virtual).find((vmod3) => vmod3.id === id);
2123
- if (vmod2) return vmod2.resolvedId;
2089
+ resolveId(id2) {
2090
+ if (vmods.includes(id2)) return resolve3(id2);
2124
2091
  },
2125
- async load(id) {
2126
- switch (id) {
2127
- case virtual.serverBuild.resolvedId: {
2092
+ async load(id2) {
2093
+ switch (id2) {
2094
+ case resolve3(serverBuildId): {
2128
2095
  return await getServerEntry();
2129
2096
  }
2130
- case virtual.serverManifest.resolvedId: {
2097
+ case resolve3(serverManifestId): {
2131
2098
  let reactRouterManifest = ctx.isSsrBuild ? await ctx.getReactRouterServerManifest() : await getReactRouterManifestForDev();
2132
2099
  return `export default ${(0, import_jsesc.default)(reactRouterManifest, {
2133
2100
  es6: true
2134
2101
  })};`;
2135
2102
  }
2136
- case virtual.browserManifest.resolvedId: {
2103
+ case resolve3(browserManifestId): {
2137
2104
  if (viteCommand === "build") {
2138
2105
  throw new Error("This module only exists in development");
2139
2106
  }
@@ -2147,15 +2114,15 @@ var reactRouterVitePlugin = () => {
2147
2114
  }
2148
2115
  },
2149
2116
  {
2150
- name: "react-router:dot-server",
2117
+ name: "react-router-dot-server",
2151
2118
  enforce: "pre",
2152
- async resolveId(id, importer, options) {
2119
+ async resolveId(id2, importer, options) {
2153
2120
  let isOptimizeDeps = viteCommand === "serve" && options?.scan === true;
2154
2121
  if (isOptimizeDeps || options?.ssr) return;
2155
- let isResolving = options?.custom?.["react-router:dot-server"] ?? false;
2122
+ let isResolving = options?.custom?.["react-router-dot-server"] ?? false;
2156
2123
  if (isResolving) return;
2157
- options.custom = { ...options.custom, "react-router:dot-server": true };
2158
- 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);
2159
2126
  if (!resolved) return;
2160
2127
  let serverFileRE = /\.server(\.[cm]?[jt]sx?)?$/;
2161
2128
  let serverDirRE = /\/\.server\//;
@@ -2165,9 +2132,9 @@ var reactRouterVitePlugin = () => {
2165
2132
  if (viteCommand !== "build" && importer.endsWith(".html")) {
2166
2133
  return;
2167
2134
  }
2168
- let vite2 = getVite();
2135
+ let vite2 = importViteEsmSync();
2169
2136
  let importerShort = vite2.normalizePath(
2170
- path6.relative(ctx.rootDirectory, importer)
2137
+ path4.relative(ctx.rootDirectory, importer)
2171
2138
  );
2172
2139
  let isRoute = getRoute(ctx.reactRouterConfig, importer);
2173
2140
  if (isRoute) {
@@ -2178,12 +2145,12 @@ var reactRouterVitePlugin = () => {
2178
2145
  [
2179
2146
  import_picocolors3.default.red(`Server-only module referenced by client`),
2180
2147
  "",
2181
- ` '${id}' imported by route '${importerShort}'`,
2148
+ ` '${id2}' imported by route '${importerShort}'`,
2182
2149
  "",
2183
2150
  ` React Router automatically removes server-code from these exports:`,
2184
2151
  ` ${serverOnlyExports}`,
2185
2152
  "",
2186
- ` But other route exports in '${importerShort}' depend on '${id}'.`,
2153
+ ` But other route exports in '${importerShort}' depend on '${id2}'.`,
2187
2154
  "",
2188
2155
  " See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
2189
2156
  ""
@@ -2194,7 +2161,7 @@ var reactRouterVitePlugin = () => {
2194
2161
  [
2195
2162
  import_picocolors3.default.red(`Server-only module referenced by client`),
2196
2163
  "",
2197
- ` '${id}' imported by '${importerShort}'`,
2164
+ ` '${id2}' imported by '${importerShort}'`,
2198
2165
  "",
2199
2166
  " See https://remix.run/docs/en/main/guides/vite#splitting-up-client-and-server-code",
2200
2167
  ""
@@ -2203,12 +2170,12 @@ var reactRouterVitePlugin = () => {
2203
2170
  }
2204
2171
  },
2205
2172
  {
2206
- name: "react-router:dot-client",
2207
- async transform(code, id, options) {
2173
+ name: "react-router-dot-client",
2174
+ async transform(code, id2, options) {
2208
2175
  if (!options?.ssr) return;
2209
2176
  let clientFileRE = /\.client(\.[cm]?[jt]sx?)?$/;
2210
2177
  let clientDirRE = /\/\.client\//;
2211
- if (clientFileRE.test(id) || clientDirRE.test(id)) {
2178
+ if (clientFileRE.test(id2) || clientDirRE.test(id2)) {
2212
2179
  let exports2 = (0, import_es_module_lexer.parse)(code)[1];
2213
2180
  return {
2214
2181
  code: exports2.map(
@@ -2221,9 +2188,9 @@ var reactRouterVitePlugin = () => {
2221
2188
  },
2222
2189
  plugin,
2223
2190
  {
2224
- name: "react-router:route-exports",
2225
- async transform(code, id, options) {
2226
- 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);
2227
2194
  if (!route) return;
2228
2195
  if (!options?.ssr && !ctx.reactRouterConfig.ssr) {
2229
2196
  let serverOnlyExports = (0, import_es_module_lexer.parse)(code)[1].map((exp) => exp.n).filter((exp) => SERVER_ONLY_ROUTE_EXPORTS.includes(exp));
@@ -2240,7 +2207,7 @@ var reactRouterVitePlugin = () => {
2240
2207
  }
2241
2208
  }
2242
2209
  }
2243
- let [filepath] = id.split("?");
2210
+ let [filepath] = id2.split("?");
2244
2211
  let ast = (0, import_parser.parse)(code, { sourceType: "module" });
2245
2212
  if (!options?.ssr) {
2246
2213
  removeExports(ast, SERVER_ONLY_ROUTE_EXPORTS);
@@ -2248,23 +2215,22 @@ var reactRouterVitePlugin = () => {
2248
2215
  transform(ast);
2249
2216
  return generate2(ast, {
2250
2217
  sourceMaps: true,
2251
- filename: id,
2218
+ filename: id2,
2252
2219
  sourceFileName: filepath
2253
2220
  });
2254
2221
  }
2255
2222
  },
2256
2223
  {
2257
- name: "react-router:inject-hmr-runtime",
2224
+ name: "react-router-inject-hmr-runtime",
2258
2225
  enforce: "pre",
2259
- resolveId(id) {
2260
- if (id === virtualInjectHmrRuntime.id) {
2261
- return virtualInjectHmrRuntime.resolvedId;
2262
- }
2226
+ resolveId(id2) {
2227
+ if (id2 === injectHmrRuntimeId)
2228
+ return resolve3(injectHmrRuntimeId);
2263
2229
  },
2264
- async load(id) {
2265
- if (id !== virtualInjectHmrRuntime.resolvedId) return;
2230
+ async load(id2) {
2231
+ if (id2 !== resolve3(injectHmrRuntimeId)) return;
2266
2232
  return [
2267
- `import RefreshRuntime from "${virtualHmrRuntime.id}"`,
2233
+ `import RefreshRuntime from "${hmrRuntimeId}"`,
2268
2234
  "RefreshRuntime.injectIntoGlobalHook(window)",
2269
2235
  "window.$RefreshReg$ = () => {}",
2270
2236
  "window.$RefreshSig$ = () => (type) => type",
@@ -2273,17 +2239,17 @@ var reactRouterVitePlugin = () => {
2273
2239
  }
2274
2240
  },
2275
2241
  {
2276
- name: "react-router:hmr-runtime",
2242
+ name: "react-router-hmr-runtime",
2277
2243
  enforce: "pre",
2278
- resolveId(id) {
2279
- if (id === virtualHmrRuntime.id) return virtualHmrRuntime.resolvedId;
2244
+ resolveId(id2) {
2245
+ if (id2 === hmrRuntimeId) return resolve3(hmrRuntimeId);
2280
2246
  },
2281
- async load(id) {
2282
- if (id !== virtualHmrRuntime.resolvedId) return;
2283
- let reactRefreshDir = path6.dirname(
2247
+ async load(id2) {
2248
+ if (id2 !== resolve3(hmrRuntimeId)) return;
2249
+ let reactRefreshDir = path4.dirname(
2284
2250
  require.resolve("react-refresh/package.json")
2285
2251
  );
2286
- let reactRefreshRuntimePath = path6.join(
2252
+ let reactRefreshRuntimePath = path4.join(
2287
2253
  reactRefreshDir,
2288
2254
  "cjs/react-refresh-runtime.development.js"
2289
2255
  );
@@ -2299,11 +2265,11 @@ var reactRouterVitePlugin = () => {
2299
2265
  }
2300
2266
  },
2301
2267
  {
2302
- name: "react-router:react-refresh-babel",
2303
- async transform(code, id, options) {
2268
+ name: "react-router-react-refresh-babel",
2269
+ async transform(code, id2, options) {
2304
2270
  if (viteCommand !== "serve") return;
2305
- if (id.includes("/node_modules/")) return;
2306
- let [filepath] = id.split("?");
2271
+ if (id2.includes("/node_modules/")) return;
2272
+ let [filepath] = id2.split("?");
2307
2273
  let extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
2308
2274
  if (!extensionsRE.test(filepath)) return;
2309
2275
  let devRuntime = "react/jsx-dev-runtime";
@@ -2311,10 +2277,13 @@ var reactRouterVitePlugin = () => {
2311
2277
  let isJSX = filepath.endsWith("x");
2312
2278
  let useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
2313
2279
  if (!useFastRefresh) return;
2280
+ if (isRouteEntry(id2)) {
2281
+ return { code: addRefreshWrapper(ctx.reactRouterConfig, code, id2) };
2282
+ }
2314
2283
  let result = await babel.transformAsync(code, {
2315
2284
  babelrc: false,
2316
2285
  configFile: false,
2317
- filename: id,
2286
+ filename: id2,
2318
2287
  sourceFileName: filepath,
2319
2288
  parserOpts: {
2320
2289
  sourceType: "module",
@@ -2327,18 +2296,18 @@ var reactRouterVitePlugin = () => {
2327
2296
  code = result.code;
2328
2297
  let refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
2329
2298
  if (refreshContentRE.test(code)) {
2330
- code = addRefreshWrapper(ctx.reactRouterConfig, code, id);
2299
+ code = addRefreshWrapper(ctx.reactRouterConfig, code, id2);
2331
2300
  }
2332
2301
  return { code, map: result.map };
2333
2302
  }
2334
2303
  },
2335
2304
  {
2336
- name: "react-router:hmr-updates",
2305
+ name: "react-router-hmr-updates",
2337
2306
  async handleHotUpdate({ server, file, modules, read }) {
2338
2307
  let route = getRoute(ctx.reactRouterConfig, file);
2339
2308
  let hmrEventData = { route: null };
2340
2309
  if (route) {
2341
- let serverManifest = (await server.ssrLoadModule(virtual.serverManifest.id)).default;
2310
+ let serverManifest = (await server.ssrLoadModule(serverManifestId)).default;
2342
2311
  let oldRouteMetadata = serverManifest.routes[route.id];
2343
2312
  let newRouteMetadata = await getRouteMetadata(
2344
2313
  ctx,
@@ -2364,69 +2333,39 @@ var reactRouterVitePlugin = () => {
2364
2333
  });
2365
2334
  return modules;
2366
2335
  }
2367
- },
2368
- {
2369
- name: "react-router-server-change-trigger-client-hmr",
2370
- // This hook is only available in Vite v6+ so this is a no-op in v5.
2371
- // Previously the server and client modules were shared in a single module
2372
- // graph. This meant that changes to server code automatically resulted in
2373
- // client HMR updates. In Vite v6+ these module graphs are separate from
2374
- // each other so we need to manually trigger client HMR updates if server
2375
- // code has changed.
2376
- hotUpdate({ server, modules }) {
2377
- if (this.environment.name !== "ssr" && modules.length <= 0) {
2378
- return;
2379
- }
2380
- let clientModules = uniqueNodes(
2381
- modules.flatMap(
2382
- (mod) => getParentClientNodes(server.environments.client.moduleGraph, mod)
2383
- )
2384
- );
2385
- for (let clientModule of clientModules) {
2386
- server.environments.client.reloadModule(clientModule);
2387
- }
2388
- }
2389
2336
  }
2390
2337
  ];
2391
2338
  };
2392
- function getParentClientNodes(clientModuleGraph, module2) {
2393
- if (!module2.id) {
2394
- return [];
2395
- }
2396
- let clientModule = clientModuleGraph.getModuleById(module2.id);
2397
- if (clientModule) {
2398
- return [clientModule];
2399
- }
2400
- return [...module2.importers].flatMap(
2401
- (importer) => getParentClientNodes(clientModuleGraph, importer)
2402
- );
2403
- }
2404
- function uniqueNodes(nodes) {
2405
- let nodeUrls = /* @__PURE__ */ new Set();
2406
- let unique = [];
2407
- for (let node of nodes) {
2408
- if (nodeUrls.has(node.url)) {
2409
- continue;
2410
- }
2411
- nodeUrls.add(node.url);
2412
- unique.push(node);
2413
- }
2414
- return unique;
2415
- }
2416
- function addRefreshWrapper(reactRouterConfig, code, id) {
2417
- let route = getRoute(reactRouterConfig, id);
2418
- let acceptExports = route ? [
2339
+ function addRefreshWrapper(reactRouterConfig, code, id2) {
2340
+ let route = getRoute(reactRouterConfig, id2);
2341
+ let acceptExports = route || isRouteEntry(id2) ? [
2419
2342
  "clientAction",
2420
2343
  "clientLoader",
2344
+ "clientMiddleware",
2421
2345
  "handle",
2422
2346
  "meta",
2423
2347
  "links",
2424
2348
  "shouldRevalidate"
2425
2349
  ] : [];
2426
- 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}`;
2427
2366
  }
2428
2367
  var REACT_REFRESH_HEADER = `
2429
- import RefreshRuntime from "${virtualHmrRuntime.id}";
2368
+ import RefreshRuntime from "${hmrRuntimeId}";
2430
2369
 
2431
2370
  const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
2432
2371
  let prevRefreshReg;
@@ -2445,7 +2384,7 @@ if (import.meta.hot && !inWebWorker) {
2445
2384
  RefreshRuntime.register(type, __SOURCE__ + " " + id)
2446
2385
  };
2447
2386
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
2448
- }`.replaceAll("\n", "");
2387
+ }`.trim();
2449
2388
  var REACT_REFRESH_FOOTER = `
2450
2389
  if (import.meta.hot && !inWebWorker) {
2451
2390
  window.$RefreshReg$ = prevRefreshReg;
@@ -2459,11 +2398,11 @@ if (import.meta.hot && !inWebWorker) {
2459
2398
  if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
2460
2399
  });
2461
2400
  });
2462
- }`;
2401
+ }`.trim();
2463
2402
  function getRoute(pluginConfig, file) {
2464
- let vite2 = getVite();
2403
+ let vite2 = importViteEsmSync();
2465
2404
  let routePath = vite2.normalizePath(
2466
- path6.relative(pluginConfig.appDirectory, file)
2405
+ path4.relative(pluginConfig.appDirectory, file)
2467
2406
  );
2468
2407
  let route = Object.values(pluginConfig.routes).find(
2469
2408
  (r) => vite2.normalizePath(r.file) === routePath
@@ -2485,7 +2424,7 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
2485
2424
  caseSensitive: route.caseSensitive,
2486
2425
  url: combineURLs(
2487
2426
  ctx.publicPath,
2488
- "/" + path6.relative(
2427
+ "/" + path4.relative(
2489
2428
  ctx.rootDirectory,
2490
2429
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
2491
2430
  )
@@ -2508,11 +2447,11 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
2508
2447
  return info;
2509
2448
  }
2510
2449
  async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, serverBuildDirectory) {
2511
- let serverBuildPath = path6.join(
2450
+ let serverBuildPath = path4.join(
2512
2451
  serverBuildDirectory,
2513
2452
  reactRouterConfig.serverBuildFile
2514
2453
  );
2515
- let build = await import(url.pathToFileURL(serverBuildPath).toString());
2454
+ let build = await import(url2.pathToFileURL(serverBuildPath).toString());
2516
2455
  let { createRequestHandler: createHandler } = await import("react-router");
2517
2456
  return {
2518
2457
  build,
@@ -2530,9 +2469,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
2530
2469
  let html = await response.text();
2531
2470
  validatePrerenderedResponse(response, html, "SPA Mode", "/");
2532
2471
  validatePrerenderedHtml(html, "SPA Mode");
2533
- await fse.writeFile(path6.join(clientBuildDirectory, "index.html"), html);
2472
+ await fse.writeFile(path4.join(clientBuildDirectory, "index.html"), html);
2534
2473
  viteConfig.logger.info(
2535
- "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"
2536
2475
  );
2537
2476
  }
2538
2477
  async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
@@ -2562,14 +2501,14 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2562
2501
  // build time or runtime
2563
2502
  "X-React-Router-Prerender": "yes"
2564
2503
  };
2565
- for (let path7 of routesToPrerender) {
2566
- 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);
2567
2506
  let hasLoaders = matches?.some((m) => m.route.loader);
2568
2507
  let data;
2569
2508
  if (hasLoaders) {
2570
2509
  data = await prerenderData(
2571
2510
  handler,
2572
- path7,
2511
+ path5,
2573
2512
  clientBuildDirectory,
2574
2513
  reactRouterConfig,
2575
2514
  viteConfig,
@@ -2582,7 +2521,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2582
2521
  if (isResourceRoute) {
2583
2522
  await prerenderResourceRoute(
2584
2523
  handler,
2585
- path7,
2524
+ path5,
2586
2525
  clientBuildDirectory,
2587
2526
  reactRouterConfig,
2588
2527
  viteConfig,
@@ -2591,7 +2530,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2591
2530
  } else {
2592
2531
  await prerenderRoute(
2593
2532
  handler,
2594
- path7,
2533
+ path5,
2595
2534
  clientBuildDirectory,
2596
2535
  reactRouterConfig,
2597
2536
  viteConfig,
@@ -2648,9 +2587,9 @@ async function prerenderData(handler, prerenderPath, clientBuildDirectory, react
2648
2587
  let response = await handler(request);
2649
2588
  let data = await response.text();
2650
2589
  validatePrerenderedResponse(response, data, "Prerender", normalizedPath);
2651
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2652
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
2653
- 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));
2654
2593
  await fse.outputFile(outfile, data);
2655
2594
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2656
2595
  return data;
@@ -2667,9 +2606,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
2667
2606
  if (!reactRouterConfig.ssr) {
2668
2607
  validatePrerenderedHtml(html, "Prerender");
2669
2608
  }
2670
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2671
- let outfile = path6.join(outdir, ...normalizedPath.split("/"), "index.html");
2672
- 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));
2673
2612
  await fse.outputFile(outfile, html);
2674
2613
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2675
2614
  }
@@ -2679,9 +2618,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
2679
2618
  let response = await handler(request);
2680
2619
  let text = await response.text();
2681
2620
  validatePrerenderedResponse(response, text, "Prerender", normalizedPath);
2682
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2683
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
2684
- 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));
2685
2624
  await fse.outputFile(outfile, text);
2686
2625
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2687
2626
  }
@@ -2690,17 +2629,17 @@ async function prerenderManifest(build, clientBuildDirectory, reactRouterConfig,
2690
2629
  /\/\/+/g,
2691
2630
  "/"
2692
2631
  );
2693
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2694
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
2695
- 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));
2696
2635
  let manifestData = JSON.stringify(build.assets.routes);
2697
2636
  await fse.outputFile(outfile, manifestData);
2698
2637
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2699
2638
  }
2700
- function validatePrerenderedResponse(response, html, prefix, path7) {
2639
+ function validatePrerenderedResponse(response, html, prefix, path5) {
2701
2640
  if (response.status !== 200) {
2702
2641
  throw new Error(
2703
- `${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.
2704
2643
  ${html}`
2705
2644
  );
2706
2645
  }
@@ -2735,6 +2674,8 @@ function createPrerenderRoutes(manifest, parentId = "", routesByParentId = group
2735
2674
  loader: route.module.loader ? () => null : void 0,
2736
2675
  action: void 0,
2737
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
2738
2679
  };
2739
2680
  return route.index ? {
2740
2681
  index: true,