@react-router/dev 0.0.0-experimental-ab0e85b04 → 0.0.0-experimental-e56aa53bc

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