@react-router/dev 0.0.0-experimental-1d760f6a6 → 0.0.0-experimental-b2bc694a6
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/CHANGELOG.md +9 -0
- package/dist/cli/index.js +80 -17
- package/dist/config.d.ts +27 -0
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +57 -8
- package/dist/vite.js +63 -10
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @react-router/dev v0.0.0-experimental-
|
|
3
|
+
* @react-router/dev v0.0.0-experimental-b2bc694a6
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -143,6 +143,15 @@ async function createContext({
|
|
|
143
143
|
optimizeDeps: {
|
|
144
144
|
noDiscovery: true
|
|
145
145
|
},
|
|
146
|
+
css: {
|
|
147
|
+
// This empty PostCSS config object prevents the PostCSS config file from
|
|
148
|
+
// being loaded. We don't need it in a React Router config context, and
|
|
149
|
+
// there's also an issue in Vite 5 when using a .ts PostCSS config file in
|
|
150
|
+
// an ESM project: https://github.com/vitejs/vite/issues/15869. Consumers
|
|
151
|
+
// can work around this in their own Vite config file, but they can't
|
|
152
|
+
// configure this internal usage of vite-node.
|
|
153
|
+
postcss: {}
|
|
154
|
+
},
|
|
146
155
|
configFile: false,
|
|
147
156
|
envFile: false,
|
|
148
157
|
plugins: []
|
|
@@ -339,12 +348,17 @@ async function resolveConfig({
|
|
|
339
348
|
serverModuleFormat: "esm",
|
|
340
349
|
ssr: true
|
|
341
350
|
};
|
|
351
|
+
let userAndPresetConfigs = mergeReactRouterConfig(
|
|
352
|
+
...presets,
|
|
353
|
+
reactRouterUserConfig
|
|
354
|
+
);
|
|
342
355
|
let {
|
|
343
356
|
appDirectory: userAppDirectory,
|
|
344
357
|
basename: basename2,
|
|
345
358
|
buildDirectory: userBuildDirectory,
|
|
346
359
|
buildEnd,
|
|
347
360
|
prerender,
|
|
361
|
+
routeDiscovery: userRouteDiscovery,
|
|
348
362
|
serverBuildFile,
|
|
349
363
|
serverBundles,
|
|
350
364
|
serverModuleFormat,
|
|
@@ -352,7 +366,7 @@ async function resolveConfig({
|
|
|
352
366
|
} = {
|
|
353
367
|
...defaults,
|
|
354
368
|
// Default values should be completely overridden by user/preset config, not merged
|
|
355
|
-
...
|
|
369
|
+
...userAndPresetConfigs
|
|
356
370
|
};
|
|
357
371
|
if (!ssr && serverBundles) {
|
|
358
372
|
serverBundles = void 0;
|
|
@@ -363,6 +377,32 @@ async function resolveConfig({
|
|
|
363
377
|
"The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
|
|
364
378
|
);
|
|
365
379
|
}
|
|
380
|
+
let routeDiscovery;
|
|
381
|
+
if (userRouteDiscovery == null) {
|
|
382
|
+
if (ssr) {
|
|
383
|
+
routeDiscovery = {
|
|
384
|
+
mode: "lazy",
|
|
385
|
+
manifestPath: "/__manifest"
|
|
386
|
+
};
|
|
387
|
+
} else {
|
|
388
|
+
routeDiscovery = { mode: "initial" };
|
|
389
|
+
}
|
|
390
|
+
} else if (userRouteDiscovery.mode === "initial") {
|
|
391
|
+
routeDiscovery = userRouteDiscovery;
|
|
392
|
+
} else if (userRouteDiscovery.mode === "lazy") {
|
|
393
|
+
if (!ssr) {
|
|
394
|
+
return err(
|
|
395
|
+
'The `routeDiscovery.mode` config cannot be set to "lazy" when setting `ssr:false`'
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
let { manifestPath } = userRouteDiscovery;
|
|
399
|
+
if (manifestPath != null && !manifestPath.startsWith("/")) {
|
|
400
|
+
return err(
|
|
401
|
+
'The `routeDiscovery.manifestPath` config must be a root-relative pathname beginning with a slash (i.e., "/__manifest")'
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
routeDiscovery = userRouteDiscovery;
|
|
405
|
+
}
|
|
366
406
|
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
367
407
|
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
368
408
|
let rootRouteFile = findEntry(appDirectory, "root");
|
|
@@ -430,6 +470,7 @@ async function resolveConfig({
|
|
|
430
470
|
future,
|
|
431
471
|
prerender,
|
|
432
472
|
routes: routes2,
|
|
473
|
+
routeDiscovery,
|
|
433
474
|
serverBuildFile,
|
|
434
475
|
serverBundles,
|
|
435
476
|
serverModuleFormat,
|
|
@@ -442,12 +483,13 @@ async function resolveConfig({
|
|
|
442
483
|
}
|
|
443
484
|
async function createConfigLoader({
|
|
444
485
|
rootDirectory: root,
|
|
445
|
-
watch: watch2
|
|
486
|
+
watch: watch2,
|
|
487
|
+
mode
|
|
446
488
|
}) {
|
|
447
489
|
root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
448
490
|
let viteNodeContext = await createContext({
|
|
449
491
|
root,
|
|
450
|
-
mode
|
|
492
|
+
mode
|
|
451
493
|
});
|
|
452
494
|
let reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
453
495
|
absolute: true
|
|
@@ -523,9 +565,13 @@ async function createConfigLoader({
|
|
|
523
565
|
}
|
|
524
566
|
};
|
|
525
567
|
}
|
|
526
|
-
async function loadConfig({
|
|
568
|
+
async function loadConfig({
|
|
569
|
+
rootDirectory,
|
|
570
|
+
mode
|
|
571
|
+
}) {
|
|
527
572
|
let configLoader = await createConfigLoader({
|
|
528
573
|
rootDirectory,
|
|
574
|
+
mode,
|
|
529
575
|
watch: false
|
|
530
576
|
});
|
|
531
577
|
let config = await configLoader.getConfig();
|
|
@@ -819,12 +865,12 @@ var init_generate = __esm({
|
|
|
819
865
|
});
|
|
820
866
|
|
|
821
867
|
// typegen/index.ts
|
|
822
|
-
async function run(rootDirectory) {
|
|
823
|
-
const ctx = await createContext2({ rootDirectory, watch: false });
|
|
868
|
+
async function run(rootDirectory, { mode }) {
|
|
869
|
+
const ctx = await createContext2({ rootDirectory, mode, watch: false });
|
|
824
870
|
await writeAll(ctx);
|
|
825
871
|
}
|
|
826
|
-
async function watch(rootDirectory, { logger }
|
|
827
|
-
const ctx = await createContext2({ rootDirectory, watch: true });
|
|
872
|
+
async function watch(rootDirectory, { mode, logger }) {
|
|
873
|
+
const ctx = await createContext2({ rootDirectory, mode, watch: true });
|
|
828
874
|
await writeAll(ctx);
|
|
829
875
|
logger?.info(import_picocolors3.default.green("generated types"), { timestamp: true, clear: true });
|
|
830
876
|
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
@@ -847,9 +893,10 @@ async function watch(rootDirectory, { logger } = {}) {
|
|
|
847
893
|
}
|
|
848
894
|
async function createContext2({
|
|
849
895
|
rootDirectory,
|
|
850
|
-
watch: watch2
|
|
896
|
+
watch: watch2,
|
|
897
|
+
mode
|
|
851
898
|
}) {
|
|
852
|
-
const configLoader = await createConfigLoader({ rootDirectory, watch: watch2 });
|
|
899
|
+
const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
|
|
853
900
|
const configResult = await configLoader.getConfig();
|
|
854
901
|
if (!configResult.ok) {
|
|
855
902
|
throw new Error(configResult.error);
|
|
@@ -944,6 +991,7 @@ var init_typegen = __esm({
|
|
|
944
991
|
export const isSpaMode: ServerBuild["isSpaMode"];
|
|
945
992
|
export const prerender: ServerBuild["prerender"];
|
|
946
993
|
export const publicPath: ServerBuild["publicPath"];
|
|
994
|
+
export const routeDiscovery: ServerBuild["routeDiscovery"];
|
|
947
995
|
export const routes: ServerBuild["routes"];
|
|
948
996
|
export const ssr: ServerBuild["ssr"];
|
|
949
997
|
export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
|
|
@@ -1268,8 +1316,9 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
1268
1316
|
""
|
|
1269
1317
|
) : null;
|
|
1270
1318
|
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
1319
|
+
let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
|
|
1271
1320
|
return path7.posix.join(
|
|
1272
|
-
|
|
1321
|
+
assetsDir,
|
|
1273
1322
|
`[name]${routeChunkSuffix}-[hash].js`
|
|
1274
1323
|
);
|
|
1275
1324
|
}
|
|
@@ -1423,7 +1472,10 @@ __export(build_exports, {
|
|
|
1423
1472
|
async function build(root, viteBuildOptions) {
|
|
1424
1473
|
await preloadVite();
|
|
1425
1474
|
let vite2 = getVite();
|
|
1426
|
-
let configResult = await loadConfig({
|
|
1475
|
+
let configResult = await loadConfig({
|
|
1476
|
+
rootDirectory: root,
|
|
1477
|
+
mode: viteBuildOptions.mode ?? "production"
|
|
1478
|
+
});
|
|
1427
1479
|
if (!configResult.ok) {
|
|
1428
1480
|
throw new Error(configResult.error);
|
|
1429
1481
|
}
|
|
@@ -1751,7 +1803,10 @@ init_typegen();
|
|
|
1751
1803
|
init_vite();
|
|
1752
1804
|
async function routes(rootDirectory, flags = {}) {
|
|
1753
1805
|
rootDirectory = resolveRootDirectory(rootDirectory, flags);
|
|
1754
|
-
let configResult = await loadConfig({
|
|
1806
|
+
let configResult = await loadConfig({
|
|
1807
|
+
rootDirectory,
|
|
1808
|
+
mode: flags.mode ?? "production"
|
|
1809
|
+
});
|
|
1755
1810
|
if (!configResult.ok) {
|
|
1756
1811
|
console.error(import_picocolors7.default.red(configResult.error));
|
|
1757
1812
|
process.exit(1);
|
|
@@ -1796,7 +1851,10 @@ async function generateEntry(entry, rootDirectory, flags = {}) {
|
|
|
1796
1851
|
return;
|
|
1797
1852
|
}
|
|
1798
1853
|
rootDirectory = resolveRootDirectory(rootDirectory, flags);
|
|
1799
|
-
let configResult = await loadConfig({
|
|
1854
|
+
let configResult = await loadConfig({
|
|
1855
|
+
rootDirectory,
|
|
1856
|
+
mode: flags.mode ?? "production"
|
|
1857
|
+
});
|
|
1800
1858
|
if (!configResult.ok) {
|
|
1801
1859
|
console.error(import_picocolors7.default.red(configResult.error));
|
|
1802
1860
|
return;
|
|
@@ -1884,12 +1942,17 @@ async function typegen(root, flags) {
|
|
|
1884
1942
|
await preloadVite();
|
|
1885
1943
|
const vite2 = getVite();
|
|
1886
1944
|
const logger = vite2.createLogger("info", { prefix: "[react-router]" });
|
|
1887
|
-
await watch(root, {
|
|
1945
|
+
await watch(root, {
|
|
1946
|
+
mode: flags.mode ?? "development",
|
|
1947
|
+
logger
|
|
1948
|
+
});
|
|
1888
1949
|
await new Promise(() => {
|
|
1889
1950
|
});
|
|
1890
1951
|
return;
|
|
1891
1952
|
}
|
|
1892
|
-
await run(root
|
|
1953
|
+
await run(root, {
|
|
1954
|
+
mode: flags.mode ?? "production"
|
|
1955
|
+
});
|
|
1893
1956
|
}
|
|
1894
1957
|
|
|
1895
1958
|
// cli/run.ts
|
package/dist/config.d.ts
CHANGED
|
@@ -102,6 +102,22 @@ 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
|
+
};
|
|
105
121
|
/**
|
|
106
122
|
* The file name of the server build output. This file
|
|
107
123
|
* should end in a `.js` extension and should be deployed to your server.
|
|
@@ -148,6 +164,17 @@ type ResolvedReactRouterConfig = Readonly<{
|
|
|
148
164
|
* function returning an array to dynamically generate URLs.
|
|
149
165
|
*/
|
|
150
166
|
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"];
|
|
151
178
|
/**
|
|
152
179
|
* An object of all available routes, keyed by route id.
|
|
153
180
|
*/
|
package/dist/config.js
CHANGED
package/dist/routes.js
CHANGED
package/dist/vite/cloudflare.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-b2bc694a6
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -113,7 +113,9 @@ function fromNodeRequest(nodeReq, nodeRes) {
|
|
|
113
113
|
}
|
|
114
114
|
async function toNodeRequest(res, nodeRes) {
|
|
115
115
|
nodeRes.statusCode = res.status;
|
|
116
|
-
nodeRes.
|
|
116
|
+
if (!nodeRes.req || nodeRes.req.httpVersionMajor < 2) {
|
|
117
|
+
nodeRes.statusMessage = res.statusText;
|
|
118
|
+
}
|
|
117
119
|
let cookiesStrings = [];
|
|
118
120
|
for (let [name, value] of res.headers) {
|
|
119
121
|
if (name === "set-cookie") {
|
|
@@ -213,6 +215,15 @@ async function createContext({
|
|
|
213
215
|
optimizeDeps: {
|
|
214
216
|
noDiscovery: true
|
|
215
217
|
},
|
|
218
|
+
css: {
|
|
219
|
+
// This empty PostCSS config object prevents the PostCSS config file from
|
|
220
|
+
// being loaded. We don't need it in a React Router config context, and
|
|
221
|
+
// there's also an issue in Vite 5 when using a .ts PostCSS config file in
|
|
222
|
+
// an ESM project: https://github.com/vitejs/vite/issues/15869. Consumers
|
|
223
|
+
// can work around this in their own Vite config file, but they can't
|
|
224
|
+
// configure this internal usage of vite-node.
|
|
225
|
+
postcss: {}
|
|
226
|
+
},
|
|
216
227
|
configFile: false,
|
|
217
228
|
envFile: false,
|
|
218
229
|
plugins: []
|
|
@@ -432,12 +443,17 @@ async function resolveConfig({
|
|
|
432
443
|
serverModuleFormat: "esm",
|
|
433
444
|
ssr: true
|
|
434
445
|
};
|
|
446
|
+
let userAndPresetConfigs = mergeReactRouterConfig(
|
|
447
|
+
...presets,
|
|
448
|
+
reactRouterUserConfig
|
|
449
|
+
);
|
|
435
450
|
let {
|
|
436
451
|
appDirectory: userAppDirectory,
|
|
437
452
|
basename,
|
|
438
453
|
buildDirectory: userBuildDirectory,
|
|
439
454
|
buildEnd,
|
|
440
455
|
prerender,
|
|
456
|
+
routeDiscovery: userRouteDiscovery,
|
|
441
457
|
serverBuildFile,
|
|
442
458
|
serverBundles,
|
|
443
459
|
serverModuleFormat,
|
|
@@ -445,7 +461,7 @@ async function resolveConfig({
|
|
|
445
461
|
} = {
|
|
446
462
|
...defaults,
|
|
447
463
|
// Default values should be completely overridden by user/preset config, not merged
|
|
448
|
-
...
|
|
464
|
+
...userAndPresetConfigs
|
|
449
465
|
};
|
|
450
466
|
if (!ssr && serverBundles) {
|
|
451
467
|
serverBundles = void 0;
|
|
@@ -456,6 +472,32 @@ async function resolveConfig({
|
|
|
456
472
|
"The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
|
|
457
473
|
);
|
|
458
474
|
}
|
|
475
|
+
let routeDiscovery;
|
|
476
|
+
if (userRouteDiscovery == null) {
|
|
477
|
+
if (ssr) {
|
|
478
|
+
routeDiscovery = {
|
|
479
|
+
mode: "lazy",
|
|
480
|
+
manifestPath: "/__manifest"
|
|
481
|
+
};
|
|
482
|
+
} else {
|
|
483
|
+
routeDiscovery = { mode: "initial" };
|
|
484
|
+
}
|
|
485
|
+
} else if (userRouteDiscovery.mode === "initial") {
|
|
486
|
+
routeDiscovery = userRouteDiscovery;
|
|
487
|
+
} else if (userRouteDiscovery.mode === "lazy") {
|
|
488
|
+
if (!ssr) {
|
|
489
|
+
return err(
|
|
490
|
+
'The `routeDiscovery.mode` config cannot be set to "lazy" when setting `ssr:false`'
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
let { manifestPath } = userRouteDiscovery;
|
|
494
|
+
if (manifestPath != null && !manifestPath.startsWith("/")) {
|
|
495
|
+
return err(
|
|
496
|
+
'The `routeDiscovery.manifestPath` config must be a root-relative pathname beginning with a slash (i.e., "/__manifest")'
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
routeDiscovery = userRouteDiscovery;
|
|
500
|
+
}
|
|
459
501
|
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
460
502
|
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
461
503
|
let rootRouteFile = findEntry(appDirectory, "root");
|
|
@@ -523,6 +565,7 @@ async function resolveConfig({
|
|
|
523
565
|
future,
|
|
524
566
|
prerender,
|
|
525
567
|
routes,
|
|
568
|
+
routeDiscovery,
|
|
526
569
|
serverBuildFile,
|
|
527
570
|
serverBundles,
|
|
528
571
|
serverModuleFormat,
|
|
@@ -535,12 +578,13 @@ async function resolveConfig({
|
|
|
535
578
|
}
|
|
536
579
|
async function createConfigLoader({
|
|
537
580
|
rootDirectory: root,
|
|
538
|
-
watch
|
|
581
|
+
watch,
|
|
582
|
+
mode
|
|
539
583
|
}) {
|
|
540
584
|
root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
541
585
|
let viteNodeContext = await createContext({
|
|
542
586
|
root,
|
|
543
|
-
mode
|
|
587
|
+
mode
|
|
544
588
|
});
|
|
545
589
|
let reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
546
590
|
absolute: true
|
|
@@ -616,9 +660,13 @@ async function createConfigLoader({
|
|
|
616
660
|
}
|
|
617
661
|
};
|
|
618
662
|
}
|
|
619
|
-
async function loadConfig({
|
|
663
|
+
async function loadConfig({
|
|
664
|
+
rootDirectory,
|
|
665
|
+
mode
|
|
666
|
+
}) {
|
|
620
667
|
let configLoader = await createConfigLoader({
|
|
621
668
|
rootDirectory,
|
|
669
|
+
mode,
|
|
622
670
|
watch: false
|
|
623
671
|
});
|
|
624
672
|
let config = await configLoader.getConfig();
|
|
@@ -663,14 +711,15 @@ var cloudflareDevProxyVitePlugin = (options = {}) => {
|
|
|
663
711
|
let future;
|
|
664
712
|
return {
|
|
665
713
|
name: PLUGIN_NAME,
|
|
666
|
-
config: async (config) => {
|
|
714
|
+
config: async (config, configEnv) => {
|
|
667
715
|
await preloadVite();
|
|
668
716
|
const vite2 = getVite();
|
|
669
717
|
const serverConditions = [
|
|
670
718
|
...vite2.defaultServerConditions ?? []
|
|
671
719
|
];
|
|
672
720
|
let configResult = await loadConfig({
|
|
673
|
-
rootDirectory: config.root ?? process.cwd()
|
|
721
|
+
rootDirectory: config.root ?? process.cwd(),
|
|
722
|
+
mode: configEnv.mode
|
|
674
723
|
});
|
|
675
724
|
if (!configResult.ok) {
|
|
676
725
|
throw new Error(configResult.error);
|
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-b2bc694a6
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -154,6 +154,15 @@ async function createContext({
|
|
|
154
154
|
optimizeDeps: {
|
|
155
155
|
noDiscovery: true
|
|
156
156
|
},
|
|
157
|
+
css: {
|
|
158
|
+
// This empty PostCSS config object prevents the PostCSS config file from
|
|
159
|
+
// being loaded. We don't need it in a React Router config context, and
|
|
160
|
+
// there's also an issue in Vite 5 when using a .ts PostCSS config file in
|
|
161
|
+
// an ESM project: https://github.com/vitejs/vite/issues/15869. Consumers
|
|
162
|
+
// can work around this in their own Vite config file, but they can't
|
|
163
|
+
// configure this internal usage of vite-node.
|
|
164
|
+
postcss: {}
|
|
165
|
+
},
|
|
157
166
|
configFile: false,
|
|
158
167
|
envFile: false,
|
|
159
168
|
plugins: []
|
|
@@ -396,12 +405,17 @@ async function resolveConfig({
|
|
|
396
405
|
serverModuleFormat: "esm",
|
|
397
406
|
ssr: true
|
|
398
407
|
};
|
|
408
|
+
let userAndPresetConfigs = mergeReactRouterConfig(
|
|
409
|
+
...presets,
|
|
410
|
+
reactRouterUserConfig
|
|
411
|
+
);
|
|
399
412
|
let {
|
|
400
413
|
appDirectory: userAppDirectory,
|
|
401
414
|
basename: basename2,
|
|
402
415
|
buildDirectory: userBuildDirectory,
|
|
403
416
|
buildEnd,
|
|
404
417
|
prerender,
|
|
418
|
+
routeDiscovery: userRouteDiscovery,
|
|
405
419
|
serverBuildFile,
|
|
406
420
|
serverBundles,
|
|
407
421
|
serverModuleFormat,
|
|
@@ -409,7 +423,7 @@ async function resolveConfig({
|
|
|
409
423
|
} = {
|
|
410
424
|
...defaults,
|
|
411
425
|
// Default values should be completely overridden by user/preset config, not merged
|
|
412
|
-
...
|
|
426
|
+
...userAndPresetConfigs
|
|
413
427
|
};
|
|
414
428
|
if (!ssr && serverBundles) {
|
|
415
429
|
serverBundles = void 0;
|
|
@@ -420,6 +434,32 @@ async function resolveConfig({
|
|
|
420
434
|
"The `prerender` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths"
|
|
421
435
|
);
|
|
422
436
|
}
|
|
437
|
+
let routeDiscovery;
|
|
438
|
+
if (userRouteDiscovery == null) {
|
|
439
|
+
if (ssr) {
|
|
440
|
+
routeDiscovery = {
|
|
441
|
+
mode: "lazy",
|
|
442
|
+
manifestPath: "/__manifest"
|
|
443
|
+
};
|
|
444
|
+
} else {
|
|
445
|
+
routeDiscovery = { mode: "initial" };
|
|
446
|
+
}
|
|
447
|
+
} else if (userRouteDiscovery.mode === "initial") {
|
|
448
|
+
routeDiscovery = userRouteDiscovery;
|
|
449
|
+
} else if (userRouteDiscovery.mode === "lazy") {
|
|
450
|
+
if (!ssr) {
|
|
451
|
+
return err(
|
|
452
|
+
'The `routeDiscovery.mode` config cannot be set to "lazy" when setting `ssr:false`'
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
let { manifestPath } = userRouteDiscovery;
|
|
456
|
+
if (manifestPath != null && !manifestPath.startsWith("/")) {
|
|
457
|
+
return err(
|
|
458
|
+
'The `routeDiscovery.manifestPath` config must be a root-relative pathname beginning with a slash (i.e., "/__manifest")'
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
routeDiscovery = userRouteDiscovery;
|
|
462
|
+
}
|
|
423
463
|
let appDirectory = import_pathe3.default.resolve(root, userAppDirectory || "app");
|
|
424
464
|
let buildDirectory = import_pathe3.default.resolve(root, userBuildDirectory);
|
|
425
465
|
let rootRouteFile = findEntry(appDirectory, "root");
|
|
@@ -487,6 +527,7 @@ async function resolveConfig({
|
|
|
487
527
|
future,
|
|
488
528
|
prerender,
|
|
489
529
|
routes,
|
|
530
|
+
routeDiscovery,
|
|
490
531
|
serverBuildFile,
|
|
491
532
|
serverBundles,
|
|
492
533
|
serverModuleFormat,
|
|
@@ -499,12 +540,13 @@ async function resolveConfig({
|
|
|
499
540
|
}
|
|
500
541
|
async function createConfigLoader({
|
|
501
542
|
rootDirectory: root,
|
|
502
|
-
watch: watch2
|
|
543
|
+
watch: watch2,
|
|
544
|
+
mode
|
|
503
545
|
}) {
|
|
504
546
|
root = root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
505
547
|
let viteNodeContext = await createContext({
|
|
506
548
|
root,
|
|
507
|
-
mode
|
|
549
|
+
mode
|
|
508
550
|
});
|
|
509
551
|
let reactRouterConfigFile = findEntry(root, "react-router.config", {
|
|
510
552
|
absolute: true
|
|
@@ -800,8 +842,8 @@ function formatParamProperties(fullpath2) {
|
|
|
800
842
|
}
|
|
801
843
|
|
|
802
844
|
// typegen/index.ts
|
|
803
|
-
async function watch(rootDirectory, { logger }
|
|
804
|
-
const ctx = await createContext2({ rootDirectory, watch: true });
|
|
845
|
+
async function watch(rootDirectory, { mode, logger }) {
|
|
846
|
+
const ctx = await createContext2({ rootDirectory, mode, watch: true });
|
|
805
847
|
await writeAll(ctx);
|
|
806
848
|
logger?.info(import_picocolors2.default.green("generated types"), { timestamp: true, clear: true });
|
|
807
849
|
ctx.configLoader.onChange(async ({ result, routeConfigChanged }) => {
|
|
@@ -824,9 +866,10 @@ async function watch(rootDirectory, { logger } = {}) {
|
|
|
824
866
|
}
|
|
825
867
|
async function createContext2({
|
|
826
868
|
rootDirectory,
|
|
827
|
-
watch: watch2
|
|
869
|
+
watch: watch2,
|
|
870
|
+
mode
|
|
828
871
|
}) {
|
|
829
|
-
const configLoader = await createConfigLoader({ rootDirectory, watch: watch2 });
|
|
872
|
+
const configLoader = await createConfigLoader({ rootDirectory, mode, watch: watch2 });
|
|
830
873
|
const configResult = await configLoader.getConfig();
|
|
831
874
|
if (!configResult.ok) {
|
|
832
875
|
throw new Error(configResult.error);
|
|
@@ -907,6 +950,7 @@ var virtual = import_dedent2.default`
|
|
|
907
950
|
export const isSpaMode: ServerBuild["isSpaMode"];
|
|
908
951
|
export const prerender: ServerBuild["prerender"];
|
|
909
952
|
export const publicPath: ServerBuild["publicPath"];
|
|
953
|
+
export const routeDiscovery: ServerBuild["routeDiscovery"];
|
|
910
954
|
export const routes: ServerBuild["routes"];
|
|
911
955
|
export const ssr: ServerBuild["ssr"];
|
|
912
956
|
export const unstable_getCriticalCss: ServerBuild["unstable_getCriticalCss"];
|
|
@@ -967,7 +1011,9 @@ function fromNodeRequest(nodeReq, nodeRes) {
|
|
|
967
1011
|
}
|
|
968
1012
|
async function toNodeRequest(res, nodeRes) {
|
|
969
1013
|
nodeRes.statusCode = res.status;
|
|
970
|
-
nodeRes.
|
|
1014
|
+
if (!nodeRes.req || nodeRes.req.httpVersionMajor < 2) {
|
|
1015
|
+
nodeRes.statusMessage = res.statusText;
|
|
1016
|
+
}
|
|
971
1017
|
let cookiesStrings = [];
|
|
972
1018
|
for (let [name, value] of res.headers) {
|
|
973
1019
|
if (name === "set-cookie") {
|
|
@@ -2376,6 +2422,9 @@ var reactRouterVitePlugin = () => {
|
|
|
2376
2422
|
export const ssr = ${ctx.reactRouterConfig.ssr};
|
|
2377
2423
|
export const isSpaMode = ${isSpaMode};
|
|
2378
2424
|
export const prerender = ${JSON.stringify(prerenderPaths)};
|
|
2425
|
+
export const routeDiscovery = ${JSON.stringify(
|
|
2426
|
+
ctx.reactRouterConfig.routeDiscovery
|
|
2427
|
+
)};
|
|
2379
2428
|
export const publicPath = ${JSON.stringify(ctx.publicPath)};
|
|
2380
2429
|
export const entry = { module: entryServer };
|
|
2381
2430
|
export const routes = {
|
|
@@ -2709,14 +2758,17 @@ var reactRouterVitePlugin = () => {
|
|
|
2709
2758
|
prefix: "[react-router]"
|
|
2710
2759
|
});
|
|
2711
2760
|
rootDirectory = viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
2761
|
+
let mode = viteConfigEnv.mode;
|
|
2712
2762
|
if (viteCommand === "serve") {
|
|
2713
2763
|
typegenWatcherPromise = watch(rootDirectory, {
|
|
2764
|
+
mode,
|
|
2714
2765
|
// ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
|
|
2715
2766
|
logger: vite2.createLogger("warn", { prefix: "[react-router]" })
|
|
2716
2767
|
});
|
|
2717
2768
|
}
|
|
2718
2769
|
reactRouterConfigLoader = await createConfigLoader({
|
|
2719
2770
|
rootDirectory,
|
|
2771
|
+
mode,
|
|
2720
2772
|
watch: viteCommand === "serve"
|
|
2721
2773
|
});
|
|
2722
2774
|
await updatePluginContext();
|
|
@@ -4393,8 +4445,9 @@ async function getEnvironmentOptionsResolvers(ctx, viteCommand) {
|
|
|
4393
4445
|
""
|
|
4394
4446
|
) : null;
|
|
4395
4447
|
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
4448
|
+
let assetsDir = (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi ? viteUserConfig?.environments?.client?.build?.assetsDir : null) ?? viteUserConfig?.build?.assetsDir ?? "assets";
|
|
4396
4449
|
return path6.posix.join(
|
|
4397
|
-
|
|
4450
|
+
assetsDir,
|
|
4398
4451
|
`[name]${routeChunkSuffix}-[hash].js`
|
|
4399
4452
|
);
|
|
4400
4453
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-router/dev",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-b2bc694a6",
|
|
4
4
|
"description": "Dev tools and CLI for React Router",
|
|
5
5
|
"homepage": "https://reactrouter.com",
|
|
6
6
|
"bugs": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"set-cookie-parser": "^2.6.0",
|
|
87
87
|
"valibot": "^0.41.0",
|
|
88
88
|
"vite-node": "3.0.0-beta.2",
|
|
89
|
-
"@react-router/node": "0.0.0-experimental-
|
|
89
|
+
"@react-router/node": "0.0.0-experimental-b2bc694a6"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@types/babel__core": "^7.20.5",
|
|
@@ -110,15 +110,15 @@
|
|
|
110
110
|
"vite": "^6.1.0",
|
|
111
111
|
"wireit": "0.14.9",
|
|
112
112
|
"wrangler": "^4.2.0",
|
|
113
|
-
"
|
|
114
|
-
"react-router": "
|
|
113
|
+
"react-router": "^0.0.0-experimental-b2bc694a6",
|
|
114
|
+
"@react-router/serve": "0.0.0-experimental-b2bc694a6"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
117
|
"typescript": "^5.1.0",
|
|
118
118
|
"vite": "^5.1.0 || ^6.0.0",
|
|
119
119
|
"wrangler": "^3.28.2 || ^4.0.0",
|
|
120
|
-
"@react-router/serve": "^0.0.0-experimental-
|
|
121
|
-
"react-router": "^0.0.0-experimental-
|
|
120
|
+
"@react-router/serve": "^0.0.0-experimental-b2bc694a6",
|
|
121
|
+
"react-router": "^0.0.0-experimental-b2bc694a6"
|
|
122
122
|
},
|
|
123
123
|
"peerDependenciesMeta": {
|
|
124
124
|
"@react-router/serve": {
|