@react-router/dev 0.0.0-experimental-e988dc602 → 0.0.0-experimental-d050831b5

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-e988dc602
2
+ * @react-router/dev v0.0.0-experimental-d050831b5
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"));
@@ -57,12 +57,12 @@ var import_pick3 = __toESM(require("lodash/pick"));
57
57
  var import_jsesc = __toESM(require("jsesc"));
58
58
  var import_picocolors3 = __toESM(require("picocolors"));
59
59
  var import_kebabCase = __toESM(require("lodash/kebabCase"));
60
+ var import_tinyglobby = require("tinyglobby");
60
61
 
61
62
  // typegen/index.ts
62
- var import_node_fs2 = __toESM(require("fs"));
63
- var import_dedent2 = __toESM(require("dedent"));
63
+ var import_promises = __toESM(require("fs/promises"));
64
64
  var Path4 = __toESM(require("pathe"));
65
- var import_picocolors2 = __toESM(require("picocolors"));
65
+ var import_picocolors2 = require("picocolors");
66
66
 
67
67
  // config/config.ts
68
68
  var import_node_fs = __toESM(require("fs"));
@@ -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
- basename: basename2,
417
+ basename: basename3,
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,
@@ -481,12 +529,13 @@ async function resolveConfig({
481
529
  };
482
530
  let reactRouterConfig = deepFreeze({
483
531
  appDirectory,
484
- basename: basename2,
532
+ basename: basename3,
485
533
  buildDirectory,
486
534
  buildEnd,
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 dirname4 = import_pathe3.default.dirname(path6);
596
+ return !dirname4.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
+ dirname4 !== 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,17 +729,85 @@ 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"];
632
- 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);
739
+ function isEntryFile(entryBasename, filename2) {
740
+ return entryExts.some((ext) => filename2 === `${entryBasename}${ext}`);
741
+ }
742
+ function findEntry(dir, basename3, 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, basename3 + 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;
637
782
  }
638
783
  }
639
- return void 0;
784
+ return false;
640
785
  }
641
786
 
787
+ // typegen/context.ts
788
+ async function createContext2({
789
+ rootDirectory,
790
+ watch: watch2,
791
+ mode
792
+ }) {
793
+ const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
794
+ const configResult = await configLoader.getConfig();
795
+ if (!configResult.ok) {
796
+ throw new Error(configResult.error);
797
+ }
798
+ const config = configResult.value;
799
+ return {
800
+ configLoader,
801
+ rootDirectory,
802
+ config
803
+ };
804
+ }
805
+
806
+ // typegen/generate.ts
807
+ var import_dedent = __toESM(require("dedent"));
808
+ var Path3 = __toESM(require("pathe"));
809
+ var Pathe = __toESM(require("pathe/utils"));
810
+
642
811
  // vite/babel.ts
643
812
  var babel_exports = {};
644
813
  __export(babel_exports, {
@@ -652,26 +821,6 @@ var t = __toESM(require("@babel/types"));
652
821
  var traverse = require("@babel/traverse").default;
653
822
  var generate = require("@babel/generator").default;
654
823
 
655
- // typegen/generate.ts
656
- var import_dedent = __toESM(require("dedent"));
657
- var Path3 = __toESM(require("pathe"));
658
- var Pathe2 = __toESM(require("pathe/utils"));
659
-
660
- // typegen/paths.ts
661
- var Path2 = __toESM(require("pathe"));
662
- var Pathe = __toESM(require("pathe/utils"));
663
- function getTypesDir(ctx) {
664
- return Path2.join(ctx.rootDirectory, ".react-router/types");
665
- }
666
- function getTypesPath(ctx, route) {
667
- return Path2.join(
668
- getTypesDir(ctx),
669
- Path2.relative(ctx.rootDirectory, ctx.config.appDirectory),
670
- Path2.dirname(route.file),
671
- "+types/" + Pathe.filename(route.file) + ".ts"
672
- );
673
- }
674
-
675
824
  // typegen/params.ts
676
825
  function parse2(fullpath2) {
677
826
  const result = {};
@@ -702,194 +851,330 @@ function lineage(routes, route) {
702
851
  }
703
852
  function fullpath(lineage2) {
704
853
  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("/");
854
+ return "/" + lineage2.map((route) => route.path?.replace(/^\//, "")?.replace(/\/$/, "")).filter((path6) => path6 !== void 0 && path6 !== "").join("/");
706
855
  }
707
856
 
708
857
  // typegen/generate.ts
709
- function generate2(ctx, route) {
710
- const lineage2 = lineage(ctx.config.routes, route);
711
- const fullpath2 = fullpath(lineage2);
712
- const typesPath = getTypesPath(ctx, route);
713
- const parents = lineage2.slice(0, -1);
714
- const parentTypeImports = parents.map((parent, i) => {
715
- const rel = Path3.relative(
716
- Path3.dirname(typesPath),
717
- getTypesPath(ctx, parent)
718
- );
719
- const indent = i === 0 ? "" : " ".repeat(2);
720
- let source = noExtension(rel);
721
- if (!source.startsWith("../")) source = "./" + source;
722
- return `${indent}import type { Info as Parent${i} } from "${source}.js"`;
723
- }).join("\n");
724
- return import_dedent.default`
725
- // React Router generated types for route:
726
- // ${route.file}
727
-
728
- import type * as T from "react-router/route-module"
729
-
730
- ${parentTypeImports}
731
-
732
- type Module = typeof import("../${Pathe2.filename(route.file)}.js")
733
-
734
- export type Info = {
735
- parents: [${parents.map((_, i) => `Parent${i}`).join(", ")}],
736
- id: "${route.id}"
737
- file: "${route.file}"
738
- path: "${route.path}"
739
- params: {${formatParamProperties(
740
- fullpath2
741
- )}} & { [key: string]: string | undefined }
742
- module: Module
743
- loaderData: T.CreateLoaderData<Module>
744
- actionData: T.CreateActionData<Module>
745
- }
746
-
747
- export namespace Route {
748
- export type LinkDescriptors = T.LinkDescriptors
749
- export type LinksFunction = () => LinkDescriptors
750
-
751
- export type MetaArgs = T.CreateMetaArgs<Info>
752
- export type MetaDescriptors = T.MetaDescriptors
753
- export type MetaFunction = (args: MetaArgs) => MetaDescriptors
754
-
755
- export type HeadersArgs = T.HeadersArgs
756
- export type HeadersFunction = (args: HeadersArgs) => Headers | HeadersInit
858
+ function typesDirectory(ctx) {
859
+ return Path3.join(ctx.rootDirectory, ".react-router/types");
860
+ }
861
+ function generateFuture(ctx) {
862
+ const filename2 = Path3.join(typesDirectory(ctx), "+future.ts");
863
+ const content = import_dedent.default`
864
+ // Generated by React Router
757
865
 
758
- export type unstable_MiddlewareFunction = T.CreateServerMiddlewareFunction<Info>
759
- export type unstable_ClientMiddlewareFunction = T.CreateClientMiddlewareFunction<Info>
760
- export type LoaderArgs = T.CreateServerLoaderArgs<Info>
761
- export type ClientLoaderArgs = T.CreateClientLoaderArgs<Info>
762
- export type ActionArgs = T.CreateServerActionArgs<Info>
763
- export type ClientActionArgs = T.CreateClientActionArgs<Info>
866
+ import "react-router";
764
867
 
765
- export type HydrateFallbackProps = T.CreateHydrateFallbackProps<Info>
766
- export type ComponentProps = T.CreateComponentProps<Info>
767
- export type ErrorBoundaryProps = T.CreateErrorBoundaryProps<Info>
868
+ declare module "react-router" {
869
+ interface Future {
870
+ unstable_middleware: ${ctx.config.future.unstable_middleware}
871
+ }
768
872
  }
769
873
  `;
874
+ return { filename: filename2, content };
770
875
  }
771
- var noExtension = (path7) => Path3.join(Path3.dirname(path7), Pathe2.filename(path7));
772
- function formatParamProperties(fullpath2) {
773
- const params = parse2(fullpath2);
774
- const properties = Object.entries(params).map(
775
- ([name, isRequired]) => isRequired ? `"${name}": string` : `"${name}"?: string`
776
- );
777
- return properties.join("; ");
778
- }
876
+ function generateServerBuild(ctx) {
877
+ const filename2 = Path3.join(typesDirectory(ctx), "+server-build.d.ts");
878
+ const content = import_dedent.default`
879
+ // Generated by React Router
779
880
 
780
- // typegen/index.ts
781
- async function watch(rootDirectory, { logger } = {}) {
782
- const ctx = await createContext2({ rootDirectory, watch: true });
783
- await writeAll(ctx);
784
- 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
- });
881
+ declare module "virtual:react-router/server-build" {
882
+ import { ServerBuild } from "react-router";
883
+ export const assets: ServerBuild["assets"];
884
+ export const assetsBuildDirectory: ServerBuild["assetsBuildDirectory"];
885
+ export const basename: ServerBuild["basename"];
886
+ export const entry: ServerBuild["entry"];
887
+ export const future: ServerBuild["future"];
888
+ export const isSpaMode: ServerBuild["isSpaMode"];
889
+ export const prerender: ServerBuild["prerender"];
890
+ export const publicPath: ServerBuild["publicPath"];
891
+ export const routeDiscovery: ServerBuild["routeDiscovery"];
892
+ export const routes: ServerBuild["routes"];
893
+ export const ssr: ServerBuild["ssr"];
894
+ export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
797
895
  }
798
- });
799
- return {
800
- close: async () => await ctx.configLoader.close()
801
- };
802
- }
803
- async function createContext2({
804
- rootDirectory,
805
- watch: watch2
806
- }) {
807
- const configLoader = await createConfigLoader({ rootDirectory, watch: watch2 });
808
- const configResult = await configLoader.getConfig();
809
- if (!configResult.ok) {
810
- throw new Error(configResult.error);
811
- }
812
- const config = configResult.value;
813
- return {
814
- configLoader,
815
- rootDirectory,
816
- config
817
- };
896
+ `;
897
+ return { filename: filename2, content };
818
898
  }
819
- async function writeAll(ctx) {
820
- const typegenDir = getTypesDir(ctx);
821
- import_node_fs2.default.rmSync(typegenDir, { recursive: true, force: true });
899
+ var { t: t2 } = babel_exports;
900
+ function generatePages(ctx) {
901
+ const filename2 = Path3.join(typesDirectory(ctx), "+pages.ts");
902
+ const fullpaths = /* @__PURE__ */ new Set();
822
903
  Object.values(ctx.config.routes).forEach((route) => {
823
- const typesPath = getTypesPath(ctx, route);
824
- const content = generate2(ctx, route);
825
- import_node_fs2.default.mkdirSync(Path4.dirname(typesPath), { recursive: true });
826
- import_node_fs2.default.writeFileSync(typesPath, content);
904
+ if (route.id !== "root" && !route.path) return;
905
+ const lineage2 = lineage(ctx.config.routes, route);
906
+ const fullpath2 = fullpath(lineage2);
907
+ fullpaths.add(fullpath2);
827
908
  });
828
- const registerPath = Path4.join(typegenDir, "+register.ts");
829
- import_node_fs2.default.writeFileSync(registerPath, register(ctx));
830
- const virtualPath = Path4.join(typegenDir, "+virtual.d.ts");
831
- import_node_fs2.default.writeFileSync(virtualPath, virtual);
832
- }
833
- function register(ctx) {
834
- const register2 = import_dedent2.default`
835
- import "react-router";
909
+ const pagesType = t2.tsTypeAliasDeclaration(
910
+ t2.identifier("Pages"),
911
+ null,
912
+ t2.tsTypeLiteral(
913
+ Array.from(fullpaths).map((fullpath2) => {
914
+ return t2.tsPropertySignature(
915
+ t2.stringLiteral(fullpath2),
916
+ t2.tsTypeAnnotation(
917
+ t2.tsTypeLiteral([
918
+ t2.tsPropertySignature(
919
+ t2.identifier("params"),
920
+ t2.tsTypeAnnotation(paramsType(fullpath2))
921
+ )
922
+ ])
923
+ )
924
+ );
925
+ })
926
+ )
927
+ );
928
+ const content = import_dedent.default`
929
+ // Generated by React Router
836
930
 
837
- declare module "react-router" {
838
- interface Register {
839
- params: Params;
931
+ import "react-router"
932
+
933
+ declare module "react-router" {
934
+ interface Register {
935
+ pages: Pages
936
+ }
840
937
  }
841
- }
842
- `;
843
- 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
- );
847
- const typeParams = t2.tsTypeAliasDeclaration(
848
- t2.identifier("Params"),
938
+ ` + "\n\n" + generate(pagesType).code;
939
+ return { filename: filename2, content };
940
+ }
941
+ function generateRoutes(ctx) {
942
+ const filename2 = Path3.join(typesDirectory(ctx), "+routes-pre.ts");
943
+ const routesType = t2.tsTypeAliasDeclaration(
944
+ t2.identifier("routesPre"),
849
945
  null,
850
946
  t2.tsTypeLiteral(
851
947
  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);
856
- const params = parse2(fullpath2);
857
948
  return t2.tsPropertySignature(
858
- t2.stringLiteral(fullpath2),
949
+ t2.stringLiteral(route.id),
859
950
  t2.tsTypeAnnotation(
860
- t2.tsTypeLiteral(
861
- Object.entries(params).map(([param, isRequired]) => {
862
- const property = t2.tsPropertySignature(
863
- t2.stringLiteral(param),
864
- t2.tsTypeAnnotation(t2.tsStringKeyword())
865
- );
866
- property.optional = !isRequired;
867
- return property;
868
- })
869
- )
951
+ t2.tsTypeLiteral([
952
+ t2.tsPropertySignature(
953
+ t2.identifier("parentId"),
954
+ t2.tsTypeAnnotation(
955
+ route.parentId ? t2.tsLiteralType(t2.stringLiteral(route.parentId)) : t2.tsUndefinedKeyword()
956
+ )
957
+ ),
958
+ t2.tsPropertySignature(
959
+ t2.identifier("path"),
960
+ t2.tsTypeAnnotation(
961
+ route.path ? t2.tsLiteralType(t2.stringLiteral(route.path)) : t2.tsUndefinedKeyword()
962
+ )
963
+ ),
964
+ t2.tsPropertySignature(
965
+ t2.identifier("params"),
966
+ t2.tsTypeAnnotation(paramsType(route.path ?? ""))
967
+ ),
968
+ t2.tsPropertySignature(
969
+ t2.identifier("index"),
970
+ t2.tsTypeAnnotation(
971
+ t2.tsLiteralType(t2.booleanLiteral(route.index ?? false))
972
+ )
973
+ ),
974
+ t2.tsPropertySignature(
975
+ t2.identifier("file"),
976
+ t2.tsTypeAnnotation(t2.tsLiteralType(t2.stringLiteral(route.file)))
977
+ )
978
+ ])
870
979
  )
871
980
  );
872
- }).filter((x) => x !== void 0)
981
+ })
873
982
  )
874
983
  );
875
- return [register2, generate(typeParams).code].join("\n\n");
984
+ const content = import_dedent.default`
985
+ // Generated by React Router
986
+
987
+ import "react-router"
988
+
989
+ declare module "react-router" {
990
+ interface Register {
991
+ routesPre: routesPre
992
+ }
993
+ }
994
+ ` + "\n\n" + generate(routesType).code;
995
+ return { filename: filename2, content };
996
+ }
997
+ function generateRouteModuleAnnotations(ctx) {
998
+ return Object.values(ctx.config.routes).filter((route) => isRouteInAppDirectory(ctx, route)).map((route) => {
999
+ const filename2 = getRouteModuleAnnotationsFilepath(ctx, route);
1000
+ const parents = getParents(ctx, route);
1001
+ const content = import_dedent.default`
1002
+ // Generated by React Router
1003
+
1004
+ import type {
1005
+ Params,
1006
+ RouteModuleAnnotations,
1007
+ CreateLoaderData,
1008
+ CreateActionData,
1009
+ } from "react-router/internal";
1010
+
1011
+ ${parents.map((parent) => parent.import).join("\n" + " ".repeat(3))}
1012
+ type Parents = [${parents.map((parent) => parent.name).join(", ")}]
1013
+
1014
+ type Id = "${route.id}"
1015
+ type Module = typeof import("../${Pathe.filename(route.file)}.js")
1016
+
1017
+ export type unstable_Props = {
1018
+ params: Params[Id]
1019
+ loaderData: CreateLoaderData<Module>
1020
+ actionData: CreateActionData<Module>
1021
+ }
1022
+
1023
+ type Annotations = RouteModuleAnnotations<unstable_Props & {
1024
+ parents: Parents,
1025
+ module: Module,
1026
+ }>;
1027
+
1028
+ export namespace Route {
1029
+ // links
1030
+ export type LinkDescriptors = Annotations["LinkDescriptors"];
1031
+ export type LinksFunction = Annotations["LinksFunction"];
1032
+
1033
+ // meta
1034
+ export type MetaArgs = Annotations["MetaArgs"];
1035
+ export type MetaDescriptors = Annotations["MetaDescriptors"];
1036
+ export type MetaFunction = Annotations["MetaFunction"];
1037
+
1038
+ // headers
1039
+ export type HeadersArgs = Annotations["HeadersArgs"];
1040
+ export type HeadersFunction = Annotations["HeadersFunction"];
1041
+
1042
+ // unstable_middleware
1043
+ export type unstable_MiddlewareFunction = Annotations["unstable_MiddlewareFunction"];
1044
+
1045
+ // unstable_clientMiddleware
1046
+ export type unstable_ClientMiddlewareFunction = Annotations["unstable_ClientMiddlewareFunction"];
1047
+
1048
+ // loader
1049
+ export type LoaderArgs = Annotations["LoaderArgs"];
1050
+
1051
+ // clientLoader
1052
+ export type ClientLoaderArgs = Annotations["ClientLoaderArgs"];
1053
+
1054
+ // action
1055
+ export type ActionArgs = Annotations["ActionArgs"];
1056
+
1057
+ // clientAction
1058
+ export type ClientActionArgs = Annotations["ClientActionArgs"];
1059
+
1060
+ // HydrateFallback
1061
+ export type HydrateFallbackProps = Annotations["HydrateFallbackProps"];
1062
+
1063
+ // Component
1064
+ export type ComponentProps = Annotations["ComponentProps"];
1065
+
1066
+ // ErrorBoundary
1067
+ export type ErrorBoundaryProps = Annotations["ErrorBoundaryProps"];
1068
+ }
1069
+ `;
1070
+ return { filename: filename2, content };
1071
+ });
1072
+ }
1073
+ function isRouteInAppDirectory(ctx, route) {
1074
+ const absoluteRoutePath = Path3.resolve(ctx.config.appDirectory, route.file);
1075
+ return absoluteRoutePath.startsWith(ctx.config.appDirectory);
1076
+ }
1077
+ function getRouteModuleAnnotationsFilepath(ctx, route) {
1078
+ return Path3.join(
1079
+ typesDirectory(ctx),
1080
+ Path3.relative(ctx.rootDirectory, ctx.config.appDirectory),
1081
+ Path3.dirname(route.file),
1082
+ "+types/" + Pathe.filename(route.file) + ".ts"
1083
+ );
1084
+ }
1085
+ function getParents(ctx, route) {
1086
+ const typesPath = getRouteModuleAnnotationsFilepath(ctx, route);
1087
+ const lineage2 = lineage(ctx.config.routes, route);
1088
+ const parents = lineage2.slice(0, -1);
1089
+ return parents.map((parent, i) => {
1090
+ const rel = Path3.relative(
1091
+ Path3.dirname(typesPath),
1092
+ getRouteModuleAnnotationsFilepath(ctx, parent)
1093
+ );
1094
+ let source = noExtension(rel);
1095
+ if (!source.startsWith("../")) source = "./" + source;
1096
+ const name = `Parent${i}`;
1097
+ return {
1098
+ name,
1099
+ import: `import type { unstable_Props as ${name} } from "${source}.js"`
1100
+ };
1101
+ });
1102
+ }
1103
+ function noExtension(path6) {
1104
+ return Path3.join(Path3.dirname(path6), Pathe.filename(path6));
1105
+ }
1106
+ function paramsType(path6) {
1107
+ const params = parse2(path6);
1108
+ return t2.tsTypeLiteral(
1109
+ Object.entries(params).map(([param, isRequired]) => {
1110
+ const property = t2.tsPropertySignature(
1111
+ t2.stringLiteral(param),
1112
+ t2.tsTypeAnnotation(t2.tsStringKeyword())
1113
+ );
1114
+ property.optional = !isRequired;
1115
+ return property;
1116
+ })
1117
+ );
1118
+ }
1119
+
1120
+ // typegen/index.ts
1121
+ async function clearRouteModuleAnnotations(ctx) {
1122
+ await import_promises.default.rm(
1123
+ Path4.join(typesDirectory(ctx), Path4.basename(ctx.config.appDirectory)),
1124
+ { recursive: true, force: true }
1125
+ );
1126
+ }
1127
+ async function write(...files) {
1128
+ return Promise.all(
1129
+ files.map(async ({ filename: filename2, content }) => {
1130
+ await import_promises.default.mkdir(Path4.dirname(filename2), { recursive: true });
1131
+ await import_promises.default.writeFile(filename2, content);
1132
+ })
1133
+ );
1134
+ }
1135
+ async function watch(rootDirectory, { mode, logger }) {
1136
+ const ctx = await createContext2({ rootDirectory, mode, watch: true });
1137
+ await import_promises.default.rm(typesDirectory(ctx), { recursive: true, force: true });
1138
+ await write(
1139
+ generateFuture(ctx),
1140
+ generatePages(ctx),
1141
+ generateRoutes(ctx),
1142
+ generateServerBuild(ctx),
1143
+ ...generateRouteModuleAnnotations(ctx)
1144
+ );
1145
+ logger?.info((0, import_picocolors2.green)("generated types"), { timestamp: true, clear: true });
1146
+ ctx.configLoader.onChange(
1147
+ async ({ result, configChanged, routeConfigChanged }) => {
1148
+ if (!result.ok) {
1149
+ logger?.error((0, import_picocolors2.red)(result.error), { timestamp: true, clear: true });
1150
+ return;
1151
+ }
1152
+ ctx.config = result.value;
1153
+ if (configChanged) {
1154
+ await write(generateFuture(ctx));
1155
+ logger?.info((0, import_picocolors2.green)("regenerated types"), {
1156
+ timestamp: true,
1157
+ clear: true
1158
+ });
1159
+ }
1160
+ if (routeConfigChanged) {
1161
+ await clearRouteModuleAnnotations(ctx);
1162
+ await write(
1163
+ generatePages(ctx),
1164
+ generateRoutes(ctx),
1165
+ ...generateRouteModuleAnnotations(ctx)
1166
+ );
1167
+ logger?.info((0, import_picocolors2.green)("regenerated types"), {
1168
+ timestamp: true,
1169
+ clear: true
1170
+ });
1171
+ }
1172
+ }
1173
+ );
1174
+ return {
1175
+ close: async () => await ctx.configLoader.close()
1176
+ };
876
1177
  }
877
- var virtual = import_dedent2.default`
878
- declare module "virtual:react-router/server-build" {
879
- import { ServerBuild } from "react-router";
880
- export const assets: ServerBuild["assets"];
881
- export const assetsBuildDirectory: ServerBuild["assetsBuildDirectory"];
882
- export const basename: ServerBuild["basename"];
883
- export const entry: ServerBuild["entry"];
884
- export const future: ServerBuild["future"];
885
- export const isSpaMode: ServerBuild["isSpaMode"];
886
- export const prerender: ServerBuild["prerender"];
887
- export const publicPath: ServerBuild["publicPath"];
888
- export const routes: ServerBuild["routes"];
889
- export const ssr: ServerBuild["ssr"];
890
- export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
891
- }
892
- `;
893
1178
 
894
1179
  // vite/node-adapter.ts
895
1180
  var import_node_events = require("events");
@@ -945,7 +1230,9 @@ function fromNodeRequest(nodeReq, nodeRes) {
945
1230
  }
946
1231
  async function toNodeRequest(res, nodeRes) {
947
1232
  nodeRes.statusCode = res.status;
948
- nodeRes.statusMessage = res.statusText;
1233
+ if (!nodeRes.req || nodeRes.req.httpVersionMajor < 2) {
1234
+ nodeRes.statusMessage = res.statusText;
1235
+ }
949
1236
  let cookiesStrings = [];
950
1237
  for (let [name, value] of res.headers) {
951
1238
  if (name === "set-cookie") {
@@ -966,17 +1253,17 @@ async function toNodeRequest(res, nodeRes) {
966
1253
  }
967
1254
 
968
1255
  // vite/styles.ts
969
- var path5 = __toESM(require("path"));
1256
+ var path4 = __toESM(require("path"));
970
1257
  var import_react_router = require("react-router");
971
1258
 
972
1259
  // vite/resolve-file-url.ts
973
- var path4 = __toESM(require("path"));
1260
+ var path3 = __toESM(require("path"));
974
1261
  var resolveFileUrl = ({ rootDirectory }, filePath) => {
975
1262
  let vite2 = getVite();
976
- let relativePath = path4.relative(rootDirectory, filePath);
977
- let isWithinRoot = !relativePath.startsWith("..") && !path4.isAbsolute(relativePath);
1263
+ let relativePath = path3.relative(rootDirectory, filePath);
1264
+ let isWithinRoot = !relativePath.startsWith("..") && !path3.isAbsolute(relativePath);
978
1265
  if (!isWithinRoot) {
979
- return path4.posix.join("/@fs", vite2.normalizePath(filePath));
1266
+ return path3.posix.join("/@fs", vite2.normalizePath(filePath));
980
1267
  }
981
1268
  return "/" + vite2.normalizePath(relativePath);
982
1269
  };
@@ -1013,7 +1300,7 @@ var getStylesForFiles = async ({
1013
1300
  let deps = /* @__PURE__ */ new Set();
1014
1301
  try {
1015
1302
  for (let file of files) {
1016
- let normalizedPath = path5.resolve(rootDirectory, file).replace(/\\/g, "/");
1303
+ let normalizedPath = path4.resolve(rootDirectory, file).replace(/\\/g, "/");
1017
1304
  let node = await viteDevServer.moduleGraph.getModuleById(normalizedPath);
1018
1305
  if (!node) {
1019
1306
  try {
@@ -1114,9 +1401,9 @@ var getStylesForPathname = async ({
1114
1401
  return void 0;
1115
1402
  }
1116
1403
  let routesWithChildren = createRoutesWithChildren(reactRouterConfig.routes);
1117
- let appPath = path5.relative(process.cwd(), reactRouterConfig.appDirectory);
1404
+ let appPath = path4.relative(process.cwd(), reactRouterConfig.appDirectory);
1118
1405
  let documentRouteFiles = (0, import_react_router.matchRoutes)(routesWithChildren, pathname, reactRouterConfig.basename)?.map(
1119
- (match) => path5.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1406
+ (match) => path4.resolve(appPath, reactRouterConfig.routes[match.route.id].file)
1120
1407
  ) ?? [];
1121
1408
  let styles = await getStylesForFiles({
1122
1409
  viteDevServer,
@@ -1124,13 +1411,27 @@ var getStylesForPathname = async ({
1124
1411
  loadCssContents,
1125
1412
  files: [
1126
1413
  // Always include the client entry file when crawling the module graph for CSS
1127
- path5.relative(rootDirectory, entryClientFilePath),
1414
+ path4.relative(rootDirectory, entryClientFilePath),
1128
1415
  // Then include any styles from the matched routes
1129
1416
  ...documentRouteFiles
1130
1417
  ]
1131
1418
  });
1132
1419
  return styles;
1133
1420
  };
1421
+ var getCssStringFromViteDevModuleCode = (code) => {
1422
+ let cssContent = void 0;
1423
+ const ast = import_parser.parse(code, { sourceType: "module" });
1424
+ traverse(ast, {
1425
+ VariableDeclaration(path6) {
1426
+ const declaration = path6.node.declarations[0];
1427
+ if (declaration?.id?.type === "Identifier" && declaration.id.name === "__vite__css" && declaration.init?.type === "StringLiteral") {
1428
+ cssContent = declaration.init.value;
1429
+ path6.stop();
1430
+ }
1431
+ }
1432
+ });
1433
+ return cssContent;
1434
+ };
1134
1435
 
1135
1436
  // vite/virtual-module.ts
1136
1437
  function create(name) {
@@ -1154,10 +1455,10 @@ var removeExports = (ast, exportsToRemove) => {
1154
1455
  let exportsFiltered = false;
1155
1456
  let markedForRemoval = /* @__PURE__ */ new Set();
1156
1457
  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) => {
1458
+ ExportDeclaration(path6) {
1459
+ if (path6.node.type === "ExportNamedDeclaration") {
1460
+ if (path6.node.specifiers.length) {
1461
+ path6.node.specifiers = path6.node.specifiers.filter((specifier) => {
1161
1462
  if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
1162
1463
  if (exportsToRemove.includes(specifier.exported.name)) {
1163
1464
  exportsFiltered = true;
@@ -1166,12 +1467,12 @@ var removeExports = (ast, exportsToRemove) => {
1166
1467
  }
1167
1468
  return true;
1168
1469
  });
1169
- if (path7.node.specifiers.length === 0) {
1170
- markedForRemoval.add(path7);
1470
+ if (path6.node.specifiers.length === 0) {
1471
+ markedForRemoval.add(path6);
1171
1472
  }
1172
1473
  }
1173
- if (path7.node.declaration?.type === "VariableDeclaration") {
1174
- let declaration = path7.node.declaration;
1474
+ if (path6.node.declaration?.type === "VariableDeclaration") {
1475
+ let declaration = path6.node.declaration;
1175
1476
  declaration.declarations = declaration.declarations.filter(
1176
1477
  (declaration2) => {
1177
1478
  if (declaration2.id.type === "Identifier" && exportsToRemove.includes(declaration2.id.name)) {
@@ -1185,30 +1486,30 @@ var removeExports = (ast, exportsToRemove) => {
1185
1486
  }
1186
1487
  );
1187
1488
  if (declaration.declarations.length === 0) {
1188
- markedForRemoval.add(path7);
1489
+ markedForRemoval.add(path6);
1189
1490
  }
1190
1491
  }
1191
- if (path7.node.declaration?.type === "FunctionDeclaration") {
1192
- let id = path7.node.declaration.id;
1492
+ if (path6.node.declaration?.type === "FunctionDeclaration") {
1493
+ let id = path6.node.declaration.id;
1193
1494
  if (id && exportsToRemove.includes(id.name)) {
1194
- markedForRemoval.add(path7);
1495
+ markedForRemoval.add(path6);
1195
1496
  }
1196
1497
  }
1197
- if (path7.node.declaration?.type === "ClassDeclaration") {
1198
- let id = path7.node.declaration.id;
1498
+ if (path6.node.declaration?.type === "ClassDeclaration") {
1499
+ let id = path6.node.declaration.id;
1199
1500
  if (id && exportsToRemove.includes(id.name)) {
1200
- markedForRemoval.add(path7);
1501
+ markedForRemoval.add(path6);
1201
1502
  }
1202
1503
  }
1203
1504
  }
1204
- if (path7.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1205
- markedForRemoval.add(path7);
1505
+ if (path6.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
1506
+ markedForRemoval.add(path6);
1206
1507
  }
1207
1508
  }
1208
1509
  });
1209
1510
  if (markedForRemoval.size > 0 || exportsFiltered) {
1210
- for (let path7 of markedForRemoval) {
1211
- path7.remove();
1511
+ for (let path6 of markedForRemoval) {
1512
+ path6.remove();
1212
1513
  }
1213
1514
  (0, import_babel_dead_code_elimination.deadCodeElimination)(ast, previouslyReferencedIdentifiers);
1214
1515
  }
@@ -1279,28 +1580,28 @@ function codeToAst(code, cache, cacheKey) {
1279
1580
  )
1280
1581
  );
1281
1582
  }
1282
- function assertNodePath(path7) {
1583
+ function assertNodePath(path6) {
1283
1584
  invariant(
1284
- path7 && !Array.isArray(path7),
1285
- `Expected a Path, but got ${Array.isArray(path7) ? "an array" : path7}`
1585
+ path6 && !Array.isArray(path6),
1586
+ `Expected a Path, but got ${Array.isArray(path6) ? "an array" : path6}`
1286
1587
  );
1287
1588
  }
1288
- function assertNodePathIsStatement(path7) {
1589
+ function assertNodePathIsStatement(path6) {
1289
1590
  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}`
1591
+ path6 && !Array.isArray(path6) && t.isStatement(path6.node),
1592
+ `Expected a Statement path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1292
1593
  );
1293
1594
  }
1294
- function assertNodePathIsVariableDeclarator(path7) {
1595
+ function assertNodePathIsVariableDeclarator(path6) {
1295
1596
  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}`
1597
+ path6 && !Array.isArray(path6) && t.isVariableDeclarator(path6.node),
1598
+ `Expected an Identifier path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1298
1599
  );
1299
1600
  }
1300
- function assertNodePathIsPattern(path7) {
1601
+ function assertNodePathIsPattern(path6) {
1301
1602
  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}`
1603
+ path6 && !Array.isArray(path6) && t.isPattern(path6.node),
1604
+ `Expected a Pattern path, but got ${Array.isArray(path6) ? "an array" : path6?.node?.type}`
1304
1605
  );
1305
1606
  }
1306
1607
  function getExportDependencies(code, cache, cacheKey) {
@@ -1336,8 +1637,8 @@ function getExportDependencies(code, cache, cacheKey) {
1336
1637
  }
1337
1638
  let isWithinExportDestructuring = Boolean(
1338
1639
  identifier.findParent(
1339
- (path7) => Boolean(
1340
- path7.isPattern() && path7.parentPath?.isVariableDeclarator() && path7.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1640
+ (path6) => Boolean(
1641
+ path6.isPattern() && path6.parentPath?.isVariableDeclarator() && path6.parentPath.parentPath?.parentPath?.isExportNamedDeclaration()
1341
1642
  )
1342
1643
  )
1343
1644
  );
@@ -1415,7 +1716,7 @@ function getExportDependencies(code, cache, cacheKey) {
1415
1716
  for (let specifier of node.specifiers) {
1416
1717
  if (t.isIdentifier(specifier.exported)) {
1417
1718
  let name = specifier.exported.name;
1418
- let specifierPath = exportPath.get("specifiers").find((path7) => path7.node === specifier);
1719
+ let specifierPath = exportPath.get("specifiers").find((path6) => path6.node === specifier);
1419
1720
  invariant(
1420
1721
  specifierPath,
1421
1722
  `Expected to find specifier path for ${name}`
@@ -1432,22 +1733,22 @@ function getExportDependencies(code, cache, cacheKey) {
1432
1733
  }
1433
1734
  );
1434
1735
  }
1435
- function getDependentIdentifiersForPath(path7, state) {
1736
+ function getDependentIdentifiersForPath(path6, state) {
1436
1737
  let { visited, identifiers } = state ?? {
1437
1738
  visited: /* @__PURE__ */ new Set(),
1438
1739
  identifiers: /* @__PURE__ */ new Set()
1439
1740
  };
1440
- if (visited.has(path7)) {
1741
+ if (visited.has(path6)) {
1441
1742
  return identifiers;
1442
1743
  }
1443
- visited.add(path7);
1444
- path7.traverse({
1445
- Identifier(path8) {
1446
- if (identifiers.has(path8)) {
1744
+ visited.add(path6);
1745
+ path6.traverse({
1746
+ Identifier(path7) {
1747
+ if (identifiers.has(path7)) {
1447
1748
  return;
1448
1749
  }
1449
- identifiers.add(path8);
1450
- let binding = path8.scope.getBinding(path8.node.name);
1750
+ identifiers.add(path7);
1751
+ let binding = path7.scope.getBinding(path7.node.name);
1451
1752
  if (!binding) {
1452
1753
  return;
1453
1754
  }
@@ -1469,7 +1770,7 @@ function getDependentIdentifiersForPath(path7, state) {
1469
1770
  }
1470
1771
  }
1471
1772
  });
1472
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1773
+ let topLevelStatement = getTopLevelStatementPathForPath(path6);
1473
1774
  let withinImportStatement = topLevelStatement.isImportDeclaration();
1474
1775
  let withinExportStatement = topLevelStatement.isExportDeclaration();
1475
1776
  if (!withinImportStatement && !withinExportStatement) {
@@ -1478,9 +1779,9 @@ function getDependentIdentifiersForPath(path7, state) {
1478
1779
  identifiers
1479
1780
  });
1480
1781
  }
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());
1782
+ if (withinExportStatement && path6.isIdentifier() && (t.isPattern(path6.parentPath.node) || // [foo]
1783
+ t.isPattern(path6.parentPath.parentPath?.node))) {
1784
+ let variableDeclarator = path6.findParent((p) => p.isVariableDeclarator());
1484
1785
  assertNodePath(variableDeclarator);
1485
1786
  getDependentIdentifiersForPath(variableDeclarator, {
1486
1787
  visited,
@@ -1489,16 +1790,16 @@ function getDependentIdentifiersForPath(path7, state) {
1489
1790
  }
1490
1791
  return identifiers;
1491
1792
  }
1492
- function getTopLevelStatementPathForPath(path7) {
1493
- let ancestry = path7.getAncestry();
1793
+ function getTopLevelStatementPathForPath(path6) {
1794
+ let ancestry = path6.getAncestry();
1494
1795
  let topLevelStatement = ancestry[ancestry.length - 2];
1495
1796
  assertNodePathIsStatement(topLevelStatement);
1496
1797
  return topLevelStatement;
1497
1798
  }
1498
1799
  function getTopLevelStatementsForPaths(paths) {
1499
1800
  let topLevelStatements = /* @__PURE__ */ new Set();
1500
- for (let path7 of paths) {
1501
- let topLevelStatement = getTopLevelStatementPathForPath(path7);
1801
+ for (let path6 of paths) {
1802
+ let topLevelStatement = getTopLevelStatementPathForPath(path6);
1502
1803
  topLevelStatements.add(topLevelStatement.node);
1503
1804
  }
1504
1805
  return topLevelStatements;
@@ -1861,7 +2162,7 @@ function getRouteChunkNameFromModuleId(id) {
1861
2162
  }
1862
2163
 
1863
2164
  // vite/with-props.ts
1864
- var import_dedent3 = __toESM(require("dedent"));
2165
+ var import_dedent2 = __toESM(require("dedent"));
1865
2166
  var vmod = create("with-props");
1866
2167
  var NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
1867
2168
  var plugin = {
@@ -1872,7 +2173,7 @@ var plugin = {
1872
2173
  },
1873
2174
  async load(id) {
1874
2175
  if (id !== vmod.resolvedId) return;
1875
- return import_dedent3.default`
2176
+ return import_dedent2.default`
1876
2177
  import { createElement as h } from "react";
1877
2178
  import { useActionData, useLoaderData, useMatches, useParams, useRouteError } from "react-router";
1878
2179
 
@@ -1915,24 +2216,24 @@ var plugin = {
1915
2216
  };
1916
2217
  var transform = (ast) => {
1917
2218
  const hocs = [];
1918
- function getHocUid(path7, hocName) {
1919
- const uid = path7.scope.generateUidIdentifier(hocName);
2219
+ function getHocUid(path6, hocName) {
2220
+ const uid = path6.scope.generateUidIdentifier(hocName);
1920
2221
  hocs.push([hocName, uid]);
1921
2222
  return uid;
1922
2223
  }
1923
2224
  traverse(ast, {
1924
- ExportDeclaration(path7) {
1925
- if (path7.isExportDefaultDeclaration()) {
1926
- const declaration = path7.get("declaration");
2225
+ ExportDeclaration(path6) {
2226
+ if (path6.isExportDefaultDeclaration()) {
2227
+ const declaration = path6.get("declaration");
1927
2228
  const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : void 0;
1928
2229
  if (expr) {
1929
- const uid = getHocUid(path7, "withComponentProps");
2230
+ const uid = getHocUid(path6, "withComponentProps");
1930
2231
  declaration.replaceWith(t.callExpression(uid, [expr]));
1931
2232
  }
1932
2233
  return;
1933
2234
  }
1934
- if (path7.isExportNamedDeclaration()) {
1935
- const decl = path7.get("declaration");
2235
+ if (path6.isExportNamedDeclaration()) {
2236
+ const decl = path6.get("declaration");
1936
2237
  if (decl.isVariableDeclaration()) {
1937
2238
  decl.get("declarations").forEach((varDeclarator) => {
1938
2239
  const id = varDeclarator.get("id");
@@ -1942,7 +2243,7 @@ var transform = (ast) => {
1942
2243
  if (!id.isIdentifier()) return;
1943
2244
  const { name } = id.node;
1944
2245
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1945
- const uid = getHocUid(path7, `with${name}Props`);
2246
+ const uid = getHocUid(path6, `with${name}Props`);
1946
2247
  init.replaceWith(t.callExpression(uid, [expr]));
1947
2248
  });
1948
2249
  return;
@@ -1952,7 +2253,7 @@ var transform = (ast) => {
1952
2253
  if (!id) return;
1953
2254
  const { name } = id;
1954
2255
  if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
1955
- const uid = getHocUid(path7, `with${name}Props`);
2256
+ const uid = getHocUid(path6, `with${name}Props`);
1956
2257
  decl.replaceWith(
1957
2258
  t.variableDeclaration("const", [
1958
2259
  t.variableDeclarator(
@@ -2017,7 +2318,6 @@ var SSR_BUNDLE_PREFIX = "ssrBundle_";
2017
2318
  function isSsrBundleEnvironmentName(name) {
2018
2319
  return name.startsWith(SSR_BUNDLE_PREFIX);
2019
2320
  }
2020
- var CSS_DEV_HELPER_ENVIRONMENT_NAME = "__react_router_css_dev_helper__";
2021
2321
  function getServerEnvironmentEntries(ctx, record) {
2022
2322
  return Object.entries(record).filter(
2023
2323
  ([name]) => ctx.buildManifest?.serverBundles ? isSsrBundleEnvironmentName(name) : name === "ssr"
@@ -2033,7 +2333,7 @@ var isRouteVirtualModule = (id) => {
2033
2333
  return isRouteEntryModuleId(id) || isRouteChunkModuleId(id);
2034
2334
  };
2035
2335
  var isServerBuildVirtualModuleId = (id) => {
2036
- return id.split("?")[0] === virtual2.serverBuild.id;
2336
+ return id.split("?")[0] === virtual.serverBuild.id;
2037
2337
  };
2038
2338
  var getServerBuildFile = (viteManifest) => {
2039
2339
  let serverBuildIds = Object.keys(viteManifest).filter(
@@ -2053,23 +2353,23 @@ var virtualHmrRuntime = create("hmr-runtime");
2053
2353
  var virtualInjectHmrRuntime = create("inject-hmr-runtime");
2054
2354
  var normalizeRelativeFilePath = (file, reactRouterConfig) => {
2055
2355
  let vite2 = getVite();
2056
- let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
2057
- let relativePath = path6.relative(reactRouterConfig.appDirectory, fullPath);
2356
+ let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2357
+ let relativePath = path5.relative(reactRouterConfig.appDirectory, fullPath);
2058
2358
  return vite2.normalizePath(relativePath).split("?")[0];
2059
2359
  };
2060
2360
  var resolveRelativeRouteFilePath = (route, reactRouterConfig) => {
2061
2361
  let vite2 = getVite();
2062
2362
  let file = route.file;
2063
- let fullPath = path6.resolve(reactRouterConfig.appDirectory, file);
2363
+ let fullPath = path5.resolve(reactRouterConfig.appDirectory, file);
2064
2364
  return vite2.normalizePath(fullPath);
2065
2365
  };
2066
- var virtual2 = {
2366
+ var virtual = {
2067
2367
  serverBuild: create("server-build"),
2068
2368
  serverManifest: create("server-manifest"),
2069
2369
  browserManifest: create("browser-manifest")
2070
2370
  };
2071
2371
  var invalidateVirtualModules = (viteDevServer) => {
2072
- Object.values(virtual2).forEach((vmod2) => {
2372
+ Object.values(virtual).forEach((vmod2) => {
2073
2373
  let mod = viteDevServer.moduleGraph.getModuleById(vmod2.resolvedId);
2074
2374
  if (mod) {
2075
2375
  viteDevServer.moduleGraph.invalidateModule(mod);
@@ -2083,7 +2383,7 @@ var getHash = (source, maxLength) => {
2083
2383
  var resolveChunk = (ctx, viteManifest, absoluteFilePath) => {
2084
2384
  let vite2 = getVite();
2085
2385
  let rootRelativeFilePath = vite2.normalizePath(
2086
- path6.relative(ctx.rootDirectory, absoluteFilePath)
2386
+ path5.relative(ctx.rootDirectory, absoluteFilePath)
2087
2387
  );
2088
2388
  let entryChunk = viteManifest[rootRelativeFilePath];
2089
2389
  if (!entryChunk) {
@@ -2147,7 +2447,7 @@ function dedupe(array2) {
2147
2447
  return [...new Set(array2)];
2148
2448
  }
2149
2449
  var writeFileSafe = async (file, contents) => {
2150
- await fse.ensureDir(path6.dirname(file));
2450
+ await fse.ensureDir(path5.dirname(file));
2151
2451
  await fse.writeFile(file, contents);
2152
2452
  };
2153
2453
  var getExportNames = (code) => {
@@ -2173,7 +2473,7 @@ var compileRouteFile = async (viteChildCompiler, ctx, routeFile, readRouteFile)
2173
2473
  }
2174
2474
  let ssr = true;
2175
2475
  let { pluginContainer, moduleGraph } = viteChildCompiler;
2176
- let routePath = path6.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2476
+ let routePath = path5.resolve(ctx.reactRouterConfig.appDirectory, routeFile);
2177
2477
  let url2 = resolveFileUrl(ctx, routePath);
2178
2478
  let resolveId = async () => {
2179
2479
  let result = await pluginContainer.resolveId(url2, void 0, { ssr });
@@ -2215,12 +2515,12 @@ var resolveEnvironmentBuildContext = ({
2215
2515
  };
2216
2516
  return resolvedBuildContext;
2217
2517
  };
2218
- var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path6.join(
2518
+ var getServerBuildDirectory = (reactRouterConfig, { serverBundleId } = {}) => path5.join(
2219
2519
  reactRouterConfig.buildDirectory,
2220
2520
  "server",
2221
2521
  ...serverBundleId ? [serverBundleId] : []
2222
2522
  );
2223
- var getClientBuildDirectory = (reactRouterConfig) => path6.join(reactRouterConfig.buildDirectory, "client");
2523
+ var getClientBuildDirectory = (reactRouterConfig) => path5.join(reactRouterConfig.buildDirectory, "client");
2224
2524
  var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2225
2525
  if (!ctx.buildManifest) {
2226
2526
  return void 0;
@@ -2238,14 +2538,13 @@ var getServerBundleRouteIds = (vitePluginContext, ctx) => {
2238
2538
  );
2239
2539
  return Object.keys(serverBundleRoutes);
2240
2540
  };
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")),
2541
+ var defaultEntriesDir = path5.resolve(
2542
+ path5.dirname(require.resolve("@react-router/dev/package.json")),
2244
2543
  "dist",
2245
2544
  "config",
2246
2545
  "defaults"
2247
2546
  );
2248
- var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename3) => path6.join(defaultEntriesDir, filename3));
2547
+ var defaultEntries = fse.readdirSync(defaultEntriesDir).map((filename2) => path5.join(defaultEntriesDir, filename2));
2249
2548
  invariant(defaultEntries.length > 0, "No default entries found");
2250
2549
  var reactRouterDevLoadContext = () => void 0;
2251
2550
  var reactRouterVitePlugin = () => {
@@ -2341,10 +2640,10 @@ var reactRouterVitePlugin = () => {
2341
2640
  }
2342
2641
  }).join("\n")}
2343
2642
  export { default as assets } from ${JSON.stringify(
2344
- virtual2.serverManifest.id
2643
+ virtual.serverManifest.id
2345
2644
  )};
2346
2645
  export const assetsBuildDirectory = ${JSON.stringify(
2347
- path6.relative(
2646
+ path5.relative(
2348
2647
  ctx.rootDirectory,
2349
2648
  getClientBuildDirectory(ctx.reactRouterConfig)
2350
2649
  )
@@ -2354,6 +2653,9 @@ var reactRouterVitePlugin = () => {
2354
2653
  export const ssr = ${ctx.reactRouterConfig.ssr};
2355
2654
  export const isSpaMode = ${isSpaMode};
2356
2655
  export const prerender = ${JSON.stringify(prerenderPaths)};
2656
+ export const routeDiscovery = ${JSON.stringify(
2657
+ ctx.reactRouterConfig.routeDiscovery
2658
+ )};
2357
2659
  export const publicPath = ${JSON.stringify(ctx.publicPath)};
2358
2660
  export const entry = { module: entryServer };
2359
2661
  export const routes = {
@@ -2380,7 +2682,7 @@ var reactRouterVitePlugin = () => {
2380
2682
  };
2381
2683
  let loadViteManifest = async (directory) => {
2382
2684
  let manifestContents = await fse.readFile(
2383
- path6.resolve(directory, ".vite", "manifest.json"),
2685
+ path5.resolve(directory, ".vite", "manifest.json"),
2384
2686
  "utf-8"
2385
2687
  );
2386
2688
  return JSON.parse(manifestContents);
@@ -2411,7 +2713,7 @@ var reactRouterVitePlugin = () => {
2411
2713
  let contents;
2412
2714
  try {
2413
2715
  contents = await fse.readFile(
2414
- path6.join(entry.path, entry.name),
2716
+ path5.join(entry.path, entry.name),
2415
2717
  "utf-8"
2416
2718
  );
2417
2719
  } catch (e) {
@@ -2420,7 +2722,7 @@ var reactRouterVitePlugin = () => {
2420
2722
  }
2421
2723
  let hash = (0, import_node_crypto.createHash)("sha384").update(contents).digest().toString("base64");
2422
2724
  let filepath = getVite().normalizePath(
2423
- path6.relative(clientBuildDirectory, path6.join(entry.path, entry.name))
2725
+ path5.relative(clientBuildDirectory, path5.join(entry.path, entry.name))
2424
2726
  );
2425
2727
  sriManifest[`${ctx2.publicPath}${filepath}`] = `sha384-${hash}`;
2426
2728
  }
@@ -2447,7 +2749,7 @@ var reactRouterVitePlugin = () => {
2447
2749
  );
2448
2750
  let enforceSplitRouteModules = ctx.reactRouterConfig.future.unstable_splitRouteModules === "enforce";
2449
2751
  for (let route of Object.values(ctx.reactRouterConfig.routes)) {
2450
- let routeFile = path6.join(ctx.reactRouterConfig.appDirectory, route.file);
2752
+ let routeFile = path5.join(ctx.reactRouterConfig.appDirectory, route.file);
2451
2753
  let sourceExports = routeManifestExports[route.id];
2452
2754
  let isRootRoute = route.parentId === void 0;
2453
2755
  let hasClientAction = sourceExports.includes("clientAction");
@@ -2523,7 +2825,7 @@ var reactRouterVitePlugin = () => {
2523
2825
  }
2524
2826
  let fingerprintedValues = { entry, routes: browserRoutes };
2525
2827
  let version = getHash(JSON.stringify(fingerprintedValues), 8);
2526
- let manifestPath = path6.posix.join(
2828
+ let manifestPath = path5.posix.join(
2527
2829
  viteConfig.build.assetsDir,
2528
2830
  `manifest-${version}.js`
2529
2831
  );
@@ -2535,7 +2837,7 @@ var reactRouterVitePlugin = () => {
2535
2837
  sri: void 0
2536
2838
  };
2537
2839
  await writeFileSafe(
2538
- path6.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2840
+ path5.join(getClientBuildDirectory(ctx.reactRouterConfig), manifestPath),
2539
2841
  `window.__reactRouterManifest=${JSON.stringify(
2540
2842
  reactRouterBrowserManifest
2541
2843
  )};`
@@ -2620,7 +2922,7 @@ var reactRouterVitePlugin = () => {
2620
2922
  let sri = void 0;
2621
2923
  let reactRouterManifestForDev = {
2622
2924
  version: String(Math.random()),
2623
- url: combineURLs(ctx.publicPath, virtual2.browserManifest.url),
2925
+ url: combineURLs(ctx.publicPath, virtual.browserManifest.url),
2624
2926
  hmr: {
2625
2927
  runtime: combineURLs(ctx.publicPath, virtualInjectHmrRuntime.url)
2626
2928
  },
@@ -2645,31 +2947,17 @@ var reactRouterVitePlugin = () => {
2645
2947
  if (dep.file && isCssModulesFile(dep.file)) {
2646
2948
  return cssModulesManifest[dep.file];
2647
2949
  }
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
- }
2950
+ let transformedCssCode = (await viteDevServer.transformRequest(dep.url))?.code;
2668
2951
  invariant(
2669
- typeof cssMod === "object" && cssMod !== null && "default" in cssMod && typeof cssMod.default === "string",
2952
+ transformedCssCode,
2670
2953
  `Failed to load CSS for ${dep.file ?? dep.url}`
2671
2954
  );
2672
- return cssMod.default;
2955
+ let cssString = getCssStringFromViteDevModuleCode(transformedCssCode);
2956
+ invariant(
2957
+ typeof cssString === "string",
2958
+ `Failed to extract CSS for ${dep.file ?? dep.url}`
2959
+ );
2960
+ return cssString;
2673
2961
  };
2674
2962
  return [
2675
2963
  {
@@ -2687,14 +2975,17 @@ var reactRouterVitePlugin = () => {
2687
2975
  prefix: "[react-router]"
2688
2976
  });
2689
2977
  rootDirectory = viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
2978
+ let mode = viteConfigEnv.mode;
2690
2979
  if (viteCommand === "serve") {
2691
2980
  typegenWatcherPromise = watch(rootDirectory, {
2981
+ mode,
2692
2982
  // ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
2693
2983
  logger: vite2.createLogger("warn", { prefix: "[react-router]" })
2694
2984
  });
2695
2985
  }
2696
2986
  reactRouterConfigLoader = await createConfigLoader({
2697
2987
  rootDirectory,
2988
+ mode,
2698
2989
  watch: viteCommand === "serve"
2699
2990
  });
2700
2991
  await updatePluginContext();
@@ -2732,7 +3023,7 @@ var reactRouterVitePlugin = () => {
2732
3023
  ...Object.values(ctx.reactRouterConfig.routes).map(
2733
3024
  (route) => resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
2734
3025
  )
2735
- ] : [],
3026
+ ].map(import_tinyglobby.escapePath) : [],
2736
3027
  include: [
2737
3028
  // Pre-bundle React dependencies to avoid React duplicates,
2738
3029
  // even if React dependencies are not direct dependencies.
@@ -2835,7 +3126,7 @@ var reactRouterVitePlugin = () => {
2835
3126
  ctx.reactRouterConfig
2836
3127
  )
2837
3128
  )
2838
- ],
3129
+ ].map(import_tinyglobby.escapePath),
2839
3130
  include: [
2840
3131
  "react",
2841
3132
  "react/jsx-dev-runtime",
@@ -2952,7 +3243,8 @@ var reactRouterVitePlugin = () => {
2952
3243
  reactRouterConfigLoader.onChange(
2953
3244
  async ({
2954
3245
  result,
2955
- configCodeUpdated,
3246
+ configCodeChanged,
3247
+ routeConfigCodeChanged,
2956
3248
  configChanged,
2957
3249
  routeConfigChanged
2958
3250
  }) => {
@@ -2964,19 +3256,13 @@ var reactRouterVitePlugin = () => {
2964
3256
  });
2965
3257
  return;
2966
3258
  }
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
- }
3259
+ let message = configChanged ? "Config changed." : routeConfigChanged ? "Route config changed." : configCodeChanged ? "Config saved." : routeConfigCodeChanged ? " Route config saved." : "Config saved";
3260
+ logger.info(import_picocolors3.default.green(message), {
3261
+ clear: true,
3262
+ timestamp: true
3263
+ });
2978
3264
  await updatePluginContext();
2979
- if (configChanged) {
3265
+ if (configChanged || routeConfigChanged) {
2980
3266
  invalidateVirtualModules(viteDevServer);
2981
3267
  }
2982
3268
  }
@@ -3017,11 +3303,11 @@ var reactRouterVitePlugin = () => {
3017
3303
  return;
3018
3304
  }
3019
3305
  build = await ssrEnvironment.runner.import(
3020
- virtual2.serverBuild.id
3306
+ virtual.serverBuild.id
3021
3307
  );
3022
3308
  } else {
3023
3309
  build = await viteDevServer.ssrLoadModule(
3024
- virtual2.serverBuild.id
3310
+ virtual.serverBuild.id
3025
3311
  );
3026
3312
  }
3027
3313
  let handler = (0, import_react_router2.createRequestHandler)(build, "development");
@@ -3056,37 +3342,84 @@ var reactRouterVitePlugin = () => {
3056
3342
  let serverBuildDirectory = future.unstable_viteEnvironmentApi ? this.environment.config?.build?.outDir : ctx.environmentBuildContext?.options.build?.outDir ?? getServerBuildDirectory(ctx.reactRouterConfig);
3057
3343
  let ssrViteManifest = await loadViteManifest(serverBuildDirectory);
3058
3344
  let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest);
3345
+ let userSsrEmitAssets = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.ssrEmitAssets ?? viteUserConfig.environments?.ssr?.build?.emitAssets : null) ?? viteUserConfig.build?.ssrEmitAssets ?? false;
3059
3346
  let movedAssetPaths = [];
3347
+ let removedAssetPaths = [];
3348
+ let copiedAssetPaths = [];
3060
3349
  for (let ssrAssetPath of ssrAssetPaths) {
3061
- let src = path6.join(serverBuildDirectory, ssrAssetPath);
3062
- let dest = path6.join(clientBuildDirectory, ssrAssetPath);
3063
- if (!fse.existsSync(dest)) {
3064
- await fse.move(src, dest);
3065
- movedAssetPaths.push(dest);
3066
- } else {
3067
- await fse.remove(src);
3350
+ let src = path5.join(serverBuildDirectory, ssrAssetPath);
3351
+ let dest = path5.join(clientBuildDirectory, ssrAssetPath);
3352
+ if (!userSsrEmitAssets) {
3353
+ if (!fse.existsSync(dest)) {
3354
+ await fse.move(src, dest);
3355
+ movedAssetPaths.push(dest);
3356
+ } else {
3357
+ await fse.remove(src);
3358
+ removedAssetPaths.push(dest);
3359
+ }
3360
+ } else if (!fse.existsSync(dest)) {
3361
+ await fse.copy(src, dest);
3362
+ copiedAssetPaths.push(dest);
3068
3363
  }
3069
3364
  }
3070
- let ssrCssPaths = Object.values(ssrViteManifest).flatMap(
3071
- (chunk) => chunk.css ?? []
3072
- );
3365
+ if (!userSsrEmitAssets) {
3366
+ let ssrCssPaths = Object.values(ssrViteManifest).flatMap(
3367
+ (chunk) => chunk.css ?? []
3368
+ );
3369
+ await Promise.all(
3370
+ ssrCssPaths.map(async (cssPath) => {
3371
+ let src = path5.join(serverBuildDirectory, cssPath);
3372
+ await fse.remove(src);
3373
+ removedAssetPaths.push(src);
3374
+ })
3375
+ );
3376
+ }
3377
+ let cleanedAssetPaths = [...removedAssetPaths, ...movedAssetPaths];
3378
+ let handledAssetPaths = [...cleanedAssetPaths, ...copiedAssetPaths];
3379
+ let cleanedAssetDirs = new Set(cleanedAssetPaths.map(path5.dirname));
3073
3380
  await Promise.all(
3074
- ssrCssPaths.map(
3075
- (cssPath) => fse.remove(path6.join(serverBuildDirectory, cssPath))
3076
- )
3381
+ Array.from(cleanedAssetDirs).map(async (dir) => {
3382
+ try {
3383
+ const files = await fse.readdir(dir);
3384
+ if (files.length === 0) {
3385
+ await fse.remove(dir);
3386
+ }
3387
+ } catch {
3388
+ }
3389
+ })
3077
3390
  );
3078
- if (movedAssetPaths.length) {
3079
- viteConfig.logger.info(
3080
- [
3081
- "",
3082
- `${import_picocolors3.default.green("\u2713")} ${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`,
3083
- ...movedAssetPaths.map(
3084
- (movedAssetPath) => import_picocolors3.default.dim(path6.relative(ctx.rootDirectory, movedAssetPath))
3085
- ),
3086
- ""
3087
- ].join("\n")
3088
- );
3391
+ if (handledAssetPaths.length) {
3392
+ viteConfig.logger.info("");
3393
+ }
3394
+ function logHandledAssets(paths, message) {
3395
+ invariant(viteConfig);
3396
+ if (paths.length) {
3397
+ viteConfig.logger.info(
3398
+ [
3399
+ `${import_picocolors3.default.green("\u2713")} ${message}`,
3400
+ ...paths.map(
3401
+ (assetPath) => import_picocolors3.default.dim(path5.relative(ctx.rootDirectory, assetPath))
3402
+ )
3403
+ ].join("\n")
3404
+ );
3405
+ }
3089
3406
  }
3407
+ logHandledAssets(
3408
+ removedAssetPaths,
3409
+ `${removedAssetPaths.length} asset${removedAssetPaths.length > 1 ? "s" : ""} cleaned from React Router server build.`
3410
+ );
3411
+ logHandledAssets(
3412
+ movedAssetPaths,
3413
+ `${movedAssetPaths.length} asset${movedAssetPaths.length > 1 ? "s" : ""} moved from React Router server build to client assets.`
3414
+ );
3415
+ logHandledAssets(
3416
+ copiedAssetPaths,
3417
+ `${copiedAssetPaths.length} asset${copiedAssetPaths.length > 1 ? "s" : ""} copied from React Router server build to client assets.`
3418
+ );
3419
+ if (handledAssetPaths.length) {
3420
+ viteConfig.logger.info("");
3421
+ }
3422
+ process.env.IS_RR_BUILD_REQUEST = "yes";
3090
3423
  if (isPrerenderingEnabled(ctx.reactRouterConfig)) {
3091
3424
  await handlePrerender(
3092
3425
  viteConfig,
@@ -3159,7 +3492,7 @@ var reactRouterVitePlugin = () => {
3159
3492
  );
3160
3493
  let isMainChunkExport = (name) => !chunkedExports.includes(name);
3161
3494
  let mainChunkReexports = sourceExports.filter(isMainChunkExport).join(", ");
3162
- let chunkBasePath = `./${path6.basename(id)}`;
3495
+ let chunkBasePath = `./${path5.basename(id)}`;
3163
3496
  return [
3164
3497
  `export { ${mainChunkReexports} } from "${getRouteChunkModuleId(
3165
3498
  chunkBasePath,
@@ -3179,7 +3512,7 @@ var reactRouterVitePlugin = () => {
3179
3512
  async transform(code, id, options) {
3180
3513
  if (!id.endsWith(BUILD_CLIENT_ROUTE_QUERY_STRING)) return;
3181
3514
  let routeModuleId = id.replace(BUILD_CLIENT_ROUTE_QUERY_STRING, "");
3182
- let routeFileName = path6.basename(routeModuleId);
3515
+ let routeFileName = path5.basename(routeModuleId);
3183
3516
  let sourceExports = await getRouteModuleExports(
3184
3517
  viteChildCompiler,
3185
3518
  ctx,
@@ -3245,16 +3578,16 @@ var reactRouterVitePlugin = () => {
3245
3578
  name: "react-router:virtual-modules",
3246
3579
  enforce: "pre",
3247
3580
  resolveId(id) {
3248
- const vmod2 = Object.values(virtual2).find((vmod3) => vmod3.id === id);
3581
+ const vmod2 = Object.values(virtual).find((vmod3) => vmod3.id === id);
3249
3582
  if (vmod2) return vmod2.resolvedId;
3250
3583
  },
3251
3584
  async load(id) {
3252
3585
  switch (id) {
3253
- case virtual2.serverBuild.resolvedId: {
3586
+ case virtual.serverBuild.resolvedId: {
3254
3587
  let routeIds = getServerBundleRouteIds(this, ctx);
3255
3588
  return await getServerEntry({ routeIds });
3256
3589
  }
3257
- case virtual2.serverManifest.resolvedId: {
3590
+ case virtual.serverManifest.resolvedId: {
3258
3591
  let routeIds = getServerBundleRouteIds(this, ctx);
3259
3592
  let reactRouterManifest = viteCommand === "build" ? (await generateReactRouterManifestsForBuild({
3260
3593
  routeIds
@@ -3272,7 +3605,7 @@ var reactRouterVitePlugin = () => {
3272
3605
  es6: true
3273
3606
  })};`;
3274
3607
  }
3275
- case virtual2.browserManifest.resolvedId: {
3608
+ case virtual.browserManifest.resolvedId: {
3276
3609
  if (viteCommand === "build") {
3277
3610
  throw new Error("This module only exists in development");
3278
3611
  }
@@ -3306,7 +3639,7 @@ var reactRouterVitePlugin = () => {
3306
3639
  }
3307
3640
  let vite2 = getVite();
3308
3641
  let importerShort = vite2.normalizePath(
3309
- path6.relative(ctx.rootDirectory, importer)
3642
+ path5.relative(ctx.rootDirectory, importer)
3310
3643
  );
3311
3644
  if (isRoute(ctx.reactRouterConfig, importer)) {
3312
3645
  let serverOnlyExports = SERVER_ONLY_ROUTE_EXPORTS.map(
@@ -3429,10 +3762,10 @@ var reactRouterVitePlugin = () => {
3429
3762
  },
3430
3763
  async load(id) {
3431
3764
  if (id !== virtualHmrRuntime.resolvedId) return;
3432
- let reactRefreshDir = path6.dirname(
3765
+ let reactRefreshDir = path5.dirname(
3433
3766
  require.resolve("react-refresh/package.json")
3434
3767
  );
3435
- let reactRefreshRuntimePath = path6.join(
3768
+ let reactRefreshRuntimePath = path5.join(
3436
3769
  reactRefreshDir,
3437
3770
  "cjs/react-refresh-runtime.development.js"
3438
3771
  );
@@ -3613,7 +3946,7 @@ if (import.meta.hot && !inWebWorker) {
3613
3946
  function getRoute(pluginConfig, file) {
3614
3947
  let vite2 = getVite();
3615
3948
  let routePath = vite2.normalizePath(
3616
- path6.relative(pluginConfig.appDirectory, file)
3949
+ path5.relative(pluginConfig.appDirectory, file)
3617
3950
  );
3618
3951
  let route = Object.values(pluginConfig.routes).find(
3619
3952
  (r) => vite2.normalizePath(r.file) === routePath
@@ -3652,7 +3985,7 @@ async function getRouteMetadata(cache, ctx, viteChildCompiler, route, readRouteF
3652
3985
  caseSensitive: route.caseSensitive,
3653
3986
  url: combineURLs(
3654
3987
  ctx.publicPath,
3655
- "/" + path6.relative(
3988
+ "/" + path5.relative(
3656
3989
  ctx.rootDirectory,
3657
3990
  resolveRelativeRouteFilePath(route, ctx.reactRouterConfig)
3658
3991
  )
@@ -3680,7 +4013,7 @@ function isSpaModeEnabled(reactRouterConfig) {
3680
4013
  return reactRouterConfig.ssr === false && !isPrerenderingEnabled(reactRouterConfig);
3681
4014
  }
3682
4015
  async function getPrerenderBuildAndHandler(viteConfig, serverBuildDirectory, serverBuildFile) {
3683
- let serverBuildPath = path6.join(serverBuildDirectory, serverBuildFile);
4016
+ let serverBuildPath = path5.join(serverBuildDirectory, serverBuildFile);
3684
4017
  let build = await import(url.pathToFileURL(serverBuildPath).toString());
3685
4018
  let { createRequestHandler: createHandler } = await import("react-router");
3686
4019
  return {
@@ -3703,16 +4036,16 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
3703
4036
  let response = await handler(request);
3704
4037
  let html = await response.text();
3705
4038
  let isPrerenderSpaFallback = build.prerender.includes("/");
3706
- let filename3 = isPrerenderSpaFallback ? "__spa-fallback.html" : "index.html";
4039
+ let filename2 = isPrerenderSpaFallback ? "__spa-fallback.html" : "index.html";
3707
4040
  if (response.status !== 200) {
3708
4041
  if (isPrerenderSpaFallback) {
3709
4042
  throw new Error(
3710
- `Prerender: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename3}\` file.
4043
+ `Prerender: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename2}\` file.
3711
4044
  ` + html
3712
4045
  );
3713
4046
  } else {
3714
4047
  throw new Error(
3715
- `SPA Mode: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename3}\` file.
4048
+ `SPA Mode: Received a ${response.status} status code from \`entry.server.tsx\` while prerendering your \`${filename2}\` file.
3716
4049
  ` + html
3717
4050
  );
3718
4051
  }
@@ -3722,9 +4055,9 @@ async function handleSpaMode(viteConfig, reactRouterConfig, serverBuildDirectory
3722
4055
  "SPA Mode: Did you forget to include `<Scripts/>` in your root route? Your pre-rendered HTML cannot hydrate without `<Scripts />`."
3723
4056
  );
3724
4057
  }
3725
- await fse.writeFile(path6.join(clientBuildDirectory, filename3), html);
3726
- let prettyDir = path6.relative(process.cwd(), clientBuildDirectory);
3727
- let prettyPath = path6.join(prettyDir, filename3);
4058
+ await fse.writeFile(path5.join(clientBuildDirectory, filename2), html);
4059
+ let prettyDir = path5.relative(process.cwd(), clientBuildDirectory);
4060
+ let prettyPath = path5.join(prettyDir, filename2);
3728
4061
  if (build.prerender.length > 0) {
3729
4062
  viteConfig.logger.info(
3730
4063
  `Prerender (html): SPA Fallback -> ${import_picocolors3.default.bold(prettyPath)}`
@@ -3740,22 +4073,17 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3740
4073
  serverBuildPath
3741
4074
  );
3742
4075
  let routes = createPrerenderRoutes(reactRouterConfig.routes);
3743
- for (let path7 of build.prerender) {
3744
- let matches = (0, import_react_router2.matchRoutes)(routes, `/${path7}/`.replace(/^\/\/+/, "/"));
4076
+ for (let path6 of build.prerender) {
4077
+ let matches = (0, import_react_router2.matchRoutes)(routes, `/${path6}/`.replace(/^\/\/+/, "/"));
3745
4078
  if (!matches) {
3746
4079
  throw new Error(
3747
- `Unable to prerender path because it does not match any routes: ${path7}`
4080
+ `Unable to prerender path because it does not match any routes: ${path6}`
3748
4081
  );
3749
4082
  }
3750
4083
  }
3751
4084
  let buildRoutes = createPrerenderRoutes(build.routes);
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(/^\/\/+/, "/"));
4085
+ for (let path6 of build.prerender) {
4086
+ let matches = (0, import_react_router2.matchRoutes)(buildRoutes, `/${path6}/`.replace(/^\/\/+/, "/"));
3759
4087
  if (!matches) {
3760
4088
  continue;
3761
4089
  }
@@ -3768,20 +4096,18 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3768
4096
  if (manifestRoute.loader) {
3769
4097
  await prerenderData(
3770
4098
  handler,
3771
- path7,
4099
+ path6,
3772
4100
  [leafRoute.id],
3773
4101
  clientBuildDirectory,
3774
4102
  reactRouterConfig,
3775
- viteConfig,
3776
- { headers }
4103
+ viteConfig
3777
4104
  );
3778
4105
  await prerenderResourceRoute(
3779
4106
  handler,
3780
- path7,
4107
+ path6,
3781
4108
  clientBuildDirectory,
3782
4109
  reactRouterConfig,
3783
- viteConfig,
3784
- { headers }
4110
+ viteConfig
3785
4111
  );
3786
4112
  } else {
3787
4113
  viteConfig.logger.warn(
@@ -3796,26 +4122,24 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
3796
4122
  if (!isResourceRoute && hasLoaders) {
3797
4123
  data = await prerenderData(
3798
4124
  handler,
3799
- path7,
4125
+ path6,
3800
4126
  null,
3801
4127
  clientBuildDirectory,
3802
4128
  reactRouterConfig,
3803
- viteConfig,
3804
- { headers }
4129
+ viteConfig
3805
4130
  );
3806
4131
  }
3807
4132
  await prerenderRoute(
3808
4133
  handler,
3809
- path7,
4134
+ path6,
3810
4135
  clientBuildDirectory,
3811
4136
  reactRouterConfig,
3812
4137
  viteConfig,
3813
4138
  data ? {
3814
4139
  headers: {
3815
- ...headers,
3816
4140
  "X-React-Router-Prerender-Data": encodeURI(data)
3817
4141
  }
3818
- } : { headers }
4142
+ } : void 0
3819
4143
  );
3820
4144
  }
3821
4145
  }
@@ -3860,9 +4184,9 @@ async function prerenderData(handler, prerenderPath, onlyRoutes, clientBuildDire
3860
4184
  ${normalizedPath}`
3861
4185
  );
3862
4186
  }
3863
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3864
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
3865
- await fse.ensureDir(path6.dirname(outfile));
4187
+ let outdir = path5.relative(process.cwd(), clientBuildDirectory);
4188
+ let outfile = path5.join(outdir, ...normalizedPath.split("/"));
4189
+ await fse.ensureDir(path5.dirname(outfile));
3866
4190
  await fse.outputFile(outfile, data);
3867
4191
  viteConfig.logger.info(
3868
4192
  `Prerender (data): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3899,9 +4223,9 @@ async function prerenderRoute(handler, prerenderPath, clientBuildDirectory, reac
3899
4223
  ${html}`
3900
4224
  );
3901
4225
  }
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));
4226
+ let outdir = path5.relative(process.cwd(), clientBuildDirectory);
4227
+ let outfile = path5.join(outdir, ...normalizedPath.split("/"), "index.html");
4228
+ await fse.ensureDir(path5.dirname(outfile));
3905
4229
  await fse.outputFile(outfile, html);
3906
4230
  viteConfig.logger.info(
3907
4231
  `Prerender (html): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3918,9 +4242,9 @@ async function prerenderResourceRoute(handler, prerenderPath, clientBuildDirecto
3918
4242
  ${content.toString("utf8")}`
3919
4243
  );
3920
4244
  }
3921
- let outdir = path6.relative(process.cwd(), clientBuildDirectory);
3922
- let outfile = path6.join(outdir, ...normalizedPath.split("/"));
3923
- await fse.ensureDir(path6.dirname(outfile));
4245
+ let outdir = path5.relative(process.cwd(), clientBuildDirectory);
4246
+ let outfile = path5.join(outdir, ...normalizedPath.split("/"));
4247
+ await fse.ensureDir(path5.dirname(outfile));
3924
4248
  await fse.outputFile(outfile, content);
3925
4249
  viteConfig.logger.info(
3926
4250
  `Prerender (resource): ${prerenderPath} -> ${import_picocolors3.default.bold(outfile)}`
@@ -3996,14 +4320,14 @@ async function validateSsrFalsePrerenderExports(viteConfig, ctx, manifest, viteC
3996
4320
  }
3997
4321
  let prerenderRoutes = createPrerenderRoutes(manifest.routes);
3998
4322
  let prerenderedRoutes = /* @__PURE__ */ new Set();
3999
- for (let path7 of prerenderPaths) {
4323
+ for (let path6 of prerenderPaths) {
4000
4324
  let matches = (0, import_react_router2.matchRoutes)(
4001
4325
  prerenderRoutes,
4002
- `/${path7}/`.replace(/^\/\/+/, "/")
4326
+ `/${path6}/`.replace(/^\/\/+/, "/")
4003
4327
  );
4004
4328
  invariant(
4005
4329
  matches,
4006
- `Unable to prerender path because it does not match any routes: ${path7}`
4330
+ `Unable to prerender path because it does not match any routes: ${path6}`
4007
4331
  );
4008
4332
  matches.forEach((m) => prerenderedRoutes.add(m.route.id));
4009
4333
  }
@@ -4170,8 +4494,8 @@ function validateRouteChunks({
4170
4494
  async function cleanBuildDirectory(viteConfig, ctx) {
4171
4495
  let buildDirectory = ctx.reactRouterConfig.buildDirectory;
4172
4496
  let isWithinRoot = () => {
4173
- let relativePath = path6.relative(ctx.rootDirectory, buildDirectory);
4174
- return !relativePath.startsWith("..") && !path6.isAbsolute(relativePath);
4497
+ let relativePath = path5.relative(ctx.rootDirectory, buildDirectory);
4498
+ return !relativePath.startsWith("..") && !path5.isAbsolute(relativePath);
4175
4499
  };
4176
4500
  if (viteConfig.build.emptyOutDir ?? isWithinRoot()) {
4177
4501
  await fse.remove(buildDirectory);
@@ -4182,7 +4506,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4182
4506
  ([environmentName, options]) => {
4183
4507
  let outDir = options.build?.outDir;
4184
4508
  invariant(outDir, `Expected build.outDir for ${environmentName}`);
4185
- return path6.join(outDir, ".vite/manifest.json");
4509
+ return path5.join(outDir, ".vite/manifest.json");
4186
4510
  }
4187
4511
  );
4188
4512
  await Promise.all(
@@ -4192,7 +4516,7 @@ async function cleanViteManifests(environmentsOptions, ctx) {
4192
4516
  if (!ctx.viteManifestEnabled) {
4193
4517
  await fse.remove(viteManifestPath);
4194
4518
  }
4195
- let viteDir = path6.dirname(viteManifestPath);
4519
+ let viteDir = path5.dirname(viteManifestPath);
4196
4520
  let viteDirFiles = await fse.readdir(viteDir);
4197
4521
  if (viteDirFiles.length === 0) {
4198
4522
  await fse.remove(viteDir);
@@ -4210,12 +4534,12 @@ async function getBuildManifest({
4210
4534
  }
4211
4535
  let { normalizePath } = await import("vite");
4212
4536
  let serverBuildDirectory = getServerBuildDirectory(reactRouterConfig);
4213
- let resolvedAppDirectory = path6.resolve(rootDirectory, appDirectory);
4537
+ let resolvedAppDirectory = path5.resolve(rootDirectory, appDirectory);
4214
4538
  let rootRelativeRoutes = Object.fromEntries(
4215
4539
  Object.entries(routes).map(([id, route]) => {
4216
- let filePath = path6.join(resolvedAppDirectory, route.file);
4540
+ let filePath = path5.join(resolvedAppDirectory, route.file);
4217
4541
  let rootRelativeFilePath = normalizePath(
4218
- path6.relative(rootDirectory, filePath)
4542
+ path5.relative(rootDirectory, filePath)
4219
4543
  );
4220
4544
  return [id, { ...route, file: rootRelativeFilePath }];
4221
4545
  })
@@ -4233,7 +4557,7 @@ async function getBuildManifest({
4233
4557
  (route2) => configRouteToBranchRoute({
4234
4558
  ...route2,
4235
4559
  // Ensure absolute paths are passed to the serverBundles function
4236
- file: path6.join(resolvedAppDirectory, route2.file)
4560
+ file: path5.join(resolvedAppDirectory, route2.file)
4237
4561
  })
4238
4562
  )
4239
4563
  });
@@ -4257,10 +4581,10 @@ async function getBuildManifest({
4257
4581
  buildManifest.serverBundles[serverBundleId] ??= {
4258
4582
  id: serverBundleId,
4259
4583
  file: normalizePath(
4260
- path6.join(
4261
- path6.relative(
4584
+ path5.join(
4585
+ path5.relative(
4262
4586
  rootDirectory,
4263
- path6.join(serverBuildDirectory, serverBundleId)
4587
+ path5.join(serverBuildDirectory, serverBundleId)
4264
4588
  ),
4265
4589
  reactRouterConfig.serverBuildFile
4266
4590
  )
@@ -4279,10 +4603,10 @@ function mergeEnvironmentOptions(base, ...overrides) {
4279
4603
  }
4280
4604
  async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4281
4605
  let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
4282
- let packageRoot = path6.dirname(
4606
+ let packageRoot = path5.dirname(
4283
4607
  require.resolve("@react-router/dev/package.json")
4284
4608
  );
4285
- let { moduleSyncEnabled } = await import(`file:///${path6.join(packageRoot, "module-sync-enabled/index.mjs")}`);
4609
+ let { moduleSyncEnabled } = await import(`file:///${path5.join(packageRoot, "module-sync-enabled/index.mjs")}`);
4286
4610
  let vite2 = getVite();
4287
4611
  let viteServerConditions = [
4288
4612
  ...vite2.defaultServerConditions ?? [],
@@ -4339,7 +4663,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4339
4663
  copyPublicDir: false,
4340
4664
  // Assets in the public directory are only used by the client
4341
4665
  rollupOptions: {
4342
- input: (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ?? virtual2.serverBuild.id,
4666
+ input: (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig.environments?.ssr?.build?.rollupOptions?.input : viteUserConfig.build?.rollupOptions?.input) ?? virtual.serverBuild.id,
4343
4667
  output: {
4344
4668
  entryFileNames: serverBuildFile,
4345
4669
  format: serverModuleFormat
@@ -4356,7 +4680,7 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4356
4680
  ctx.entryClientFilePath,
4357
4681
  ...Object.values(ctx.reactRouterConfig.routes).flatMap(
4358
4682
  (route) => {
4359
- let routeFilePath = path6.resolve(
4683
+ let routeFilePath = path5.resolve(
4360
4684
  ctx.reactRouterConfig.appDirectory,
4361
4685
  route.file
4362
4686
  );
@@ -4379,8 +4703,9 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4379
4703
  ""
4380
4704
  ) : null;
4381
4705
  let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
4382
- return path6.posix.join(
4383
- (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : viteUserConfig?.build?.assetsDir) ?? "assets",
4706
+ let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
4707
+ return path5.posix.join(
4708
+ assetsDir,
4384
4709
  `[name]${routeChunkSuffix}-[hash].js`
4385
4710
  );
4386
4711
  }
@@ -4415,9 +4740,6 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
4415
4740
  }
4416
4741
  });
4417
4742
  }
4418
- if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi && viteCommand === "serve") {
4419
- environmentOptionsResolvers[CSS_DEV_HELPER_ENVIRONMENT_NAME] = () => ({});
4420
- }
4421
4743
  return environmentOptionsResolvers;
4422
4744
  }
4423
4745
  function resolveEnvironmentsOptions(environmentResolvers, resolverOptions) {