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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -102,22 +102,6 @@ type ReactRouterConfig = {
102
102
  * other platforms and tools.
103
103
  */
104
104
  presets?: Array<Preset>;
105
- /**
106
- * Control the "Lazy Route Discovery" behavior
107
- *
108
- * - `routeDiscovery.mode`: By default, this resolves to `lazy` which will
109
- * lazily discover routes as the user navigates around your application.
110
- * You can set this to `initial` to opt-out of this behavior and load all
111
- * routes with the initial HTML document load.
112
- * - `routeDiscovery.manifestPath`: The path to serve the manifest file from.
113
- * Only applies to `mode: "lazy"` and defaults to `/__manifest`.
114
- */
115
- routeDiscovery?: {
116
- mode: "lazy";
117
- manifestPath?: string;
118
- } | {
119
- mode: "initial";
120
- };
121
105
  /**
122
106
  * The file name of the server build output. This file
123
107
  * should end in a `.js` extension and should be deployed to your server.
@@ -164,17 +148,6 @@ type ResolvedReactRouterConfig = Readonly<{
164
148
  * function returning an array to dynamically generate URLs.
165
149
  */
166
150
  prerender: ReactRouterConfig["prerender"];
167
- /**
168
- * Control the "Lazy Route Discovery" behavior
169
- *
170
- * - `routeDiscovery.mode`: By default, this resolves to `lazy` which will
171
- * lazily discover routes as the user navigates around your application.
172
- * You can set this to `initial` to opt-out of this behavior and load all
173
- * routes with the initial HTML document load.
174
- * - `routeDiscovery.manifestPath`: The path to serve the manifest file from.
175
- * Only applies to `mode: "lazy"` and defaults to `/__manifest`.
176
- */
177
- routeDiscovery: ReactRouterConfig["routeDiscovery"];
178
151
  /**
179
152
  * An object of all available routes, keyed by route id.
180
153
  */
package/dist/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-ab0e85b04
2
+ * @react-router/dev v0.0.0-experimental-e56aa53bc
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/routes.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-ab0e85b04
2
+ * @react-router/dev v0.0.0-experimental-e56aa53bc
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-ab0e85b04
2
+ * @react-router/dev v0.0.0-experimental-e56aa53bc
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -113,9 +113,7 @@ function fromNodeRequest(nodeReq, nodeRes) {
113
113
  }
114
114
  async function toNodeRequest(res, nodeRes) {
115
115
  nodeRes.statusCode = res.status;
116
- if (!nodeRes.req || nodeRes.req.httpVersionMajor < 2) {
117
- nodeRes.statusMessage = res.statusText;
118
- }
116
+ nodeRes.statusMessage = res.statusText;
119
117
  let cookiesStrings = [];
120
118
  for (let [name, value] of res.headers) {
121
119
  if (name === "set-cookie") {
@@ -197,15 +195,13 @@ var ssrExternals = isReactRouterRepo() ? [
197
195
  // vite/vite-node.ts
198
196
  async function createContext({
199
197
  root,
200
- mode,
201
- customLogger
198
+ mode
202
199
  }) {
203
200
  await preloadVite();
204
201
  const vite2 = getVite();
205
202
  const devServer = await vite2.createServer({
206
203
  root,
207
204
  mode,
208
- customLogger,
209
205
  server: {
210
206
  preTransformRequests: false,
211
207
  hmr: false,
@@ -217,15 +213,6 @@ async function createContext({
217
213
  optimizeDeps: {
218
214
  noDiscovery: true
219
215
  },
220
- css: {
221
- // This empty PostCSS config object prevents the PostCSS config file from
222
- // being loaded. We don't need it in a React Router config context, and
223
- // there's also an issue in Vite 5 when using a .ts PostCSS config file in
224
- // an ESM project: https://github.com/vitejs/vite/issues/15869. Consumers
225
- // can work around this in their own Vite config file, but they can't
226
- // configure this internal usage of vite-node.
227
- postcss: {}
228
- },
229
216
  configFile: false,
230
217
  envFile: false,
231
218
  plugins: []
@@ -303,7 +290,7 @@ function validateRouteConfig({
303
290
  `Route config in "${routeConfigFile}" is invalid.`,
304
291
  root ? `${root}` : [],
305
292
  nested ? Object.entries(nested).map(
306
- ([path3, message]) => `Path: routes.${path3}
293
+ ([path4, message]) => `Path: routes.${path4}
307
294
  ${message}`
308
295
  ) : []
309
296
  ].flat().join("\n\n")
@@ -396,8 +383,7 @@ function err(error) {
396
383
  async function resolveConfig({
397
384
  root,
398
385
  viteNodeContext,
399
- reactRouterConfigFile,
400
- skipRoutes
386
+ reactRouterConfigFile
401
387
  }) {
402
388
  let reactRouterUserConfig = {};
403
389
  if (reactRouterConfigFile) {
@@ -446,17 +432,12 @@ async function resolveConfig({
446
432
  serverModuleFormat: "esm",
447
433
  ssr: true
448
434
  };
449
- let userAndPresetConfigs = mergeReactRouterConfig(
450
- ...presets,
451
- reactRouterUserConfig
452
- );
453
435
  let {
454
436
  appDirectory: userAppDirectory,
455
437
  basename,
456
438
  buildDirectory: userBuildDirectory,
457
439
  buildEnd,
458
440
  prerender,
459
- routeDiscovery: userRouteDiscovery,
460
441
  serverBuildFile,
461
442
  serverBundles,
462
443
  serverModuleFormat,
@@ -464,7 +445,7 @@ async function resolveConfig({
464
445
  } = {
465
446
  ...defaults,
466
447
  // Default values should be completely overridden by user/preset config, not merged
467
- ...userAndPresetConfigs
448
+ ...mergeReactRouterConfig(...presets, reactRouterUserConfig)
468
449
  };
469
450
  if (!ssr && serverBundles) {
470
451
  serverBundles = void 0;
@@ -475,32 +456,6 @@ async function resolveConfig({
475
456
  "The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
476
457
  );
477
458
  }
478
- let routeDiscovery;
479
- if (userRouteDiscovery == null) {
480
- if (ssr) {
481
- routeDiscovery = {
482
- mode: "lazy",
483
- manifestPath: "/__manifest"
484
- };
485
- } else {
486
- routeDiscovery = { mode: "initial" };
487
- }
488
- } else if (userRouteDiscovery.mode === "initial") {
489
- routeDiscovery = userRouteDiscovery;
490
- } else if (userRouteDiscovery.mode === "lazy") {
491
- if (!ssr) {
492
- return err(
493
- 'The `routeDiscovery.mode` config cannot be set to "lazy" when setting `ssr:false`'
494
- );
495
- }
496
- let { manifestPath } = userRouteDiscovery;
497
- if (manifestPath != null && !manifestPath.startsWith("/")) {
498
- return err(
499
- 'The `routeDiscovery.manifestPath` config must be a root-relative pathname beginning with a slash (i.e., "/__manifest")'
500
- );
501
- }
502
- routeDiscovery = userRouteDiscovery;
503
- }
504
459
  let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
505
460
  let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
506
461
  let rootRouteFile = findEntry(appDirectory, "root");
@@ -513,50 +468,45 @@ async function resolveConfig({
513
468
  `Could not find a root route module in the app directory as "${rootRouteDisplayPath}"`
514
469
  );
515
470
  }
516
- let routes = {};
517
- if (!skipRoutes) {
518
- routes = {
519
- root: { path: "", id: "root", file: rootRouteFile }
520
- };
521
- let routeConfigFile = findEntry(appDirectory, "routes");
522
- try {
523
- if (!routeConfigFile) {
524
- let routeConfigDisplayPath = import_pathe3.default.relative(
525
- root,
526
- import_pathe3.default.join(appDirectory, "routes.ts")
527
- );
528
- return err(
529
- `Route config file not found at "${routeConfigDisplayPath}".`
530
- );
531
- }
532
- setAppDirectory(appDirectory);
533
- let routeConfigExport = (await viteNodeContext.runner.executeFile(
534
- import_pathe3.default.join(appDirectory, routeConfigFile)
535
- )).default;
536
- let routeConfig = await routeConfigExport;
537
- let result = validateRouteConfig({
538
- routeConfigFile,
539
- routeConfig
540
- });
541
- if (!result.valid) {
542
- return err(result.message);
543
- }
544
- routes = {
545
- ...routes,
546
- ...configRoutesToRouteManifest(appDirectory, routeConfig)
547
- };
548
- } catch (error) {
549
- return err(
550
- [
551
- import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
552
- "",
553
- error.loc?.file && error.loc?.column && error.frame ? [
554
- import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
555
- error.frame.trim?.()
556
- ] : error.stack
557
- ].flat().join("\n")
471
+ let routes = {
472
+ root: { path: "", id: "root", file: rootRouteFile }
473
+ };
474
+ let routeConfigFile = findEntry(appDirectory, "routes");
475
+ try {
476
+ if (!routeConfigFile) {
477
+ let routeConfigDisplayPath = import_pathe3.default.relative(
478
+ root,
479
+ import_pathe3.default.join(appDirectory, "routes.ts")
558
480
  );
481
+ return err(`Route config file not found at "${routeConfigDisplayPath}".`);
559
482
  }
483
+ setAppDirectory(appDirectory);
484
+ let routeConfigExport = (await viteNodeContext.runner.executeFile(
485
+ import_pathe3.default.join(appDirectory, routeConfigFile)
486
+ )).default;
487
+ let routeConfig = await routeConfigExport;
488
+ let result = validateRouteConfig({
489
+ routeConfigFile,
490
+ routeConfig
491
+ });
492
+ if (!result.valid) {
493
+ return err(result.message);
494
+ }
495
+ routes = {
496
+ ...routes,
497
+ ...configRoutesToRouteManifest(appDirectory, routeConfig)
498
+ };
499
+ } catch (error) {
500
+ return err(
501
+ [
502
+ import_picocolors.default.red(`Route config in "${routeConfigFile}" is invalid.`),
503
+ "",
504
+ error.loc?.file && error.loc?.column && error.frame ? [
505
+ import_pathe3.default.relative(appDirectory, error.loc.file) + ":" + error.loc.line + ":" + error.loc.column,
506
+ error.frame.trim?.()
507
+ ] : error.stack
508
+ ].flat().join("\n")
509
+ );
560
510
  }
561
511
  let future = {
562
512
  unstable_middleware: reactRouterUserConfig.future?.unstable_middleware ?? false,
@@ -573,7 +523,6 @@ async function resolveConfig({
573
523
  future,
574
524
  prerender,
575
525
  routes,
576
- routeDiscovery,
577
526
  serverBuildFile,
578
527
  serverBundles,
579
528
  serverModuleFormat,
@@ -586,35 +535,24 @@ async function resolveConfig({
586
535
  }
587
536
  async function createConfigLoader({
588
537
  rootDirectory: root,
589
- watch,
590
- mode,
591
- skipRoutes
538
+ watch
592
539
  }) {
593
- root = import_pathe3.default.normalize(root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd());
594
- let vite2 = await import("vite");
540
+ root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
595
541
  let viteNodeContext = await createContext({
596
542
  root,
597
- mode,
598
- // Filter out any info level logs from vite-node
599
- customLogger: vite2.createLogger("warn", {
600
- prefix: "[react-router]"
601
- })
543
+ mode: watch ? "development" : "production"
602
544
  });
603
- let reactRouterConfigFile;
604
- let updateReactRouterConfigFile = () => {
605
- reactRouterConfigFile = findEntry(root, "react-router.config", {
606
- absolute: true
607
- });
608
- };
609
- updateReactRouterConfigFile();
610
- let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile, skipRoutes });
545
+ let reactRouterConfigFile = findEntry(root, "react-router.config", {
546
+ absolute: true
547
+ });
548
+ let getConfig = () => resolveConfig({ root, viteNodeContext, reactRouterConfigFile });
611
549
  let appDirectory;
612
550
  let initialConfigResult = await getConfig();
613
551
  if (!initialConfigResult.ok) {
614
552
  throw new Error(initialConfigResult.error);
615
553
  }
616
- appDirectory = import_pathe3.default.normalize(initialConfigResult.value.appDirectory);
617
- let currentConfig = initialConfigResult.value;
554
+ appDirectory = initialConfigResult.value.appDirectory;
555
+ let lastConfig = initialConfigResult.value;
618
556
  let fsWatcher;
619
557
  let changeHandlers = [];
620
558
  return {
@@ -627,71 +565,41 @@ async function createConfigLoader({
627
565
  }
628
566
  changeHandlers.push(handler);
629
567
  if (!fsWatcher) {
630
- fsWatcher = import_chokidar.default.watch([root, appDirectory], {
631
- ignoreInitial: true,
632
- ignored: (path3) => {
633
- let dirname = import_pathe3.default.dirname(path3);
634
- return !dirname.startsWith(appDirectory) && // Ensure we're only watching files outside of the app directory
635
- // that are at the root level, not nested in subdirectories
636
- path3 !== root && // Watch the root directory itself
637
- dirname !== root;
638
- }
639
- });
568
+ fsWatcher = import_chokidar.default.watch(
569
+ [
570
+ ...reactRouterConfigFile ? [reactRouterConfigFile] : [],
571
+ appDirectory
572
+ ],
573
+ { ignoreInitial: true }
574
+ );
640
575
  fsWatcher.on("all", async (...args) => {
641
576
  let [event, rawFilepath] = args;
642
577
  let filepath = import_pathe3.default.normalize(rawFilepath);
643
- let fileAddedOrRemoved = event === "add" || event === "unlink";
644
- let appFileAddedOrRemoved = fileAddedOrRemoved && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
645
- let rootRelativeFilepath = import_pathe3.default.relative(root, filepath);
646
- let configFileAddedOrRemoved = fileAddedOrRemoved && isEntryFile("react-router.config", rootRelativeFilepath);
647
- if (configFileAddedOrRemoved) {
648
- updateReactRouterConfigFile();
649
- }
650
- let moduleGraphChanged = configFileAddedOrRemoved || Boolean(
578
+ let appFileAddedOrRemoved = appDirectory && (event === "add" || event === "unlink") && filepath.startsWith(import_pathe3.default.normalize(appDirectory));
579
+ let configCodeUpdated = Boolean(
651
580
  viteNodeContext.devServer?.moduleGraph.getModuleById(filepath)
652
581
  );
653
- if (!moduleGraphChanged && !appFileAddedOrRemoved) {
654
- return;
582
+ if (configCodeUpdated || appFileAddedOrRemoved) {
583
+ viteNodeContext.devServer?.moduleGraph.invalidateAll();
584
+ viteNodeContext.runner?.moduleCache.clear();
655
585
  }
656
- viteNodeContext.devServer?.moduleGraph.invalidateAll();
657
- viteNodeContext.runner?.moduleCache.clear();
658
- let result = await getConfig();
659
- let prevAppDirectory = appDirectory;
660
- appDirectory = import_pathe3.default.normalize(
661
- (result.value ?? currentConfig).appDirectory
662
- );
663
- if (appDirectory !== prevAppDirectory) {
664
- fsWatcher.unwatch(prevAppDirectory);
665
- fsWatcher.add(appDirectory);
666
- }
667
- let configCodeChanged = configFileAddedOrRemoved || reactRouterConfigFile !== void 0 && isEntryFileDependency(
668
- viteNodeContext.devServer.moduleGraph,
669
- reactRouterConfigFile,
670
- filepath
671
- );
672
- let routeConfigFile = !skipRoutes ? findEntry(appDirectory, "routes", {
673
- absolute: true
674
- }) : void 0;
675
- let routeConfigCodeChanged = routeConfigFile !== void 0 && isEntryFileDependency(
676
- viteNodeContext.devServer.moduleGraph,
677
- routeConfigFile,
678
- filepath
679
- );
680
- let configChanged = result.ok && !(0, import_isEqual.default)(omitRoutes(currentConfig), omitRoutes(result.value));
681
- let routeConfigChanged = result.ok && !(0, import_isEqual.default)(currentConfig?.routes, result.value.routes);
682
- for (let handler2 of changeHandlers) {
683
- handler2({
684
- result,
685
- configCodeChanged,
686
- routeConfigCodeChanged,
687
- configChanged,
688
- routeConfigChanged,
689
- path: filepath,
690
- event
691
- });
692
- }
693
- if (result.ok) {
694
- currentConfig = result.value;
586
+ if (appFileAddedOrRemoved || configCodeUpdated) {
587
+ let result = await getConfig();
588
+ let configChanged = result.ok && !(0, import_isEqual.default)(lastConfig, result.value);
589
+ let routeConfigChanged = result.ok && !(0, import_isEqual.default)(lastConfig?.routes, result.value.routes);
590
+ for (let handler2 of changeHandlers) {
591
+ handler2({
592
+ result,
593
+ configCodeUpdated,
594
+ configChanged,
595
+ routeConfigChanged,
596
+ path: filepath,
597
+ event
598
+ });
599
+ }
600
+ if (result.ok) {
601
+ lastConfig = result.value;
602
+ }
695
603
  }
696
604
  });
697
605
  }
@@ -708,74 +616,24 @@ async function createConfigLoader({
708
616
  }
709
617
  };
710
618
  }
711
- async function loadConfig({
712
- rootDirectory,
713
- mode,
714
- skipRoutes
715
- }) {
619
+ async function loadConfig({ rootDirectory }) {
716
620
  let configLoader = await createConfigLoader({
717
621
  rootDirectory,
718
- mode,
719
- skipRoutes,
720
622
  watch: false
721
623
  });
722
624
  let config = await configLoader.getConfig();
723
625
  await configLoader.close();
724
626
  return config;
725
627
  }
726
- function omitRoutes(config) {
727
- return {
728
- ...config,
729
- routes: {}
730
- };
731
- }
732
628
  var entryExts = [".js", ".jsx", ".ts", ".tsx"];
733
- function isEntryFile(entryBasename, filename) {
734
- return entryExts.some((ext) => filename === `${entryBasename}${ext}`);
735
- }
736
629
  function findEntry(dir, basename, options) {
737
- let currentDir = import_pathe3.default.resolve(dir);
738
- let { root } = import_pathe3.default.parse(currentDir);
739
- while (true) {
740
- for (let ext of options?.extensions ?? entryExts) {
741
- let file = import_pathe3.default.resolve(currentDir, basename + ext);
742
- if (import_node_fs.default.existsSync(file)) {
743
- return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
744
- }
745
- }
746
- if (!options?.walkParents) {
747
- return void 0;
748
- }
749
- let parentDir = import_pathe3.default.dirname(currentDir);
750
- if (currentDir === root || parentDir === currentDir) {
751
- return void 0;
752
- }
753
- currentDir = parentDir;
754
- }
755
- }
756
- function isEntryFileDependency(moduleGraph, entryFilepath, filepath, visited = /* @__PURE__ */ new Set()) {
757
- entryFilepath = import_pathe3.default.normalize(entryFilepath);
758
- filepath = import_pathe3.default.normalize(filepath);
759
- if (visited.has(filepath)) {
760
- return false;
761
- }
762
- visited.add(filepath);
763
- if (filepath === entryFilepath) {
764
- return true;
765
- }
766
- let mod = moduleGraph.getModuleById(filepath);
767
- if (!mod) {
768
- return false;
769
- }
770
- for (let importer of mod.importers) {
771
- if (!importer.id) {
772
- continue;
773
- }
774
- if (importer.id === entryFilepath || isEntryFileDependency(moduleGraph, entryFilepath, importer.id, visited)) {
775
- return true;
630
+ for (let ext of entryExts) {
631
+ let file = import_pathe3.default.resolve(dir, basename + ext);
632
+ if (import_node_fs.default.existsSync(file)) {
633
+ return options?.absolute ?? false ? file : import_pathe3.default.relative(dir, file);
776
634
  }
777
635
  }
778
- return false;
636
+ return void 0;
779
637
  }
780
638
 
781
639
  // vite/cloudflare-dev-proxy.ts
@@ -794,15 +652,14 @@ var cloudflareDevProxyVitePlugin = (options = {}) => {
794
652
  let future;
795
653
  return {
796
654
  name: PLUGIN_NAME,
797
- config: async (config, configEnv) => {
655
+ config: async (config) => {
798
656
  await preloadVite();
799
657
  const vite2 = getVite();
800
658
  const serverConditions = [
801
659
  ...vite2.defaultServerConditions ?? []
802
660
  ];
803
661
  let configResult = await loadConfig({
804
- rootDirectory: config.root ?? process.cwd(),
805
- mode: configEnv.mode
662
+ rootDirectory: config.root ?? process.cwd()
806
663
  });
807
664
  if (!configResult.ok) {
808
665
  throw new Error(configResult.error);