@react-router/dev 7.14.1 → 7.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/dist/cli/index.js +33 -15
- package/dist/config.d.ts +12 -4
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +32 -14
- package/dist/vite.js +554 -446
- package/package.json +6 -6
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v7.
|
|
2
|
+
* @react-router/dev v7.15.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -461,10 +461,15 @@ async function resolveConfig({
|
|
|
461
461
|
"The `prerender`/`prerender.paths` config must be a boolean, an array of string paths, or a function returning a boolean or array of string paths."
|
|
462
462
|
);
|
|
463
463
|
}
|
|
464
|
-
|
|
464
|
+
if (typeof prerender2 === "object" && "unstable_concurrency" in prerender2) {
|
|
465
|
+
return err(
|
|
466
|
+
"The `prerender.unstable_concurrency` config field has been stabilized as `prerender.concurrency`"
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
let isValidConcurrencyConfig = typeof prerender2 != "object" || !("concurrency" in prerender2) || typeof prerender2.concurrency === "number" && Number.isInteger(prerender2.concurrency) && prerender2.concurrency > 0;
|
|
465
470
|
if (!isValidConcurrencyConfig) {
|
|
466
471
|
return err(
|
|
467
|
-
"The `prerender.
|
|
472
|
+
"The `prerender.concurrency` config must be a positive integer if specified."
|
|
468
473
|
);
|
|
469
474
|
}
|
|
470
475
|
}
|
|
@@ -556,20 +561,31 @@ async function resolveConfig({
|
|
|
556
561
|
}
|
|
557
562
|
}
|
|
558
563
|
let futureConfig = userAndPresetConfigs.future;
|
|
559
|
-
if (futureConfig
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
564
|
+
if (futureConfig) {
|
|
565
|
+
if ("unstable_splitRouteModules" in futureConfig) {
|
|
566
|
+
return err(
|
|
567
|
+
"The `future.unstable_splitRouteModules` flag has been stabilized as `future.v8_splitRouteModules`"
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
if ("unstable_viteEnvironmentApi" in futureConfig) {
|
|
571
|
+
return err(
|
|
572
|
+
"The `future.unstable_viteEnvironmentApi` flag has been stabilized as `future.v8_viteEnvironmentApi`"
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
if ("unstable_passThroughRequests" in futureConfig) {
|
|
576
|
+
return err(
|
|
577
|
+
"The `future.unstable_passThroughRequests` flag has been stabilized as `future.v8_passThroughRequests`"
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
if ("unstable_subResourceIntegrity" in futureConfig) {
|
|
581
|
+
return err(
|
|
582
|
+
"The `future.unstable_subResourceIntegrity` flag has been stabilized and moved to a top-level `config.subResourceIntegrity` field"
|
|
583
|
+
);
|
|
584
|
+
}
|
|
568
585
|
}
|
|
569
586
|
let future = {
|
|
570
587
|
unstable_optimizeDeps: userAndPresetConfigs.future?.unstable_optimizeDeps ?? false,
|
|
571
|
-
|
|
572
|
-
unstable_subResourceIntegrity: userAndPresetConfigs.future?.unstable_subResourceIntegrity ?? false,
|
|
588
|
+
v8_passThroughRequests: userAndPresetConfigs.future?.v8_passThroughRequests ?? false,
|
|
573
589
|
unstable_trailingSlashAwareDataRequests: userAndPresetConfigs.future?.unstable_trailingSlashAwareDataRequests ?? false,
|
|
574
590
|
unstable_previewServerPrerendering: userAndPresetConfigs.future?.unstable_previewServerPrerendering ?? false,
|
|
575
591
|
v8_middleware: userAndPresetConfigs.future?.v8_middleware ?? false,
|
|
@@ -577,6 +593,7 @@ async function resolveConfig({
|
|
|
577
593
|
v8_viteEnvironmentApi: (userAndPresetConfigs.future?.v8_viteEnvironmentApi || userAndPresetConfigs.future?.unstable_previewServerPrerendering) ?? false
|
|
578
594
|
};
|
|
579
595
|
let allowedActionOrigins = userAndPresetConfigs.allowedActionOrigins ?? false;
|
|
596
|
+
let subResourceIntegrity = userAndPresetConfigs.subResourceIntegrity ?? false;
|
|
580
597
|
let reactRouterConfig = deepFreeze({
|
|
581
598
|
appDirectory,
|
|
582
599
|
basename: basename3,
|
|
@@ -590,6 +607,7 @@ async function resolveConfig({
|
|
|
590
607
|
serverBundles,
|
|
591
608
|
serverModuleFormat,
|
|
592
609
|
ssr,
|
|
610
|
+
subResourceIntegrity,
|
|
593
611
|
allowedActionOrigins,
|
|
594
612
|
unstable_routeConfig: routeConfig
|
|
595
613
|
});
|
|
@@ -1096,7 +1114,7 @@ function routeFilesType({
|
|
|
1096
1114
|
t2.tsPropertySignature(
|
|
1097
1115
|
t2.identifier("page"),
|
|
1098
1116
|
t2.tsTypeAnnotation(
|
|
1099
|
-
pages ? t2.tsUnionType(
|
|
1117
|
+
pages.size > 0 ? t2.tsUnionType(
|
|
1100
1118
|
Array.from(pages).map(
|
|
1101
1119
|
(page) => t2.tsLiteralType(t2.stringLiteral(page))
|
|
1102
1120
|
)
|
|
@@ -3354,7 +3372,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3354
3372
|
)};`
|
|
3355
3373
|
);
|
|
3356
3374
|
let sri = void 0;
|
|
3357
|
-
if (ctx.reactRouterConfig.
|
|
3375
|
+
if (ctx.reactRouterConfig.subResourceIntegrity) {
|
|
3358
3376
|
sri = await generateSriManifest(ctx);
|
|
3359
3377
|
}
|
|
3360
3378
|
let reactRouterServerManifest = {
|
|
@@ -4928,8 +4946,8 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4928
4946
|
};
|
|
4929
4947
|
let concurrency = 1;
|
|
4930
4948
|
let { prerender: prerender2 } = reactRouterConfig;
|
|
4931
|
-
if (typeof prerender2 === "object" && "
|
|
4932
|
-
concurrency = prerender2.
|
|
4949
|
+
if (typeof prerender2 === "object" && "concurrency" in prerender2) {
|
|
4950
|
+
concurrency = prerender2.concurrency ?? 1;
|
|
4933
4951
|
}
|
|
4934
4952
|
const pMap = await import("p-map");
|
|
4935
4953
|
await pMap.default(build.prerender, prerenderSinglePath, { concurrency });
|
|
@@ -5611,8 +5629,8 @@ function assertPrerenderPathsMatchRoutes(config, prerenderPaths) {
|
|
|
5611
5629
|
function getPrerenderConcurrencyConfig(reactRouterConfig) {
|
|
5612
5630
|
let concurrency = 1;
|
|
5613
5631
|
let { prerender: prerender2 } = reactRouterConfig;
|
|
5614
|
-
if (typeof prerender2 === "object" && "
|
|
5615
|
-
concurrency = prerender2.
|
|
5632
|
+
if (typeof prerender2 === "object" && "concurrency" in prerender2) {
|
|
5633
|
+
concurrency = prerender2.concurrency ?? 1;
|
|
5616
5634
|
}
|
|
5617
5635
|
return concurrency;
|
|
5618
5636
|
}
|
|
@@ -5677,7 +5695,6 @@ function escapeHtml(html) {
|
|
|
5677
5695
|
// vite/rsc/plugin.ts
|
|
5678
5696
|
var import_es_module_lexer3 = require("es-module-lexer");
|
|
5679
5697
|
var Path5 = __toESM(require("pathe"));
|
|
5680
|
-
var babel2 = __toESM(require("@babel/core"));
|
|
5681
5698
|
var import_picocolors5 = __toESM(require("picocolors"));
|
|
5682
5699
|
var import_fs = require("fs");
|
|
5683
5700
|
var import_promises4 = require("fs/promises");
|
|
@@ -5685,12 +5702,91 @@ var import_pathe6 = __toESM(require("pathe"));
|
|
|
5685
5702
|
|
|
5686
5703
|
// vite/rsc/virtual-route-config.ts
|
|
5687
5704
|
var import_pathe5 = __toESM(require("pathe"));
|
|
5705
|
+
var js = String.raw;
|
|
5688
5706
|
function createVirtualRouteConfig({
|
|
5689
5707
|
appDirectory,
|
|
5690
5708
|
routeConfig
|
|
5691
5709
|
}) {
|
|
5692
5710
|
let routeIdByFile = /* @__PURE__ */ new Map();
|
|
5693
|
-
let code =
|
|
5711
|
+
let code = js`import * as React from "react";
|
|
5712
|
+
function frameworkRoute(lazy) {
|
|
5713
|
+
return async () => {
|
|
5714
|
+
const mod = await lazy();
|
|
5715
|
+
let Component;
|
|
5716
|
+
let Layout;
|
|
5717
|
+
let ErrorBoundary;
|
|
5718
|
+
let HydrateFallback;
|
|
5719
|
+
if ("default" in mod && mod.default) {
|
|
5720
|
+
if ("ServerComponent" in mod && mod.ServerComponent) {
|
|
5721
|
+
throw new Error("Module cannot have both a default export and a ServerComponent export");
|
|
5722
|
+
}
|
|
5723
|
+
Component = mod.default;
|
|
5724
|
+
} else if ("ServerComponent" in mod && mod.ServerComponent) {
|
|
5725
|
+
Component = mod.ServerComponent;
|
|
5726
|
+
}
|
|
5727
|
+
if ("Layout" in mod && mod.Layout) {
|
|
5728
|
+
if ("ServerLayout" in mod && mod.ServerLayout) {
|
|
5729
|
+
throw new Error("Module cannot have both a Layout export and a ServerLayout export");
|
|
5730
|
+
}
|
|
5731
|
+
Layout = mod.Layout;
|
|
5732
|
+
} else if ("ServerLayout" in mod && mod.ServerLayout) {
|
|
5733
|
+
Layout = mod.ServerLayout;
|
|
5734
|
+
}
|
|
5735
|
+
if ("ErrorBoundary" in mod && mod.ErrorBoundary) {
|
|
5736
|
+
if ("ServerErrorBoundary" in mod && mod.ServerErrorBoundary) {
|
|
5737
|
+
throw new Error(
|
|
5738
|
+
"Module cannot have both an ErrorBoundary export and a ServerErrorBoundary export",
|
|
5739
|
+
);
|
|
5740
|
+
}
|
|
5741
|
+
ErrorBoundary = mod.ErrorBoundary;
|
|
5742
|
+
} else if ("ServerErrorBoundary" in mod && mod.ServerErrorBoundary) {
|
|
5743
|
+
ErrorBoundary = mod.ServerErrorBoundary;
|
|
5744
|
+
}
|
|
5745
|
+
if ("HydrateFallback" in mod && mod.HydrateFallback) {
|
|
5746
|
+
if ("ServerHydrateFallback" in mod && mod.ServerHydrateFallback) {
|
|
5747
|
+
throw new Error(
|
|
5748
|
+
"Module cannot have both a HydrateFallback export and a ServerHydrateFallback export",
|
|
5749
|
+
);
|
|
5750
|
+
}
|
|
5751
|
+
HydrateFallback = mod.HydrateFallback;
|
|
5752
|
+
} else if ("ServerHydrateFallback" in mod && mod.ServerHydrateFallback) {
|
|
5753
|
+
HydrateFallback = mod.ServerHydrateFallback;
|
|
5754
|
+
}
|
|
5755
|
+
|
|
5756
|
+
const {
|
|
5757
|
+
action,
|
|
5758
|
+
clientAction,
|
|
5759
|
+
clientLoader,
|
|
5760
|
+
clientMiddleware,
|
|
5761
|
+
handle,
|
|
5762
|
+
headers,
|
|
5763
|
+
links,
|
|
5764
|
+
loader,
|
|
5765
|
+
meta,
|
|
5766
|
+
middleware,
|
|
5767
|
+
shouldRevalidate,
|
|
5768
|
+
} = mod;
|
|
5769
|
+
|
|
5770
|
+
return {
|
|
5771
|
+
Component,
|
|
5772
|
+
ErrorBoundary,
|
|
5773
|
+
HydrateFallback,
|
|
5774
|
+
Layout,
|
|
5775
|
+
action,
|
|
5776
|
+
clientAction,
|
|
5777
|
+
clientLoader,
|
|
5778
|
+
clientMiddleware,
|
|
5779
|
+
handle,
|
|
5780
|
+
headers,
|
|
5781
|
+
links,
|
|
5782
|
+
loader,
|
|
5783
|
+
meta,
|
|
5784
|
+
middleware,
|
|
5785
|
+
shouldRevalidate,
|
|
5786
|
+
};
|
|
5787
|
+
};
|
|
5788
|
+
}
|
|
5789
|
+
export default [`;
|
|
5694
5790
|
const closeRouteSymbol = Symbol("CLOSE_ROUTE");
|
|
5695
5791
|
let stack = [
|
|
5696
5792
|
...routeConfig
|
|
@@ -5706,9 +5802,9 @@ function createVirtualRouteConfig({
|
|
|
5706
5802
|
const routeFile = import_pathe5.default.resolve(appDirectory, route.file);
|
|
5707
5803
|
const routeId = route.id || createRouteId2(route.file, appDirectory);
|
|
5708
5804
|
routeIdByFile.set(routeFile, routeId);
|
|
5709
|
-
code += `lazy: () => import(${JSON.stringify(
|
|
5710
|
-
`${routeFile}
|
|
5711
|
-
)}),`;
|
|
5805
|
+
code += `lazy: frameworkRoute(() => import(${JSON.stringify(
|
|
5806
|
+
`${routeFile}`
|
|
5807
|
+
)})),`;
|
|
5712
5808
|
code += `id: ${JSON.stringify(routeId)},`;
|
|
5713
5809
|
if (typeof route.path === "string") {
|
|
5714
5810
|
code += `path: ${JSON.stringify(route.path)},`;
|
|
@@ -5736,227 +5832,282 @@ function createRouteId2(file, appDirectory) {
|
|
|
5736
5832
|
|
|
5737
5833
|
// vite/rsc/virtual-route-modules.ts
|
|
5738
5834
|
var import_es_module_lexer2 = require("es-module-lexer");
|
|
5739
|
-
var
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
...SERVER_COMPONENT_EXPORTS,
|
|
5751
|
-
"loader",
|
|
5752
|
-
"action",
|
|
5753
|
-
"middleware",
|
|
5754
|
-
"headers"
|
|
5755
|
-
];
|
|
5756
|
-
var SERVER_ROUTE_EXPORTS_SET = new Set(SERVER_ROUTE_EXPORTS);
|
|
5757
|
-
function isServerRouteExport(name) {
|
|
5758
|
-
return SERVER_ROUTE_EXPORTS_SET.has(name);
|
|
5759
|
-
}
|
|
5760
|
-
var CLIENT_NON_COMPONENT_EXPORTS2 = [
|
|
5761
|
-
"clientAction",
|
|
5762
|
-
"clientLoader",
|
|
5763
|
-
"clientMiddleware",
|
|
5764
|
-
"handle",
|
|
5765
|
-
"meta",
|
|
5766
|
-
"links",
|
|
5767
|
-
"shouldRevalidate"
|
|
5768
|
-
];
|
|
5769
|
-
var CLIENT_ROUTE_EXPORTS2 = [
|
|
5770
|
-
...CLIENT_NON_COMPONENT_EXPORTS2,
|
|
5771
|
-
"default",
|
|
5772
|
-
"ErrorBoundary",
|
|
5773
|
-
"HydrateFallback",
|
|
5774
|
-
"Layout"
|
|
5775
|
-
];
|
|
5776
|
-
var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS2);
|
|
5777
|
-
function isClientRouteExport(name) {
|
|
5778
|
-
return CLIENT_ROUTE_EXPORTS_SET.has(name);
|
|
5779
|
-
}
|
|
5780
|
-
var mutuallyExclusiveRouteExports = /* @__PURE__ */ new Map([
|
|
5781
|
-
["ErrorBoundary", "ServerErrorBoundary"],
|
|
5782
|
-
["HydrateFallback", "ServerHydrateFallback"],
|
|
5783
|
-
["Layout", "ServerLayout"],
|
|
5784
|
-
["default", "ServerComponent"]
|
|
5785
|
-
]);
|
|
5786
|
-
var ROUTE_EXPORTS = [
|
|
5787
|
-
...SERVER_ROUTE_EXPORTS,
|
|
5788
|
-
...CLIENT_ROUTE_EXPORTS2
|
|
5789
|
-
];
|
|
5790
|
-
var ROUTE_EXPORTS_SET = new Set(ROUTE_EXPORTS);
|
|
5791
|
-
function isRouteExport(name) {
|
|
5792
|
-
return ROUTE_EXPORTS_SET.has(name);
|
|
5793
|
-
}
|
|
5794
|
-
function isCustomRouteExport(name) {
|
|
5795
|
-
return !isRouteExport(name);
|
|
5796
|
-
}
|
|
5797
|
-
function hasReactServerCondition(viteEnvironment) {
|
|
5798
|
-
return viteEnvironment.config.resolve.conditions.includes("react-server");
|
|
5799
|
-
}
|
|
5800
|
-
function transformVirtualRouteModules({
|
|
5801
|
-
id,
|
|
5802
|
-
code,
|
|
5803
|
-
viteCommand,
|
|
5804
|
-
routeIdByFile,
|
|
5805
|
-
rootRouteFile,
|
|
5806
|
-
viteEnvironment
|
|
5807
|
-
}) {
|
|
5808
|
-
if (isVirtualRouteModuleId(id) || routeIdByFile.has(id)) {
|
|
5809
|
-
return createVirtualRouteModuleCode({
|
|
5810
|
-
id,
|
|
5811
|
-
code,
|
|
5812
|
-
rootRouteFile,
|
|
5813
|
-
viteCommand,
|
|
5814
|
-
viteEnvironment
|
|
5815
|
-
});
|
|
5816
|
-
}
|
|
5817
|
-
if (isVirtualServerRouteModuleId(id)) {
|
|
5818
|
-
return createVirtualServerRouteModuleCode({
|
|
5819
|
-
id,
|
|
5820
|
-
code,
|
|
5821
|
-
viteEnvironment
|
|
5822
|
-
});
|
|
5823
|
-
}
|
|
5824
|
-
if (isVirtualClientRouteModuleId(id)) {
|
|
5825
|
-
return createVirtualClientRouteModuleCode({
|
|
5826
|
-
id,
|
|
5827
|
-
code,
|
|
5828
|
-
rootRouteFile,
|
|
5829
|
-
viteCommand
|
|
5830
|
-
});
|
|
5831
|
-
}
|
|
5832
|
-
}
|
|
5833
|
-
async function createVirtualRouteModuleCode({
|
|
5834
|
-
id,
|
|
5835
|
-
code: routeSource,
|
|
5836
|
-
rootRouteFile,
|
|
5837
|
-
viteCommand,
|
|
5838
|
-
viteEnvironment
|
|
5835
|
+
var ENSURE_CLIENT_ROUTE_MODULE_CHUNK_FOR_HMR = `
|
|
5836
|
+
import * as ___EnsureClientRouteModuleForHMR_REACT___ from "react";
|
|
5837
|
+
export function EnsureClientRouteModuleForHMR___() { return ___EnsureClientRouteModuleForHMR_REACT___.createElement(___EnsureClientRouteModuleForHMR_REACT___.Fragment, null) }
|
|
5838
|
+
`;
|
|
5839
|
+
function virtualRouteModulesPlugin({
|
|
5840
|
+
enforceSplitRouteModules,
|
|
5841
|
+
environments: { client = ["client", "ssr"], server = ["rsc"] } = {},
|
|
5842
|
+
getRouteIdForFile,
|
|
5843
|
+
isRootRouteModule,
|
|
5844
|
+
transformToJs,
|
|
5845
|
+
shouldTransform
|
|
5839
5846
|
}) {
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5847
|
+
let clientEnvironments = new Set(client);
|
|
5848
|
+
let serverEnvironments = new Set(server);
|
|
5849
|
+
let cache = /* @__PURE__ */ new Map();
|
|
5850
|
+
async function createClientRouteEntry(id, code, isRootRouteModule2, routeId) {
|
|
5851
|
+
let result = "";
|
|
5852
|
+
let routeChunks = detectRouteChunks2(cache, id, code, isRootRouteModule2);
|
|
5853
|
+
let { staticExports } = await parseRouteExports(code);
|
|
5854
|
+
validateRouteModuleExports(staticExports);
|
|
5855
|
+
let needsReactImport = false;
|
|
5856
|
+
for (let exportName of staticExports) {
|
|
5857
|
+
if (isServerRouteExport(exportName)) {
|
|
5858
|
+
continue;
|
|
5849
5859
|
}
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5860
|
+
if ((exportName === "clientAction" || exportName === "clientLoader") && routeChunks.hasRouteChunkByExportName[exportName]) {
|
|
5861
|
+
result += `export const ${exportName} = async (...args) => import("${createId(id, "client-route-module", exportName)}").then(mod => mod.${exportName}(...args));
|
|
5862
|
+
`;
|
|
5863
|
+
} else if (exportName === "HydrateFallback") {
|
|
5864
|
+
needsReactImport = true;
|
|
5865
|
+
result += `export const ${exportName} = React.lazy(() => import("${createId(
|
|
5866
|
+
id,
|
|
5867
|
+
"client-route-module",
|
|
5868
|
+
routeChunks.hasRouteChunkByExportName[exportName] ? exportName : "shared"
|
|
5869
|
+
)}").then(mod => ({ default: mod.${exportName} })));
|
|
5870
|
+
`;
|
|
5871
|
+
} else {
|
|
5872
|
+
result += `export { ${exportName} } from "${createId(
|
|
5873
|
+
id,
|
|
5874
|
+
"client-route-module",
|
|
5875
|
+
routeChunks.hasRouteChunkByExportName[exportName] ? exportName : "shared"
|
|
5876
|
+
)}";
|
|
5857
5877
|
`;
|
|
5878
|
+
}
|
|
5879
|
+
}
|
|
5880
|
+
if (needsReactImport) {
|
|
5881
|
+
result = `import * as React from "react";
|
|
5882
|
+
${result}`;
|
|
5883
|
+
}
|
|
5884
|
+
if (enforceSplitRouteModules() && !isRootRouteModule2) {
|
|
5885
|
+
let { hasRouteChunkByExportName } = routeChunks;
|
|
5886
|
+
let hasClientAction = staticExports.includes("clientAction");
|
|
5887
|
+
let hasClientLoader = staticExports.includes("clientLoader");
|
|
5888
|
+
let hasClientMiddleware = staticExports.includes("clientMiddleware");
|
|
5889
|
+
let hasHydrateFallback = staticExports.includes("HydrateFallback");
|
|
5890
|
+
validateRouteChunks2({
|
|
5891
|
+
id: routeId,
|
|
5892
|
+
valid: {
|
|
5893
|
+
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
5894
|
+
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
5895
|
+
clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.clientMiddleware,
|
|
5896
|
+
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
5897
|
+
}
|
|
5898
|
+
});
|
|
5899
|
+
}
|
|
5900
|
+
return {
|
|
5901
|
+
code: '"use client";\n' + result
|
|
5902
|
+
};
|
|
5858
5903
|
}
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5904
|
+
async function createServerRouteEntry(id, code, isRootRouteModule2, routeId) {
|
|
5905
|
+
let result = "";
|
|
5906
|
+
let routeChunks = detectRouteChunks2(cache, id, code, isRootRouteModule2);
|
|
5907
|
+
let { staticExports } = await parseRouteExports(code);
|
|
5908
|
+
validateRouteModuleExports(staticExports);
|
|
5909
|
+
let needsReactImport = false;
|
|
5910
|
+
for (let exportName of staticExports) {
|
|
5911
|
+
if (isClientRouteExport(exportName)) {
|
|
5912
|
+
result += `export { ${exportName} } from "${createId(
|
|
5913
|
+
id,
|
|
5914
|
+
"client-route-module",
|
|
5915
|
+
routeChunks.hasRouteChunkByExportName[exportName] ? exportName : "shared"
|
|
5916
|
+
)}";
|
|
5862
5917
|
`;
|
|
5863
|
-
|
|
5918
|
+
} else if (isServerComponentExport(exportName)) {
|
|
5919
|
+
needsReactImport = true;
|
|
5920
|
+
result += `import { ${exportName} as ${exportName}WithoutCss } from "${createId(id, "server-route-module")}";
|
|
5864
5921
|
`;
|
|
5865
|
-
|
|
5922
|
+
result += `export function ${exportName}(props) {
|
|
5866
5923
|
`;
|
|
5867
|
-
|
|
5924
|
+
result += ` return React.createElement(React.Fragment, null,
|
|
5868
5925
|
`;
|
|
5869
|
-
|
|
5926
|
+
result += ` import.meta.viteRsc.loadCss(),
|
|
5870
5927
|
`;
|
|
5871
|
-
|
|
5928
|
+
result += ` React.createElement(EnsureClientRouteModuleForHMR___, null),
|
|
5872
5929
|
`;
|
|
5873
|
-
|
|
5930
|
+
result += ` React.createElement(${exportName}WithoutCss, props),
|
|
5874
5931
|
`;
|
|
5875
|
-
|
|
5876
|
-
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5932
|
+
result += ` );
|
|
5877
5933
|
`;
|
|
5878
|
-
|
|
5879
|
-
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5934
|
+
result += `}
|
|
5880
5935
|
`;
|
|
5881
|
-
|
|
5882
|
-
|
|
5936
|
+
} else {
|
|
5937
|
+
result += `export { ${exportName} } from "${createId(id, "server-route-module")}";
|
|
5883
5938
|
`;
|
|
5939
|
+
}
|
|
5884
5940
|
}
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5941
|
+
if (needsReactImport) {
|
|
5942
|
+
result = `import * as React from "react";
|
|
5943
|
+
import { EnsureClientRouteModuleForHMR___ } from "${createId(id, "client-route-module", "shared")}";
|
|
5944
|
+
|
|
5945
|
+
${result}`;
|
|
5946
|
+
}
|
|
5947
|
+
if (isRootRouteModule2 && !staticExports.includes("ErrorBoundary") && !staticExports.includes("ServerErrorBoundary")) {
|
|
5948
|
+
result += `export { ErrorBoundary } from "${createId(id, "client-route-module", "shared")}";
|
|
5892
5949
|
`;
|
|
5950
|
+
}
|
|
5951
|
+
if (enforceSplitRouteModules() && !isRootRouteModule2) {
|
|
5952
|
+
let { hasRouteChunkByExportName } = routeChunks;
|
|
5953
|
+
let hasClientAction = staticExports.includes("clientAction");
|
|
5954
|
+
let hasClientLoader = staticExports.includes("clientLoader");
|
|
5955
|
+
let hasClientMiddleware = staticExports.includes("clientMiddleware");
|
|
5956
|
+
let hasHydrateFallback = staticExports.includes("HydrateFallback");
|
|
5957
|
+
validateRouteChunks2({
|
|
5958
|
+
id: routeId,
|
|
5959
|
+
valid: {
|
|
5960
|
+
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
5961
|
+
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
5962
|
+
clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.clientMiddleware,
|
|
5963
|
+
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
5964
|
+
}
|
|
5965
|
+
});
|
|
5966
|
+
}
|
|
5967
|
+
return {
|
|
5968
|
+
code: result
|
|
5969
|
+
};
|
|
5893
5970
|
}
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
}) {
|
|
5901
|
-
if (!hasReactServerCondition(viteEnvironment)) {
|
|
5902
|
-
throw new Error(
|
|
5903
|
-
[
|
|
5904
|
-
"Virtual server route module was loaded outside of the RSC environment.",
|
|
5905
|
-
`Environment Name: ${viteEnvironment.name}`,
|
|
5906
|
-
`Module ID: ${id}`
|
|
5907
|
-
].join("\n")
|
|
5908
|
-
);
|
|
5971
|
+
function createServerRouteModule(code) {
|
|
5972
|
+
const ast = import_parser.parse(code, {
|
|
5973
|
+
sourceType: "module"
|
|
5974
|
+
});
|
|
5975
|
+
removeExports(ast, CLIENT_ROUTE_EXPORTS2);
|
|
5976
|
+
return generate(ast);
|
|
5909
5977
|
}
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5978
|
+
async function createClientRouteModuleChunk(id, code, chunk, routeId, isRootRouteModule2, isDevMode) {
|
|
5979
|
+
let routeChunks = detectRouteChunks2(cache, id, code, isRootRouteModule2);
|
|
5980
|
+
const ast = import_parser.parse(code, {
|
|
5981
|
+
sourceType: "module"
|
|
5982
|
+
});
|
|
5983
|
+
const { staticExports } = await parseRouteExports(code);
|
|
5984
|
+
if (chunk === "shared") {
|
|
5985
|
+
removeExports(ast, [
|
|
5986
|
+
...SERVER_ROUTE_EXPORTS,
|
|
5987
|
+
...routeChunks.chunkedExports
|
|
5988
|
+
]);
|
|
5989
|
+
} else {
|
|
5990
|
+
const toRemove = /* @__PURE__ */ new Set([...SERVER_ROUTE_EXPORTS, ...staticExports]);
|
|
5991
|
+
toRemove.delete(chunk);
|
|
5992
|
+
removeExports(ast, Array.from(toRemove));
|
|
5922
5993
|
}
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
rootRouteFile,
|
|
5930
|
-
viteCommand
|
|
5931
|
-
}) {
|
|
5932
|
-
const { staticExports, hasClientExports } = parseRouteExports(routeSource);
|
|
5933
|
-
const clientRouteModuleAst = import_parser.parse(routeSource, {
|
|
5934
|
-
sourceType: "module"
|
|
5935
|
-
});
|
|
5936
|
-
removeExports(clientRouteModuleAst, SERVER_ROUTE_EXPORTS);
|
|
5937
|
-
const generatorResult = generate(clientRouteModuleAst);
|
|
5938
|
-
generatorResult.code = '"use client";' + generatorResult.code;
|
|
5939
|
-
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary") && !staticExports.includes("ServerErrorBoundary")) {
|
|
5940
|
-
const hasRootLayout = staticExports.includes("Layout");
|
|
5941
|
-
generatorResult.code += `
|
|
5994
|
+
const generated = generate(ast);
|
|
5995
|
+
let result = '"use client";\n' + generated.code;
|
|
5996
|
+
if (chunk === "shared") {
|
|
5997
|
+
if (isRootRouteModule2 && !staticExports.includes("ErrorBoundary") && !staticExports.includes("ServerErrorBoundary")) {
|
|
5998
|
+
const hasRootLayout = staticExports.includes("Layout") || staticExports.includes("ServerLayout");
|
|
5999
|
+
result += `
|
|
5942
6000
|
import { createElement as __rr_createElement } from "react";
|
|
5943
6001
|
`;
|
|
5944
|
-
|
|
6002
|
+
result += `import { UNSAFE_RSCDefaultRootErrorBoundary } from "react-router";
|
|
5945
6003
|
`;
|
|
5946
|
-
|
|
6004
|
+
result += `export function ErrorBoundary() {
|
|
5947
6005
|
`;
|
|
5948
|
-
|
|
6006
|
+
result += ` return __rr_createElement(UNSAFE_RSCDefaultRootErrorBoundary, { hasRootLayout: ${hasRootLayout} });
|
|
5949
6007
|
`;
|
|
5950
|
-
|
|
6008
|
+
result += `}
|
|
5951
6009
|
`;
|
|
6010
|
+
}
|
|
6011
|
+
result += ENSURE_CLIENT_ROUTE_MODULE_CHUNK_FOR_HMR;
|
|
6012
|
+
}
|
|
6013
|
+
let hasAction = staticExports.includes("action");
|
|
6014
|
+
let hasLoader = staticExports.includes("loader");
|
|
6015
|
+
let hasComponent = staticExports.includes("default") || staticExports.includes("ServerComponent");
|
|
6016
|
+
let hasErrorBoundary = staticExports.includes("ErrorBoundary") || staticExports.includes("ServerErrorBoundary");
|
|
6017
|
+
if (isDevMode) {
|
|
6018
|
+
result += `export function ReactRouterHMRMeta___() {return null;};
|
|
6019
|
+
`;
|
|
6020
|
+
result += `Object.assign(ReactRouterHMRMeta___, {
|
|
6021
|
+
hasAction: ${JSON.stringify(hasAction)},
|
|
6022
|
+
hasComponent: ${JSON.stringify(hasComponent)},
|
|
6023
|
+
hasErrorBoundary: ${JSON.stringify(hasErrorBoundary)},
|
|
6024
|
+
hasLoader: ${JSON.stringify(hasLoader)},
|
|
6025
|
+
hasClientLoader: ${JSON.stringify(staticExports.includes("clientLoader"))},
|
|
6026
|
+
});
|
|
6027
|
+
`;
|
|
6028
|
+
result += `
|
|
6029
|
+
if (import.meta.hot) {
|
|
6030
|
+
`;
|
|
6031
|
+
result += ` import.meta.hot.accept((mod) => {
|
|
6032
|
+
if (typeof __reactRouterDataRouter === "object") {
|
|
6033
|
+
__reactRouterDataRouter._updateRoutesForHMR(new Map([[${JSON.stringify(routeId)}, {
|
|
6034
|
+
routeModule: mod,
|
|
6035
|
+
...mod.ReactRouterHMRMeta___,
|
|
6036
|
+
}]]));
|
|
6037
|
+
|
|
6038
|
+
if (${chunk === "shared" ? "!mod.default || " : ""}mod.clientLoader || (
|
|
6039
|
+
mod.ReactRouterHMRMeta___.hasClientLoader || ReactRouterHMRMeta___.hasClientLoader || ReactRouterHMRMeta___.hasLoader
|
|
6040
|
+
)) {
|
|
6041
|
+
__reactRouterDataRouter.revalidate();
|
|
6042
|
+
}
|
|
6043
|
+
}
|
|
6044
|
+
});
|
|
6045
|
+
`;
|
|
6046
|
+
result += `}
|
|
6047
|
+
`;
|
|
6048
|
+
}
|
|
6049
|
+
return {
|
|
6050
|
+
code: result
|
|
6051
|
+
};
|
|
5952
6052
|
}
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
6053
|
+
return {
|
|
6054
|
+
name: "react-router-rsc-virtual-route-modules",
|
|
6055
|
+
enforce: "pre",
|
|
6056
|
+
async transform(_code, id) {
|
|
6057
|
+
const [filename2, ...rest] = id.split("?");
|
|
6058
|
+
const routeId = getRouteIdForFile(filename2);
|
|
6059
|
+
if (!routeId || shouldTransform && !shouldTransform?.(filename2)) {
|
|
6060
|
+
return;
|
|
6061
|
+
}
|
|
6062
|
+
let isClientEnvironment = clientEnvironments.has(this.environment.name);
|
|
6063
|
+
let isServerEnvironment = serverEnvironments.has(this.environment.name);
|
|
6064
|
+
if (!isClientEnvironment && !isServerEnvironment) {
|
|
6065
|
+
return;
|
|
6066
|
+
}
|
|
6067
|
+
let code = await transformToJs(_code, filename2);
|
|
6068
|
+
let searchParams = rest.length > 0 ? new URLSearchParams(rest.join("?")) : null;
|
|
6069
|
+
let clientRouteModuleType = searchParams?.get("client-route-module");
|
|
6070
|
+
let isServerRouteModule = searchParams?.has("server-route-module");
|
|
6071
|
+
if (clientRouteModuleType) {
|
|
6072
|
+
return await createClientRouteModuleChunk(
|
|
6073
|
+
id,
|
|
6074
|
+
code,
|
|
6075
|
+
clientRouteModuleType,
|
|
6076
|
+
routeId,
|
|
6077
|
+
isRootRouteModule(filename2),
|
|
6078
|
+
this.environment.mode === "dev"
|
|
6079
|
+
);
|
|
6080
|
+
}
|
|
6081
|
+
if (isServerRouteModule) {
|
|
6082
|
+
return createServerRouteModule(code);
|
|
6083
|
+
}
|
|
6084
|
+
if (isClientEnvironment) {
|
|
6085
|
+
return await createClientRouteEntry(
|
|
6086
|
+
id,
|
|
6087
|
+
code,
|
|
6088
|
+
isRootRouteModule(filename2),
|
|
6089
|
+
routeId
|
|
6090
|
+
);
|
|
6091
|
+
}
|
|
6092
|
+
return await createServerRouteEntry(
|
|
6093
|
+
id,
|
|
6094
|
+
code,
|
|
6095
|
+
isRootRouteModule(filename2),
|
|
6096
|
+
routeId
|
|
6097
|
+
);
|
|
6098
|
+
}
|
|
6099
|
+
};
|
|
6100
|
+
}
|
|
6101
|
+
function createId(id, type, value) {
|
|
6102
|
+
let [base, ...rest] = id.split("?");
|
|
6103
|
+
const searchParams = new URLSearchParams(rest.join("?"));
|
|
6104
|
+
searchParams.delete("client-route-module");
|
|
6105
|
+
searchParams.delete("server-route-module");
|
|
6106
|
+
searchParams.set(type, value || "");
|
|
6107
|
+
return `${base}?${searchParams.toString()}`;
|
|
5958
6108
|
}
|
|
5959
|
-
function parseRouteExports(code) {
|
|
6109
|
+
async function parseRouteExports(code) {
|
|
6110
|
+
await import_es_module_lexer2.init;
|
|
5960
6111
|
const [, exportSpecifiers] = (0, import_es_module_lexer2.parse)(code);
|
|
5961
6112
|
const staticExports = exportSpecifiers.map(({ n: name }) => name);
|
|
5962
6113
|
return {
|
|
@@ -5964,27 +6115,115 @@ function parseRouteExports(code) {
|
|
|
5964
6115
|
hasClientExports: staticExports.some(isClientRouteExport)
|
|
5965
6116
|
};
|
|
5966
6117
|
}
|
|
5967
|
-
|
|
5968
|
-
|
|
6118
|
+
var CLIENT_NON_COMPONENT_EXPORTS2 = [
|
|
6119
|
+
"clientAction",
|
|
6120
|
+
"clientLoader",
|
|
6121
|
+
"clientMiddleware",
|
|
6122
|
+
"handle",
|
|
6123
|
+
"meta",
|
|
6124
|
+
"links",
|
|
6125
|
+
"shouldRevalidate"
|
|
6126
|
+
];
|
|
6127
|
+
var CLIENT_ROUTE_EXPORTS2 = [
|
|
6128
|
+
...CLIENT_NON_COMPONENT_EXPORTS2,
|
|
6129
|
+
"default",
|
|
6130
|
+
"ErrorBoundary",
|
|
6131
|
+
"HydrateFallback",
|
|
6132
|
+
"Layout"
|
|
6133
|
+
];
|
|
6134
|
+
var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS2);
|
|
6135
|
+
function isClientRouteExport(name) {
|
|
6136
|
+
return CLIENT_ROUTE_EXPORTS_SET.has(name);
|
|
5969
6137
|
}
|
|
5970
|
-
|
|
5971
|
-
|
|
6138
|
+
var SERVER_COMPONENT_EXPORTS = [
|
|
6139
|
+
"ServerComponent",
|
|
6140
|
+
"ServerLayout",
|
|
6141
|
+
"ServerHydrateFallback",
|
|
6142
|
+
"ServerErrorBoundary"
|
|
6143
|
+
];
|
|
6144
|
+
var SERVER_COMPONENT_EXPORTS_SET = new Set(SERVER_COMPONENT_EXPORTS);
|
|
6145
|
+
function isServerComponentExport(name) {
|
|
6146
|
+
return SERVER_COMPONENT_EXPORTS_SET.has(name);
|
|
5972
6147
|
}
|
|
5973
|
-
|
|
5974
|
-
|
|
6148
|
+
var SERVER_ROUTE_EXPORTS = [
|
|
6149
|
+
...SERVER_COMPONENT_EXPORTS,
|
|
6150
|
+
"loader",
|
|
6151
|
+
"action",
|
|
6152
|
+
"middleware",
|
|
6153
|
+
"headers"
|
|
6154
|
+
];
|
|
6155
|
+
var SERVER_ROUTE_EXPORTS_SET = new Set(SERVER_ROUTE_EXPORTS);
|
|
6156
|
+
function isServerRouteExport(name) {
|
|
6157
|
+
return SERVER_ROUTE_EXPORTS_SET.has(name);
|
|
5975
6158
|
}
|
|
5976
|
-
|
|
5977
|
-
|
|
6159
|
+
var CLIENT_MODULE_CHUNKS = /* @__PURE__ */ new Set([
|
|
6160
|
+
"clientAction",
|
|
6161
|
+
"clientLoader",
|
|
6162
|
+
"clientMiddleware",
|
|
6163
|
+
"HydrateFallback"
|
|
6164
|
+
]);
|
|
6165
|
+
var MUTUALLY_EXCLUSIVE_ROUTE_EXPORTS = /* @__PURE__ */ new Map([
|
|
6166
|
+
["ErrorBoundary", "ServerErrorBoundary"],
|
|
6167
|
+
["HydrateFallback", "ServerHydrateFallback"],
|
|
6168
|
+
["Layout", "ServerLayout"],
|
|
6169
|
+
["default", "ServerComponent"]
|
|
6170
|
+
]);
|
|
6171
|
+
function validateRouteModuleExports(toValidate) {
|
|
6172
|
+
let errors = [];
|
|
6173
|
+
for (let [clientExport, serverExport] of MUTUALLY_EXCLUSIVE_ROUTE_EXPORTS) {
|
|
6174
|
+
if (toValidate.includes(clientExport) && toValidate.includes(serverExport)) {
|
|
6175
|
+
errors.push([clientExport, serverExport]);
|
|
6176
|
+
}
|
|
6177
|
+
}
|
|
6178
|
+
if (errors.length > 0) {
|
|
6179
|
+
throw new Error(
|
|
6180
|
+
`Invalid route module exports. The following pairs of exports are mutually exclusive and cannot be exported from the same module:
|
|
6181
|
+
` + errors.map(
|
|
6182
|
+
([clientExport, serverExport]) => `- ${clientExport} and ${serverExport}`
|
|
6183
|
+
).join("\n")
|
|
6184
|
+
);
|
|
6185
|
+
}
|
|
5978
6186
|
}
|
|
5979
|
-
function
|
|
5980
|
-
|
|
6187
|
+
function detectRouteChunks2(cache, id, code, isRootRouteModule) {
|
|
6188
|
+
function noRouteChunks() {
|
|
6189
|
+
return {
|
|
6190
|
+
chunkedExports: [],
|
|
6191
|
+
hasRouteChunks: false,
|
|
6192
|
+
hasRouteChunkByExportName: {
|
|
6193
|
+
clientAction: false,
|
|
6194
|
+
clientLoader: false,
|
|
6195
|
+
clientMiddleware: false,
|
|
6196
|
+
HydrateFallback: false
|
|
6197
|
+
}
|
|
6198
|
+
};
|
|
6199
|
+
}
|
|
6200
|
+
if (isRootRouteModule) {
|
|
6201
|
+
return noRouteChunks();
|
|
6202
|
+
}
|
|
6203
|
+
if (!Array.from(CLIENT_MODULE_CHUNKS).some(
|
|
6204
|
+
(exportName) => code.includes(exportName)
|
|
6205
|
+
)) {
|
|
6206
|
+
return noRouteChunks();
|
|
6207
|
+
}
|
|
6208
|
+
let [filename2] = id.split("?");
|
|
6209
|
+
return detectRouteChunks(code, cache, filename2);
|
|
5981
6210
|
}
|
|
5982
|
-
function
|
|
6211
|
+
function validateRouteChunks2({
|
|
5983
6212
|
id,
|
|
5984
|
-
|
|
6213
|
+
valid
|
|
5985
6214
|
}) {
|
|
5986
|
-
|
|
5987
|
-
|
|
6215
|
+
let invalidChunks = Object.entries(valid).filter(([_, isValid]) => !isValid).map(([chunkName]) => chunkName);
|
|
6216
|
+
if (invalidChunks.length === 0) {
|
|
6217
|
+
return;
|
|
6218
|
+
}
|
|
6219
|
+
let plural = invalidChunks.length > 1;
|
|
6220
|
+
throw new Error(
|
|
6221
|
+
[
|
|
6222
|
+
`Error splitting route module: ${id}`,
|
|
6223
|
+
invalidChunks.map((name) => `- ${name}`).join("\n"),
|
|
6224
|
+
`${plural ? "These exports" : "This export"} could not be split into ${plural ? "their own chunks" : "its own chunk"} because ${plural ? "they share" : "it shares"} code with other exports. You should extract any shared code into its own module and then import it within the route module.`
|
|
6225
|
+
].join("\n\n")
|
|
6226
|
+
);
|
|
5988
6227
|
}
|
|
5989
6228
|
|
|
5990
6229
|
// vite/rsc/plugin.ts
|
|
@@ -6010,6 +6249,62 @@ function reactRouterRSCVitePlugin() {
|
|
|
6010
6249
|
newConfig.routes.root.file
|
|
6011
6250
|
);
|
|
6012
6251
|
}
|
|
6252
|
+
function isRootRouteModule(id) {
|
|
6253
|
+
return import_pathe6.default.normalize(id) === import_pathe6.default.normalize(rootRouteFile);
|
|
6254
|
+
}
|
|
6255
|
+
function getRouteIdForFile(file) {
|
|
6256
|
+
let normalizedFile = import_pathe6.default.normalize(file);
|
|
6257
|
+
let directMatch = routeIdByFile?.get(normalizedFile);
|
|
6258
|
+
if (directMatch) {
|
|
6259
|
+
return directMatch;
|
|
6260
|
+
}
|
|
6261
|
+
return Array.from(routeIdByFile ?? []).find(
|
|
6262
|
+
([routeFile]) => import_pathe6.default.normalize(routeFile).endsWith(normalizedFile)
|
|
6263
|
+
)?.[1];
|
|
6264
|
+
}
|
|
6265
|
+
function isMdxRouteModule(filename2) {
|
|
6266
|
+
let extension = import_pathe6.default.extname(filename2).toLowerCase();
|
|
6267
|
+
return extension === ".md" || extension === ".mdx";
|
|
6268
|
+
}
|
|
6269
|
+
function getTransformLanguage(filename2) {
|
|
6270
|
+
let extension = import_pathe6.default.extname(filename2).toLowerCase();
|
|
6271
|
+
switch (extension) {
|
|
6272
|
+
case ".ts":
|
|
6273
|
+
case ".cts":
|
|
6274
|
+
case ".mts":
|
|
6275
|
+
return "ts";
|
|
6276
|
+
case ".tsx":
|
|
6277
|
+
return "tsx";
|
|
6278
|
+
case ".js":
|
|
6279
|
+
case ".cjs":
|
|
6280
|
+
case ".mjs":
|
|
6281
|
+
case ".jsx":
|
|
6282
|
+
case ".md":
|
|
6283
|
+
case ".mdx":
|
|
6284
|
+
return "jsx";
|
|
6285
|
+
default:
|
|
6286
|
+
return void 0;
|
|
6287
|
+
}
|
|
6288
|
+
}
|
|
6289
|
+
async function transformToJs(code, filename2) {
|
|
6290
|
+
await preloadVite();
|
|
6291
|
+
let vite2 = getVite();
|
|
6292
|
+
let lang = getTransformLanguage(filename2);
|
|
6293
|
+
return ("transformWithOxc" in vite2 && typeof vite2.transformWithOxc === "function" ? await vite2.transformWithOxc(code, filename2, {
|
|
6294
|
+
lang,
|
|
6295
|
+
jsx: {
|
|
6296
|
+
runtime: "automatic",
|
|
6297
|
+
development: viteCommand !== "build",
|
|
6298
|
+
target: "esnext"
|
|
6299
|
+
}
|
|
6300
|
+
}) : await vite2.transformWithEsbuild(code, filename2, {
|
|
6301
|
+
loader: lang,
|
|
6302
|
+
target: "esnext",
|
|
6303
|
+
format: "esm",
|
|
6304
|
+
jsx: "automatic",
|
|
6305
|
+
jsxDev: viteCommand !== "build"
|
|
6306
|
+
})).code;
|
|
6307
|
+
}
|
|
6013
6308
|
return [
|
|
6014
6309
|
{
|
|
6015
6310
|
name: "react-router/rsc",
|
|
@@ -6035,12 +6330,10 @@ function reactRouterRSCVitePlugin() {
|
|
|
6035
6330
|
if (userConfig.serverBundles) errors.push("serverBundles");
|
|
6036
6331
|
if (userConfig.future?.v8_middleware === false)
|
|
6037
6332
|
errors.push("future.v8_middleware: false");
|
|
6038
|
-
if (userConfig.future?.v8_splitRouteModules)
|
|
6039
|
-
errors.push("future.v8_splitRouteModules");
|
|
6040
6333
|
if (userConfig.future?.v8_viteEnvironmentApi === false)
|
|
6041
6334
|
errors.push("future.v8_viteEnvironmentApi: false");
|
|
6042
|
-
if (userConfig.
|
|
6043
|
-
errors.push("
|
|
6335
|
+
if (userConfig.subResourceIntegrity)
|
|
6336
|
+
errors.push("subResourceIntegrity");
|
|
6044
6337
|
if (errors.length) {
|
|
6045
6338
|
return `RSC Framework Mode does not currently support the following React Router config:
|
|
6046
6339
|
${errors.map((x) => ` - ${x}`).join("\n")}
|
|
@@ -6199,27 +6492,6 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6199
6492
|
]
|
|
6200
6493
|
}
|
|
6201
6494
|
}
|
|
6202
|
-
},
|
|
6203
|
-
build: {
|
|
6204
|
-
rollupOptions: {
|
|
6205
|
-
// Copied from https://github.com/vitejs/vite-plugin-react/blob/c602225271d4acf462ba00f8d6d8a2e42492c5cd/packages/common/warning.ts
|
|
6206
|
-
onwarn(warning, defaultHandler) {
|
|
6207
|
-
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
|
|
6208
|
-
return;
|
|
6209
|
-
}
|
|
6210
|
-
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
|
6211
|
-
return;
|
|
6212
|
-
}
|
|
6213
|
-
if (viteUserConfig.build?.rollupOptions?.onwarn) {
|
|
6214
|
-
viteUserConfig.build.rollupOptions.onwarn(
|
|
6215
|
-
warning,
|
|
6216
|
-
defaultHandler
|
|
6217
|
-
);
|
|
6218
|
-
} else {
|
|
6219
|
-
defaultHandler(warning);
|
|
6220
|
-
}
|
|
6221
|
-
}
|
|
6222
|
-
}
|
|
6223
6495
|
}
|
|
6224
6496
|
};
|
|
6225
6497
|
},
|
|
@@ -6362,20 +6634,16 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6362
6634
|
}
|
|
6363
6635
|
}
|
|
6364
6636
|
},
|
|
6365
|
-
{
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
viteEnvironment: this.environment
|
|
6376
|
-
});
|
|
6377
|
-
}
|
|
6378
|
-
},
|
|
6637
|
+
virtualRouteModulesPlugin({
|
|
6638
|
+
environments: {
|
|
6639
|
+
client: ["client", "ssr"],
|
|
6640
|
+
server: ["rsc"]
|
|
6641
|
+
},
|
|
6642
|
+
getRouteIdForFile,
|
|
6643
|
+
isRootRouteModule,
|
|
6644
|
+
transformToJs,
|
|
6645
|
+
enforceSplitRouteModules: () => config.future.v8_splitRouteModules === "enforce"
|
|
6646
|
+
}),
|
|
6379
6647
|
{
|
|
6380
6648
|
name: "react-router/rsc/virtual-basename",
|
|
6381
6649
|
resolveId(id) {
|
|
@@ -6417,121 +6685,21 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6417
6685
|
async load(id) {
|
|
6418
6686
|
if (id !== virtual2.injectHmrRuntime.resolvedId) return;
|
|
6419
6687
|
return viteCommand === "serve" ? [
|
|
6420
|
-
`import
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6688
|
+
`if (import.meta.hot) {
|
|
6689
|
+
import.meta.hot.accept();
|
|
6690
|
+
import.meta.hot.on('rsc:update', () => {
|
|
6691
|
+
// Defer revalidation to the next animation frame so React Fast Refresh
|
|
6692
|
+
// can apply pending client component updates first. Without this delay,
|
|
6693
|
+
// the RSC payload (showing updated text) can arrive and be reconciled
|
|
6694
|
+
// against a DOM that still has the old text, causing a hydration mismatch.
|
|
6695
|
+
requestAnimationFrame(() => {
|
|
6696
|
+
__reactRouterDataRouter.revalidate()
|
|
6697
|
+
});
|
|
6698
|
+
})
|
|
6699
|
+
}`
|
|
6425
6700
|
].join("\n") : "";
|
|
6426
6701
|
}
|
|
6427
6702
|
},
|
|
6428
|
-
{
|
|
6429
|
-
name: "react-router/rsc/hmr/runtime",
|
|
6430
|
-
enforce: "pre",
|
|
6431
|
-
resolveId(id) {
|
|
6432
|
-
if (id === virtual2.hmrRuntime.id) return virtual2.hmrRuntime.resolvedId;
|
|
6433
|
-
},
|
|
6434
|
-
async load(id) {
|
|
6435
|
-
if (id !== virtual2.hmrRuntime.resolvedId) return;
|
|
6436
|
-
const reactRefreshDir = import_pathe6.default.dirname(
|
|
6437
|
-
require.resolve("react-refresh/package.json")
|
|
6438
|
-
);
|
|
6439
|
-
const reactRefreshRuntimePath = (0, import_pathe6.join)(
|
|
6440
|
-
reactRefreshDir,
|
|
6441
|
-
"cjs/react-refresh-runtime.development.js"
|
|
6442
|
-
);
|
|
6443
|
-
return [
|
|
6444
|
-
"const exports = {}",
|
|
6445
|
-
await (0, import_promises4.readFile)(reactRefreshRuntimePath, "utf8"),
|
|
6446
|
-
await (0, import_promises4.readFile)(
|
|
6447
|
-
require.resolve("./static/rsc-refresh-utils.mjs"),
|
|
6448
|
-
"utf8"
|
|
6449
|
-
),
|
|
6450
|
-
"export default exports"
|
|
6451
|
-
].join("\n");
|
|
6452
|
-
}
|
|
6453
|
-
},
|
|
6454
|
-
{
|
|
6455
|
-
name: "react-router/rsc/hmr/react-refresh",
|
|
6456
|
-
async transform(code, id, options) {
|
|
6457
|
-
if (viteCommand !== "serve") return;
|
|
6458
|
-
if (id.includes("/node_modules/")) return;
|
|
6459
|
-
const filepath = id.split("?")[0];
|
|
6460
|
-
const extensionsRE = /\.(jsx?|tsx?|mdx?)$/;
|
|
6461
|
-
if (!extensionsRE.test(filepath)) return;
|
|
6462
|
-
const devRuntime = "react/jsx-dev-runtime";
|
|
6463
|
-
const ssr = options?.ssr === true;
|
|
6464
|
-
const isJSX = filepath.endsWith("x");
|
|
6465
|
-
const useFastRefresh = !ssr && (isJSX || code.includes(devRuntime));
|
|
6466
|
-
if (!useFastRefresh) return;
|
|
6467
|
-
if (isVirtualClientRouteModuleId(id)) {
|
|
6468
|
-
const routeId = routeIdByFile?.get(filepath);
|
|
6469
|
-
return { code: addRefreshWrapper2({ routeId, code, id }) };
|
|
6470
|
-
}
|
|
6471
|
-
const result = await babel2.transformAsync(code, {
|
|
6472
|
-
babelrc: false,
|
|
6473
|
-
configFile: false,
|
|
6474
|
-
filename: id,
|
|
6475
|
-
sourceFileName: filepath,
|
|
6476
|
-
parserOpts: {
|
|
6477
|
-
sourceType: "module",
|
|
6478
|
-
allowAwaitOutsideFunction: true
|
|
6479
|
-
},
|
|
6480
|
-
plugins: [[require("react-refresh/babel"), { skipEnvCheck: true }]],
|
|
6481
|
-
sourceMaps: true
|
|
6482
|
-
});
|
|
6483
|
-
if (result === null) return;
|
|
6484
|
-
code = result.code;
|
|
6485
|
-
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
6486
|
-
if (refreshContentRE.test(code)) {
|
|
6487
|
-
code = addRefreshWrapper2({ code, id });
|
|
6488
|
-
}
|
|
6489
|
-
return { code, map: result.map };
|
|
6490
|
-
}
|
|
6491
|
-
},
|
|
6492
|
-
{
|
|
6493
|
-
name: "react-router/rsc/hmr/updates",
|
|
6494
|
-
async hotUpdate({ server, file, modules }) {
|
|
6495
|
-
if (this.environment.name !== "rsc") return;
|
|
6496
|
-
const clientModules = server.environments.client.moduleGraph.getModulesByFile(file);
|
|
6497
|
-
const vite2 = await import("vite");
|
|
6498
|
-
const isServerOnlyChange = !clientModules || clientModules.size === 0 || // Handle CSS injected from server-first routes (with ?direct query
|
|
6499
|
-
// string) since the client graph has a reference to the CSS
|
|
6500
|
-
vite2.isCSSRequest(file) && Array.from(clientModules).some(
|
|
6501
|
-
(mod) => mod.id?.includes("?direct")
|
|
6502
|
-
);
|
|
6503
|
-
for (const mod of getModulesWithImporters(modules)) {
|
|
6504
|
-
if (!mod.file) continue;
|
|
6505
|
-
const normalizedPath = import_pathe6.default.normalize(mod.file);
|
|
6506
|
-
const routeId = routeIdByFile?.get(normalizedPath);
|
|
6507
|
-
if (routeId !== void 0) {
|
|
6508
|
-
const routeSource = await (0, import_promises4.readFile)(normalizedPath, "utf8");
|
|
6509
|
-
const virtualRouteModuleCode = (await server.environments.rsc.pluginContainer.transform(
|
|
6510
|
-
routeSource,
|
|
6511
|
-
`${normalizedPath}?route-module`
|
|
6512
|
-
)).code;
|
|
6513
|
-
const { staticExports } = parseRouteExports(virtualRouteModuleCode);
|
|
6514
|
-
const hasAction = staticExports.includes("action");
|
|
6515
|
-
const hasComponent = staticExports.includes("default");
|
|
6516
|
-
const hasErrorBoundary = staticExports.includes("ErrorBoundary");
|
|
6517
|
-
const hasLoader = staticExports.includes("loader");
|
|
6518
|
-
server.hot.send({
|
|
6519
|
-
type: "custom",
|
|
6520
|
-
event: "react-router:hmr",
|
|
6521
|
-
data: {
|
|
6522
|
-
routeId,
|
|
6523
|
-
isServerOnlyChange,
|
|
6524
|
-
hasAction,
|
|
6525
|
-
hasComponent,
|
|
6526
|
-
hasErrorBoundary,
|
|
6527
|
-
hasLoader
|
|
6528
|
-
}
|
|
6529
|
-
});
|
|
6530
|
-
}
|
|
6531
|
-
}
|
|
6532
|
-
return modules;
|
|
6533
|
-
}
|
|
6534
|
-
},
|
|
6535
6703
|
{
|
|
6536
6704
|
name: "react-router/rsc/virtual-react-router-serve-config",
|
|
6537
6705
|
resolveId(id) {
|
|
@@ -6655,7 +6823,6 @@ var virtual2 = {
|
|
|
6655
6823
|
routeConfig: create("unstable_rsc/routes"),
|
|
6656
6824
|
routeDiscovery: create("unstable_rsc/route-discovery"),
|
|
6657
6825
|
injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
|
|
6658
|
-
hmrRuntime: create("unstable_rsc/runtime"),
|
|
6659
6826
|
basename: create("unstable_rsc/basename"),
|
|
6660
6827
|
reactRouterServeConfig: create("unstable_rsc/react-router-serve-config")
|
|
6661
6828
|
};
|
|
@@ -6672,71 +6839,12 @@ function invalidateVirtualModules2(viteDevServer) {
|
|
|
6672
6839
|
function getRootDirectory(viteUserConfig) {
|
|
6673
6840
|
return viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
6674
6841
|
}
|
|
6675
|
-
function getModulesWithImporters(modules) {
|
|
6676
|
-
const visited = /* @__PURE__ */ new Set();
|
|
6677
|
-
const result = /* @__PURE__ */ new Set();
|
|
6678
|
-
function walk(module2) {
|
|
6679
|
-
if (visited.has(module2)) return;
|
|
6680
|
-
visited.add(module2);
|
|
6681
|
-
result.add(module2);
|
|
6682
|
-
for (const importer of module2.importers) {
|
|
6683
|
-
walk(importer);
|
|
6684
|
-
}
|
|
6685
|
-
}
|
|
6686
|
-
for (const module2 of modules) {
|
|
6687
|
-
walk(module2);
|
|
6688
|
-
}
|
|
6689
|
-
return result;
|
|
6690
|
-
}
|
|
6691
|
-
function addRefreshWrapper2({
|
|
6692
|
-
routeId,
|
|
6693
|
-
code,
|
|
6694
|
-
id
|
|
6695
|
-
}) {
|
|
6696
|
-
const acceptExports = routeId !== void 0 ? CLIENT_NON_COMPONENT_EXPORTS2 : [];
|
|
6697
|
-
return REACT_REFRESH_HEADER2.replaceAll("__SOURCE__", JSON.stringify(id)) + code + REACT_REFRESH_FOOTER2.replaceAll("__SOURCE__", JSON.stringify(id)).replaceAll("__ACCEPT_EXPORTS__", JSON.stringify(acceptExports)).replaceAll("__ROUTE_ID__", JSON.stringify(routeId));
|
|
6698
|
-
}
|
|
6699
|
-
var REACT_REFRESH_HEADER2 = `
|
|
6700
|
-
import RefreshRuntime from "${virtual2.hmrRuntime.id}";
|
|
6701
|
-
|
|
6702
|
-
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
6703
|
-
let prevRefreshReg;
|
|
6704
|
-
let prevRefreshSig;
|
|
6705
|
-
|
|
6706
|
-
if (import.meta.hot && !inWebWorker) {
|
|
6707
|
-
if (!window.__vite_plugin_react_preamble_installed__) {
|
|
6708
|
-
throw new Error(
|
|
6709
|
-
"React Router Vite plugin can't detect preamble. Something is wrong."
|
|
6710
|
-
);
|
|
6711
|
-
}
|
|
6712
|
-
|
|
6713
|
-
prevRefreshReg = window.$RefreshReg$;
|
|
6714
|
-
prevRefreshSig = window.$RefreshSig$;
|
|
6715
|
-
window.$RefreshReg$ = (type, id) => {
|
|
6716
|
-
RefreshRuntime.register(type, __SOURCE__ + " " + id)
|
|
6717
|
-
};
|
|
6718
|
-
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
6719
|
-
}`.replaceAll("\n", "");
|
|
6720
|
-
var REACT_REFRESH_FOOTER2 = `
|
|
6721
|
-
if (import.meta.hot && !inWebWorker) {
|
|
6722
|
-
window.$RefreshReg$ = prevRefreshReg;
|
|
6723
|
-
window.$RefreshSig$ = prevRefreshSig;
|
|
6724
|
-
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
6725
|
-
RefreshRuntime.registerExportsForReactRefresh(__SOURCE__, currentExports);
|
|
6726
|
-
import.meta.hot.accept((nextExports) => {
|
|
6727
|
-
if (!nextExports) return;
|
|
6728
|
-
__ROUTE_ID__ && window.__reactRouterRouteModuleUpdates.set(__ROUTE_ID__, nextExports);
|
|
6729
|
-
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(currentExports, nextExports, __ACCEPT_EXPORTS__);
|
|
6730
|
-
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
6731
|
-
});
|
|
6732
|
-
});
|
|
6733
|
-
}`;
|
|
6734
6842
|
var getClientBuildDirectory2 = (reactRouterConfig) => import_pathe6.default.join(reactRouterConfig.buildDirectory, "client");
|
|
6735
6843
|
function getPrerenderConcurrencyConfig2(reactRouterConfig) {
|
|
6736
6844
|
let concurrency = 1;
|
|
6737
6845
|
let { prerender: prerender2 } = reactRouterConfig;
|
|
6738
|
-
if (typeof prerender2 === "object" && "
|
|
6739
|
-
concurrency = prerender2.
|
|
6846
|
+
if (typeof prerender2 === "object" && "concurrency" in prerender2) {
|
|
6847
|
+
concurrency = prerender2.concurrency ?? 1;
|
|
6740
6848
|
}
|
|
6741
6849
|
return concurrency;
|
|
6742
6850
|
}
|