@react-router/dev 0.0.0-experimental-818f8e08d → 0.0.0-experimental-aecfb0db1

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-818f8e08d
2
+ * @react-router/dev v0.0.0-experimental-aecfb0db1
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -47,7 +47,7 @@ module.exports = __toCommonJS(vite_exports);
47
47
  // vite/plugin.ts
48
48
  var import_node_crypto = require("crypto");
49
49
  var fs3 = __toESM(require("fs"));
50
- var path6 = __toESM(require("path"));
50
+ var path5 = __toESM(require("path"));
51
51
  var url = __toESM(require("url"));
52
52
  var fse = __toESM(require("fs-extra"));
53
53
  var babel = __toESM(require("@babel/core"));
@@ -61,7 +61,7 @@ var import_kebabCase = __toESM(require("lodash/kebabCase"));
61
61
  // typegen/index.ts
62
62
  var import_node_fs2 = __toESM(require("fs"));
63
63
  var import_dedent2 = __toESM(require("dedent"));
64
- var Path4 = __toESM(require("pathe"));
64
+ var Path5 = __toESM(require("pathe"));
65
65
  var import_picocolors2 = __toESM(require("picocolors"));
66
66
 
67
67
  // config/config.ts
@@ -136,13 +136,15 @@ var ssrExternals = isReactRouterRepo() ? [
136
136
  // vite/vite-node.ts
137
137
  async function createContext({
138
138
  root,
139
- mode
139
+ mode,
140
+ customLogger
140
141
  }) {
141
142
  await preloadVite();
142
143
  const vite2 = getVite();
143
144
  const devServer = await vite2.createServer({
144
145
  root,
145
146
  mode,
147
+ customLogger,
146
148
  server: {
147
149
  preTransformRequests: false,
148
150
  hmr: false,
@@ -240,7 +242,7 @@ function validateRouteConfig({
240
242
  `Route config in "${routeConfigFile}" is invalid.`,
241
243
  root ? `${root}` : [],
242
244
  nested ? Object.entries(nested).map(
243
- ([path7, message]) => `Path: routes.${path7}
245
+ ([path6, message]) => `Path: routes.${path6}
244
246
  ${message}`
245
247
  ) : []
246
248
  ].flat().join("\n\n")
@@ -356,7 +358,8 @@ function err(error) {
356
358
  async function resolveConfig({
357
359
  root,
358
360
  viteNodeContext,
359
- reactRouterConfigFile
361
+ reactRouterConfigFile,
362
+ skipRoutes
360
363
  }) {
361
364
  let reactRouterUserConfig = {};
362
365
  if (reactRouterConfigFile) {
@@ -472,45 +475,50 @@ async function resolveConfig({
472
475
  `Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
473
476
  );
474
477
  }
475
- let routes = {
476
- root: { path: "", id: "root", file: rootRouteFile }
477
- };
478
- let routeConfigFile = findEntry(appDirectory, "routes");
479
- try {
480
- if (!routeConfigFile) {
481
- let routeConfigDisplayPath = import_pathe3.default.relative(
482
- root,
483
- import_pathe3.default.join(appDirectory, "routes.ts")
484
- );
485
- return err(`Route config file not found at "${routeConfigDisplayPath}".`);
486
- }
487
- setAppDirectory(appDirectory);
488
- let routeConfigExport = (await viteNodeContext.runner.executeFile(
489
- import_pathe3.default.join(appDirectory, routeConfigFile)
490
- )).default;
491
- let routeConfig = await routeConfigExport;
492
- let result = validateRouteConfig({
493
- routeConfigFile,
494
- routeConfig
495
- });
496
- if (!result.valid) {
497
- return err(result.message);
498
- }
478
+ let routes = {};
479
+ if (!skipRoutes) {
499
480
  routes = {
500
- ...routes,
501
- ...configRoutesToRouteManifest(appDirectory, routeConfig)
481
+ root: { path: "", id: "root", file: rootRouteFile }
502
482
  };
503
- } catch (error) {
504
- return err(
505
- [
506
- import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
507
- "",
508
- error.loc?.file && error.loc?.column && error.frame ? [
509
- import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
510
- error.frame.trim?.()
511
- ] : error.stack
512
- ].flat().join("\n")
513
- );
483
+ let routeConfigFile = findEntry(appDirectory, "routes");
484
+ try {
485
+ if (!routeConfigFile) {
486
+ let routeConfigDisplayPath = import_pathe3.default.relative(
487
+ root,
488
+ import_pathe3.default.join(appDirectory, "routes.ts")
489
+ );
490
+ return err(
491
+ `Route config file not found at "${routeConfigDisplayPath}".`
492
+ );
493
+ }
494
+ setAppDirectory(appDirectory);
495
+ let routeConfigExport = (await viteNodeContext.runner.executeFile(
496
+ import_pathe3.default.join(appDirectory, routeConfigFile)
497
+ )).default;
498
+ let routeConfig = await routeConfigExport;
499
+ let result = validateRouteConfig({
500
+ routeConfigFile,
501
+ routeConfig
502
+ });
503
+ if (!result.valid) {
504
+ return err(result.message);
505
+ }
506
+ routes = {
507
+ ...routes,
508
+ ...configRoutesToRouteManifest(appDirectory, routeConfig)
509
+ };
510
+ } catch (error) {
511
+ return err(
512
+ [
513
+ import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
514
+ "",
515
+ error.loc?.file && error.loc?.column && error.frame ? [
516
+ import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
517
+ error.frame.trim?.()
518
+ ] : error.stack
519
+ ].flat().join("\n")
520
+ );
521
+ }
514
522
  }
515
523
  let future = {
516
524
  unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
@@ -541,24 +549,34 @@ async function resolveConfig({
541
549
  async function createConfigLoader({
542
550
  rootDirectory: root,
543
551
  watch: watch2,
544
- mode
552
+ mode,
553
+ skipRoutes
545
554
  }) {
546
- root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
555
+ root = import_pathe3.default.normalize(root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd());
556
+ let vite2 = await import("vite");
547
557
  let viteNodeContext = await createContext({
548
558
  root,
549
- mode
550
- });
551
- let reactRouterConfigFile = findEntry(root, "react-router.config", {
552
- absolute: true
559
+ mode,
560
+ // Filter out any info level logs from vite-node
561
+ customLogger: vite2.createLogger("warn", {
562
+ prefix: "[react-router]"
563
+ })
553
564
  });
554
- let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
565
+ let reactRouterConfigFile;
566
+ let updateReactRouterConfigFile = () => {
567
+ reactRouterConfigFile = findEntry(root, "react-router.config", {
568
+ absolute: true
569
+ });
570
+ };
571
+ updateReactRouterConfigFile();
572
+ let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile, skipRoutes });
555
573
  let appDirectory;
556
574
  let initialConfigResult = await getConfig();
557
575
  if (!initialConfigResult.ok) {
558
576
  throw new Error(initialConfigResult.error);
559
577
  }
560
- appDirectory = initialConfigResult.value.appDirectory;
561
- let lastConfig = initialConfigResult.value;
578
+ appDirectory = import_pathe3.default.normalize(initialConfigResult.value.appDirectory);
579
+ let currentConfig = initialConfigResult.value;
562
580
  let fsWatcher;
563
581
  let changeHandlers = [];
564
582
  return {
@@ -571,41 +589,71 @@ async function createConfigLoader({
571
589
  }
572
590
  changeHandlers.push(handler);
573
591
  if (!fsWatcher) {
574
- fsWatcher = import_chokidar.default.watch(
575
- [
576
- ...reactRouterConfigFile ? [reactRouterConfigFile] : [],
577
- appDirectory
578
- ],
579
- { ignoreInitial: true }
580
- );
592
+ fsWatcher = import_chokidar.default.watch([root, appDirectory], {
593
+ ignoreInitial: true,
594
+ ignored: (path6) => {
595
+ let dirname5 = import_pathe3.default.dirname(path6);
596
+ return !dirname5.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
597
+ // that are at the root level, not nested in subdirectories
598
+ path6 !== root && // Watch the root directory itself
599
+ dirname5 !== root;
600
+ }
601
+ });
581
602
  fsWatcher.on("all", async (...args) => {
582
603
  let [event, rawFilepath] = args;
583
604
  let filepath = import_pathe3.default.normalize(rawFilepath);
584
- let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
585
- let configCodeUpdated = Boolean(
605
+ let fileAddedOrRemoved = event === "add" || event === "unlink";
606
+ let appFileAddedOrRemoved = fileAddedOrRemoved && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
607
+ let rootRelativeFilepath = import_pathe3.default.relative(root, filepath);
608
+ let configFileAddedOrRemoved = fileAddedOrRemoved && isEntryFile("react-router.config", rootRelativeFilepath);
609
+ if (configFileAddedOrRemoved) {
610
+ updateReactRouterConfigFile();
611
+ }
612
+ let moduleGraphChanged = configFileAddedOrRemoved || Boolean(
586
613
  viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
587
614
  );
588
- if (configCodeUpdated || appFileAddedOrRemoved) {
589
- viteNodeContext.devServer?.moduleGraph.invalidateAll();
590
- viteNodeContext.runner?.moduleCache.clear();
615
+ if (!moduleGraphChanged && !appFileAddedOrRemoved) {
616
+ return;
591
617
  }
592
- if (appFileAddedOrRemoved || configCodeUpdated) {
593
- let result = await getConfig();
594
- let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
595
- let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
596
- for (let handler2 of changeHandlers) {
597
- handler2({
598
- result,
599
- configCodeUpdated,
600
- configChanged,
601
- routeConfigChanged,
602
- path: filepath,
603
- event
604
- });
605
- }
606
- if (result.ok) {
607
- lastConfig = result.value;
608
- }
618
+ viteNodeContext.devServer?.moduleGraph.invalidateAll();
619
+ viteNodeContext.runner?.moduleCache.clear();
620
+ let result = await getConfig();
621
+ let prevAppDirectory = appDirectory;
622
+ appDirectory = import_pathe3.default.normalize(
623
+ (result.value ?? currentConfig).appDirectory
624
+ );
625
+ if (appDirectory !== prevAppDirectory) {
626
+ fsWatcher.unwatch(prevAppDirectory);
627
+ fsWatcher.add(appDirectory);
628
+ }
629
+ let configCodeChanged = configFileAddedOrRemoved || reactRouterConfigFile !== void 0 && isEntryFileDependency(
630
+ viteNodeContext.devServer.moduleGraph,
631
+ reactRouterConfigFile,
632
+ filepath
633
+ );
634
+ let routeConfigFile = !skipRoutes ? findEntry(appDirectory, "routes", {
635
+ absolute: true
636
+ }) : void 0;
637
+ let routeConfigCodeChanged = routeConfigFile !== void 0 && isEntryFileDependency(
638
+ viteNodeContext.devServer.moduleGraph,
639
+ routeConfigFile,
640
+ filepath
641
+ );
642
+ let configChanged = result.ok && !(0, import_isEqual.default)(omitRoutes(currentConfig), omitRoutes(result.value));
643
+ let routeConfigChanged = result.ok && !(0, import_isEqual.default)(currentConfig?.routes, result.value.routes);
644
+ for (let handler2 of changeHandlers) {
645
+ handler2({
646
+ result,
647
+ configCodeChanged,
648
+ routeConfigCodeChanged,
649
+ configChanged,
650
+ routeConfigChanged,
651
+ path: filepath,
652
+ event
653
+ });
654
+ }
655
+ if (result.ok) {
656
+ currentConfig = result.value;
609
657
  }
610
658
  });
611
659
  }
@@ -681,7 +729,16 @@ async function resolveEntryFiles({
681
729
  let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
682
730
  return { entryClientFilePath, entryServerFilePath };
683
731
  }
732
+ function omitRoutes(config) {
733
+ return {
734
+ ...config,
735
+ routes: {}
736
+ };
737
+ }
684
738
  var entryExts = [".js", ".jsx", ".ts", ".tsx"];
739
+ function isEntryFile(entryBasename, filename3) {
740
+ return entryExts.some((ext) => filename3 === `${entryBasename}${ext}`);
741
+ }
685
742
  function findEntry(dir, basename2, options) {
686
743
  let currentDir = import_pathe3.default.resolve(dir);
687
744
  let { root } = import_pathe3.default.parse(currentDir);
@@ -702,6 +759,30 @@ function findEntry(dir, basename2, options) {
702
759
  currentDir = parentDir;
703
760
  }
704
761
  }
762
+ function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /* @__PURE__ */ new Set()) {
763
+ entryFilepath = import_pathe3.default.normalize(entryFilepath);
764
+ filepath = import_pathe3.default.normalize(filepath);
765
+ if (visited.has(filepath)) {
766
+ return false;
767
+ }
768
+ visited.add(filepath);
769
+ if (filepath === entryFilepath) {
770
+ return true;
771
+ }
772
+ let mod = moduleGraph.getModuleById(filepath);
773
+ if (!mod) {
774
+ return false;
775
+ }
776
+ for (let importer of mod.importers) {
777
+ if (!importer.id) {
778
+ continue;
779
+ }
780
+ if (importer.id === entryFilepath || isEntryFileDependency(moduleGraph, entryFilepath, importer.id, visited)) {
781
+ return true;
782
+ }
783
+ }
784
+ return false;
785
+ }
705
786
 
706
787
  // vite/babel.ts
707
788
  var babel_exports = {};
@@ -718,20 +799,20 @@ var generate = require("@babel/generator").default;
718
799
 
719
800
  // typegen/generate.ts
720
801
  var import_dedent = __toESM(require("dedent"));
721
- var Path3 = __toESM(require("pathe"));
802
+ var Path4 = __toESM(require("pathe"));
722
803
  var Pathe2 = __toESM(require("pathe/utils"));
723
804
 
724
805
  // typegen/paths.ts
725
- var Path2 = __toESM(require("pathe"));
806
+ var Path3 = __toESM(require("pathe"));
726
807
  var Pathe = __toESM(require("pathe/utils"));
727
808
  function getTypesDir(ctx) {
728
- return Path2.join(ctx.rootDirectory, ".react-router/types");
809
+ return Path3.join(ctx.rootDirectory, ".react-router/types");
729
810
  }
730
811
  function getTypesPath(ctx, route) {
731
- return Path2.join(
812
+ return Path3.join(
732
813
  getTypesDir(ctx),
733
- Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
734
- Path2.dirname(route.file),
814
+ Path3.relative(ctx.rootDirectory, ctx.config.appDirectory),
815
+ Path3.dirname(route.file),
735
816
  "+types/" + Pathe.filename(route.file) + ".ts"
736
817
  );
737
818
  }
@@ -766,7 +847,7 @@ function lineage(routes, route) {
766
847
  }
767
848
  function fullpath(lineage2) {
768
849
  if (lineage2.length === 1 && lineage2[0].id === "root") return "/";
769
- return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path7) => path7 !== void 0 && path7 !== "").join("/");
850
+ return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path6) => path6 !== void 0 && path6 !== "").join("/");
770
851
  }
771
852
 
772
853
  // typegen/generate.ts
@@ -776,8 +857,8 @@ function generate2(ctx, route) {
776
857
  const typesPath = getTypesPath(ctx, route);
777
858
  const parents = lineage2.slice(0, -1);
778
859
  const parentTypeImports = parents.map((parent, i) => {
779
- const rel = Path3.relative(
780
- Path3.dirname(typesPath),
860
+ const rel = Path4.relative(
861
+ Path4.dirname(typesPath),
781
862
  getTypesPath(ctx, parent)
782
863
  );
783
864
  const indent = i === 0 ? "" : " ".repeat(2);
@@ -832,7 +913,7 @@ function generate2(ctx, route) {
832
913
  }
833
914
  `;
834
915
  }
835
- var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
916
+ var noExtension = (path6) => Path4.join(Path4.dirname(path6), Pathe2.filename(path6));
836
917
  function formatParamProperties(fullpath2) {
837
918
  const params = parse2(fullpath2);
838
919
  const properties = Object.entries(params).map(
@@ -846,20 +927,22 @@ async function watch(rootDirectory, { mode, logger }) {
846
927
  const ctx = await createContext2({ rootDirectory, mode, watch: true });
847
928
  await writeAll(ctx);
848
929
  logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
849
- ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
850
- if (!result.ok) {
851
- logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
852
- return;
853
- }
854
- ctx.config = result.value;
855
- if (routeConfigChanged) {
856
- await writeAll(ctx);
857
- logger?.info(import_picocolors2.default.green("regenerated types"), {
858
- timestamp: true,
859
- clear: true
860
- });
930
+ ctx.configLoader.onChange(
931
+ async ({ result, configChanged, routeConfigChanged }) => {
932
+ if (!result.ok) {
933
+ logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
934
+ return;
935
+ }
936
+ ctx.config = result.value;
937
+ if (configChanged || routeConfigChanged) {
938
+ await writeAll(ctx);
939
+ logger?.info(import_picocolors2.default.green("regenerated types"), {
940
+ timestamp: true,
941
+ clear: true
942
+ });
943
+ }
861
944
  }
862
- });
945
+ );
863
946
  return {
864
947
  close: async () => await ctx.configLoader.close()
865
948
  };
@@ -887,12 +970,12 @@ async function writeAll(ctx) {
887
970
  Object.values(ctx.config.routes).forEach((route) => {
888
971
  const typesPath = getTypesPath(ctx, route);
889
972
  const content = generate2(ctx, route);
890
- import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
973
+ import_node_fs2.default.mkdirSync(Path5.dirname(typesPath), { recursive: true });
891
974
  import_node_fs2.default.writeFileSync(typesPath, content);
892
975
  });
893
- const registerPath = Path4.join(typegenDir, "+register.ts");
976
+ const registerPath = Path5.join(typegenDir, "+register.ts");
894
977
  import_node_fs2.default.writeFileSync(registerPath, register(ctx));
895
- const virtualPath = Path4.join(typegenDir, "+virtual.d.ts");
978
+ const virtualPath = Path5.join(typegenDir, "+virtual.d.ts");
896
979
  import_node_fs2.default.writeFileSync(virtualPath, virtual);
897
980
  }
898
981
  function register(ctx) {
@@ -903,21 +986,25 @@ function register(ctx) {
903
986
  interface Register {
904
987
  params: Params;
905
988
  }
989
+
990
+ interface Future {
991
+ unstable_middleware: ${ctx.config.future.unstable_middleware}
992
+ }
906
993
  }
907
994
  `;
908
995
  const { t: t2 } = babel_exports;
909
- const indexPaths = new Set(
910
- Object.values(ctx.config.routes).filter((route) => route.index).map((route) => route.path)
911
- );
996
+ const fullpaths = /* @__PURE__ */ new Set();
997
+ Object.values(ctx.config.routes).forEach((route) => {
998
+ if (route.id !== "root" && !route.path) return;
999
+ const lineage2 = lineage(ctx.config.routes, route);
1000
+ const fullpath2 = fullpath(lineage2);
1001
+ fullpaths.add(fullpath2);
1002
+ });
912
1003
  const typeParams = t2.tsTypeAliasDeclaration(
913
1004
  t2.identifier("Params"),
914
1005
  null,
915
1006
  t2.tsTypeLiteral(
916
- Object.values(ctx.config.routes).map((route) => {
917
- if (route.id !== "root" && !route.path) return void 0;
918
- if (!route.index && indexPaths.has(route.path)) return void 0;
919
- const lineage2 = lineage(ctx.config.routes, route);
920
- const fullpath2 = fullpath(lineage2);
1007
+ Array.from(fullpaths).map((fullpath2) => {
921
1008
  const params = parse2(fullpath2);
922
1009
  return t2.tsPropertySignature(
923
1010
  t2.stringLiteral(fullpath2),
@@ -934,7 +1021,7 @@ function register(ctx) {
934
1021
  )
935
1022
  )
936
1023
  );
937
- }).filter((x) => x !== void 0)
1024
+ })
938
1025
  )
939
1026
  );
940
1027
  return [register2, generate(typeParams).code].join("\n\n");
@@ -1034,17 +1121,17 @@ async function toNodeRequest(res, nodeRes) {
1034
1121
  }
1035
1122
 
1036
1123
  // vite/styles.ts
1037
- var path5 = __toESM(require("path"));
1124
+ var path4 = __toESM(require("path"));
1038
1125
  var import_react_router = require("react-router");
1039
1126
 
1040
1127
  // vite/resolve-file-url.ts
1041
- var path4 = __toESM(require("path"));
1128
+ var path3 = __toESM(require("path"));
1042
1129
  var resolveFileUrl = ({ rootDirectory }, filePath) => {
1043
1130
  let vite2 = getVite();
1044
- let relativePath = path4.relative(rootDirectory, filePath);
1045
- let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
1131
+ let relativePath = path3.relative(rootDirectory, filePath);
1132
+ let isWithinRoot = !relativePath.startsWith("..") && !path3.isAbsolute(relativePath);
1046
1133
  if (!isWithinRoot) {
1047
- return path4.posix.join("/@fs", vite2.normalizePath(filePath));
1134
+ return path3.posix.join("/@fs", vite2.normalizePath(filePath));
1048
1135
  }
1049
1136
  return "/" + vite2.normalizePath(relativePath);
1050
1137
  };
@@ -1081,7 +1168,7 @@ var getStylesForFiles = async ({
1081
1168
  let deps = /* @__PURE__ */ new Set();
1082
1169
  try {
1083
1170
  for (let file of files) {
1084
- let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
1171
+ let normalizedPath = path4.resolve(rootDirectory, file).replace(/\\/g, "/");
1085
1172
  let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
1086
1173
  if (!node) {
1087
1174
  try {
@@ -1182,9 +1269,9 @@ var getStylesForPathname = async ({
1182
1269
  return void 0;
1183
1270
  }
1184
1271
  let routesWithChildren = createRoutesWithChildren(reactRouterConfig.routes);
1185
- let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
1272
+ let appPath = path4.relative(process.cwd(), reactRouterConfig.appDirectory);
1186
1273
  let documentRouteFiles = (0, import_react_router.matchRoutes)(routesWithChildren, pathname, reactRouterConfig.basename)?.map(
1187
- (match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1274
+ (match) => path4.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1188
1275
  ) ?? [];
1189
1276
  let styles = await getStylesForFiles({
1190
1277
  viteDevServer,
@@ -1192,13 +1279,27 @@ var getStylesForPathname = async ({
1192
1279
  loadCssContents,
1193
1280
  files: [
1194
1281
  // Always include the client entry file when crawling the module graph for CSS
1195
- path5.relative(rootDirectory, entryClientFilePath),
1282
+ path4.relative(rootDirectory, entryClientFilePath),
1196
1283
  // Then include any styles from the matched routes
1197
1284
  ...documentRouteFiles
1198
1285
  ]
1199
1286
  });
1200
1287
  return styles;
1201
1288
  };
1289
+ var getCssStringFromViteDevModuleCode = (code) => {
1290
+ let cssContent = void 0;
1291
+ const ast = import_parser.parse(code, { sourceType: "module" });
1292
+ traverse(ast, {
1293
+ VariableDeclaration(path6) {
1294
+ const declaration = path6.node.declarations[0];
1295
+ if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
1296
+ cssContent = declaration.init.value;
1297
+ path6.stop();
1298
+ }
1299
+ }
1300
+ });
1301
+ return cssContent;
1302
+ };
1202
1303
 
1203
1304
  // vite/virtual-module.ts
1204
1305
  function create(name) {
@@ -1222,10 +1323,10 @@ var removeExports = (ast, exportsToRemove) => {
1222
1323
  let exportsFiltered = false;
1223
1324
  let markedForRemoval = /* @__PURE__ */ new Set();
1224
1325
  traverse(ast, {
1225
- ExportDeclaration(path7) {
1226
- if (path7.node.type === "ExportNamedDeclaration") {
1227
- if (path7.node.specifiers.length) {
1228
- path7.node.specifiers = path7.node.specifiers.filter((specifier) => {
1326
+ ExportDeclaration(path6) {
1327
+ if (path6.node.type === "ExportNamedDeclaration") {
1328
+ if (path6.node.specifiers.length) {
1329
+ path6.node.specifiers = path6.node.specifiers.filter((specifier) => {
1229
1330
  if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
1230
1331
  if (exportsToRemove.includes(specifier.exported.name)) {
1231
1332
  exportsFiltered = true;
@@ -1234,12 +1335,12 @@ var removeExports = (ast, exportsToRemove) => {
1234
1335
  }
1235
1336
  return true;
1236
1337
  });
1237
- if (path7.node.specifiers.length === 0) {
1238
- markedForRemoval.add(path7);
1338
+ if (path6.node.specifiers.length === 0) {
1339
+ markedForRemoval.add(path6);
1239
1340
  }
1240
1341
  }
1241
- if (path7.node.declaration?.type === "VariableDeclaration") {
1242
- let declaration = path7.node.declaration;
1342
+ if (path6.node.declaration?.type === "VariableDeclaration") {
1343
+ let declaration = path6.node.declaration;
1243
1344
  declaration.declarations = declaration.declarations.filter(
1244
1345
  (declaration2) => {
1245
1346
  if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
@@ -1253,30 +1354,30 @@ var removeExports = (ast, exportsToRemove) => {
1253
1354
  }
1254
1355
  );
1255
1356
  if (declaration.declarations.length === 0) {
1256
- markedForRemoval.add(path7);
1357
+ markedForRemoval.add(path6);
1257
1358
  }
1258
1359
  }
1259
- if (path7.node.declaration?.type === "FunctionDeclaration") {
1260
- let id = path7.node.declaration.id;
1360
+ if (path6.node.declaration?.type === "FunctionDeclaration") {
1361
+ let id = path6.node.declaration.id;
1261
1362
  if (id && exportsToRemove.includes(id.name)) {
1262
- markedForRemoval.add(path7);
1363
+ markedForRemoval.add(path6);
1263
1364
  }
1264
1365
  }
1265
- if (path7.node.declaration?.type === "ClassDeclaration") {
1266
- let id = path7.node.declaration.id;
1366
+ if (path6.node.declaration?.type === "ClassDeclaration") {
1367
+ let id = path6.node.declaration.id;
1267
1368
  if (id && exportsToRemove.includes(id.name)) {
1268
- markedForRemoval.add(path7);
1369
+ markedForRemoval.add(path6);
1269
1370
  }
1270
1371
  }
1271
1372
  }
1272
- if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1273
- markedForRemoval.add(path7);
1373
+ if (path6.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1374
+ markedForRemoval.add(path6);
1274
1375
  }
1275
1376
  }
1276
1377
  });
1277
1378
  if (markedForRemoval.size > 0 || exportsFiltered) {
1278
- for (let path7 of markedForRemoval) {
1279
- path7.remove();
1379
+ for (let path6 of markedForRemoval) {
1380
+ path6.remove();
1280
1381
  }
1281
1382
  (0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
1282
1383
  }
@@ -1347,28 +1448,28 @@ function codeToAst(code, cache, cacheKey) {
1347
1448
  )
1348
1449
  );
1349
1450
  }
1350
- function assertNodePath(path7) {
1451
+ function assertNodePath(path6) {
1351
1452
  invariant(
1352
- path7 && !Array.isArray(path7),
1353
- `Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
1453
+ path6 && !Array.isArray(path6),
1454
+ `Expected a Path, but got ${Array.isArray(path6) ? "an array" : path6}`
1354
1455
  );
1355
1456
  }
1356
- function assertNodePathIsStatement(path7) {
1457
+ function assertNodePathIsStatement(path6) {
1357
1458
  invariant(
1358
- path7 && !Array.isArray(path7) && t.isStatement(path7.node),
1359
- `Expected a Statement path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1459
+ path6 && !Array.isArray(path6) && t.isStatement(path6.node),
1460
+ `Expected a Statement path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1360
1461
  );
1361
1462
  }
1362
- function assertNodePathIsVariableDeclarator(path7) {
1463
+ function assertNodePathIsVariableDeclarator(path6) {
1363
1464
  invariant(
1364
- path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
1365
- `Expected an Identifier path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1465
+ path6 && !Array.isArray(path6) && t.isVariableDeclarator(path6.node),
1466
+ `Expected an Identifier path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1366
1467
  );
1367
1468
  }
1368
- function assertNodePathIsPattern(path7) {
1469
+ function assertNodePathIsPattern(path6) {
1369
1470
  invariant(
1370
- path7 && !Array.isArray(path7) && t.isPattern(path7.node),
1371
- `Expected a Pattern path, but got ${Array.isArray(path7) ? "an array" : path7?.node?.type}`
1471
+ path6 && !Array.isArray(path6) && t.isPattern(path6.node),
1472
+ `Expected a Pattern path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1372
1473
  );
1373
1474
  }
1374
1475
  function getExportDependencies(code, cache, cacheKey) {
@@ -1404,8 +1505,8 @@ function getExportDependencies(code, cache, cacheKey) {
1404
1505
  }
1405
1506
  let isWithinExportDestructuring = Boolean(
1406
1507
  identifier.findParent(
1407
- (path7) => Boolean(
1408
- path7.isPattern() && path7.parentPath?.isVariableDeclarator() && path7.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1508
+ (path6) => Boolean(
1509
+ path6.isPattern() && path6.parentPath?.isVariableDeclarator() && path6.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1409
1510
  )
1410
1511
  )
1411
1512
  );
@@ -1483,7 +1584,7 @@ function getExportDependencies(code, cache, cacheKey) {
1483
1584
  for (let specifier of node.specifiers) {
1484
1585
  if (t.isIdentifier(specifier.exported)) {
1485
1586
  let name = specifier.exported.name;
1486
- let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
1587
+ let specifierPath = exportPath.get("specifiers").find((path6) => path6.node === specifier);
1487
1588
  invariant(
1488
1589
  specifierPath,
1489
1590
  `Expected to find specifier path for ${name}`
@@ -1500,22 +1601,22 @@ function getExportDependencies(code, cache, cacheKey) {
1500
1601
  }
1501
1602
  );
1502
1603
  }
1503
- function getDependentIdentifiersForPath(path7, state) {
1604
+ function getDependentIdentifiersForPath(path6, state) {
1504
1605
  let { visited, identifiers } = state ?? {
1505
1606
  visited: /* @__PURE__ */ new Set(),
1506
1607
  identifiers: /* @__PURE__ */ new Set()
1507
1608
  };
1508
- if (visited.has(path7)) {
1609
+ if (visited.has(path6)) {
1509
1610
  return identifiers;
1510
1611
  }
1511
- visited.add(path7);
1512
- path7.traverse({
1513
- Identifier(path8) {
1514
- if (identifiers.has(path8)) {
1612
+ visited.add(path6);
1613
+ path6.traverse({
1614
+ Identifier(path7) {
1615
+ if (identifiers.has(path7)) {
1515
1616
  return;
1516
1617
  }
1517
- identifiers.add(path8);
1518
- let binding = path8.scope.getBinding(path8.node.name);
1618
+ identifiers.add(path7);
1619
+ let binding = path7.scope.getBinding(path7.node.name);
1519
1620
  if (!binding) {
1520
1621
  return;
1521
1622
  }
@@ -1537,7 +1638,7 @@ function getDependentIdentifiersForPath(path7, state) {
1537
1638
  }
1538
1639
  }
1539
1640
  });
1540
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1641
+ let topLevelStatement = getTopLevelStatementPathForPath(path6);
1541
1642
  let withinImportStatement = topLevelStatement.isImportDeclaration();
1542
1643
  let withinExportStatement = topLevelStatement.isExportDeclaration();
1543
1644
  if (!withinImportStatement && !withinExportStatement) {
@@ -1546,9 +1647,9 @@ function getDependentIdentifiersForPath(path7, state) {
1546
1647
  identifiers
1547
1648
  });
1548
1649
  }
1549
- if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
1550
- t.isPattern(path7.parentPath.parentPath?.node))) {
1551
- let variableDeclarator = path7.findParent((p) => p.isVariableDeclarator());
1650
+ if (withinExportStatement && path6.isIdentifier() && (t.isPattern(path6.parentPath.node) || // [foo]
1651
+ t.isPattern(path6.parentPath.parentPath?.node))) {
1652
+ let variableDeclarator = path6.findParent((p) => p.isVariableDeclarator());
1552
1653
  assertNodePath(variableDeclarator);
1553
1654
  getDependentIdentifiersForPath(variableDeclarator, {
1554
1655
  visited,
@@ -1557,16 +1658,16 @@ function getDependentIdentifiersForPath(path7, state) {
1557
1658
  }
1558
1659
  return identifiers;
1559
1660
  }
1560
- function getTopLevelStatementPathForPath(path7) {
1561
- let ancestry = path7.getAncestry();
1661
+ function getTopLevelStatementPathForPath(path6) {
1662
+ let ancestry = path6.getAncestry();
1562
1663
  let topLevelStatement = ancestry[ancestry.length - 2];
1563
1664
  assertNodePathIsStatement(topLevelStatement);
1564
1665
  return topLevelStatement;
1565
1666
  }
1566
1667
  function getTopLevelStatementsForPaths(paths) {
1567
1668
  let topLevelStatements = /* @__PURE__ */ new Set();
1568
- for (let path7 of paths) {
1569
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1669
+ for (let path6 of paths) {
1670
+ let topLevelStatement = getTopLevelStatementPathForPath(path6);
1570
1671
  topLevelStatements.add(topLevelStatement.node);
1571
1672
  }
1572
1673
  return topLevelStatements;
@@ -1983,24 +2084,24 @@ var plugin = {
1983
2084
  };
1984
2085
  var transform = (ast) => {
1985
2086
  const hocs = [];
1986
- function getHocUid(path7, hocName) {
1987
- const uid = path7.scope.generateUidIdentifier(hocName);
2087
+ function getHocUid(path6, hocName) {
2088
+ const uid = path6.scope.generateUidIdentifier(hocName);
1988
2089
  hocs.push([hocName, uid]);
1989
2090
  return uid;
1990
2091
  }
1991
2092
  traverse(ast, {
1992
- ExportDeclaration(path7) {
1993
- if (path7.isExportDefaultDeclaration()) {
1994
- const declaration = path7.get("declaration");
2093
+ ExportDeclaration(path6) {
2094
+ if (path6.isExportDefaultDeclaration()) {
2095
+ const declaration = path6.get("declaration");
1995
2096
  const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
1996
2097
  if (expr) {
1997
- const uid = getHocUid(path7, "withComponentProps");
2098
+ const uid = getHocUid(path6, "withComponentProps");
1998
2099
  declaration.replaceWith(t.callExpression(uid, [expr]));
1999
2100
  }
2000
2101
  return;
2001
2102
  }
2002
- if (path7.isExportNamedDeclaration()) {
2003
- const decl = path7.get("declaration");
2103
+ if (path6.isExportNamedDeclaration()) {
2104
+ const decl = path6.get("declaration");
2004
2105
  if (decl.isVariableDeclaration()) {
2005
2106
  decl.get("declarations").forEach((varDeclarator) => {
2006
2107
  const id = varDeclarator.get("id");
@@ -2010,7 +2111,7 @@ var transform = (ast) => {
2010
2111
  if (!id.isIdentifier()) return;
2011
2112
  const { name } = id.node;
2012
2113
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
2013
- const uid = getHocUid(path7, `with${name}Props`);
2114
+ const uid = getHocUid(path6, `with${name}Props`);
2014
2115
  init.replaceWith(t.callExpression(uid, [expr]));
2015
2116
  });
2016
2117
  return;
@@ -2020,7 +2121,7 @@ var transform = (ast) => {
2020
2121
  if (!id) return;
2021
2122
  const { name } = id;
2022
2123
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
2023
- const uid = getHocUid(path7, `with${name}Props`);
2124
+ const uid = getHocUid(path6, `with${name}Props`);
2024
2125
  decl.replaceWith(
2025
2126
  t.variableDeclaration("const", [
2026
2127
  t.variableDeclarator(
@@ -2085,7 +2186,6 @@ var SSR_BUNDLE_PREFIX = "ssrBundle_";
2085
2186
  function isSsrBundleEnvironmentName(name) {
2086
2187
  return name.startsWith(SSR_BUNDLE_PREFIX);
2087
2188
  }
2088
- var CSS_DEV_HELPER_ENVIRONMENT_NAME = "__react_router_css_dev_helper__";
2089
2189
  function getServerEnvironmentEntries(ctx, record) {
2090
2190
  return Object.entries(record).filter(
2091
2191
  ([name]) => ctx.buildManifest?.serverBundles ? isSsrBundleEnvironmentName(name) : name === "ssr"
@@ -2121,14 +2221,14 @@ var virtualHmrRuntime = create("hmr-runtime");
2121
2221
  var virtualInjectHmrRuntime = create("inject-hmr-runtime");
2122
2222
  var normalizeRelativeFilePath = (file, reactRouterConfig) => {
2123
2223
  let vite2 = getVite();
2124
- let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
2125
- let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
2224
+ let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2225
+ let relativePath = path5.relative(reactRouterConfig.appDirectory, fullPath);
2126
2226
  return vite2.normalizePath(relativePath).split("?")[0];
2127
2227
  };
2128
2228
  var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
2129
2229
  let vite2 = getVite();
2130
2230
  let file = route.file;
2131
- let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
2231
+ let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2132
2232
  return vite2.normalizePath(fullPath);
2133
2233
  };
2134
2234
  var virtual2 = {
@@ -2151,7 +2251,7 @@ var getHash = (source, maxLength) => {
2151
2251
  var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
2152
2252
  let vite2 = getVite();
2153
2253
  let rootRelativeFilePath = vite2.normalizePath(
2154
- path6.relative(ctx.rootDirectory, absoluteFilePath)
2254
+ path5.relative(ctx.rootDirectory, absoluteFilePath)
2155
2255
  );
2156
2256
  let entryChunk = viteManifest[rootRelativeFilePath];
2157
2257
  if (!entryChunk) {
@@ -2215,7 +2315,7 @@ function dedupe(array2) {
2215
2315
  return [...new Set(array2)];
2216
2316
  }
2217
2317
  var writeFileSafe = async (file, contents) => {
2218
- await fse.ensureDir(path6.dirname(file));
2318
+ await fse.ensureDir(path5.dirname(file));
2219
2319
  await fse.writeFile(file, contents);
2220
2320
  };
2221
2321
  var getExportNames = (code) => {
@@ -2241,7 +2341,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
2241
2341
  }
2242
2342
  let ssr = true;
2243
2343
  let { pluginContainer, moduleGraph } = viteChildCompiler;
2244
- let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2344
+ let routePath = path5.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2245
2345
  let url2 = resolveFileUrl(ctx, routePath);
2246
2346
  let resolveId = async () => {
2247
2347
  let result = await pluginContainer.resolveId(url2, void 0, { ssr });
@@ -2283,12 +2383,12 @@ var resolveEnvironmentBuildContext = ({
2283
2383
  };
2284
2384
  return resolvedBuildContext;
2285
2385
  };
2286
- var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
2386
+ var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path5.join(
2287
2387
  reactRouterConfig.buildDirectory,
2288
2388
  "server",
2289
2389
  ...serverBundleId ? [serverBundleId] : []
2290
2390
  );
2291
- var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
2391
+ var getClientBuildDirectory = (reactRouterConfig) => path5.join(reactRouterConfig.buildDirectory, "client");
2292
2392
  var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2293
2393
  if (!ctx.buildManifest) {
2294
2394
  return void 0;
@@ -2306,14 +2406,13 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2306
2406
  );
2307
2407
  return Object.keys(serverBundleRoutes);
2308
2408
  };
2309
- var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
2310
- var defaultEntriesDir = path6.resolve(
2311
- path6.dirname(require.resolve("@react-router/dev/package.json")),
2409
+ var defaultEntriesDir = path5.resolve(
2410
+ path5.dirname(require.resolve("@react-router/dev/package.json")),
2312
2411
  "dist",
2313
2412
  "config",
2314
2413
  "defaults"
2315
2414
  );
2316
- var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
2415
+ var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path5.join(defaultEntriesDir, filename3));
2317
2416
  invariant(defaultEntries.length > 0, "No default entries found");
2318
2417
  var reactRouterDevLoadContext = () => void 0;
2319
2418
  var reactRouterVitePlugin = () => {
@@ -2412,7 +2511,7 @@ var reactRouterVitePlugin = () => {
2412
2511
  virtual2.serverManifest.id
2413
2512
  )};
2414
2513
  export const assetsBuildDirectory = ${JSON.stringify(
2415
- path6.relative(
2514
+ path5.relative(
2416
2515
  ctx.rootDirectory,
2417
2516
  getClientBuildDirectory(ctx.reactRouterConfig)
2418
2517
  )
@@ -2451,7 +2550,7 @@ var reactRouterVitePlugin = () => {
2451
2550
  };
2452
2551
  let loadViteManifest = async (directory) => {
2453
2552
  let manifestContents = await fse.readFile(
2454
- path6.resolve(directory, ".vite", "manifest.json"),
2553
+ path5.resolve(directory, ".vite", "manifest.json"),
2455
2554
  "utf-8"
2456
2555
  );
2457
2556
  return JSON.parse(manifestContents);
@@ -2482,7 +2581,7 @@ var reactRouterVitePlugin = () => {
2482
2581
  let contents;
2483
2582
  try {
2484
2583
  contents = await fse.readFile(
2485
- path6.join(entry.path, entry.name),
2584
+ path5.join(entry.path, entry.name),
2486
2585
  "utf-8"
2487
2586
  );
2488
2587
  } catch (e) {
@@ -2491,7 +2590,7 @@ var reactRouterVitePlugin = () => {
2491
2590
  }
2492
2591
  let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
2493
2592
  let filepath = getVite().normalizePath(
2494
- path6.relative(clientBuildDirectory, path6.join(entry.path, entry.name))
2593
+ path5.relative(clientBuildDirectory, path5.join(entry.path, entry.name))
2495
2594
  );
2496
2595
  sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
2497
2596
  }
@@ -2518,7 +2617,7 @@ var reactRouterVitePlugin = () => {
2518
2617
  );
2519
2618
  let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
2520
2619
  for (let route of Object.values(ctx.reactRouterConfig.routes)) {
2521
- let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
2620
+ let routeFile = path5.join(ctx.reactRouterConfig.appDirectory, route.file);
2522
2621
  let sourceExports = routeManifestExports[route.id];
2523
2622
  let isRootRoute = route.parentId === void 0;
2524
2623
  let hasClientAction = sourceExports.includes("clientAction");
@@ -2594,7 +2693,7 @@ var reactRouterVitePlugin = () => {
2594
2693
  }
2595
2694
  let fingerprintedValues = { entry, routes: browserRoutes };
2596
2695
  let version = getHash(JSON.stringify(fingerprintedValues), 8);
2597
- let manifestPath = path6.posix.join(
2696
+ let manifestPath = path5.posix.join(
2598
2697
  viteConfig.build.assetsDir,
2599
2698
  `manifest-${version}.js`
2600
2699
  );
@@ -2606,7 +2705,7 @@ var reactRouterVitePlugin = () => {
2606
2705
  sri: void 0
2607
2706
  };
2608
2707
  await writeFileSafe(
2609
- path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2708
+ path5.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2610
2709
  `window.__reactRouterManifest=${JSON.stringify(
2611
2710
  reactRouterBrowserManifest
2612
2711
  )};`
@@ -2716,31 +2815,17 @@ var reactRouterVitePlugin = () => {
2716
2815
  if (dep.file && isCssModulesFile(dep.file)) {
2717
2816
  return cssModulesManifest[dep.file];
2718
2817
  }
2719
- const vite2 = getVite();
2720
- const viteMajor = parseInt(vite2.version.split(".")[0], 10);
2721
- const url2 = viteMajor >= 6 ? (
2722
- // We need the ?inline query in Vite v6 when loading CSS in SSR
2723
- // since it does not expose the default export for CSS in a
2724
- // server environment. This is to align with non-SSR
2725
- // environments. For backwards compatibility with v5 we keep
2726
- // using the URL without ?inline query because the HMR code was
2727
- // relying on the implicit SSR-client module graph relationship.
2728
- injectQuery(dep.url, "inline")
2729
- ) : dep.url;
2730
- let cssMod;
2731
- if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi) {
2732
- const cssDevHelperEnvironment = viteDevServer.environments[CSS_DEV_HELPER_ENVIRONMENT_NAME];
2733
- invariant(cssDevHelperEnvironment, "Missing CSS dev helper environment");
2734
- invariant(vite2.isRunnableDevEnvironment(cssDevHelperEnvironment));
2735
- cssMod = await cssDevHelperEnvironment.runner.import(url2);
2736
- } else {
2737
- cssMod = await viteDevServer.ssrLoadModule(url2);
2738
- }
2818
+ let transformedCssCode = (await viteDevServer.transformRequest(dep.url))?.code;
2739
2819
  invariant(
2740
- typeof cssMod === "object" && cssMod !== null && "default" in cssMod && typeof cssMod.default === "string",
2820
+ transformedCssCode,
2741
2821
  `Failed to load CSS for ${dep.file ?? dep.url}`
2742
2822
  );
2743
- return cssMod.default;
2823
+ let cssString = getCssStringFromViteDevModuleCode(transformedCssCode);
2824
+ invariant(
2825
+ typeof cssString === "string",
2826
+ `Failed to extract CSS for ${dep.file ?? dep.url}`
2827
+ );
2828
+ return cssString;
2744
2829
  };
2745
2830
  return [
2746
2831
  {
@@ -3026,7 +3111,8 @@ var reactRouterVitePlugin = () => {
3026
3111
  reactRouterConfigLoader.onChange(
3027
3112
  async ({
3028
3113
  result,
3029
- configCodeUpdated,
3114
+ configCodeChanged,
3115
+ routeConfigCodeChanged,
3030
3116
  configChanged,
3031
3117
  routeConfigChanged
3032
3118
  }) => {
@@ -3038,19 +3124,13 @@ var reactRouterVitePlugin = () => {
3038
3124
  });
3039
3125
  return;
3040
3126
  }
3041
- if (routeConfigChanged) {
3042
- logger.info(import_picocolors3.default.green("Route config changed."), {
3043
- clear: true,
3044
- timestamp: true
3045
- });
3046
- } else if (configCodeUpdated) {
3047
- logger.info(import_picocolors3.default.green("Config updated."), {
3048
- clear: true,
3049
- timestamp: true
3050
- });
3051
- }
3127
+ let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
3128
+ logger.info(import_picocolors3.default.green(message), {
3129
+ clear: true,
3130
+ timestamp: true
3131
+ });
3052
3132
  await updatePluginContext();
3053
- if (configChanged) {
3133
+ if (configChanged || routeConfigChanged) {
3054
3134
  invalidateVirtualModules(viteDevServer);
3055
3135
  }
3056
3136
  }
@@ -3132,8 +3212,8 @@ var reactRouterVitePlugin = () => {
3132
3212
  let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
3133
3213
  let movedAssetPaths = [];
3134
3214
  for (let ssrAssetPath of ssrAssetPaths) {
3135
- let src = path6.join(serverBuildDirectory, ssrAssetPath);
3136
- let dest = path6.join(clientBuildDirectory, ssrAssetPath);
3215
+ let src = path5.join(serverBuildDirectory, ssrAssetPath);
3216
+ let dest = path5.join(clientBuildDirectory, ssrAssetPath);
3137
3217
  if (!fse.existsSync(dest)) {
3138
3218
  await fse.move(src, dest);
3139
3219
  movedAssetPaths.push(dest);
@@ -3146,7 +3226,7 @@ var reactRouterVitePlugin = () => {
3146
3226
  );
3147
3227
  await Promise.all(
3148
3228
  ssrCssPaths.map(
3149
- (cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
3229
+ (cssPath) => fse.remove(path5.join(serverBuildDirectory, cssPath))
3150
3230
  )
3151
3231
  );
3152
3232
  if (movedAssetPaths.length) {
@@ -3155,7 +3235,7 @@ var reactRouterVitePlugin = () => {
3155
3235
  "",
3156
3236
  `${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
3157
3237
  ...movedAssetPaths.map(
3158
- (movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
3238
+ (movedAssetPath) => import_picocolors3.default.dim(path5.relative(ctx.rootDirectory, movedAssetPath))
3159
3239
  ),
3160
3240
  ""
3161
3241
  ].join("\n")
@@ -3234,7 +3314,7 @@ var reactRouterVitePlugin = () => {
3234
3314
  );
3235
3315
  let isMainChunkExport = (name) => !chunkedExports.includes(name);
3236
3316
  let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
3237
- let chunkBasePath = `./${path6.basename(id)}`;
3317
+ let chunkBasePath = `./${path5.basename(id)}`;
3238
3318
  return [
3239
3319
  `export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
3240
3320
  chunkBasePath,
@@ -3254,7 +3334,7 @@ var reactRouterVitePlugin = () => {
3254
3334
  async transform(code, id, options) {
3255
3335
  if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
3256
3336
  let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
3257
- let routeFileName = path6.basename(routeModuleId);
3337
+ let routeFileName = path5.basename(routeModuleId);
3258
3338
  let sourceExports = await getRouteModuleExports(
3259
3339
  viteChildCompiler,
3260
3340
  ctx,
@@ -3381,7 +3461,7 @@ var reactRouterVitePlugin = () => {
3381
3461
  }
3382
3462
  let vite2 = getVite();
3383
3463
  let importerShort = vite2.normalizePath(
3384
- path6.relative(ctx.rootDirectory, importer)
3464
+ path5.relative(ctx.rootDirectory, importer)
3385
3465
  );
3386
3466
  if (isRoute(ctx.reactRouterConfig, importer)) {
3387
3467
  let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
@@ -3504,10 +3584,10 @@ var reactRouterVitePlugin = () => {
3504
3584
  },
3505
3585
  async load(id) {
3506
3586
  if (id !== virtualHmrRuntime.resolvedId) return;
3507
- let reactRefreshDir = path6.dirname(
3587
+ let reactRefreshDir = path5.dirname(
3508
3588
  require.resolve("react-refresh/package.json")
3509
3589
  );
3510
- let reactRefreshRuntimePath = path6.join(
3590
+ let reactRefreshRuntimePath = path5.join(
3511
3591
  reactRefreshDir,
3512
3592
  "cjs/react-refresh-runtime.development.js"
3513
3593
  );
@@ -3688,7 +3768,7 @@ if (import.meta.hot && !inWebWorker) {
3688
3768
  function getRoute(pluginConfig, file) {
3689
3769
  let vite2 = getVite();
3690
3770
  let routePath = vite2.normalizePath(
3691
- path6.relative(pluginConfig.appDirectory, file)
3771
+ path5.relative(pluginConfig.appDirectory, file)
3692
3772
  );
3693
3773
  let route = Object.values(pluginConfig.routes).find(
3694
3774
  (r) => vite2.normalizePath(r.file) === routePath
@@ -3727,7 +3807,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
3727
3807
  caseSensitive: route.caseSensitive,
3728
3808
  url: combineURLs(
3729
3809
  ctx.publicPath,
3730
- "/" + path6.relative(
3810
+ "/" + path5.relative(
3731
3811
  ctx.rootDirectory,
3732
3812
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
3733
3813
  )
@@ -3755,7 +3835,7 @@ function isSpaModeEnabled(reactRouterConfig) {
3755
3835
  return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
3756
3836
  }
3757
3837
  async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
3758
- let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
3838
+ let serverBuildPath = path5.join(serverBuildDirectory, serverBuildFile);
3759
3839
  let build = await import(url.pathToFileURL(serverBuildPath).toString());
3760
3840
  let { createRequestHandler: createHandler } = await import("react-router");
3761
3841
  return {
@@ -3797,9 +3877,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
3797
3877
  "SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
3798
3878
  );
3799
3879
  }
3800
- await fse.writeFile(path6.join(clientBuildDirectory, filename3), html);
3801
- let prettyDir = path6.relative(process.cwd(), clientBuildDirectory);
3802
- let prettyPath = path6.join(prettyDir, filename3);
3880
+ await fse.writeFile(path5.join(clientBuildDirectory, filename3), html);
3881
+ let prettyDir = path5.relative(process.cwd(), clientBuildDirectory);
3882
+ let prettyPath = path5.join(prettyDir, filename3);
3803
3883
  if (build.prerender.length > 0) {
3804
3884
  viteConfig.logger.info(
3805
3885
  `Prerender (html): SPA Fallback -> ${import_picocolors3.default.bold(prettyPath)}`
@@ -3815,17 +3895,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3815
3895
  serverBuildPath
3816
3896
  );
3817
3897
  let routes = createPrerenderRoutes(reactRouterConfig.routes);
3818
- for (let path7 of build.prerender) {
3819
- let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
3898
+ for (let path6 of build.prerender) {
3899
+ let matches = (0, import_react_router2.matchRoutes)(routes, `/${path6}/`.replace(/^\/\/+/, "/"));
3820
3900
  if (!matches) {
3821
3901
  throw new Error(
3822
- `Unable to prerender path because it does not match any routes: ${path7}`
3902
+ `Unable to prerender path because it does not match any routes: ${path6}`
3823
3903
  );
3824
3904
  }
3825
3905
  }
3826
3906
  let buildRoutes = createPrerenderRoutes(build.routes);
3827
- for (let path7 of build.prerender) {
3828
- let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path7}/`.replace(/^\/\/+/, "/"));
3907
+ for (let path6 of build.prerender) {
3908
+ let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path6}/`.replace(/^\/\/+/, "/"));
3829
3909
  if (!matches) {
3830
3910
  continue;
3831
3911
  }
@@ -3838,7 +3918,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3838
3918
  if (manifestRoute.loader) {
3839
3919
  await prerenderData(
3840
3920
  handler,
3841
- path7,
3921
+ path6,
3842
3922
  [leafRoute.id],
3843
3923
  clientBuildDirectory,
3844
3924
  reactRouterConfig,
@@ -3846,7 +3926,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3846
3926
  );
3847
3927
  await prerenderResourceRoute(
3848
3928
  handler,
3849
- path7,
3929
+ path6,
3850
3930
  clientBuildDirectory,
3851
3931
  reactRouterConfig,
3852
3932
  viteConfig
@@ -3864,7 +3944,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3864
3944
  if (!isResourceRoute && hasLoaders) {
3865
3945
  data = await prerenderData(
3866
3946
  handler,
3867
- path7,
3947
+ path6,
3868
3948
  null,
3869
3949
  clientBuildDirectory,
3870
3950
  reactRouterConfig,
@@ -3873,7 +3953,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3873
3953
  }
3874
3954
  await prerenderRoute(
3875
3955
  handler,
3876
- path7,
3956
+ path6,
3877
3957
  clientBuildDirectory,
3878
3958
  reactRouterConfig,
3879
3959
  viteConfig,
@@ -3926,9 +4006,9 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
3926
4006
  ${normalizedPath}`
3927
4007
  );
3928
4008
  }
3929
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3930
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
3931
- await fse.ensureDir(path6.dirname(outfile));
4009
+ let outdir = path5.relative(process.cwd(), clientBuildDirectory);
4010
+ let outfile = path5.join(outdir, ...normalizedPath.split("/"));
4011
+ await fse.ensureDir(path5.dirname(outfile));
3932
4012
  await fse.outputFile(outfile, data);
3933
4013
  viteConfig.logger.info(
3934
4014
  `Prerender (data): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3965,9 +4045,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
3965
4045
  ${html}`
3966
4046
  );
3967
4047
  }
3968
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3969
- let outfile = path6.join(outdir, ...normalizedPath.split("/"), "index.html");
3970
- await fse.ensureDir(path6.dirname(outfile));
4048
+ let outdir = path5.relative(process.cwd(), clientBuildDirectory);
4049
+ let outfile = path5.join(outdir, ...normalizedPath.split("/"), "index.html");
4050
+ await fse.ensureDir(path5.dirname(outfile));
3971
4051
  await fse.outputFile(outfile, html);
3972
4052
  viteConfig.logger.info(
3973
4053
  `Prerender (html): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3984,9 +4064,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
3984
4064
  ${content.toString("utf8")}`
3985
4065
  );
3986
4066
  }
3987
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3988
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
3989
- await fse.ensureDir(path6.dirname(outfile));
4067
+ let outdir = path5.relative(process.cwd(), clientBuildDirectory);
4068
+ let outfile = path5.join(outdir, ...normalizedPath.split("/"));
4069
+ await fse.ensureDir(path5.dirname(outfile));
3990
4070
  await fse.outputFile(outfile, content);
3991
4071
  viteConfig.logger.info(
3992
4072
  `Prerender (resource): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -4062,14 +4142,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
4062
4142
  }
4063
4143
  let prerenderRoutes = createPrerenderRoutes(manifest.routes);
4064
4144
  let prerenderedRoutes = /* @__PURE__ */ new Set();
4065
- for (let path7 of prerenderPaths) {
4145
+ for (let path6 of prerenderPaths) {
4066
4146
  let matches = (0, import_react_router2.matchRoutes)(
4067
4147
  prerenderRoutes,
4068
- `/${path7}/`.replace(/^\/\/+/, "/")
4148
+ `/${path6}/`.replace(/^\/\/+/, "/")
4069
4149
  );
4070
4150
  invariant(
4071
4151
  matches,
4072
- `Unable to prerender path because it does not match any routes: ${path7}`
4152
+ `Unable to prerender path because it does not match any routes: ${path6}`
4073
4153
  );
4074
4154
  matches.forEach((m) => prerenderedRoutes.add(m.route.id));
4075
4155
  }
@@ -4236,8 +4316,8 @@ function validateRouteChunks({
4236
4316
  async function cleanBuildDirectory(viteConfig, ctx) {
4237
4317
  let buildDirectory = ctx.reactRouterConfig.buildDirectory;
4238
4318
  let isWithinRoot = () => {
4239
- let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
4240
- return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
4319
+ let relativePath = path5.relative(ctx.rootDirectory, buildDirectory);
4320
+ return !relativePath.startsWith("..") && !path5.isAbsolute(relativePath);
4241
4321
  };
4242
4322
  if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
4243
4323
  await fse.remove(buildDirectory);
@@ -4248,7 +4328,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4248
4328
  ([environmentName, options]) => {
4249
4329
  let outDir = options.build?.outDir;
4250
4330
  invariant(outDir, `Expected build.outDir for ${environmentName}`);
4251
- return path6.join(outDir, ".vite/manifest.json");
4331
+ return path5.join(outDir, ".vite/manifest.json");
4252
4332
  }
4253
4333
  );
4254
4334
  await Promise.all(
@@ -4258,7 +4338,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4258
4338
  if (!ctx.viteManifestEnabled) {
4259
4339
  await fse.remove(viteManifestPath);
4260
4340
  }
4261
- let viteDir = path6.dirname(viteManifestPath);
4341
+ let viteDir = path5.dirname(viteManifestPath);
4262
4342
  let viteDirFiles = await fse.readdir(viteDir);
4263
4343
  if (viteDirFiles.length === 0) {
4264
4344
  await fse.remove(viteDir);
@@ -4276,12 +4356,12 @@ async function getBuildManifest({
4276
4356
  }
4277
4357
  let { normalizePath } = await import("vite");
4278
4358
  let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
4279
- let resolvedAppDirectory = path6.resolve(rootDirectory, appDirectory);
4359
+ let resolvedAppDirectory = path5.resolve(rootDirectory, appDirectory);
4280
4360
  let rootRelativeRoutes = Object.fromEntries(
4281
4361
  Object.entries(routes).map(([id, route]) => {
4282
- let filePath = path6.join(resolvedAppDirectory, route.file);
4362
+ let filePath = path5.join(resolvedAppDirectory, route.file);
4283
4363
  let rootRelativeFilePath = normalizePath(
4284
- path6.relative(rootDirectory, filePath)
4364
+ path5.relative(rootDirectory, filePath)
4285
4365
  );
4286
4366
  return [id, { ...route, file: rootRelativeFilePath }];
4287
4367
  })
@@ -4299,7 +4379,7 @@ async function getBuildManifest({
4299
4379
  (route2) => configRouteToBranchRoute({
4300
4380
  ...route2,
4301
4381
  // Ensure absolute paths are passed to the serverBundles function
4302
- file: path6.join(resolvedAppDirectory, route2.file)
4382
+ file: path5.join(resolvedAppDirectory, route2.file)
4303
4383
  })
4304
4384
  )
4305
4385
  });
@@ -4323,10 +4403,10 @@ async function getBuildManifest({
4323
4403
  buildManifest.serverBundles[serverBundleId] ??= {
4324
4404
  id: serverBundleId,
4325
4405
  file: normalizePath(
4326
- path6.join(
4327
- path6.relative(
4406
+ path5.join(
4407
+ path5.relative(
4328
4408
  rootDirectory,
4329
- path6.join(serverBuildDirectory, serverBundleId)
4409
+ path5.join(serverBuildDirectory, serverBundleId)
4330
4410
  ),
4331
4411
  reactRouterConfig.serverBuildFile
4332
4412
  )
@@ -4345,10 +4425,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
4345
4425
  }
4346
4426
  async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4347
4427
  let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
4348
- let packageRoot = path6.dirname(
4428
+ let packageRoot = path5.dirname(
4349
4429
  require.resolve("@react-router/dev/package.json")
4350
4430
  );
4351
- let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
4431
+ let { moduleSyncEnabled } = await import(`file:///${path5.join(packageRoot, "module-sync-enabled/index.mjs")}`);
4352
4432
  let vite2 = getVite();
4353
4433
  let viteServerConditions = [
4354
4434
  ...vite2.defaultServerConditions ?? [],
@@ -4422,7 +4502,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4422
4502
  ctx.entryClientFilePath,
4423
4503
  ...Object.values(ctx.reactRouterConfig.routes).flatMap(
4424
4504
  (route) => {
4425
- let routeFilePath = path6.resolve(
4505
+ let routeFilePath = path5.resolve(
4426
4506
  ctx.reactRouterConfig.appDirectory,
4427
4507
  route.file
4428
4508
  );
@@ -4446,7 +4526,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4446
4526
  ) : null;
4447
4527
  let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
4448
4528
  let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
4449
- return path6.posix.join(
4529
+ return path5.posix.join(
4450
4530
  assetsDir,
4451
4531
  `[name]${routeChunkSuffix}-[hash].js`
4452
4532
  );
@@ -4482,9 +4562,6 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4482
4562
  }
4483
4563
  });
4484
4564
  }
4485
- if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi && viteCommand === "serve") {
4486
- environmentOptionsResolvers[CSS_DEV_HELPER_ENVIRONMENT_NAME] = () => ({});
4487
- }
4488
4565
  return environmentOptionsResolvers;
4489
4566
  }
4490
4567
  function resolveEnvironmentsOptions(environmentResolvers, resolverOptions) {