@react-router/dev 7.5.3-pre.0 → 7.6.0-pre.0

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.5.3-pre.0
2
+ * @react-router/dev v7.6.0-pre.0
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,
@@ -154,6 +156,15 @@ async function createContext({
154
156
  optimizeDeps: {
155
157
  noDiscovery: true
156
158
  },
159
+ css: {
160
+ // This empty PostCSS config object prevents the PostCSS config file from
161
+ // being loaded. We don't need it in a React Router config context, and
162
+ // there's also an issue in Vite 5 when using a .ts PostCSS config file in
163
+ // an ESM project: https://github.com/vitejs/vite/issues/15869. Consumers
164
+ // can work around this in their own Vite config file, but they can't
165
+ // configure this internal usage of vite-node.
166
+ postcss: {}
167
+ },
157
168
  configFile: false,
158
169
  envFile: false,
159
170
  plugins: []
@@ -231,7 +242,7 @@ function validateRouteConfig({
231
242
  `Route config in "${routeConfigFile}" is invalid.`,
232
243
  root ? `${root}` : [],
233
244
  nested ? Object.entries(nested).map(
234
- ([path7, message]) => `Path: routes.${path7}
245
+ ([path6, message]) => `Path: routes.${path6}
235
246
  ${message}`
236
247
  ) : []
237
248
  ].flat().join("\n\n")
@@ -347,7 +358,8 @@ function err(error) {
347
358
  async function resolveConfig({
348
359
  root,
349
360
  viteNodeContext,
350
- reactRouterConfigFile
361
+ reactRouterConfigFile,
362
+ skipRoutes
351
363
  }) {
352
364
  let reactRouterUserConfig = {};
353
365
  if (reactRouterConfigFile) {
@@ -396,12 +408,17 @@ async function resolveConfig({
396
408
  serverModuleFormat: "esm",
397
409
  ssr: true
398
410
  };
411
+ let userAndPresetConfigs = mergeReactRouterConfig(
412
+ ...presets,
413
+ reactRouterUserConfig
414
+ );
399
415
  let {
400
416
  appDirectory: userAppDirectory,
401
417
  basename: basename2,
402
418
  buildDirectory: userBuildDirectory,
403
419
  buildEnd,
404
420
  prerender,
421
+ routeDiscovery: userRouteDiscovery,
405
422
  serverBuildFile,
406
423
  serverBundles,
407
424
  serverModuleFormat,
@@ -409,7 +426,7 @@ async function resolveConfig({
409
426
  } = {
410
427
  ...defaults,
411
428
  // Default values should be completely overridden by user/preset config, not merged
412
- ...mergeReactRouterConfig(...presets, reactRouterUserConfig)
429
+ ...userAndPresetConfigs
413
430
  };
414
431
  if (!ssr && serverBundles) {
415
432
  serverBundles = void 0;
@@ -420,6 +437,32 @@ async function resolveConfig({
420
437
  "The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
421
438
  );
422
439
  }
440
+ let routeDiscovery;
441
+ if (userRouteDiscovery == null) {
442
+ if (ssr) {
443
+ routeDiscovery = {
444
+ mode: "lazy",
445
+ manifestPath: "/__manifest"
446
+ };
447
+ } else {
448
+ routeDiscovery = { mode: "initial" };
449
+ }
450
+ } else if (userRouteDiscovery.mode === "initial") {
451
+ routeDiscovery = userRouteDiscovery;
452
+ } else if (userRouteDiscovery.mode === "lazy") {
453
+ if (!ssr) {
454
+ return err(
455
+ 'The `routeDiscovery.mode` config cannot be set to "lazy" when setting `ssr:false`'
456
+ );
457
+ }
458
+ let { manifestPath } = userRouteDiscovery;
459
+ if (manifestPath != null && !manifestPath.startsWith("/")) {
460
+ return err(
461
+ 'The `routeDiscovery.manifestPath` config must be a root-relative pathname beginning with a slash (i.e., "/__manifest")'
462
+ );
463
+ }
464
+ routeDiscovery = userRouteDiscovery;
465
+ }
423
466
  let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
424
467
  let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
425
468
  let rootRouteFile = findEntry(appDirectory, "root");
@@ -432,45 +475,50 @@ async function resolveConfig({
432
475
  `Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
433
476
  );
434
477
  }
435
- let routes = {
436
- root: { path: "", id: "root", file: rootRouteFile }
437
- };
438
- let routeConfigFile = findEntry(appDirectory, "routes");
439
- try {
440
- if (!routeConfigFile) {
441
- let routeConfigDisplayPath = import_pathe3.default.relative(
442
- root,
443
- import_pathe3.default.join(appDirectory, "routes.ts")
444
- );
445
- return err(`Route config file not found at "${routeConfigDisplayPath}".`);
446
- }
447
- setAppDirectory(appDirectory);
448
- let routeConfigExport = (await viteNodeContext.runner.executeFile(
449
- import_pathe3.default.join(appDirectory, routeConfigFile)
450
- )).default;
451
- let routeConfig = await routeConfigExport;
452
- let result = validateRouteConfig({
453
- routeConfigFile,
454
- routeConfig
455
- });
456
- if (!result.valid) {
457
- return err(result.message);
458
- }
478
+ let routes = {};
479
+ if (!skipRoutes) {
459
480
  routes = {
460
- ...routes,
461
- ...configRoutesToRouteManifest(appDirectory, routeConfig)
481
+ root: { path: "", id: "root", file: rootRouteFile }
462
482
  };
463
- } catch (error) {
464
- return err(
465
- [
466
- import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
467
- "",
468
- error.loc?.file && error.loc?.column && error.frame ? [
469
- import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
470
- error.frame.trim?.()
471
- ] : error.stack
472
- ].flat().join("\n")
473
- );
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
+ }
474
522
  }
475
523
  let future = {
476
524
  unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
@@ -487,6 +535,7 @@ async function resolveConfig({
487
535
  future,
488
536
  prerender,
489
537
  routes,
538
+ routeDiscovery,
490
539
  serverBuildFile,
491
540
  serverBundles,
492
541
  serverModuleFormat,
@@ -499,24 +548,35 @@ async function resolveConfig({
499
548
  }
500
549
  async function createConfigLoader({
501
550
  rootDirectory: root,
502
- watch: watch2
551
+ watch: watch2,
552
+ mode,
553
+ skipRoutes
503
554
  }) {
504
- 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");
505
557
  let viteNodeContext = await createContext({
506
558
  root,
507
- mode: watch2 ? "development" : "production"
508
- });
509
- let reactRouterConfigFile = findEntry(root, "react-router.config", {
510
- absolute: true
559
+ mode,
560
+ // Filter out any info level logs from vite-node
561
+ customLogger: vite2.createLogger("warn", {
562
+ prefix: "[react-router]"
563
+ })
511
564
  });
512
- 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 });
513
573
  let appDirectory;
514
574
  let initialConfigResult = await getConfig();
515
575
  if (!initialConfigResult.ok) {
516
576
  throw new Error(initialConfigResult.error);
517
577
  }
518
- appDirectory = initialConfigResult.value.appDirectory;
519
- let lastConfig = initialConfigResult.value;
578
+ appDirectory = import_pathe3.default.normalize(initialConfigResult.value.appDirectory);
579
+ let currentConfig = initialConfigResult.value;
520
580
  let fsWatcher;
521
581
  let changeHandlers = [];
522
582
  return {
@@ -529,41 +589,71 @@ async function createConfigLoader({
529
589
  }
530
590
  changeHandlers.push(handler);
531
591
  if (!fsWatcher) {
532
- fsWatcher = import_chokidar.default.watch(
533
- [
534
- ...reactRouterConfigFile ? [reactRouterConfigFile] : [],
535
- appDirectory
536
- ],
537
- { ignoreInitial: true }
538
- );
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
+ });
539
602
  fsWatcher.on("all", async (...args) => {
540
603
  let [event, rawFilepath] = args;
541
604
  let filepath = import_pathe3.default.normalize(rawFilepath);
542
- let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
543
- 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(
544
613
  viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
545
614
  );
546
- if (configCodeUpdated || appFileAddedOrRemoved) {
547
- viteNodeContext.devServer?.moduleGraph.invalidateAll();
548
- viteNodeContext.runner?.moduleCache.clear();
615
+ if (!moduleGraphChanged && !appFileAddedOrRemoved) {
616
+ return;
549
617
  }
550
- if (appFileAddedOrRemoved || configCodeUpdated) {
551
- let result = await getConfig();
552
- let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
553
- let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
554
- for (let handler2 of changeHandlers) {
555
- handler2({
556
- result,
557
- configCodeUpdated,
558
- configChanged,
559
- routeConfigChanged,
560
- path: filepath,
561
- event
562
- });
563
- }
564
- if (result.ok) {
565
- lastConfig = result.value;
566
- }
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;
567
657
  }
568
658
  });
569
659
  }
@@ -595,7 +685,18 @@ async function resolveEntryFiles({
595
685
  let userEntryServerFile = findEntry(appDirectory, "entry.server");
596
686
  let entryServerFile;
597
687
  let entryClientFile = userEntryClientFile || "entry.client.tsx";
598
- let pkgJson = await import_package_json.default.load(rootDirectory);
688
+ let packageJsonPath = findEntry(rootDirectory, "package", {
689
+ extensions: [".json"],
690
+ absolute: true,
691
+ walkParents: true
692
+ });
693
+ if (!packageJsonPath) {
694
+ throw new Error(
695
+ `Could not find package.json in ${rootDirectory} or any of its parent directories`
696
+ );
697
+ }
698
+ let packageJsonDirectory = import_pathe3.default.dirname(packageJsonPath);
699
+ let pkgJson = await import_package_json.default.load(packageJsonDirectory);
599
700
  let deps = pkgJson.content.dependencies ?? {};
600
701
  if (userEntryServerFile) {
601
702
  entryServerFile = userEntryServerFile;
@@ -618,7 +719,7 @@ async function resolveEntryFiles({
618
719
  await pkgJson.save();
619
720
  let packageManager = detectPackageManager() ?? "npm";
620
721
  (0, import_node_child_process.execSync)(`${packageManager} install`, {
621
- cwd: rootDirectory,
722
+ cwd: packageJsonDirectory,
622
723
  stdio: "inherit"
623
724
  });
624
725
  }
@@ -628,15 +729,59 @@ async function resolveEntryFiles({
628
729
  let entryServerFilePath = userEntryServerFile ? import_pathe3.default.resolve(reactRouterConfig.appDirectory, userEntryServerFile) : import_pathe3.default.resolve(defaultsDirectory, entryServerFile);
629
730
  return { entryClientFilePath, entryServerFilePath };
630
731
  }
732
+ function omitRoutes(config) {
733
+ return {
734
+ ...config,
735
+ routes: {}
736
+ };
737
+ }
631
738
  var entryExts = [".js", ".jsx", ".ts", ".tsx"];
739
+ function isEntryFile(entryBasename, filename3) {
740
+ return entryExts.some((ext) => filename3 === `${entryBasename}${ext}`);
741
+ }
632
742
  function findEntry(dir, basename2, options) {
633
- for (let ext of entryExts) {
634
- let file = import_pathe3.default.resolve(dir, basename2 + ext);
635
- if (import_node_fs.default.existsSync(file)) {
636
- return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
743
+ let currentDir = import_pathe3.default.resolve(dir);
744
+ let { root } = import_pathe3.default.parse(currentDir);
745
+ while (true) {
746
+ for (let ext of options?.extensions ?? entryExts) {
747
+ let file = import_pathe3.default.resolve(currentDir, basename2 + ext);
748
+ if (import_node_fs.default.existsSync(file)) {
749
+ return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
750
+ }
751
+ }
752
+ if (!options?.walkParents) {
753
+ return void 0;
637
754
  }
755
+ let parentDir = import_pathe3.default.dirname(currentDir);
756
+ if (currentDir === root || parentDir === currentDir) {
757
+ return void 0;
758
+ }
759
+ currentDir = parentDir;
638
760
  }
639
- return void 0;
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;
640
785
  }
641
786
 
642
787
  // vite/babel.ts
@@ -654,20 +799,20 @@ var generate = require("@babel/generator").default;
654
799
 
655
800
  // typegen/generate.ts
656
801
  var import_dedent = __toESM(require("dedent"));
657
- var Path3 = __toESM(require("pathe"));
802
+ var Path4 = __toESM(require("pathe"));
658
803
  var Pathe2 = __toESM(require("pathe/utils"));
659
804
 
660
805
  // typegen/paths.ts
661
- var Path2 = __toESM(require("pathe"));
806
+ var Path3 = __toESM(require("pathe"));
662
807
  var Pathe = __toESM(require("pathe/utils"));
663
808
  function getTypesDir(ctx) {
664
- return Path2.join(ctx.rootDirectory, ".react-router/types");
809
+ return Path3.join(ctx.rootDirectory, ".react-router/types");
665
810
  }
666
811
  function getTypesPath(ctx, route) {
667
- return Path2.join(
812
+ return Path3.join(
668
813
  getTypesDir(ctx),
669
- Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
670
- Path2.dirname(route.file),
814
+ Path3.relative(ctx.rootDirectory, ctx.config.appDirectory),
815
+ Path3.dirname(route.file),
671
816
  "+types/" + Pathe.filename(route.file) + ".ts"
672
817
  );
673
818
  }
@@ -702,7 +847,7 @@ function lineage(routes, route) {
702
847
  }
703
848
  function fullpath(lineage2) {
704
849
  if (lineage2.length === 1 && lineage2[0].id === "root") return "/";
705
- 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("/");
706
851
  }
707
852
 
708
853
  // typegen/generate.ts
@@ -712,8 +857,8 @@ function generate2(ctx, route) {
712
857
  const typesPath = getTypesPath(ctx, route);
713
858
  const parents = lineage2.slice(0, -1);
714
859
  const parentTypeImports = parents.map((parent, i) => {
715
- const rel = Path3.relative(
716
- Path3.dirname(typesPath),
860
+ const rel = Path4.relative(
861
+ Path4.dirname(typesPath),
717
862
  getTypesPath(ctx, parent)
718
863
  );
719
864
  const indent = i === 0 ? "" : " ".repeat(2);
@@ -768,7 +913,7 @@ function generate2(ctx, route) {
768
913
  }
769
914
  `;
770
915
  }
771
- var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
916
+ var noExtension = (path6) => Path4.join(Path4.dirname(path6), Pathe2.filename(path6));
772
917
  function formatParamProperties(fullpath2) {
773
918
  const params = parse2(fullpath2);
774
919
  const properties = Object.entries(params).map(
@@ -778,33 +923,36 @@ function formatParamProperties(fullpath2) {
778
923
  }
779
924
 
780
925
  // typegen/index.ts
781
- async function watch(rootDirectory, { logger } = {}) {
782
- const ctx = await createContext2({ rootDirectory, watch: true });
926
+ async function watch(rootDirectory, { mode, logger }) {
927
+ const ctx = await createContext2({ rootDirectory, mode, watch: true });
783
928
  await writeAll(ctx);
784
929
  logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
785
- ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
786
- if (!result.ok) {
787
- logger?.error(import_picocolors2.default.red(result.error), { timestamp: true, clear: true });
788
- return;
789
- }
790
- ctx.config = result.value;
791
- if (routeConfigChanged) {
792
- await writeAll(ctx);
793
- logger?.info(import_picocolors2.default.green("regenerated types"), {
794
- timestamp: true,
795
- clear: true
796
- });
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
+ }
797
944
  }
798
- });
945
+ );
799
946
  return {
800
947
  close: async () => await ctx.configLoader.close()
801
948
  };
802
949
  }
803
950
  async function createContext2({
804
951
  rootDirectory,
805
- watch: watch2
952
+ watch: watch2,
953
+ mode
806
954
  }) {
807
- const configLoader = await createConfigLoader({ rootDirectory, watch: watch2 });
955
+ const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
808
956
  const configResult = await configLoader.getConfig();
809
957
  if (!configResult.ok) {
810
958
  throw new Error(configResult.error);
@@ -822,12 +970,12 @@ async function writeAll(ctx) {
822
970
  Object.values(ctx.config.routes).forEach((route) => {
823
971
  const typesPath = getTypesPath(ctx, route);
824
972
  const content = generate2(ctx, route);
825
- import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
973
+ import_node_fs2.default.mkdirSync(Path5.dirname(typesPath), { recursive: true });
826
974
  import_node_fs2.default.writeFileSync(typesPath, content);
827
975
  });
828
- const registerPath = Path4.join(typegenDir, "+register.ts");
976
+ const registerPath = Path5.join(typegenDir, "+register.ts");
829
977
  import_node_fs2.default.writeFileSync(registerPath, register(ctx));
830
- const virtualPath = Path4.join(typegenDir, "+virtual.d.ts");
978
+ const virtualPath = Path5.join(typegenDir, "+virtual.d.ts");
831
979
  import_node_fs2.default.writeFileSync(virtualPath, virtual);
832
980
  }
833
981
  function register(ctx) {
@@ -838,21 +986,25 @@ function register(ctx) {
838
986
  interface Register {
839
987
  params: Params;
840
988
  }
989
+
990
+ interface Future {
991
+ unstable_middleware: ${ctx.config.future.unstable_middleware}
992
+ }
841
993
  }
842
994
  `;
843
995
  const { t: t2 } = babel_exports;
844
- const indexPaths = new Set(
845
- Object.values(ctx.config.routes).filter((route) => route.index).map((route) => route.path)
846
- );
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
+ });
847
1003
  const typeParams = t2.tsTypeAliasDeclaration(
848
1004
  t2.identifier("Params"),
849
1005
  null,
850
1006
  t2.tsTypeLiteral(
851
- Object.values(ctx.config.routes).map((route) => {
852
- if (route.id !== "root" && !route.path) return void 0;
853
- if (!route.index && indexPaths.has(route.path)) return void 0;
854
- const lineage2 = lineage(ctx.config.routes, route);
855
- const fullpath2 = fullpath(lineage2);
1007
+ Array.from(fullpaths).map((fullpath2) => {
856
1008
  const params = parse2(fullpath2);
857
1009
  return t2.tsPropertySignature(
858
1010
  t2.stringLiteral(fullpath2),
@@ -869,7 +1021,7 @@ function register(ctx) {
869
1021
  )
870
1022
  )
871
1023
  );
872
- }).filter((x) => x !== void 0)
1024
+ })
873
1025
  )
874
1026
  );
875
1027
  return [register2, generate(typeParams).code].join("\n\n");
@@ -885,6 +1037,7 @@ var virtual = import_dedent2.default`
885
1037
  export const isSpaMode: ServerBuild["isSpaMode"];
886
1038
  export const prerender: ServerBuild["prerender"];
887
1039
  export const publicPath: ServerBuild["publicPath"];
1040
+ export const routeDiscovery: ServerBuild["routeDiscovery"];
888
1041
  export const routes: ServerBuild["routes"];
889
1042
  export const ssr: ServerBuild["ssr"];
890
1043
  export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
@@ -945,7 +1098,9 @@ function fromNodeRequest(nodeReq, nodeRes) {
945
1098
  }
946
1099
  async function toNodeRequest(res, nodeRes) {
947
1100
  nodeRes.statusCode = res.status;
948
- nodeRes.statusMessage = res.statusText;
1101
+ if (!nodeRes.req || nodeRes.req.httpVersionMajor < 2) {
1102
+ nodeRes.statusMessage = res.statusText;
1103
+ }
949
1104
  let cookiesStrings = [];
950
1105
  for (let [name, value] of res.headers) {
951
1106
  if (name === "set-cookie") {
@@ -966,17 +1121,17 @@ async function toNodeRequest(res, nodeRes) {
966
1121
  }
967
1122
 
968
1123
  // vite/styles.ts
969
- var path5 = __toESM(require("path"));
1124
+ var path4 = __toESM(require("path"));
970
1125
  var import_react_router = require("react-router");
971
1126
 
972
1127
  // vite/resolve-file-url.ts
973
- var path4 = __toESM(require("path"));
1128
+ var path3 = __toESM(require("path"));
974
1129
  var resolveFileUrl = ({ rootDirectory }, filePath) => {
975
1130
  let vite2 = getVite();
976
- let relativePath = path4.relative(rootDirectory, filePath);
977
- let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
1131
+ let relativePath = path3.relative(rootDirectory, filePath);
1132
+ let isWithinRoot = !relativePath.startsWith("..") && !path3.isAbsolute(relativePath);
978
1133
  if (!isWithinRoot) {
979
- return path4.posix.join("/@fs", vite2.normalizePath(filePath));
1134
+ return path3.posix.join("/@fs", vite2.normalizePath(filePath));
980
1135
  }
981
1136
  return "/" + vite2.normalizePath(relativePath);
982
1137
  };
@@ -1013,7 +1168,7 @@ var getStylesForFiles = async ({
1013
1168
  let deps = /* @__PURE__ */ new Set();
1014
1169
  try {
1015
1170
  for (let file of files) {
1016
- let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
1171
+ let normalizedPath = path4.resolve(rootDirectory, file).replace(/\\/g, "/");
1017
1172
  let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
1018
1173
  if (!node) {
1019
1174
  try {
@@ -1114,9 +1269,9 @@ var getStylesForPathname = async ({
1114
1269
  return void 0;
1115
1270
  }
1116
1271
  let routesWithChildren = createRoutesWithChildren(reactRouterConfig.routes);
1117
- let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
1272
+ let appPath = path4.relative(process.cwd(), reactRouterConfig.appDirectory);
1118
1273
  let documentRouteFiles = (0, import_react_router.matchRoutes)(routesWithChildren, pathname, reactRouterConfig.basename)?.map(
1119
- (match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1274
+ (match) => path4.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1120
1275
  ) ?? [];
1121
1276
  let styles = await getStylesForFiles({
1122
1277
  viteDevServer,
@@ -1124,13 +1279,27 @@ var getStylesForPathname = async ({
1124
1279
  loadCssContents,
1125
1280
  files: [
1126
1281
  // Always include the client entry file when crawling the module graph for CSS
1127
- path5.relative(rootDirectory, entryClientFilePath),
1282
+ path4.relative(rootDirectory, entryClientFilePath),
1128
1283
  // Then include any styles from the matched routes
1129
1284
  ...documentRouteFiles
1130
1285
  ]
1131
1286
  });
1132
1287
  return styles;
1133
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
+ };
1134
1303
 
1135
1304
  // vite/virtual-module.ts
1136
1305
  function create(name) {
@@ -1154,10 +1323,10 @@ var removeExports = (ast, exportsToRemove) => {
1154
1323
  let exportsFiltered = false;
1155
1324
  let markedForRemoval = /* @__PURE__ */ new Set();
1156
1325
  traverse(ast, {
1157
- ExportDeclaration(path7) {
1158
- if (path7.node.type === "ExportNamedDeclaration") {
1159
- if (path7.node.specifiers.length) {
1160
- 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) => {
1161
1330
  if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
1162
1331
  if (exportsToRemove.includes(specifier.exported.name)) {
1163
1332
  exportsFiltered = true;
@@ -1166,12 +1335,12 @@ var removeExports = (ast, exportsToRemove) => {
1166
1335
  }
1167
1336
  return true;
1168
1337
  });
1169
- if (path7.node.specifiers.length === 0) {
1170
- markedForRemoval.add(path7);
1338
+ if (path6.node.specifiers.length === 0) {
1339
+ markedForRemoval.add(path6);
1171
1340
  }
1172
1341
  }
1173
- if (path7.node.declaration?.type === "VariableDeclaration") {
1174
- let declaration = path7.node.declaration;
1342
+ if (path6.node.declaration?.type === "VariableDeclaration") {
1343
+ let declaration = path6.node.declaration;
1175
1344
  declaration.declarations = declaration.declarations.filter(
1176
1345
  (declaration2) => {
1177
1346
  if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
@@ -1185,30 +1354,30 @@ var removeExports = (ast, exportsToRemove) => {
1185
1354
  }
1186
1355
  );
1187
1356
  if (declaration.declarations.length === 0) {
1188
- markedForRemoval.add(path7);
1357
+ markedForRemoval.add(path6);
1189
1358
  }
1190
1359
  }
1191
- if (path7.node.declaration?.type === "FunctionDeclaration") {
1192
- let id = path7.node.declaration.id;
1360
+ if (path6.node.declaration?.type === "FunctionDeclaration") {
1361
+ let id = path6.node.declaration.id;
1193
1362
  if (id && exportsToRemove.includes(id.name)) {
1194
- markedForRemoval.add(path7);
1363
+ markedForRemoval.add(path6);
1195
1364
  }
1196
1365
  }
1197
- if (path7.node.declaration?.type === "ClassDeclaration") {
1198
- let id = path7.node.declaration.id;
1366
+ if (path6.node.declaration?.type === "ClassDeclaration") {
1367
+ let id = path6.node.declaration.id;
1199
1368
  if (id && exportsToRemove.includes(id.name)) {
1200
- markedForRemoval.add(path7);
1369
+ markedForRemoval.add(path6);
1201
1370
  }
1202
1371
  }
1203
1372
  }
1204
- if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1205
- markedForRemoval.add(path7);
1373
+ if (path6.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1374
+ markedForRemoval.add(path6);
1206
1375
  }
1207
1376
  }
1208
1377
  });
1209
1378
  if (markedForRemoval.size > 0 || exportsFiltered) {
1210
- for (let path7 of markedForRemoval) {
1211
- path7.remove();
1379
+ for (let path6 of markedForRemoval) {
1380
+ path6.remove();
1212
1381
  }
1213
1382
  (0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
1214
1383
  }
@@ -1279,28 +1448,28 @@ function codeToAst(code, cache, cacheKey) {
1279
1448
  )
1280
1449
  );
1281
1450
  }
1282
- function assertNodePath(path7) {
1451
+ function assertNodePath(path6) {
1283
1452
  invariant(
1284
- path7 && !Array.isArray(path7),
1285
- `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}`
1286
1455
  );
1287
1456
  }
1288
- function assertNodePathIsStatement(path7) {
1457
+ function assertNodePathIsStatement(path6) {
1289
1458
  invariant(
1290
- path7 && !Array.isArray(path7) && t.isStatement(path7.node),
1291
- `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}`
1292
1461
  );
1293
1462
  }
1294
- function assertNodePathIsVariableDeclarator(path7) {
1463
+ function assertNodePathIsVariableDeclarator(path6) {
1295
1464
  invariant(
1296
- path7 && !Array.isArray(path7) && t.isVariableDeclarator(path7.node),
1297
- `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}`
1298
1467
  );
1299
1468
  }
1300
- function assertNodePathIsPattern(path7) {
1469
+ function assertNodePathIsPattern(path6) {
1301
1470
  invariant(
1302
- path7 && !Array.isArray(path7) && t.isPattern(path7.node),
1303
- `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}`
1304
1473
  );
1305
1474
  }
1306
1475
  function getExportDependencies(code, cache, cacheKey) {
@@ -1336,8 +1505,8 @@ function getExportDependencies(code, cache, cacheKey) {
1336
1505
  }
1337
1506
  let isWithinExportDestructuring = Boolean(
1338
1507
  identifier.findParent(
1339
- (path7) => Boolean(
1340
- path7.isPattern() && path7.parentPath?.isVariableDeclarator() && path7.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1508
+ (path6) => Boolean(
1509
+ path6.isPattern() && path6.parentPath?.isVariableDeclarator() && path6.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1341
1510
  )
1342
1511
  )
1343
1512
  );
@@ -1415,7 +1584,7 @@ function getExportDependencies(code, cache, cacheKey) {
1415
1584
  for (let specifier of node.specifiers) {
1416
1585
  if (t.isIdentifier(specifier.exported)) {
1417
1586
  let name = specifier.exported.name;
1418
- let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
1587
+ let specifierPath = exportPath.get("specifiers").find((path6) => path6.node === specifier);
1419
1588
  invariant(
1420
1589
  specifierPath,
1421
1590
  `Expected to find specifier path for ${name}`
@@ -1432,22 +1601,22 @@ function getExportDependencies(code, cache, cacheKey) {
1432
1601
  }
1433
1602
  );
1434
1603
  }
1435
- function getDependentIdentifiersForPath(path7, state) {
1604
+ function getDependentIdentifiersForPath(path6, state) {
1436
1605
  let { visited, identifiers } = state ?? {
1437
1606
  visited: /* @__PURE__ */ new Set(),
1438
1607
  identifiers: /* @__PURE__ */ new Set()
1439
1608
  };
1440
- if (visited.has(path7)) {
1609
+ if (visited.has(path6)) {
1441
1610
  return identifiers;
1442
1611
  }
1443
- visited.add(path7);
1444
- path7.traverse({
1445
- Identifier(path8) {
1446
- if (identifiers.has(path8)) {
1612
+ visited.add(path6);
1613
+ path6.traverse({
1614
+ Identifier(path7) {
1615
+ if (identifiers.has(path7)) {
1447
1616
  return;
1448
1617
  }
1449
- identifiers.add(path8);
1450
- let binding = path8.scope.getBinding(path8.node.name);
1618
+ identifiers.add(path7);
1619
+ let binding = path7.scope.getBinding(path7.node.name);
1451
1620
  if (!binding) {
1452
1621
  return;
1453
1622
  }
@@ -1469,7 +1638,7 @@ function getDependentIdentifiersForPath(path7, state) {
1469
1638
  }
1470
1639
  }
1471
1640
  });
1472
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1641
+ let topLevelStatement = getTopLevelStatementPathForPath(path6);
1473
1642
  let withinImportStatement = topLevelStatement.isImportDeclaration();
1474
1643
  let withinExportStatement = topLevelStatement.isExportDeclaration();
1475
1644
  if (!withinImportStatement && !withinExportStatement) {
@@ -1478,9 +1647,9 @@ function getDependentIdentifiersForPath(path7, state) {
1478
1647
  identifiers
1479
1648
  });
1480
1649
  }
1481
- if (withinExportStatement && path7.isIdentifier() && (t.isPattern(path7.parentPath.node) || // [foo]
1482
- t.isPattern(path7.parentPath.parentPath?.node))) {
1483
- 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());
1484
1653
  assertNodePath(variableDeclarator);
1485
1654
  getDependentIdentifiersForPath(variableDeclarator, {
1486
1655
  visited,
@@ -1489,16 +1658,16 @@ function getDependentIdentifiersForPath(path7, state) {
1489
1658
  }
1490
1659
  return identifiers;
1491
1660
  }
1492
- function getTopLevelStatementPathForPath(path7) {
1493
- let ancestry = path7.getAncestry();
1661
+ function getTopLevelStatementPathForPath(path6) {
1662
+ let ancestry = path6.getAncestry();
1494
1663
  let topLevelStatement = ancestry[ancestry.length - 2];
1495
1664
  assertNodePathIsStatement(topLevelStatement);
1496
1665
  return topLevelStatement;
1497
1666
  }
1498
1667
  function getTopLevelStatementsForPaths(paths) {
1499
1668
  let topLevelStatements = /* @__PURE__ */ new Set();
1500
- for (let path7 of paths) {
1501
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1669
+ for (let path6 of paths) {
1670
+ let topLevelStatement = getTopLevelStatementPathForPath(path6);
1502
1671
  topLevelStatements.add(topLevelStatement.node);
1503
1672
  }
1504
1673
  return topLevelStatements;
@@ -1915,24 +2084,24 @@ var plugin = {
1915
2084
  };
1916
2085
  var transform = (ast) => {
1917
2086
  const hocs = [];
1918
- function getHocUid(path7, hocName) {
1919
- const uid = path7.scope.generateUidIdentifier(hocName);
2087
+ function getHocUid(path6, hocName) {
2088
+ const uid = path6.scope.generateUidIdentifier(hocName);
1920
2089
  hocs.push([hocName, uid]);
1921
2090
  return uid;
1922
2091
  }
1923
2092
  traverse(ast, {
1924
- ExportDeclaration(path7) {
1925
- if (path7.isExportDefaultDeclaration()) {
1926
- const declaration = path7.get("declaration");
2093
+ ExportDeclaration(path6) {
2094
+ if (path6.isExportDefaultDeclaration()) {
2095
+ const declaration = path6.get("declaration");
1927
2096
  const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
1928
2097
  if (expr) {
1929
- const uid = getHocUid(path7, "withComponentProps");
2098
+ const uid = getHocUid(path6, "withComponentProps");
1930
2099
  declaration.replaceWith(t.callExpression(uid, [expr]));
1931
2100
  }
1932
2101
  return;
1933
2102
  }
1934
- if (path7.isExportNamedDeclaration()) {
1935
- const decl = path7.get("declaration");
2103
+ if (path6.isExportNamedDeclaration()) {
2104
+ const decl = path6.get("declaration");
1936
2105
  if (decl.isVariableDeclaration()) {
1937
2106
  decl.get("declarations").forEach((varDeclarator) => {
1938
2107
  const id = varDeclarator.get("id");
@@ -1942,7 +2111,7 @@ var transform = (ast) => {
1942
2111
  if (!id.isIdentifier()) return;
1943
2112
  const { name } = id.node;
1944
2113
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1945
- const uid = getHocUid(path7, `with${name}Props`);
2114
+ const uid = getHocUid(path6, `with${name}Props`);
1946
2115
  init.replaceWith(t.callExpression(uid, [expr]));
1947
2116
  });
1948
2117
  return;
@@ -1952,7 +2121,7 @@ var transform = (ast) => {
1952
2121
  if (!id) return;
1953
2122
  const { name } = id;
1954
2123
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1955
- const uid = getHocUid(path7, `with${name}Props`);
2124
+ const uid = getHocUid(path6, `with${name}Props`);
1956
2125
  decl.replaceWith(
1957
2126
  t.variableDeclaration("const", [
1958
2127
  t.variableDeclarator(
@@ -2017,7 +2186,6 @@ var SSR_BUNDLE_PREFIX = "ssrBundle_";
2017
2186
  function isSsrBundleEnvironmentName(name) {
2018
2187
  return name.startsWith(SSR_BUNDLE_PREFIX);
2019
2188
  }
2020
- var CSS_DEV_HELPER_ENVIRONMENT_NAME = "__react_router_css_dev_helper__";
2021
2189
  function getServerEnvironmentEntries(ctx, record) {
2022
2190
  return Object.entries(record).filter(
2023
2191
  ([name]) => ctx.buildManifest?.serverBundles ? isSsrBundleEnvironmentName(name) : name === "ssr"
@@ -2053,14 +2221,14 @@ var virtualHmrRuntime = create("hmr-runtime");
2053
2221
  var virtualInjectHmrRuntime = create("inject-hmr-runtime");
2054
2222
  var normalizeRelativeFilePath = (file, reactRouterConfig) => {
2055
2223
  let vite2 = getVite();
2056
- let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
2057
- let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
2224
+ let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2225
+ let relativePath = path5.relative(reactRouterConfig.appDirectory, fullPath);
2058
2226
  return vite2.normalizePath(relativePath).split("?")[0];
2059
2227
  };
2060
2228
  var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
2061
2229
  let vite2 = getVite();
2062
2230
  let file = route.file;
2063
- let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
2231
+ let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2064
2232
  return vite2.normalizePath(fullPath);
2065
2233
  };
2066
2234
  var virtual2 = {
@@ -2083,7 +2251,7 @@ var getHash = (source, maxLength) => {
2083
2251
  var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
2084
2252
  let vite2 = getVite();
2085
2253
  let rootRelativeFilePath = vite2.normalizePath(
2086
- path6.relative(ctx.rootDirectory, absoluteFilePath)
2254
+ path5.relative(ctx.rootDirectory, absoluteFilePath)
2087
2255
  );
2088
2256
  let entryChunk = viteManifest[rootRelativeFilePath];
2089
2257
  if (!entryChunk) {
@@ -2147,7 +2315,7 @@ function dedupe(array2) {
2147
2315
  return [...new Set(array2)];
2148
2316
  }
2149
2317
  var writeFileSafe = async (file, contents) => {
2150
- await fse.ensureDir(path6.dirname(file));
2318
+ await fse.ensureDir(path5.dirname(file));
2151
2319
  await fse.writeFile(file, contents);
2152
2320
  };
2153
2321
  var getExportNames = (code) => {
@@ -2173,7 +2341,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
2173
2341
  }
2174
2342
  let ssr = true;
2175
2343
  let { pluginContainer, moduleGraph } = viteChildCompiler;
2176
- let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2344
+ let routePath = path5.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2177
2345
  let url2 = resolveFileUrl(ctx, routePath);
2178
2346
  let resolveId = async () => {
2179
2347
  let result = await pluginContainer.resolveId(url2, void 0, { ssr });
@@ -2215,12 +2383,12 @@ var resolveEnvironmentBuildContext = ({
2215
2383
  };
2216
2384
  return resolvedBuildContext;
2217
2385
  };
2218
- var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
2386
+ var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path5.join(
2219
2387
  reactRouterConfig.buildDirectory,
2220
2388
  "server",
2221
2389
  ...serverBundleId ? [serverBundleId] : []
2222
2390
  );
2223
- var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
2391
+ var getClientBuildDirectory = (reactRouterConfig) => path5.join(reactRouterConfig.buildDirectory, "client");
2224
2392
  var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2225
2393
  if (!ctx.buildManifest) {
2226
2394
  return void 0;
@@ -2238,14 +2406,13 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2238
2406
  );
2239
2407
  return Object.keys(serverBundleRoutes);
2240
2408
  };
2241
- var injectQuery = (url2, query) => url2.includes("?") ? url2.replace("?", `?${query}&`) : `${url2}?${query}`;
2242
- var defaultEntriesDir = path6.resolve(
2243
- path6.dirname(require.resolve("@react-router/dev/package.json")),
2409
+ var defaultEntriesDir = path5.resolve(
2410
+ path5.dirname(require.resolve("@react-router/dev/package.json")),
2244
2411
  "dist",
2245
2412
  "config",
2246
2413
  "defaults"
2247
2414
  );
2248
- var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
2415
+ var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path5.join(defaultEntriesDir, filename3));
2249
2416
  invariant(defaultEntries.length > 0, "No default entries found");
2250
2417
  var reactRouterDevLoadContext = () => void 0;
2251
2418
  var reactRouterVitePlugin = () => {
@@ -2344,7 +2511,7 @@ var reactRouterVitePlugin = () => {
2344
2511
  virtual2.serverManifest.id
2345
2512
  )};
2346
2513
  export const assetsBuildDirectory = ${JSON.stringify(
2347
- path6.relative(
2514
+ path5.relative(
2348
2515
  ctx.rootDirectory,
2349
2516
  getClientBuildDirectory(ctx.reactRouterConfig)
2350
2517
  )
@@ -2354,6 +2521,9 @@ var reactRouterVitePlugin = () => {
2354
2521
  export const ssr = ${ctx.reactRouterConfig.ssr};
2355
2522
  export const isSpaMode = ${isSpaMode};
2356
2523
  export const prerender = ${JSON.stringify(prerenderPaths)};
2524
+ export const routeDiscovery = ${JSON.stringify(
2525
+ ctx.reactRouterConfig.routeDiscovery
2526
+ )};
2357
2527
  export const publicPath = ${JSON.stringify(ctx.publicPath)};
2358
2528
  export const entry = { module: entryServer };
2359
2529
  export const routes = {
@@ -2380,7 +2550,7 @@ var reactRouterVitePlugin = () => {
2380
2550
  };
2381
2551
  let loadViteManifest = async (directory) => {
2382
2552
  let manifestContents = await fse.readFile(
2383
- path6.resolve(directory, ".vite", "manifest.json"),
2553
+ path5.resolve(directory, ".vite", "manifest.json"),
2384
2554
  "utf-8"
2385
2555
  );
2386
2556
  return JSON.parse(manifestContents);
@@ -2411,7 +2581,7 @@ var reactRouterVitePlugin = () => {
2411
2581
  let contents;
2412
2582
  try {
2413
2583
  contents = await fse.readFile(
2414
- path6.join(entry.path, entry.name),
2584
+ path5.join(entry.path, entry.name),
2415
2585
  "utf-8"
2416
2586
  );
2417
2587
  } catch (e) {
@@ -2420,7 +2590,7 @@ var reactRouterVitePlugin = () => {
2420
2590
  }
2421
2591
  let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
2422
2592
  let filepath = getVite().normalizePath(
2423
- path6.relative(clientBuildDirectory, path6.join(entry.path, entry.name))
2593
+ path5.relative(clientBuildDirectory, path5.join(entry.path, entry.name))
2424
2594
  );
2425
2595
  sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
2426
2596
  }
@@ -2447,7 +2617,7 @@ var reactRouterVitePlugin = () => {
2447
2617
  );
2448
2618
  let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
2449
2619
  for (let route of Object.values(ctx.reactRouterConfig.routes)) {
2450
- let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
2620
+ let routeFile = path5.join(ctx.reactRouterConfig.appDirectory, route.file);
2451
2621
  let sourceExports = routeManifestExports[route.id];
2452
2622
  let isRootRoute = route.parentId === void 0;
2453
2623
  let hasClientAction = sourceExports.includes("clientAction");
@@ -2523,7 +2693,7 @@ var reactRouterVitePlugin = () => {
2523
2693
  }
2524
2694
  let fingerprintedValues = { entry, routes: browserRoutes };
2525
2695
  let version = getHash(JSON.stringify(fingerprintedValues), 8);
2526
- let manifestPath = path6.posix.join(
2696
+ let manifestPath = path5.posix.join(
2527
2697
  viteConfig.build.assetsDir,
2528
2698
  `manifest-${version}.js`
2529
2699
  );
@@ -2535,7 +2705,7 @@ var reactRouterVitePlugin = () => {
2535
2705
  sri: void 0
2536
2706
  };
2537
2707
  await writeFileSafe(
2538
- path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2708
+ path5.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2539
2709
  `window.__reactRouterManifest=${JSON.stringify(
2540
2710
  reactRouterBrowserManifest
2541
2711
  )};`
@@ -2645,31 +2815,17 @@ var reactRouterVitePlugin = () => {
2645
2815
  if (dep.file && isCssModulesFile(dep.file)) {
2646
2816
  return cssModulesManifest[dep.file];
2647
2817
  }
2648
- const vite2 = getVite();
2649
- const viteMajor = parseInt(vite2.version.split(".")[0], 10);
2650
- const url2 = viteMajor >= 6 ? (
2651
- // We need the ?inline query in Vite v6 when loading CSS in SSR
2652
- // since it does not expose the default export for CSS in a
2653
- // server environment. This is to align with non-SSR
2654
- // environments. For backwards compatibility with v5 we keep
2655
- // using the URL without ?inline query because the HMR code was
2656
- // relying on the implicit SSR-client module graph relationship.
2657
- injectQuery(dep.url, "inline")
2658
- ) : dep.url;
2659
- let cssMod;
2660
- if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi) {
2661
- const cssDevHelperEnvironment = viteDevServer.environments[CSS_DEV_HELPER_ENVIRONMENT_NAME];
2662
- invariant(cssDevHelperEnvironment, "Missing CSS dev helper environment");
2663
- invariant(vite2.isRunnableDevEnvironment(cssDevHelperEnvironment));
2664
- cssMod = await cssDevHelperEnvironment.runner.import(url2);
2665
- } else {
2666
- cssMod = await viteDevServer.ssrLoadModule(url2);
2667
- }
2818
+ let transformedCssCode = (await viteDevServer.transformRequest(dep.url))?.code;
2668
2819
  invariant(
2669
- typeof cssMod === "object" && cssMod !== null && "default" in cssMod && typeof cssMod.default === "string",
2820
+ transformedCssCode,
2670
2821
  `Failed to load CSS for ${dep.file ?? dep.url}`
2671
2822
  );
2672
- 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;
2673
2829
  };
2674
2830
  return [
2675
2831
  {
@@ -2687,14 +2843,17 @@ var reactRouterVitePlugin = () => {
2687
2843
  prefix: "[react-router]"
2688
2844
  });
2689
2845
  rootDirectory = viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
2846
+ let mode = viteConfigEnv.mode;
2690
2847
  if (viteCommand === "serve") {
2691
2848
  typegenWatcherPromise = watch(rootDirectory, {
2849
+ mode,
2692
2850
  // ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
2693
2851
  logger: vite2.createLogger("warn", { prefix: "[react-router]" })
2694
2852
  });
2695
2853
  }
2696
2854
  reactRouterConfigLoader = await createConfigLoader({
2697
2855
  rootDirectory,
2856
+ mode,
2698
2857
  watch: viteCommand === "serve"
2699
2858
  });
2700
2859
  await updatePluginContext();
@@ -2952,7 +3111,8 @@ var reactRouterVitePlugin = () => {
2952
3111
  reactRouterConfigLoader.onChange(
2953
3112
  async ({
2954
3113
  result,
2955
- configCodeUpdated,
3114
+ configCodeChanged,
3115
+ routeConfigCodeChanged,
2956
3116
  configChanged,
2957
3117
  routeConfigChanged
2958
3118
  }) => {
@@ -2964,19 +3124,13 @@ var reactRouterVitePlugin = () => {
2964
3124
  });
2965
3125
  return;
2966
3126
  }
2967
- if (routeConfigChanged) {
2968
- logger.info(import_picocolors3.default.green("Route config changed."), {
2969
- clear: true,
2970
- timestamp: true
2971
- });
2972
- } else if (configCodeUpdated) {
2973
- logger.info(import_picocolors3.default.green("Config updated."), {
2974
- clear: true,
2975
- timestamp: true
2976
- });
2977
- }
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
+ });
2978
3132
  await updatePluginContext();
2979
- if (configChanged) {
3133
+ if (configChanged || routeConfigChanged) {
2980
3134
  invalidateVirtualModules(viteDevServer);
2981
3135
  }
2982
3136
  }
@@ -3058,8 +3212,8 @@ var reactRouterVitePlugin = () => {
3058
3212
  let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
3059
3213
  let movedAssetPaths = [];
3060
3214
  for (let ssrAssetPath of ssrAssetPaths) {
3061
- let src = path6.join(serverBuildDirectory, ssrAssetPath);
3062
- let dest = path6.join(clientBuildDirectory, ssrAssetPath);
3215
+ let src = path5.join(serverBuildDirectory, ssrAssetPath);
3216
+ let dest = path5.join(clientBuildDirectory, ssrAssetPath);
3063
3217
  if (!fse.existsSync(dest)) {
3064
3218
  await fse.move(src, dest);
3065
3219
  movedAssetPaths.push(dest);
@@ -3072,7 +3226,7 @@ var reactRouterVitePlugin = () => {
3072
3226
  );
3073
3227
  await Promise.all(
3074
3228
  ssrCssPaths.map(
3075
- (cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
3229
+ (cssPath) => fse.remove(path5.join(serverBuildDirectory, cssPath))
3076
3230
  )
3077
3231
  );
3078
3232
  if (movedAssetPaths.length) {
@@ -3081,7 +3235,7 @@ var reactRouterVitePlugin = () => {
3081
3235
  "",
3082
3236
  `${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
3083
3237
  ...movedAssetPaths.map(
3084
- (movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
3238
+ (movedAssetPath) => import_picocolors3.default.dim(path5.relative(ctx.rootDirectory, movedAssetPath))
3085
3239
  ),
3086
3240
  ""
3087
3241
  ].join("\n")
@@ -3160,7 +3314,7 @@ var reactRouterVitePlugin = () => {
3160
3314
  );
3161
3315
  let isMainChunkExport = (name) => !chunkedExports.includes(name);
3162
3316
  let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
3163
- let chunkBasePath = `./${path6.basename(id)}`;
3317
+ let chunkBasePath = `./${path5.basename(id)}`;
3164
3318
  return [
3165
3319
  `export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
3166
3320
  chunkBasePath,
@@ -3180,7 +3334,7 @@ var reactRouterVitePlugin = () => {
3180
3334
  async transform(code, id, options) {
3181
3335
  if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
3182
3336
  let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
3183
- let routeFileName = path6.basename(routeModuleId);
3337
+ let routeFileName = path5.basename(routeModuleId);
3184
3338
  let sourceExports = await getRouteModuleExports(
3185
3339
  viteChildCompiler,
3186
3340
  ctx,
@@ -3307,7 +3461,7 @@ var reactRouterVitePlugin = () => {
3307
3461
  }
3308
3462
  let vite2 = getVite();
3309
3463
  let importerShort = vite2.normalizePath(
3310
- path6.relative(ctx.rootDirectory, importer)
3464
+ path5.relative(ctx.rootDirectory, importer)
3311
3465
  );
3312
3466
  if (isRoute(ctx.reactRouterConfig, importer)) {
3313
3467
  let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
@@ -3430,10 +3584,10 @@ var reactRouterVitePlugin = () => {
3430
3584
  },
3431
3585
  async load(id) {
3432
3586
  if (id !== virtualHmrRuntime.resolvedId) return;
3433
- let reactRefreshDir = path6.dirname(
3587
+ let reactRefreshDir = path5.dirname(
3434
3588
  require.resolve("react-refresh/package.json")
3435
3589
  );
3436
- let reactRefreshRuntimePath = path6.join(
3590
+ let reactRefreshRuntimePath = path5.join(
3437
3591
  reactRefreshDir,
3438
3592
  "cjs/react-refresh-runtime.development.js"
3439
3593
  );
@@ -3614,7 +3768,7 @@ if (import.meta.hot && !inWebWorker) {
3614
3768
  function getRoute(pluginConfig, file) {
3615
3769
  let vite2 = getVite();
3616
3770
  let routePath = vite2.normalizePath(
3617
- path6.relative(pluginConfig.appDirectory, file)
3771
+ path5.relative(pluginConfig.appDirectory, file)
3618
3772
  );
3619
3773
  let route = Object.values(pluginConfig.routes).find(
3620
3774
  (r) => vite2.normalizePath(r.file) === routePath
@@ -3653,7 +3807,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
3653
3807
  caseSensitive: route.caseSensitive,
3654
3808
  url: combineURLs(
3655
3809
  ctx.publicPath,
3656
- "/" + path6.relative(
3810
+ "/" + path5.relative(
3657
3811
  ctx.rootDirectory,
3658
3812
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
3659
3813
  )
@@ -3681,7 +3835,7 @@ function isSpaModeEnabled(reactRouterConfig) {
3681
3835
  return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
3682
3836
  }
3683
3837
  async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
3684
- let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
3838
+ let serverBuildPath = path5.join(serverBuildDirectory, serverBuildFile);
3685
3839
  let build = await import(url.pathToFileURL(serverBuildPath).toString());
3686
3840
  let { createRequestHandler: createHandler } = await import("react-router");
3687
3841
  return {
@@ -3723,9 +3877,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
3723
3877
  "SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
3724
3878
  );
3725
3879
  }
3726
- await fse.writeFile(path6.join(clientBuildDirectory, filename3), html);
3727
- let prettyDir = path6.relative(process.cwd(), clientBuildDirectory);
3728
- 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);
3729
3883
  if (build.prerender.length > 0) {
3730
3884
  viteConfig.logger.info(
3731
3885
  `Prerender (html): SPA Fallback -> ${import_picocolors3.default.bold(prettyPath)}`
@@ -3741,17 +3895,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3741
3895
  serverBuildPath
3742
3896
  );
3743
3897
  let routes = createPrerenderRoutes(reactRouterConfig.routes);
3744
- for (let path7 of build.prerender) {
3745
- 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(/^\/\/+/, "/"));
3746
3900
  if (!matches) {
3747
3901
  throw new Error(
3748
- `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}`
3749
3903
  );
3750
3904
  }
3751
3905
  }
3752
3906
  let buildRoutes = createPrerenderRoutes(build.routes);
3753
- for (let path7 of build.prerender) {
3754
- 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(/^\/\/+/, "/"));
3755
3909
  if (!matches) {
3756
3910
  continue;
3757
3911
  }
@@ -3764,7 +3918,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3764
3918
  if (manifestRoute.loader) {
3765
3919
  await prerenderData(
3766
3920
  handler,
3767
- path7,
3921
+ path6,
3768
3922
  [leafRoute.id],
3769
3923
  clientBuildDirectory,
3770
3924
  reactRouterConfig,
@@ -3772,7 +3926,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3772
3926
  );
3773
3927
  await prerenderResourceRoute(
3774
3928
  handler,
3775
- path7,
3929
+ path6,
3776
3930
  clientBuildDirectory,
3777
3931
  reactRouterConfig,
3778
3932
  viteConfig
@@ -3790,7 +3944,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3790
3944
  if (!isResourceRoute && hasLoaders) {
3791
3945
  data = await prerenderData(
3792
3946
  handler,
3793
- path7,
3947
+ path6,
3794
3948
  null,
3795
3949
  clientBuildDirectory,
3796
3950
  reactRouterConfig,
@@ -3799,7 +3953,7 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3799
3953
  }
3800
3954
  await prerenderRoute(
3801
3955
  handler,
3802
- path7,
3956
+ path6,
3803
3957
  clientBuildDirectory,
3804
3958
  reactRouterConfig,
3805
3959
  viteConfig,
@@ -3852,9 +4006,9 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
3852
4006
  ${normalizedPath}`
3853
4007
  );
3854
4008
  }
3855
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3856
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
3857
- 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));
3858
4012
  await fse.outputFile(outfile, data);
3859
4013
  viteConfig.logger.info(
3860
4014
  `Prerender (data): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3891,9 +4045,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
3891
4045
  ${html}`
3892
4046
  );
3893
4047
  }
3894
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3895
- let outfile = path6.join(outdir, ...normalizedPath.split("/"), "index.html");
3896
- 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));
3897
4051
  await fse.outputFile(outfile, html);
3898
4052
  viteConfig.logger.info(
3899
4053
  `Prerender (html): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3910,9 +4064,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
3910
4064
  ${content.toString("utf8")}`
3911
4065
  );
3912
4066
  }
3913
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3914
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
3915
- 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));
3916
4070
  await fse.outputFile(outfile, content);
3917
4071
  viteConfig.logger.info(
3918
4072
  `Prerender (resource): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3988,14 +4142,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
3988
4142
  }
3989
4143
  let prerenderRoutes = createPrerenderRoutes(manifest.routes);
3990
4144
  let prerenderedRoutes = /* @__PURE__ */ new Set();
3991
- for (let path7 of prerenderPaths) {
4145
+ for (let path6 of prerenderPaths) {
3992
4146
  let matches = (0, import_react_router2.matchRoutes)(
3993
4147
  prerenderRoutes,
3994
- `/${path7}/`.replace(/^\/\/+/, "/")
4148
+ `/${path6}/`.replace(/^\/\/+/, "/")
3995
4149
  );
3996
4150
  invariant(
3997
4151
  matches,
3998
- `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}`
3999
4153
  );
4000
4154
  matches.forEach((m) => prerenderedRoutes.add(m.route.id));
4001
4155
  }
@@ -4162,8 +4316,8 @@ function validateRouteChunks({
4162
4316
  async function cleanBuildDirectory(viteConfig, ctx) {
4163
4317
  let buildDirectory = ctx.reactRouterConfig.buildDirectory;
4164
4318
  let isWithinRoot = () => {
4165
- let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
4166
- return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
4319
+ let relativePath = path5.relative(ctx.rootDirectory, buildDirectory);
4320
+ return !relativePath.startsWith("..") && !path5.isAbsolute(relativePath);
4167
4321
  };
4168
4322
  if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
4169
4323
  await fse.remove(buildDirectory);
@@ -4174,7 +4328,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4174
4328
  ([environmentName, options]) => {
4175
4329
  let outDir = options.build?.outDir;
4176
4330
  invariant(outDir, `Expected build.outDir for ${environmentName}`);
4177
- return path6.join(outDir, ".vite/manifest.json");
4331
+ return path5.join(outDir, ".vite/manifest.json");
4178
4332
  }
4179
4333
  );
4180
4334
  await Promise.all(
@@ -4184,7 +4338,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4184
4338
  if (!ctx.viteManifestEnabled) {
4185
4339
  await fse.remove(viteManifestPath);
4186
4340
  }
4187
- let viteDir = path6.dirname(viteManifestPath);
4341
+ let viteDir = path5.dirname(viteManifestPath);
4188
4342
  let viteDirFiles = await fse.readdir(viteDir);
4189
4343
  if (viteDirFiles.length === 0) {
4190
4344
  await fse.remove(viteDir);
@@ -4202,12 +4356,12 @@ async function getBuildManifest({
4202
4356
  }
4203
4357
  let { normalizePath } = await import("vite");
4204
4358
  let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
4205
- let resolvedAppDirectory = path6.resolve(rootDirectory, appDirectory);
4359
+ let resolvedAppDirectory = path5.resolve(rootDirectory, appDirectory);
4206
4360
  let rootRelativeRoutes = Object.fromEntries(
4207
4361
  Object.entries(routes).map(([id, route]) => {
4208
- let filePath = path6.join(resolvedAppDirectory, route.file);
4362
+ let filePath = path5.join(resolvedAppDirectory, route.file);
4209
4363
  let rootRelativeFilePath = normalizePath(
4210
- path6.relative(rootDirectory, filePath)
4364
+ path5.relative(rootDirectory, filePath)
4211
4365
  );
4212
4366
  return [id, { ...route, file: rootRelativeFilePath }];
4213
4367
  })
@@ -4225,7 +4379,7 @@ async function getBuildManifest({
4225
4379
  (route2) => configRouteToBranchRoute({
4226
4380
  ...route2,
4227
4381
  // Ensure absolute paths are passed to the serverBundles function
4228
- file: path6.join(resolvedAppDirectory, route2.file)
4382
+ file: path5.join(resolvedAppDirectory, route2.file)
4229
4383
  })
4230
4384
  )
4231
4385
  });
@@ -4249,10 +4403,10 @@ async function getBuildManifest({
4249
4403
  buildManifest.serverBundles[serverBundleId] ??= {
4250
4404
  id: serverBundleId,
4251
4405
  file: normalizePath(
4252
- path6.join(
4253
- path6.relative(
4406
+ path5.join(
4407
+ path5.relative(
4254
4408
  rootDirectory,
4255
- path6.join(serverBuildDirectory, serverBundleId)
4409
+ path5.join(serverBuildDirectory, serverBundleId)
4256
4410
  ),
4257
4411
  reactRouterConfig.serverBuildFile
4258
4412
  )
@@ -4271,10 +4425,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
4271
4425
  }
4272
4426
  async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4273
4427
  let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
4274
- let packageRoot = path6.dirname(
4428
+ let packageRoot = path5.dirname(
4275
4429
  require.resolve("@react-router/dev/package.json")
4276
4430
  );
4277
- 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")}`);
4278
4432
  let vite2 = getVite();
4279
4433
  let viteServerConditions = [
4280
4434
  ...vite2.defaultServerConditions ?? [],
@@ -4348,7 +4502,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4348
4502
  ctx.entryClientFilePath,
4349
4503
  ...Object.values(ctx.reactRouterConfig.routes).flatMap(
4350
4504
  (route) => {
4351
- let routeFilePath = path6.resolve(
4505
+ let routeFilePath = path5.resolve(
4352
4506
  ctx.reactRouterConfig.appDirectory,
4353
4507
  route.file
4354
4508
  );
@@ -4371,8 +4525,9 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4371
4525
  ""
4372
4526
  ) : null;
4373
4527
  let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
4374
- return path6.posix.join(
4375
- (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : viteUserConfig?.build?.assetsDir) ?? "assets",
4528
+ let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
4529
+ return path5.posix.join(
4530
+ assetsDir,
4376
4531
  `[name]${routeChunkSuffix}-[hash].js`
4377
4532
  );
4378
4533
  }
@@ -4407,9 +4562,6 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4407
4562
  }
4408
4563
  });
4409
4564
  }
4410
- if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi && viteCommand === "serve") {
4411
- environmentOptionsResolvers[CSS_DEV_HELPER_ENVIRONMENT_NAME] = () => ({});
4412
- }
4413
4565
  return environmentOptionsResolvers;
4414
4566
  }
4415
4567
  function resolveEnvironmentsOptions(environmentResolvers, resolverOptions) {