@react-router/dev 7.1.1 → 7.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vite.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v7.1.1
2
+ * @react-router/dev v7.1.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -46,7 +46,7 @@ module.exports = __toCommonJS(vite_exports);
46
46
 
47
47
  // vite/plugin.ts
48
48
  var import_node_crypto = require("crypto");
49
- var path4 = __toESM(require("path"));
49
+ var path6 = __toESM(require("path"));
50
50
  var url = __toESM(require("url"));
51
51
  var fse = __toESM(require("fs-extra"));
52
52
  var babel = __toESM(require("@babel/core"));
@@ -70,6 +70,9 @@ var import_server = require("vite-node/server");
70
70
  var import_client = require("vite-node/client");
71
71
  var import_source_map = require("vite-node/source-map");
72
72
 
73
+ // vite/vite.ts
74
+ var import_pathe2 = __toESM(require("pathe"));
75
+
73
76
  // invariant.ts
74
77
  function invariant(value, message) {
75
78
  if (value === false || value === null || typeof value === "undefined") {
@@ -80,20 +83,41 @@ function invariant(value, message) {
80
83
  }
81
84
  }
82
85
 
83
- // vite/import-vite-esm-sync.ts
86
+ // config/is-react-router-repo.ts
87
+ var import_pathe = __toESM(require("pathe"));
88
+ function isReactRouterRepo() {
89
+ let serverRuntimePath = import_pathe.default.dirname(
90
+ require.resolve("@react-router/node/package.json")
91
+ );
92
+ let serverRuntimeParentDir = import_pathe.default.basename(
93
+ import_pathe.default.resolve(serverRuntimePath, "..")
94
+ );
95
+ return serverRuntimeParentDir === "packages";
96
+ }
97
+
98
+ // vite/vite.ts
84
99
  var vite;
85
- async function preloadViteEsm() {
86
- vite = await import("vite");
100
+ var viteImportSpecifier = isReactRouterRepo() ? (
101
+ // Support testing against different versions of Vite by ensuring that Vite
102
+ // is resolved from the current working directory when running within this
103
+ // repo. If we don't do this, Vite will always be imported relative to this
104
+ // file, which means that it will always resolve to Vite 6.
105
+ `file:///${import_pathe2.default.normalize(
106
+ require.resolve("vite/package.json", { paths: [process.cwd()] })
107
+ ).replace("package.json", "dist/node/index.js")}`
108
+ ) : "vite";
109
+ async function preloadVite() {
110
+ vite = await import(viteImportSpecifier);
87
111
  }
88
- function importViteEsmSync() {
89
- invariant(vite, "importViteEsmSync() called before preloadViteEsm()");
112
+ function getVite() {
113
+ invariant(vite, "getVite() called before preloadVite()");
90
114
  return vite;
91
115
  }
92
116
 
93
117
  // vite/vite-node.ts
94
118
  async function createContext(viteConfig = {}) {
95
- await preloadViteEsm();
96
- const vite2 = importViteEsmSync();
119
+ await preloadVite();
120
+ const vite2 = getVite();
97
121
  const devServer = await vite2.createServer(
98
122
  vite2.mergeConfig(
99
123
  {
@@ -130,7 +154,7 @@ async function createContext(viteConfig = {}) {
130
154
  }
131
155
 
132
156
  // config/config.ts
133
- var import_pathe = __toESM(require("pathe"));
157
+ var import_pathe3 = __toESM(require("pathe"));
134
158
  var import_chokidar = __toESM(require("chokidar"));
135
159
  var import_picocolors = __toESM(require("picocolors"));
136
160
  var import_pick2 = __toESM(require("lodash/pick"));
@@ -184,7 +208,7 @@ function validateRouteConfig({
184
208
  `Route config in "${routeConfigFile}" is invalid.`,
185
209
  root ? `${root}` : [],
186
210
  nested ? Object.entries(nested).map(
187
- ([path5, message]) => `Path: routes.${path5}
211
+ ([path7, message]) => `Path: routes.${path7}
188
212
  ${message}`
189
213
  ) : []
190
214
  ].flat().join("\n\n")
@@ -366,13 +390,13 @@ async function resolveConfig({
366
390
  "The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
367
391
  );
368
392
  }
369
- let appDirectory = import_pathe.default.resolve(root, userAppDirectory || "app");
370
- let buildDirectory = import_pathe.default.resolve(root, userBuildDirectory);
393
+ let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
394
+ let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
371
395
  let rootRouteFile = findEntry(appDirectory, "root");
372
396
  if (!rootRouteFile) {
373
- let rootRouteDisplayPath = import_pathe.default.relative(
397
+ let rootRouteDisplayPath = import_pathe3.default.relative(
374
398
  root,
375
- import_pathe.default.join(appDirectory, "root.tsx")
399
+ import_pathe3.default.join(appDirectory, "root.tsx")
376
400
  );
377
401
  return err(
378
402
  `Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
@@ -384,15 +408,15 @@ async function resolveConfig({
384
408
  let routeConfigFile = findEntry(appDirectory, "routes");
385
409
  try {
386
410
  if (!routeConfigFile) {
387
- let routeConfigDisplayPath = import_pathe.default.relative(
411
+ let routeConfigDisplayPath = import_pathe3.default.relative(
388
412
  root,
389
- import_pathe.default.join(appDirectory, "routes.ts")
413
+ import_pathe3.default.join(appDirectory, "routes.ts")
390
414
  );
391
415
  return err(`Route config file not found at "${routeConfigDisplayPath}".`);
392
416
  }
393
417
  setAppDirectory(appDirectory);
394
418
  let routeConfigExport = (await viteNodeContext.runner.executeFile(
395
- import_pathe.default.join(appDirectory, routeConfigFile)
419
+ import_pathe3.default.join(appDirectory, routeConfigFile)
396
420
  )).default;
397
421
  let routeConfig = await routeConfigExport;
398
422
  let result = validateRouteConfig({
@@ -412,7 +436,7 @@ async function resolveConfig({
412
436
  import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
413
437
  "",
414
438
  error.loc?.file && error.loc?.column && error.frame ? [
415
- import_pathe.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
439
+ import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
416
440
  error.frame.trim?.()
417
441
  ] : error.stack
418
442
  ].flat().join("\n")
@@ -484,8 +508,8 @@ async function createConfigLoader({
484
508
  );
485
509
  fsWatcher.on("all", async (...args) => {
486
510
  let [event, rawFilepath] = args;
487
- let filepath = import_pathe.default.normalize(rawFilepath);
488
- let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe.default.normalize(appDirectory));
511
+ let filepath = import_pathe3.default.normalize(rawFilepath);
512
+ let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
489
513
  let configCodeUpdated = Boolean(
490
514
  viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
491
515
  );
@@ -531,8 +555,8 @@ async function resolveEntryFiles({
531
555
  reactRouterConfig
532
556
  }) {
533
557
  let { appDirectory } = reactRouterConfig;
534
- let defaultsDirectory = import_pathe.default.resolve(
535
- import_pathe.default.dirname(require.resolve("@react-router/dev/package.json")),
558
+ let defaultsDirectory = import_pathe3.default.resolve(
559
+ import_pathe3.default.dirname(require.resolve("@react-router/dev/package.json")),
536
560
  "dist",
537
561
  "config",
538
562
  "defaults"
@@ -570,11 +594,11 @@ async function resolveEntryFiles({
570
594
  }
571
595
  entryServerFile = `entry.server.node.tsx`;
572
596
  }
573
- let entryClientFilePath = userEntryClientFile ? import_pathe.default.resolve(reactRouterConfig.appDirectory, userEntryClientFile) : import_pathe.default.resolve(defaultsDirectory, entryClientFile);
574
- let entryServerFilePath = userEntryServerFile ? import_pathe.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe.default.resolve(defaultsDirectory, entryServerFile);
597
+ let entryClientFilePath = userEntryClientFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryClientFile) : import_pathe3.default.resolve(defaultsDirectory, entryClientFile);
598
+ let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
575
599
  return { entryClientFilePath, entryServerFilePath };
576
600
  }
577
- var ssrExternals = isInReactRouterMonorepo() ? [
601
+ var ssrExternals = isReactRouterRepo() ? [
578
602
  // This is only needed within this repo because these packages
579
603
  // are linked to a directory outside of node_modules so Vite
580
604
  // treats them as internal code by default.
@@ -587,21 +611,12 @@ var ssrExternals = isInReactRouterMonorepo() ? [
587
611
  "@react-router/node",
588
612
  "@react-router/serve"
589
613
  ] : void 0;
590
- function isInReactRouterMonorepo() {
591
- let serverRuntimePath = import_pathe.default.dirname(
592
- require.resolve("@react-router/node/package.json")
593
- );
594
- let serverRuntimeParentDir = import_pathe.default.basename(
595
- import_pathe.default.resolve(serverRuntimePath, "..")
596
- );
597
- return serverRuntimeParentDir === "packages";
598
- }
599
614
  var entryExts = [".js", ".jsx", ".ts", ".tsx"];
600
615
  function findEntry(dir, basename2, options) {
601
616
  for (let ext of entryExts) {
602
- let file = import_pathe.default.resolve(dir, basename2 + ext);
617
+ let file = import_pathe3.default.resolve(dir, basename2 + ext);
603
618
  if (import_node_fs.default.existsSync(file)) {
604
- return options?.absolute ?? false ? file : import_pathe.default.relative(dir, file);
619
+ return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
605
620
  }
606
621
  }
607
622
  return void 0;
@@ -688,7 +703,7 @@ function generate(ctx, route) {
688
703
  }
689
704
  `;
690
705
  }
691
- var noExtension = (path5) => Path3.join(Path3.dirname(path5), Pathe2.filename(path5));
706
+ var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
692
707
  function getRouteLineage(routes, route) {
693
708
  const result = [];
694
709
  while (route) {
@@ -850,17 +865,17 @@ async function toNodeRequest(res, nodeRes) {
850
865
  }
851
866
 
852
867
  // vite/styles.ts
853
- var path3 = __toESM(require("path"));
868
+ var path5 = __toESM(require("path"));
854
869
  var import_react_router = require("react-router");
855
870
 
856
871
  // vite/resolve-file-url.ts
857
- var path2 = __toESM(require("path"));
872
+ var path4 = __toESM(require("path"));
858
873
  var resolveFileUrl = ({ rootDirectory }, filePath) => {
859
- let vite2 = importViteEsmSync();
860
- let relativePath = path2.relative(rootDirectory, filePath);
861
- let isWithinRoot = !relativePath.startsWith("..") && !path2.isAbsolute(relativePath);
874
+ let vite2 = getVite();
875
+ let relativePath = path4.relative(rootDirectory, filePath);
876
+ let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
862
877
  if (!isWithinRoot) {
863
- return path2.posix.join("/@fs", vite2.normalizePath(filePath));
878
+ return path4.posix.join("/@fs", vite2.normalizePath(filePath));
864
879
  }
865
880
  return "/" + vite2.normalizePath(relativePath);
866
881
  };
@@ -894,13 +909,13 @@ var getStylesForFiles = async ({
894
909
  cssModulesManifest,
895
910
  files
896
911
  }) => {
897
- let vite2 = importViteEsmSync();
912
+ let vite2 = getVite();
898
913
  let viteMajor = parseInt(vite2.version.split(".")[0], 10);
899
914
  let styles = {};
900
915
  let deps = /* @__PURE__ */ new Set();
901
916
  try {
902
917
  for (let file of files) {
903
- let normalizedPath = path3.resolve(rootDirectory, file).replace(/\\/g, "/");
918
+ let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
904
919
  let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
905
920
  if (!node) {
906
921
  try {
@@ -1005,9 +1020,9 @@ var getStylesForUrl = async ({
1005
1020
  return void 0;
1006
1021
  }
1007
1022
  let routes = createRoutes(build.routes);
1008
- let appPath = path3.relative(process.cwd(), reactRouterConfig.appDirectory);
1023
+ let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
1009
1024
  let documentRouteFiles = (0, import_react_router.matchRoutes)(routes, url2, build.basename)?.map(
1010
- (match) => path3.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1025
+ (match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1011
1026
  ) ?? [];
1012
1027
  let styles = await getStylesForFiles({
1013
1028
  viteDevServer,
@@ -1015,7 +1030,7 @@ var getStylesForUrl = async ({
1015
1030
  cssModulesManifest,
1016
1031
  files: [
1017
1032
  // Always include the client entry file when crawling the module graph for CSS
1018
- path3.relative(rootDirectory, entryClientFilePath),
1033
+ path5.relative(rootDirectory, entryClientFilePath),
1019
1034
  // Then include any styles from the matched routes
1020
1035
  ...documentRouteFiles
1021
1036
  ]
@@ -1045,10 +1060,10 @@ var removeExports = (ast, exportsToRemove) => {
1045
1060
  let exportsFiltered = false;
1046
1061
  let markedForRemoval = /* @__PURE__ */ new Set();
1047
1062
  traverse(ast, {
1048
- ExportDeclaration(path5) {
1049
- if (path5.node.type === "ExportNamedDeclaration") {
1050
- if (path5.node.specifiers.length) {
1051
- path5.node.specifiers = path5.node.specifiers.filter((specifier) => {
1063
+ ExportDeclaration(path7) {
1064
+ if (path7.node.type === "ExportNamedDeclaration") {
1065
+ if (path7.node.specifiers.length) {
1066
+ path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
1052
1067
  if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
1053
1068
  if (exportsToRemove.includes(specifier.exported.name)) {
1054
1069
  exportsFiltered = true;
@@ -1057,12 +1072,12 @@ var removeExports = (ast, exportsToRemove) => {
1057
1072
  }
1058
1073
  return true;
1059
1074
  });
1060
- if (path5.node.specifiers.length === 0) {
1061
- markedForRemoval.add(path5);
1075
+ if (path7.node.specifiers.length === 0) {
1076
+ markedForRemoval.add(path7);
1062
1077
  }
1063
1078
  }
1064
- if (path5.node.declaration?.type === "VariableDeclaration") {
1065
- let declaration = path5.node.declaration;
1079
+ if (path7.node.declaration?.type === "VariableDeclaration") {
1080
+ let declaration = path7.node.declaration;
1066
1081
  declaration.declarations = declaration.declarations.filter(
1067
1082
  (declaration2) => {
1068
1083
  if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
@@ -1076,30 +1091,30 @@ var removeExports = (ast, exportsToRemove) => {
1076
1091
  }
1077
1092
  );
1078
1093
  if (declaration.declarations.length === 0) {
1079
- markedForRemoval.add(path5);
1094
+ markedForRemoval.add(path7);
1080
1095
  }
1081
1096
  }
1082
- if (path5.node.declaration?.type === "FunctionDeclaration") {
1083
- let id = path5.node.declaration.id;
1097
+ if (path7.node.declaration?.type === "FunctionDeclaration") {
1098
+ let id = path7.node.declaration.id;
1084
1099
  if (id && exportsToRemove.includes(id.name)) {
1085
- markedForRemoval.add(path5);
1100
+ markedForRemoval.add(path7);
1086
1101
  }
1087
1102
  }
1088
- if (path5.node.declaration?.type === "ClassDeclaration") {
1089
- let id = path5.node.declaration.id;
1103
+ if (path7.node.declaration?.type === "ClassDeclaration") {
1104
+ let id = path7.node.declaration.id;
1090
1105
  if (id && exportsToRemove.includes(id.name)) {
1091
- markedForRemoval.add(path5);
1106
+ markedForRemoval.add(path7);
1092
1107
  }
1093
1108
  }
1094
1109
  }
1095
- if (path5.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1096
- markedForRemoval.add(path5);
1110
+ if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1111
+ markedForRemoval.add(path7);
1097
1112
  }
1098
1113
  }
1099
1114
  });
1100
1115
  if (markedForRemoval.size > 0 || exportsFiltered) {
1101
- for (let path5 of markedForRemoval) {
1102
- path5.remove();
1116
+ for (let path7 of markedForRemoval) {
1117
+ path7.remove();
1103
1118
  }
1104
1119
  (0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
1105
1120
  }
@@ -1197,24 +1212,24 @@ var plugin = {
1197
1212
  };
1198
1213
  var transform = (ast) => {
1199
1214
  const hocs = [];
1200
- function getHocUid(path5, hocName) {
1201
- const uid = path5.scope.generateUidIdentifier(hocName);
1215
+ function getHocUid(path7, hocName) {
1216
+ const uid = path7.scope.generateUidIdentifier(hocName);
1202
1217
  hocs.push([hocName, uid]);
1203
1218
  return uid;
1204
1219
  }
1205
1220
  traverse(ast, {
1206
- ExportDeclaration(path5) {
1207
- if (path5.isExportDefaultDeclaration()) {
1208
- const declaration = path5.get("declaration");
1221
+ ExportDeclaration(path7) {
1222
+ if (path7.isExportDefaultDeclaration()) {
1223
+ const declaration = path7.get("declaration");
1209
1224
  const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
1210
1225
  if (expr) {
1211
- const uid = getHocUid(path5, "withComponentProps");
1226
+ const uid = getHocUid(path7, "withComponentProps");
1212
1227
  declaration.replaceWith(t.callExpression(uid, [expr]));
1213
1228
  }
1214
1229
  return;
1215
1230
  }
1216
- if (path5.isExportNamedDeclaration()) {
1217
- const decl = path5.get("declaration");
1231
+ if (path7.isExportNamedDeclaration()) {
1232
+ const decl = path7.get("declaration");
1218
1233
  if (decl.isVariableDeclaration()) {
1219
1234
  decl.get("declarations").forEach((varDeclarator) => {
1220
1235
  const id = varDeclarator.get("id");
@@ -1224,7 +1239,7 @@ var transform = (ast) => {
1224
1239
  if (!id.isIdentifier()) return;
1225
1240
  const { name } = id.node;
1226
1241
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1227
- const uid = getHocUid(path5, `with${name}Props`);
1242
+ const uid = getHocUid(path7, `with${name}Props`);
1228
1243
  init.replaceWith(t.callExpression(uid, [expr]));
1229
1244
  });
1230
1245
  return;
@@ -1234,7 +1249,7 @@ var transform = (ast) => {
1234
1249
  if (!id) return;
1235
1250
  const { name } = id;
1236
1251
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1237
- const uid = getHocUid(path5, `with${name}Props`);
1252
+ const uid = getHocUid(path7, `with${name}Props`);
1238
1253
  decl.replaceWith(
1239
1254
  t.variableDeclaration("const", [
1240
1255
  t.variableDeclarator(
@@ -1286,9 +1301,9 @@ var BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route";
1286
1301
  var virtualHmrRuntime = create("hmr-runtime");
1287
1302
  var virtualInjectHmrRuntime = create("inject-hmr-runtime");
1288
1303
  var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
1289
- let vite2 = importViteEsmSync();
1304
+ let vite2 = getVite();
1290
1305
  let file = route.file;
1291
- let fullPath = path4.resolve(reactRouterConfig.appDirectory, file);
1306
+ let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
1292
1307
  return vite2.normalizePath(fullPath);
1293
1308
  };
1294
1309
  var virtual = {
@@ -1309,9 +1324,9 @@ var getHash = (source, maxLength) => {
1309
1324
  return typeof maxLength === "number" ? hash.slice(0, maxLength) : hash;
1310
1325
  };
1311
1326
  var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
1312
- let vite2 = importViteEsmSync();
1327
+ let vite2 = getVite();
1313
1328
  let rootRelativeFilePath = vite2.normalizePath(
1314
- path4.relative(ctx.rootDirectory, absoluteFilePath)
1329
+ path6.relative(ctx.rootDirectory, absoluteFilePath)
1315
1330
  );
1316
1331
  let entryChunk = viteManifest[rootRelativeFilePath + BUILD_CLIENT_ROUTE_QUERY_STRING] ?? viteManifest[rootRelativeFilePath];
1317
1332
  if (!entryChunk) {
@@ -1363,7 +1378,7 @@ function dedupe(array2) {
1363
1378
  return [...new Set(array2)];
1364
1379
  }
1365
1380
  var writeFileSafe = async (file, contents) => {
1366
- await fse.ensureDir(path4.dirname(file));
1381
+ await fse.ensureDir(path6.dirname(file));
1367
1382
  await fse.writeFile(file, contents);
1368
1383
  };
1369
1384
  var getRouteManifestModuleExports = async (viteChildCompiler, ctx) => {
@@ -1385,7 +1400,7 @@ var getRouteModuleExports = async (viteChildCompiler, ctx, routeFile, readRouteF
1385
1400
  }
1386
1401
  let ssr = true;
1387
1402
  let { pluginContainer, moduleGraph } = viteChildCompiler;
1388
- let routePath = path4.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
1403
+ let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
1389
1404
  let url2 = resolveFileUrl(ctx, routePath);
1390
1405
  let resolveId = async () => {
1391
1406
  let result = await pluginContainer.resolveId(url2, void 0, { ssr });
@@ -1409,19 +1424,19 @@ var getServerBundleBuildConfig = (viteUserConfig) => {
1409
1424
  }
1410
1425
  return viteUserConfig.__reactRouterServerBundleBuildConfig;
1411
1426
  };
1412
- var getServerBuildDirectory = (ctx) => path4.join(
1427
+ var getServerBuildDirectory = (ctx) => path6.join(
1413
1428
  ctx.reactRouterConfig.buildDirectory,
1414
1429
  "server",
1415
1430
  ...ctx.serverBundleBuildConfig ? [ctx.serverBundleBuildConfig.serverBundleId] : []
1416
1431
  );
1417
- var getClientBuildDirectory = (reactRouterConfig) => path4.join(reactRouterConfig.buildDirectory, "client");
1418
- var defaultEntriesDir = path4.resolve(
1419
- path4.dirname(require.resolve("@react-router/dev/package.json")),
1432
+ var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
1433
+ var defaultEntriesDir = path6.resolve(
1434
+ path6.dirname(require.resolve("@react-router/dev/package.json")),
1420
1435
  "dist",
1421
1436
  "config",
1422
1437
  "defaults"
1423
1438
  );
1424
- var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path4.join(defaultEntriesDir, filename3));
1439
+ var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
1425
1440
  invariant(defaultEntries.length > 0, "No default entries found");
1426
1441
  var reactRouterDevLoadContext = () => ({});
1427
1442
  var reactRouterVitePlugin = () => {
@@ -1510,7 +1525,7 @@ var reactRouterVitePlugin = () => {
1510
1525
  virtual.serverManifest.id
1511
1526
  )};
1512
1527
  export const assetsBuildDirectory = ${JSON.stringify(
1513
- path4.relative(
1528
+ path6.relative(
1514
1529
  ctx.rootDirectory,
1515
1530
  getClientBuildDirectory(ctx.reactRouterConfig)
1516
1531
  )
@@ -1536,7 +1551,7 @@ var reactRouterVitePlugin = () => {
1536
1551
  };
1537
1552
  let loadViteManifest = async (directory) => {
1538
1553
  let manifestContents = await fse.readFile(
1539
- path4.resolve(directory, ".vite", "manifest.json"),
1554
+ path6.resolve(directory, ".vite", "manifest.json"),
1540
1555
  "utf-8"
1541
1556
  );
1542
1557
  return JSON.parse(manifestContents);
@@ -1572,7 +1587,7 @@ var reactRouterVitePlugin = () => {
1572
1587
  ctx
1573
1588
  );
1574
1589
  for (let [key, route] of Object.entries(ctx.reactRouterConfig.routes)) {
1575
- let routeFilePath = path4.join(
1590
+ let routeFilePath = path6.join(
1576
1591
  ctx.reactRouterConfig.appDirectory,
1577
1592
  route.file
1578
1593
  );
@@ -1607,7 +1622,7 @@ var reactRouterVitePlugin = () => {
1607
1622
  }
1608
1623
  let fingerprintedValues = { entry, routes: browserRoutes };
1609
1624
  let version = getHash(JSON.stringify(fingerprintedValues), 8);
1610
- let manifestPath = path4.posix.join(
1625
+ let manifestPath = path6.posix.join(
1611
1626
  viteConfig.build.assetsDir,
1612
1627
  `manifest-${version}.js`
1613
1628
  );
@@ -1618,7 +1633,7 @@ var reactRouterVitePlugin = () => {
1618
1633
  ...nonFingerprintedValues
1619
1634
  };
1620
1635
  await writeFileSafe(
1621
- path4.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
1636
+ path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
1622
1637
  `window.__reactRouterManifest=${JSON.stringify(
1623
1638
  reactRouterBrowserManifest
1624
1639
  )};`
@@ -1681,11 +1696,22 @@ var reactRouterVitePlugin = () => {
1681
1696
  {
1682
1697
  name: "react-router",
1683
1698
  config: async (_viteUserConfig, _viteConfigEnv) => {
1684
- await preloadViteEsm();
1685
- let vite2 = importViteEsmSync();
1699
+ await preloadVite();
1700
+ let vite2 = getVite();
1686
1701
  viteUserConfig = _viteUserConfig;
1687
1702
  viteConfigEnv = _viteConfigEnv;
1688
1703
  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
+ ];
1689
1715
  logger = vite2.createLogger(viteUserConfig.logLevel, {
1690
1716
  prefix: "[react-router]"
1691
1717
  });
@@ -1735,15 +1761,15 @@ var reactRouterVitePlugin = () => {
1735
1761
  ssr: {
1736
1762
  external: ssrExternals,
1737
1763
  resolve: {
1738
- conditions: viteCommand === "build" ? [] : ["development"],
1739
- externalConditions: viteCommand === "build" ? [] : ["development"]
1764
+ conditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions],
1765
+ externalConditions: viteCommand === "build" ? viteServerConditions : ["development", ...viteServerConditions]
1740
1766
  }
1741
1767
  },
1742
1768
  optimizeDeps: {
1743
1769
  entries: ctx.reactRouterConfig.future.unstable_optimizeDeps ? [
1744
1770
  ctx.entryClientFilePath,
1745
1771
  ...Object.values(ctx.reactRouterConfig.routes).map(
1746
- (route) => path4.join(ctx.reactRouterConfig.appDirectory, route.file)
1772
+ (route) => path6.join(ctx.reactRouterConfig.appDirectory, route.file)
1747
1773
  )
1748
1774
  ] : [],
1749
1775
  include: [
@@ -1777,7 +1803,7 @@ var reactRouterVitePlugin = () => {
1777
1803
  "react-router/dom",
1778
1804
  "react-router-dom"
1779
1805
  ],
1780
- conditions: viteCommand === "build" ? [] : ["development"]
1806
+ conditions: viteCommand === "build" ? viteClientConditions : ["development", ...viteClientConditions]
1781
1807
  },
1782
1808
  base: viteUserConfig.base,
1783
1809
  // When consumer provides an allow list for files that can be read by
@@ -1799,7 +1825,7 @@ var reactRouterVitePlugin = () => {
1799
1825
  input: [
1800
1826
  ctx.entryClientFilePath,
1801
1827
  ...Object.values(ctx.reactRouterConfig.routes).map(
1802
- (route) => `${path4.resolve(
1828
+ (route) => `${path6.resolve(
1803
1829
  ctx.reactRouterConfig.appDirectory,
1804
1830
  route.file
1805
1831
  )}${BUILD_CLIENT_ROUTE_QUERY_STRING}`
@@ -1848,7 +1874,7 @@ var reactRouterVitePlugin = () => {
1848
1874
  "The React Router Vite plugin requires the use of a Vite config file"
1849
1875
  );
1850
1876
  }
1851
- let vite2 = importViteEsmSync();
1877
+ let vite2 = getVite();
1852
1878
  let childCompilerConfigFile = await vite2.loadConfigFromFile(
1853
1879
  {
1854
1880
  command: viteConfig.command,
@@ -2007,8 +2033,8 @@ var reactRouterVitePlugin = () => {
2007
2033
  let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
2008
2034
  let movedAssetPaths = [];
2009
2035
  for (let ssrAssetPath of ssrAssetPaths) {
2010
- let src = path4.join(serverBuildDirectory, ssrAssetPath);
2011
- let dest = path4.join(clientBuildDirectory, ssrAssetPath);
2036
+ let src = path6.join(serverBuildDirectory, ssrAssetPath);
2037
+ let dest = path6.join(clientBuildDirectory, ssrAssetPath);
2012
2038
  if (!fse.existsSync(dest)) {
2013
2039
  await fse.move(src, dest);
2014
2040
  movedAssetPaths.push(dest);
@@ -2021,7 +2047,7 @@ var reactRouterVitePlugin = () => {
2021
2047
  );
2022
2048
  await Promise.all(
2023
2049
  ssrCssPaths.map(
2024
- (cssPath) => fse.remove(path4.join(serverBuildDirectory, cssPath))
2050
+ (cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
2025
2051
  )
2026
2052
  );
2027
2053
  if (movedAssetPaths.length) {
@@ -2030,7 +2056,7 @@ var reactRouterVitePlugin = () => {
2030
2056
  "",
2031
2057
  `${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
2032
2058
  ...movedAssetPaths.map(
2033
- (movedAssetPath) => import_picocolors3.default.dim(path4.relative(ctx.rootDirectory, movedAssetPath))
2059
+ (movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
2034
2060
  ),
2035
2061
  ""
2036
2062
  ].join("\n")
@@ -2077,7 +2103,7 @@ var reactRouterVitePlugin = () => {
2077
2103
  async transform(_code, id, options) {
2078
2104
  if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
2079
2105
  let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
2080
- let routeFileName = path4.basename(routeModuleId);
2106
+ let routeFileName = path6.basename(routeModuleId);
2081
2107
  let sourceExports = await getRouteModuleExports(
2082
2108
  viteChildCompiler,
2083
2109
  ctx,
@@ -2139,9 +2165,9 @@ var reactRouterVitePlugin = () => {
2139
2165
  if (viteCommand !== "build" && importer.endsWith(".html")) {
2140
2166
  return;
2141
2167
  }
2142
- let vite2 = importViteEsmSync();
2168
+ let vite2 = getVite();
2143
2169
  let importerShort = vite2.normalizePath(
2144
- path4.relative(ctx.rootDirectory, importer)
2170
+ path6.relative(ctx.rootDirectory, importer)
2145
2171
  );
2146
2172
  let isRoute = getRoute(ctx.reactRouterConfig, importer);
2147
2173
  if (isRoute) {
@@ -2254,10 +2280,10 @@ var reactRouterVitePlugin = () => {
2254
2280
  },
2255
2281
  async load(id) {
2256
2282
  if (id !== virtualHmrRuntime.resolvedId) return;
2257
- let reactRefreshDir = path4.dirname(
2283
+ let reactRefreshDir = path6.dirname(
2258
2284
  require.resolve("react-refresh/package.json")
2259
2285
  );
2260
- let reactRefreshRuntimePath = path4.join(
2286
+ let reactRefreshRuntimePath = path6.join(
2261
2287
  reactRefreshDir,
2262
2288
  "cjs/react-refresh-runtime.development.js"
2263
2289
  );
@@ -2397,22 +2423,7 @@ function addRefreshWrapper(reactRouterConfig, code, id) {
2397
2423
  "links",
2398
2424
  "shouldRevalidate"
2399
2425
  ] : [];
2400
- return "\n\n" + withCommentBoundaries(
2401
- "REACT REFRESH HEADER",
2402
- REACT_REFRESH_HEADER.replaceAll("__SOURCE__", JSON.stringify(id))
2403
- ) + "\n\n" + withCommentBoundaries("REACT REFRESH BODY", code) + "\n\n" + withCommentBoundaries(
2404
- "REACT REFRESH FOOTER",
2405
- REACT_REFRESH_FOOTER.replaceAll("__SOURCE__", JSON.stringify(id)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(route?.id))
2406
- ) + "\n";
2407
- }
2408
- function withCommentBoundaries(label, text) {
2409
- let begin = `// [BEGIN] ${label} `;
2410
- begin += "-".repeat(80 - begin.length);
2411
- let end = `// [END] ${label} `;
2412
- end += "-".repeat(80 - end.length);
2413
- return `${begin}
2414
- ${text}
2415
- ${end}`;
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));
2416
2427
  }
2417
2428
  var REACT_REFRESH_HEADER = `
2418
2429
  import RefreshRuntime from "${virtualHmrRuntime.id}";
@@ -2434,7 +2445,7 @@ if (import.meta.hot && !inWebWorker) {
2434
2445
  RefreshRuntime.register(type, __SOURCE__ + " " + id)
2435
2446
  };
2436
2447
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
2437
- }`.trim();
2448
+ }`.replaceAll("\n", "");
2438
2449
  var REACT_REFRESH_FOOTER = `
2439
2450
  if (import.meta.hot && !inWebWorker) {
2440
2451
  window.$RefreshReg$ = prevRefreshReg;
@@ -2448,11 +2459,11 @@ if (import.meta.hot && !inWebWorker) {
2448
2459
  if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
2449
2460
  });
2450
2461
  });
2451
- }`.trim();
2462
+ }`;
2452
2463
  function getRoute(pluginConfig, file) {
2453
- let vite2 = importViteEsmSync();
2464
+ let vite2 = getVite();
2454
2465
  let routePath = vite2.normalizePath(
2455
- path4.relative(pluginConfig.appDirectory, file)
2466
+ path6.relative(pluginConfig.appDirectory, file)
2456
2467
  );
2457
2468
  let route = Object.values(pluginConfig.routes).find(
2458
2469
  (r) => vite2.normalizePath(r.file) === routePath
@@ -2474,7 +2485,7 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
2474
2485
  caseSensitive: route.caseSensitive,
2475
2486
  url: combineURLs(
2476
2487
  ctx.publicPath,
2477
- "/" + path4.relative(
2488
+ "/" + path6.relative(
2478
2489
  ctx.rootDirectory,
2479
2490
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
2480
2491
  )
@@ -2497,7 +2508,7 @@ async function getRouteMetadata(ctx, viteChildCompiler, route, readRouteFile) {
2497
2508
  return info;
2498
2509
  }
2499
2510
  async function getPrerenderBuildAndHandler(viteConfig, reactRouterConfig, serverBuildDirectory) {
2500
- let serverBuildPath = path4.join(
2511
+ let serverBuildPath = path6.join(
2501
2512
  serverBuildDirectory,
2502
2513
  reactRouterConfig.serverBuildFile
2503
2514
  );
@@ -2519,9 +2530,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
2519
2530
  let html = await response.text();
2520
2531
  validatePrerenderedResponse(response, html, "SPA Mode", "/");
2521
2532
  validatePrerenderedHtml(html, "SPA Mode");
2522
- await fse.writeFile(path4.join(clientBuildDirectory, "index.html"), html);
2533
+ await fse.writeFile(path6.join(clientBuildDirectory, "index.html"), html);
2523
2534
  viteConfig.logger.info(
2524
- "SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(path4.relative(process.cwd(), clientBuildDirectory)) + " directory"
2535
+ "SPA Mode: index.html has been written to your " + import_picocolors3.default.bold(path6.relative(process.cwd(), clientBuildDirectory)) + " directory"
2525
2536
  );
2526
2537
  }
2527
2538
  async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirectory, clientBuildDirectory) {
@@ -2551,14 +2562,14 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2551
2562
  // build time or runtime
2552
2563
  "X-React-Router-Prerender": "yes"
2553
2564
  };
2554
- for (let path5 of routesToPrerender) {
2555
- let matches = (0, import_react_router2.matchRoutes)(routes, path5);
2565
+ for (let path7 of routesToPrerender) {
2566
+ let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
2556
2567
  let hasLoaders = matches?.some((m) => m.route.loader);
2557
2568
  let data;
2558
2569
  if (hasLoaders) {
2559
2570
  data = await prerenderData(
2560
2571
  handler,
2561
- path5,
2572
+ path7,
2562
2573
  clientBuildDirectory,
2563
2574
  reactRouterConfig,
2564
2575
  viteConfig,
@@ -2571,7 +2582,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2571
2582
  if (isResourceRoute) {
2572
2583
  await prerenderResourceRoute(
2573
2584
  handler,
2574
- path5,
2585
+ path7,
2575
2586
  clientBuildDirectory,
2576
2587
  reactRouterConfig,
2577
2588
  viteConfig,
@@ -2580,7 +2591,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
2580
2591
  } else {
2581
2592
  await prerenderRoute(
2582
2593
  handler,
2583
- path5,
2594
+ path7,
2584
2595
  clientBuildDirectory,
2585
2596
  reactRouterConfig,
2586
2597
  viteConfig,
@@ -2637,9 +2648,9 @@ async function prerenderData(handler, prerenderPath, clientBuildDirectory, react
2637
2648
  let response = await handler(request);
2638
2649
  let data = await response.text();
2639
2650
  validatePrerenderedResponse(response, data, "Prerender", normalizedPath);
2640
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2641
- let outfile = path4.join(outdir, ...normalizedPath.split("/"));
2642
- await fse.ensureDir(path4.dirname(outfile));
2651
+ let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2652
+ let outfile = path6.join(outdir, ...normalizedPath.split("/"));
2653
+ await fse.ensureDir(path6.dirname(outfile));
2643
2654
  await fse.outputFile(outfile, data);
2644
2655
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2645
2656
  return data;
@@ -2656,9 +2667,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
2656
2667
  if (!reactRouterConfig.ssr) {
2657
2668
  validatePrerenderedHtml(html, "Prerender");
2658
2669
  }
2659
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2660
- let outfile = path4.join(outdir, ...normalizedPath.split("/"), "index.html");
2661
- await fse.ensureDir(path4.dirname(outfile));
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));
2662
2673
  await fse.outputFile(outfile, html);
2663
2674
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2664
2675
  }
@@ -2668,9 +2679,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
2668
2679
  let response = await handler(request);
2669
2680
  let text = await response.text();
2670
2681
  validatePrerenderedResponse(response, text, "Prerender", normalizedPath);
2671
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2672
- let outfile = path4.join(outdir, ...normalizedPath.split("/"));
2673
- await fse.ensureDir(path4.dirname(outfile));
2682
+ let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2683
+ let outfile = path6.join(outdir, ...normalizedPath.split("/"));
2684
+ await fse.ensureDir(path6.dirname(outfile));
2674
2685
  await fse.outputFile(outfile, text);
2675
2686
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2676
2687
  }
@@ -2679,17 +2690,17 @@ async function prerenderManifest(build, clientBuildDirectory, reactRouterConfig,
2679
2690
  /\/\/+/g,
2680
2691
  "/"
2681
2692
  );
2682
- let outdir = path4.relative(process.cwd(), clientBuildDirectory);
2683
- let outfile = path4.join(outdir, ...normalizedPath.split("/"));
2684
- await fse.ensureDir(path4.dirname(outfile));
2693
+ let outdir = path6.relative(process.cwd(), clientBuildDirectory);
2694
+ let outfile = path6.join(outdir, ...normalizedPath.split("/"));
2695
+ await fse.ensureDir(path6.dirname(outfile));
2685
2696
  let manifestData = JSON.stringify(build.assets.routes);
2686
2697
  await fse.outputFile(outfile, manifestData);
2687
2698
  viteConfig.logger.info(`Prerender: Generated ${import_picocolors3.default.bold(outfile)}`);
2688
2699
  }
2689
- function validatePrerenderedResponse(response, html, prefix, path5) {
2700
+ function validatePrerenderedResponse(response, html, prefix, path7) {
2690
2701
  if (response.status !== 200) {
2691
2702
  throw new Error(
2692
- `${prefix}: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${path5}\` path.
2703
+ `${prefix}: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${path7}\` path.
2693
2704
  ${html}`
2694
2705
  );
2695
2706
  }