@react-router/dev 0.0.0-experimental-689d76079 → 0.0.0-experimental-34996874d
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 +21 -0
- package/dist/cli/index.js +11 -5
- package/dist/config.d.ts +12 -4
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +11 -5
- package/dist/vite.js +532 -436
- package/package.json +6 -6
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-34996874d
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -461,10 +461,10 @@ 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
|
-
let isValidConcurrencyConfig = typeof prerender2 != "object" || !("
|
|
464
|
+
let isValidConcurrencyConfig = typeof prerender2 != "object" || !("concurrency" in prerender2) || typeof prerender2.concurrency === "number" && Number.isInteger(prerender2.concurrency) && prerender2.concurrency > 0;
|
|
465
465
|
if (!isValidConcurrencyConfig) {
|
|
466
466
|
return err(
|
|
467
|
-
"The `prerender.
|
|
467
|
+
"The `prerender.concurrency` config must be a positive integer if specified."
|
|
468
468
|
);
|
|
469
469
|
}
|
|
470
470
|
}
|
|
@@ -566,10 +566,14 @@ async function resolveConfig({
|
|
|
566
566
|
'The "future.unstable_viteEnvironmentApi" flag has been stabilized as "future.v8_viteEnvironmentApi"'
|
|
567
567
|
);
|
|
568
568
|
}
|
|
569
|
+
if (futureConfig?.unstable_passThroughRequests !== void 0) {
|
|
570
|
+
return err(
|
|
571
|
+
'The "future.unstable_passThroughRequests" flag has been stabilized as "future.v8_passThroughRequests"'
|
|
572
|
+
);
|
|
573
|
+
}
|
|
569
574
|
let future = {
|
|
570
575
|
unstable_optimizeDeps: userAndPresetConfigs.future?.unstable_optimizeDeps ?? false,
|
|
571
|
-
|
|
572
|
-
unstable_subResourceIntegrity: userAndPresetConfigs.future?.unstable_subResourceIntegrity ?? false,
|
|
576
|
+
v8_passThroughRequests: userAndPresetConfigs.future?.v8_passThroughRequests ?? false,
|
|
573
577
|
unstable_trailingSlashAwareDataRequests: userAndPresetConfigs.future?.unstable_trailingSlashAwareDataRequests ?? false,
|
|
574
578
|
unstable_previewServerPrerendering: userAndPresetConfigs.future?.unstable_previewServerPrerendering ?? false,
|
|
575
579
|
v8_middleware: userAndPresetConfigs.future?.v8_middleware ?? false,
|
|
@@ -577,6 +581,7 @@ async function resolveConfig({
|
|
|
577
581
|
v8_viteEnvironmentApi: (userAndPresetConfigs.future?.v8_viteEnvironmentApi || userAndPresetConfigs.future?.unstable_previewServerPrerendering) ?? false
|
|
578
582
|
};
|
|
579
583
|
let allowedActionOrigins = userAndPresetConfigs.allowedActionOrigins ?? false;
|
|
584
|
+
let subResourceIntegrity = userAndPresetConfigs.subResourceIntegrity ?? false;
|
|
580
585
|
let reactRouterConfig = deepFreeze({
|
|
581
586
|
appDirectory,
|
|
582
587
|
basename: basename3,
|
|
@@ -590,6 +595,7 @@ async function resolveConfig({
|
|
|
590
595
|
serverBundles,
|
|
591
596
|
serverModuleFormat,
|
|
592
597
|
ssr,
|
|
598
|
+
subResourceIntegrity,
|
|
593
599
|
allowedActionOrigins,
|
|
594
600
|
unstable_routeConfig: routeConfig
|
|
595
601
|
});
|
|
@@ -3354,7 +3360,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3354
3360
|
)};`
|
|
3355
3361
|
);
|
|
3356
3362
|
let sri = void 0;
|
|
3357
|
-
if (ctx.reactRouterConfig.
|
|
3363
|
+
if (ctx.reactRouterConfig.subResourceIntegrity) {
|
|
3358
3364
|
sri = await generateSriManifest(ctx);
|
|
3359
3365
|
}
|
|
3360
3366
|
let reactRouterServerManifest = {
|
|
@@ -4928,8 +4934,8 @@ async function handlePrerender(viteConfig, reactRouterConfig, serverBuildDirecto
|
|
|
4928
4934
|
};
|
|
4929
4935
|
let concurrency = 1;
|
|
4930
4936
|
let { prerender: prerender2 } = reactRouterConfig;
|
|
4931
|
-
if (typeof prerender2 === "object" && "
|
|
4932
|
-
concurrency = prerender2.
|
|
4937
|
+
if (typeof prerender2 === "object" && "concurrency" in prerender2) {
|
|
4938
|
+
concurrency = prerender2.concurrency ?? 1;
|
|
4933
4939
|
}
|
|
4934
4940
|
const pMap = await import("p-map");
|
|
4935
4941
|
await pMap.default(build.prerender, prerenderSinglePath, { concurrency });
|
|
@@ -5611,8 +5617,8 @@ function assertPrerenderPathsMatchRoutes(config, prerenderPaths) {
|
|
|
5611
5617
|
function getPrerenderConcurrencyConfig(reactRouterConfig) {
|
|
5612
5618
|
let concurrency = 1;
|
|
5613
5619
|
let { prerender: prerender2 } = reactRouterConfig;
|
|
5614
|
-
if (typeof prerender2 === "object" && "
|
|
5615
|
-
concurrency = prerender2.
|
|
5620
|
+
if (typeof prerender2 === "object" && "concurrency" in prerender2) {
|
|
5621
|
+
concurrency = prerender2.concurrency ?? 1;
|
|
5616
5622
|
}
|
|
5617
5623
|
return concurrency;
|
|
5618
5624
|
}
|
|
@@ -5677,7 +5683,6 @@ function escapeHtml(html) {
|
|
|
5677
5683
|
// vite/rsc/plugin.ts
|
|
5678
5684
|
var import_es_module_lexer3 = require("es-module-lexer");
|
|
5679
5685
|
var Path5 = __toESM(require("pathe"));
|
|
5680
|
-
var babel2 = __toESM(require("@babel/core"));
|
|
5681
5686
|
var import_picocolors5 = __toESM(require("picocolors"));
|
|
5682
5687
|
var import_fs = require("fs");
|
|
5683
5688
|
var import_promises4 = require("fs/promises");
|
|
@@ -5685,12 +5690,91 @@ var import_pathe6 = __toESM(require("pathe"));
|
|
|
5685
5690
|
|
|
5686
5691
|
// vite/rsc/virtual-route-config.ts
|
|
5687
5692
|
var import_pathe5 = __toESM(require("pathe"));
|
|
5693
|
+
var js = String.raw;
|
|
5688
5694
|
function createVirtualRouteConfig({
|
|
5689
5695
|
appDirectory,
|
|
5690
5696
|
routeConfig
|
|
5691
5697
|
}) {
|
|
5692
5698
|
let routeIdByFile = /* @__PURE__ */ new Map();
|
|
5693
|
-
let code =
|
|
5699
|
+
let code = js`import * as React from "react";
|
|
5700
|
+
function frameworkRoute(lazy) {
|
|
5701
|
+
return async () => {
|
|
5702
|
+
const mod = await lazy();
|
|
5703
|
+
let Component;
|
|
5704
|
+
let Layout;
|
|
5705
|
+
let ErrorBoundary;
|
|
5706
|
+
let HydrateFallback;
|
|
5707
|
+
if ("default" in mod && mod.default) {
|
|
5708
|
+
if ("ServerComponent" in mod && mod.ServerComponent) {
|
|
5709
|
+
throw new Error("Module cannot have both a default export and a ServerComponent export");
|
|
5710
|
+
}
|
|
5711
|
+
Component = mod.default;
|
|
5712
|
+
} else if ("ServerComponent" in mod && mod.ServerComponent) {
|
|
5713
|
+
Component = mod.ServerComponent;
|
|
5714
|
+
}
|
|
5715
|
+
if ("Layout" in mod && mod.Layout) {
|
|
5716
|
+
if ("ServerLayout" in mod && mod.ServerLayout) {
|
|
5717
|
+
throw new Error("Module cannot have both a Layout export and a ServerLayout export");
|
|
5718
|
+
}
|
|
5719
|
+
Layout = mod.Layout;
|
|
5720
|
+
} else if ("ServerLayout" in mod && mod.ServerLayout) {
|
|
5721
|
+
Layout = mod.ServerLayout;
|
|
5722
|
+
}
|
|
5723
|
+
if ("ErrorBoundary" in mod && mod.ErrorBoundary) {
|
|
5724
|
+
if ("ServerErrorBoundary" in mod && mod.ServerErrorBoundary) {
|
|
5725
|
+
throw new Error(
|
|
5726
|
+
"Module cannot have both an ErrorBoundary export and a ServerErrorBoundary export",
|
|
5727
|
+
);
|
|
5728
|
+
}
|
|
5729
|
+
ErrorBoundary = mod.ErrorBoundary;
|
|
5730
|
+
} else if ("ServerErrorBoundary" in mod && mod.ServerErrorBoundary) {
|
|
5731
|
+
ErrorBoundary = mod.ServerErrorBoundary;
|
|
5732
|
+
}
|
|
5733
|
+
if ("HydrateFallback" in mod && mod.HydrateFallback) {
|
|
5734
|
+
if ("ServerHydrateFallback" in mod && mod.ServerHydrateFallback) {
|
|
5735
|
+
throw new Error(
|
|
5736
|
+
"Module cannot have both a HydrateFallback export and a ServerHydrateFallback export",
|
|
5737
|
+
);
|
|
5738
|
+
}
|
|
5739
|
+
HydrateFallback = mod.HydrateFallback;
|
|
5740
|
+
} else if ("ServerHydrateFallback" in mod && mod.ServerHydrateFallback) {
|
|
5741
|
+
HydrateFallback = mod.ServerHydrateFallback;
|
|
5742
|
+
}
|
|
5743
|
+
|
|
5744
|
+
const {
|
|
5745
|
+
action,
|
|
5746
|
+
clientAction,
|
|
5747
|
+
clientLoader,
|
|
5748
|
+
clientMiddleware,
|
|
5749
|
+
handle,
|
|
5750
|
+
headers,
|
|
5751
|
+
links,
|
|
5752
|
+
loader,
|
|
5753
|
+
meta,
|
|
5754
|
+
middleware,
|
|
5755
|
+
shouldRevalidate,
|
|
5756
|
+
} = mod;
|
|
5757
|
+
|
|
5758
|
+
return {
|
|
5759
|
+
Component,
|
|
5760
|
+
ErrorBoundary,
|
|
5761
|
+
HydrateFallback,
|
|
5762
|
+
Layout,
|
|
5763
|
+
action,
|
|
5764
|
+
clientAction,
|
|
5765
|
+
clientLoader,
|
|
5766
|
+
clientMiddleware,
|
|
5767
|
+
handle,
|
|
5768
|
+
headers,
|
|
5769
|
+
links,
|
|
5770
|
+
loader,
|
|
5771
|
+
meta,
|
|
5772
|
+
middleware,
|
|
5773
|
+
shouldRevalidate,
|
|
5774
|
+
};
|
|
5775
|
+
};
|
|
5776
|
+
}
|
|
5777
|
+
export default [`;
|
|
5694
5778
|
const closeRouteSymbol = Symbol("CLOSE_ROUTE");
|
|
5695
5779
|
let stack = [
|
|
5696
5780
|
...routeConfig
|
|
@@ -5706,9 +5790,9 @@ function createVirtualRouteConfig({
|
|
|
5706
5790
|
const routeFile = import_pathe5.default.resolve(appDirectory, route.file);
|
|
5707
5791
|
const routeId = route.id || createRouteId2(route.file, appDirectory);
|
|
5708
5792
|
routeIdByFile.set(routeFile, routeId);
|
|
5709
|
-
code += `lazy: () => import(${JSON.stringify(
|
|
5710
|
-
`${routeFile}
|
|
5711
|
-
)}),`;
|
|
5793
|
+
code += `lazy: frameworkRoute(() => import(${JSON.stringify(
|
|
5794
|
+
`${routeFile}`
|
|
5795
|
+
)})),`;
|
|
5712
5796
|
code += `id: ${JSON.stringify(routeId)},`;
|
|
5713
5797
|
if (typeof route.path === "string") {
|
|
5714
5798
|
code += `path: ${JSON.stringify(route.path)},`;
|
|
@@ -5736,227 +5820,282 @@ function createRouteId2(file, appDirectory) {
|
|
|
5736
5820
|
|
|
5737
5821
|
// vite/rsc/virtual-route-modules.ts
|
|
5738
5822
|
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
|
|
5823
|
+
var ENSURE_CLIENT_ROUTE_MODULE_CHUNK_FOR_HMR = `
|
|
5824
|
+
import * as ___EnsureClientRouteModuleForHMR_REACT___ from "react";
|
|
5825
|
+
export function EnsureClientRouteModuleForHMR___() { return ___EnsureClientRouteModuleForHMR_REACT___.createElement(___EnsureClientRouteModuleForHMR_REACT___.Fragment, null) }
|
|
5826
|
+
`;
|
|
5827
|
+
function virtualRouteModulesPlugin({
|
|
5828
|
+
enforceSplitRouteModules,
|
|
5829
|
+
environments: { client = ["client", "ssr"], server = ["rsc"] } = {},
|
|
5830
|
+
getRouteIdForFile,
|
|
5831
|
+
isRootRouteModule,
|
|
5832
|
+
transformToJs,
|
|
5833
|
+
shouldTransform
|
|
5839
5834
|
}) {
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5835
|
+
let clientEnvironments = new Set(client);
|
|
5836
|
+
let serverEnvironments = new Set(server);
|
|
5837
|
+
let cache = /* @__PURE__ */ new Map();
|
|
5838
|
+
async function createClientRouteEntry(id, code, isRootRouteModule2, routeId) {
|
|
5839
|
+
let result = "";
|
|
5840
|
+
let routeChunks = detectRouteChunks2(cache, id, code, isRootRouteModule2);
|
|
5841
|
+
let { staticExports } = await parseRouteExports(code);
|
|
5842
|
+
validateRouteModuleExports(staticExports);
|
|
5843
|
+
let needsReactImport = false;
|
|
5844
|
+
for (let exportName of staticExports) {
|
|
5845
|
+
if (isServerRouteExport(exportName)) {
|
|
5846
|
+
continue;
|
|
5849
5847
|
}
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5848
|
+
if ((exportName === "clientAction" || exportName === "clientLoader") && routeChunks.hasRouteChunkByExportName[exportName]) {
|
|
5849
|
+
result += `export const ${exportName} = async (...args) => import("${createId(id, "client-route-module", exportName)}").then(mod => mod.${exportName}(...args));
|
|
5850
|
+
`;
|
|
5851
|
+
} else if (exportName === "HydrateFallback") {
|
|
5852
|
+
needsReactImport = true;
|
|
5853
|
+
result += `export const ${exportName} = React.lazy(() => import("${createId(
|
|
5854
|
+
id,
|
|
5855
|
+
"client-route-module",
|
|
5856
|
+
routeChunks.hasRouteChunkByExportName[exportName] ? exportName : "shared"
|
|
5857
|
+
)}").then(mod => ({ default: mod.${exportName} })));
|
|
5858
|
+
`;
|
|
5859
|
+
} else {
|
|
5860
|
+
result += `export { ${exportName} } from "${createId(
|
|
5861
|
+
id,
|
|
5862
|
+
"client-route-module",
|
|
5863
|
+
routeChunks.hasRouteChunkByExportName[exportName] ? exportName : "shared"
|
|
5864
|
+
)}";
|
|
5857
5865
|
`;
|
|
5866
|
+
}
|
|
5867
|
+
}
|
|
5868
|
+
if (needsReactImport) {
|
|
5869
|
+
result = `import * as React from "react";
|
|
5870
|
+
${result}`;
|
|
5871
|
+
}
|
|
5872
|
+
if (enforceSplitRouteModules() && !isRootRouteModule2) {
|
|
5873
|
+
let { hasRouteChunkByExportName } = routeChunks;
|
|
5874
|
+
let hasClientAction = staticExports.includes("clientAction");
|
|
5875
|
+
let hasClientLoader = staticExports.includes("clientLoader");
|
|
5876
|
+
let hasClientMiddleware = staticExports.includes("clientMiddleware");
|
|
5877
|
+
let hasHydrateFallback = staticExports.includes("HydrateFallback");
|
|
5878
|
+
validateRouteChunks2({
|
|
5879
|
+
id: routeId,
|
|
5880
|
+
valid: {
|
|
5881
|
+
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
5882
|
+
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
5883
|
+
clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.clientMiddleware,
|
|
5884
|
+
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
5885
|
+
}
|
|
5886
|
+
});
|
|
5887
|
+
}
|
|
5888
|
+
return {
|
|
5889
|
+
code: '"use client";\n' + result
|
|
5890
|
+
};
|
|
5858
5891
|
}
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5892
|
+
async function createServerRouteEntry(id, code, isRootRouteModule2, routeId) {
|
|
5893
|
+
let result = "";
|
|
5894
|
+
let routeChunks = detectRouteChunks2(cache, id, code, isRootRouteModule2);
|
|
5895
|
+
let { staticExports } = await parseRouteExports(code);
|
|
5896
|
+
validateRouteModuleExports(staticExports);
|
|
5897
|
+
let needsReactImport = false;
|
|
5898
|
+
for (let exportName of staticExports) {
|
|
5899
|
+
if (isClientRouteExport(exportName)) {
|
|
5900
|
+
result += `export { ${exportName} } from "${createId(
|
|
5901
|
+
id,
|
|
5902
|
+
"client-route-module",
|
|
5903
|
+
routeChunks.hasRouteChunkByExportName[exportName] ? exportName : "shared"
|
|
5904
|
+
)}";
|
|
5862
5905
|
`;
|
|
5863
|
-
|
|
5906
|
+
} else if (isServerComponentExport(exportName)) {
|
|
5907
|
+
needsReactImport = true;
|
|
5908
|
+
result += `import { ${exportName} as ${exportName}WithoutCss } from "${createId(id, "server-route-module")}";
|
|
5864
5909
|
`;
|
|
5865
|
-
|
|
5910
|
+
result += `export function ${exportName}(props) {
|
|
5866
5911
|
`;
|
|
5867
|
-
|
|
5912
|
+
result += ` return React.createElement(React.Fragment, null,
|
|
5868
5913
|
`;
|
|
5869
|
-
|
|
5914
|
+
result += ` import.meta.viteRsc.loadCss(),
|
|
5870
5915
|
`;
|
|
5871
|
-
|
|
5916
|
+
result += ` React.createElement(EnsureClientRouteModuleForHMR___, null),
|
|
5872
5917
|
`;
|
|
5873
|
-
|
|
5918
|
+
result += ` React.createElement(${exportName}WithoutCss, props),
|
|
5874
5919
|
`;
|
|
5875
|
-
|
|
5876
|
-
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5920
|
+
result += ` );
|
|
5877
5921
|
`;
|
|
5878
|
-
|
|
5879
|
-
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5922
|
+
result += `}
|
|
5880
5923
|
`;
|
|
5881
|
-
|
|
5882
|
-
|
|
5924
|
+
} else {
|
|
5925
|
+
result += `export { ${exportName} } from "${createId(id, "server-route-module")}";
|
|
5883
5926
|
`;
|
|
5927
|
+
}
|
|
5884
5928
|
}
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5929
|
+
if (needsReactImport) {
|
|
5930
|
+
result = `import * as React from "react";
|
|
5931
|
+
import { EnsureClientRouteModuleForHMR___ } from "${createId(id, "client-route-module", "shared")}";
|
|
5932
|
+
|
|
5933
|
+
${result}`;
|
|
5934
|
+
}
|
|
5935
|
+
if (isRootRouteModule2 && !staticExports.includes("ErrorBoundary") && !staticExports.includes("ServerErrorBoundary")) {
|
|
5936
|
+
result += `export { ErrorBoundary } from "${createId(id, "client-route-module", "shared")}";
|
|
5892
5937
|
`;
|
|
5938
|
+
}
|
|
5939
|
+
if (enforceSplitRouteModules() && !isRootRouteModule2) {
|
|
5940
|
+
let { hasRouteChunkByExportName } = routeChunks;
|
|
5941
|
+
let hasClientAction = staticExports.includes("clientAction");
|
|
5942
|
+
let hasClientLoader = staticExports.includes("clientLoader");
|
|
5943
|
+
let hasClientMiddleware = staticExports.includes("clientMiddleware");
|
|
5944
|
+
let hasHydrateFallback = staticExports.includes("HydrateFallback");
|
|
5945
|
+
validateRouteChunks2({
|
|
5946
|
+
id: routeId,
|
|
5947
|
+
valid: {
|
|
5948
|
+
clientAction: !hasClientAction || hasRouteChunkByExportName.clientAction,
|
|
5949
|
+
clientLoader: !hasClientLoader || hasRouteChunkByExportName.clientLoader,
|
|
5950
|
+
clientMiddleware: !hasClientMiddleware || hasRouteChunkByExportName.clientMiddleware,
|
|
5951
|
+
HydrateFallback: !hasHydrateFallback || hasRouteChunkByExportName.HydrateFallback
|
|
5952
|
+
}
|
|
5953
|
+
});
|
|
5954
|
+
}
|
|
5955
|
+
return {
|
|
5956
|
+
code: result
|
|
5957
|
+
};
|
|
5893
5958
|
}
|
|
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
|
-
);
|
|
5959
|
+
function createServerRouteModule(code) {
|
|
5960
|
+
const ast = import_parser.parse(code, {
|
|
5961
|
+
sourceType: "module"
|
|
5962
|
+
});
|
|
5963
|
+
removeExports(ast, CLIENT_ROUTE_EXPORTS2);
|
|
5964
|
+
return generate(ast);
|
|
5909
5965
|
}
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5966
|
+
async function createClientRouteModuleChunk(id, code, chunk, routeId, isRootRouteModule2, isDevMode) {
|
|
5967
|
+
let routeChunks = detectRouteChunks2(cache, id, code, isRootRouteModule2);
|
|
5968
|
+
const ast = import_parser.parse(code, {
|
|
5969
|
+
sourceType: "module"
|
|
5970
|
+
});
|
|
5971
|
+
const { staticExports } = await parseRouteExports(code);
|
|
5972
|
+
if (chunk === "shared") {
|
|
5973
|
+
removeExports(ast, [
|
|
5974
|
+
...SERVER_ROUTE_EXPORTS,
|
|
5975
|
+
...routeChunks.chunkedExports
|
|
5976
|
+
]);
|
|
5977
|
+
} else {
|
|
5978
|
+
const toRemove = /* @__PURE__ */ new Set([...SERVER_ROUTE_EXPORTS, ...staticExports]);
|
|
5979
|
+
toRemove.delete(chunk);
|
|
5980
|
+
removeExports(ast, Array.from(toRemove));
|
|
5922
5981
|
}
|
|
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 += `
|
|
5982
|
+
const generated = generate(ast);
|
|
5983
|
+
let result = '"use client";\n' + generated.code;
|
|
5984
|
+
if (chunk === "shared") {
|
|
5985
|
+
if (isRootRouteModule2 && !staticExports.includes("ErrorBoundary") && !staticExports.includes("ServerErrorBoundary")) {
|
|
5986
|
+
const hasRootLayout = staticExports.includes("Layout") || staticExports.includes("ServerLayout");
|
|
5987
|
+
result += `
|
|
5942
5988
|
import { createElement as __rr_createElement } from "react";
|
|
5943
5989
|
`;
|
|
5944
|
-
|
|
5990
|
+
result += `import { UNSAFE_RSCDefaultRootErrorBoundary } from "react-router";
|
|
5945
5991
|
`;
|
|
5946
|
-
|
|
5992
|
+
result += `export function ErrorBoundary() {
|
|
5947
5993
|
`;
|
|
5948
|
-
|
|
5994
|
+
result += ` return __rr_createElement(UNSAFE_RSCDefaultRootErrorBoundary, { hasRootLayout: ${hasRootLayout} });
|
|
5949
5995
|
`;
|
|
5950
|
-
|
|
5996
|
+
result += `}
|
|
5951
5997
|
`;
|
|
5998
|
+
}
|
|
5999
|
+
result += ENSURE_CLIENT_ROUTE_MODULE_CHUNK_FOR_HMR;
|
|
6000
|
+
}
|
|
6001
|
+
let hasAction = staticExports.includes("action");
|
|
6002
|
+
let hasLoader = staticExports.includes("loader");
|
|
6003
|
+
let hasComponent = staticExports.includes("default") || staticExports.includes("ServerComponent");
|
|
6004
|
+
let hasErrorBoundary = staticExports.includes("ErrorBoundary") || staticExports.includes("ServerErrorBoundary");
|
|
6005
|
+
if (isDevMode) {
|
|
6006
|
+
result += `export function ReactRouterHMRMeta___() {return null;};
|
|
6007
|
+
`;
|
|
6008
|
+
result += `Object.assign(ReactRouterHMRMeta___, {
|
|
6009
|
+
hasAction: ${JSON.stringify(hasAction)},
|
|
6010
|
+
hasComponent: ${JSON.stringify(hasComponent)},
|
|
6011
|
+
hasErrorBoundary: ${JSON.stringify(hasErrorBoundary)},
|
|
6012
|
+
hasLoader: ${JSON.stringify(hasLoader)},
|
|
6013
|
+
hasClientLoader: ${JSON.stringify(staticExports.includes("clientLoader"))},
|
|
6014
|
+
});
|
|
6015
|
+
`;
|
|
6016
|
+
result += `
|
|
6017
|
+
if (import.meta.hot) {
|
|
6018
|
+
`;
|
|
6019
|
+
result += ` import.meta.hot.accept((mod) => {
|
|
6020
|
+
if (typeof __reactRouterDataRouter === "object") {
|
|
6021
|
+
__reactRouterDataRouter._updateRoutesForHMR(new Map([[${JSON.stringify(routeId)}, {
|
|
6022
|
+
routeModule: mod,
|
|
6023
|
+
...mod.ReactRouterHMRMeta___,
|
|
6024
|
+
}]]));
|
|
6025
|
+
|
|
6026
|
+
if (${chunk === "shared" ? "!mod.default || " : ""}mod.clientLoader || (
|
|
6027
|
+
mod.ReactRouterHMRMeta___.hasClientLoader || ReactRouterHMRMeta___.hasClientLoader || ReactRouterHMRMeta___.hasLoader
|
|
6028
|
+
)) {
|
|
6029
|
+
__reactRouterDataRouter.revalidate();
|
|
6030
|
+
}
|
|
6031
|
+
}
|
|
6032
|
+
});
|
|
6033
|
+
`;
|
|
6034
|
+
result += `}
|
|
6035
|
+
`;
|
|
6036
|
+
}
|
|
6037
|
+
return {
|
|
6038
|
+
code: result
|
|
6039
|
+
};
|
|
5952
6040
|
}
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
6041
|
+
return {
|
|
6042
|
+
name: "react-router-rsc-virtual-route-modules",
|
|
6043
|
+
enforce: "pre",
|
|
6044
|
+
async transform(_code, id) {
|
|
6045
|
+
const [filename2, ...rest] = id.split("?");
|
|
6046
|
+
const routeId = getRouteIdForFile(filename2);
|
|
6047
|
+
if (!routeId || shouldTransform && !shouldTransform?.(filename2)) {
|
|
6048
|
+
return;
|
|
6049
|
+
}
|
|
6050
|
+
let isClientEnvironment = clientEnvironments.has(this.environment.name);
|
|
6051
|
+
let isServerEnvironment = serverEnvironments.has(this.environment.name);
|
|
6052
|
+
if (!isClientEnvironment && !isServerEnvironment) {
|
|
6053
|
+
return;
|
|
6054
|
+
}
|
|
6055
|
+
let code = await transformToJs(_code, filename2);
|
|
6056
|
+
let searchParams = rest.length > 0 ? new URLSearchParams(rest.join("?")) : null;
|
|
6057
|
+
let clientRouteModuleType = searchParams?.get("client-route-module");
|
|
6058
|
+
let isServerRouteModule = searchParams?.has("server-route-module");
|
|
6059
|
+
if (clientRouteModuleType) {
|
|
6060
|
+
return await createClientRouteModuleChunk(
|
|
6061
|
+
id,
|
|
6062
|
+
code,
|
|
6063
|
+
clientRouteModuleType,
|
|
6064
|
+
routeId,
|
|
6065
|
+
isRootRouteModule(filename2),
|
|
6066
|
+
this.environment.mode === "dev"
|
|
6067
|
+
);
|
|
6068
|
+
}
|
|
6069
|
+
if (isServerRouteModule) {
|
|
6070
|
+
return createServerRouteModule(code);
|
|
6071
|
+
}
|
|
6072
|
+
if (isClientEnvironment) {
|
|
6073
|
+
return await createClientRouteEntry(
|
|
6074
|
+
id,
|
|
6075
|
+
code,
|
|
6076
|
+
isRootRouteModule(filename2),
|
|
6077
|
+
routeId
|
|
6078
|
+
);
|
|
6079
|
+
}
|
|
6080
|
+
return await createServerRouteEntry(
|
|
6081
|
+
id,
|
|
6082
|
+
code,
|
|
6083
|
+
isRootRouteModule(filename2),
|
|
6084
|
+
routeId
|
|
6085
|
+
);
|
|
6086
|
+
}
|
|
6087
|
+
};
|
|
6088
|
+
}
|
|
6089
|
+
function createId(id, type, value) {
|
|
6090
|
+
let [base, ...rest] = id.split("?");
|
|
6091
|
+
const searchParams = new URLSearchParams(rest.join("?"));
|
|
6092
|
+
searchParams.delete("client-route-module");
|
|
6093
|
+
searchParams.delete("server-route-module");
|
|
6094
|
+
searchParams.set(type, value || "");
|
|
6095
|
+
return `${base}?${searchParams.toString()}`;
|
|
5958
6096
|
}
|
|
5959
|
-
function parseRouteExports(code) {
|
|
6097
|
+
async function parseRouteExports(code) {
|
|
6098
|
+
await import_es_module_lexer2.init;
|
|
5960
6099
|
const [, exportSpecifiers] = (0, import_es_module_lexer2.parse)(code);
|
|
5961
6100
|
const staticExports = exportSpecifiers.map(({ n: name }) => name);
|
|
5962
6101
|
return {
|
|
@@ -5964,27 +6103,115 @@ function parseRouteExports(code) {
|
|
|
5964
6103
|
hasClientExports: staticExports.some(isClientRouteExport)
|
|
5965
6104
|
};
|
|
5966
6105
|
}
|
|
5967
|
-
|
|
5968
|
-
|
|
6106
|
+
var CLIENT_NON_COMPONENT_EXPORTS2 = [
|
|
6107
|
+
"clientAction",
|
|
6108
|
+
"clientLoader",
|
|
6109
|
+
"clientMiddleware",
|
|
6110
|
+
"handle",
|
|
6111
|
+
"meta",
|
|
6112
|
+
"links",
|
|
6113
|
+
"shouldRevalidate"
|
|
6114
|
+
];
|
|
6115
|
+
var CLIENT_ROUTE_EXPORTS2 = [
|
|
6116
|
+
...CLIENT_NON_COMPONENT_EXPORTS2,
|
|
6117
|
+
"default",
|
|
6118
|
+
"ErrorBoundary",
|
|
6119
|
+
"HydrateFallback",
|
|
6120
|
+
"Layout"
|
|
6121
|
+
];
|
|
6122
|
+
var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS2);
|
|
6123
|
+
function isClientRouteExport(name) {
|
|
6124
|
+
return CLIENT_ROUTE_EXPORTS_SET.has(name);
|
|
5969
6125
|
}
|
|
5970
|
-
|
|
5971
|
-
|
|
6126
|
+
var SERVER_COMPONENT_EXPORTS = [
|
|
6127
|
+
"ServerComponent",
|
|
6128
|
+
"ServerLayout",
|
|
6129
|
+
"ServerHydrateFallback",
|
|
6130
|
+
"ServerErrorBoundary"
|
|
6131
|
+
];
|
|
6132
|
+
var SERVER_COMPONENT_EXPORTS_SET = new Set(SERVER_COMPONENT_EXPORTS);
|
|
6133
|
+
function isServerComponentExport(name) {
|
|
6134
|
+
return SERVER_COMPONENT_EXPORTS_SET.has(name);
|
|
5972
6135
|
}
|
|
5973
|
-
|
|
5974
|
-
|
|
6136
|
+
var SERVER_ROUTE_EXPORTS = [
|
|
6137
|
+
...SERVER_COMPONENT_EXPORTS,
|
|
6138
|
+
"loader",
|
|
6139
|
+
"action",
|
|
6140
|
+
"middleware",
|
|
6141
|
+
"headers"
|
|
6142
|
+
];
|
|
6143
|
+
var SERVER_ROUTE_EXPORTS_SET = new Set(SERVER_ROUTE_EXPORTS);
|
|
6144
|
+
function isServerRouteExport(name) {
|
|
6145
|
+
return SERVER_ROUTE_EXPORTS_SET.has(name);
|
|
5975
6146
|
}
|
|
5976
|
-
|
|
5977
|
-
|
|
6147
|
+
var CLIENT_MODULE_CHUNKS = /* @__PURE__ */ new Set([
|
|
6148
|
+
"clientAction",
|
|
6149
|
+
"clientLoader",
|
|
6150
|
+
"clientMiddleware",
|
|
6151
|
+
"HydrateFallback"
|
|
6152
|
+
]);
|
|
6153
|
+
var MUTUALLY_EXCLUSIVE_ROUTE_EXPORTS = /* @__PURE__ */ new Map([
|
|
6154
|
+
["ErrorBoundary", "ServerErrorBoundary"],
|
|
6155
|
+
["HydrateFallback", "ServerHydrateFallback"],
|
|
6156
|
+
["Layout", "ServerLayout"],
|
|
6157
|
+
["default", "ServerComponent"]
|
|
6158
|
+
]);
|
|
6159
|
+
function validateRouteModuleExports(toValidate) {
|
|
6160
|
+
let errors = [];
|
|
6161
|
+
for (let [clientExport, serverExport] of MUTUALLY_EXCLUSIVE_ROUTE_EXPORTS) {
|
|
6162
|
+
if (toValidate.includes(clientExport) && toValidate.includes(serverExport)) {
|
|
6163
|
+
errors.push([clientExport, serverExport]);
|
|
6164
|
+
}
|
|
6165
|
+
}
|
|
6166
|
+
if (errors.length > 0) {
|
|
6167
|
+
throw new Error(
|
|
6168
|
+
`Invalid route module exports. The following pairs of exports are mutually exclusive and cannot be exported from the same module:
|
|
6169
|
+
` + errors.map(
|
|
6170
|
+
([clientExport, serverExport]) => `- ${clientExport} and ${serverExport}`
|
|
6171
|
+
).join("\n")
|
|
6172
|
+
);
|
|
6173
|
+
}
|
|
5978
6174
|
}
|
|
5979
|
-
function
|
|
5980
|
-
|
|
6175
|
+
function detectRouteChunks2(cache, id, code, isRootRouteModule) {
|
|
6176
|
+
function noRouteChunks() {
|
|
6177
|
+
return {
|
|
6178
|
+
chunkedExports: [],
|
|
6179
|
+
hasRouteChunks: false,
|
|
6180
|
+
hasRouteChunkByExportName: {
|
|
6181
|
+
clientAction: false,
|
|
6182
|
+
clientLoader: false,
|
|
6183
|
+
clientMiddleware: false,
|
|
6184
|
+
HydrateFallback: false
|
|
6185
|
+
}
|
|
6186
|
+
};
|
|
6187
|
+
}
|
|
6188
|
+
if (isRootRouteModule) {
|
|
6189
|
+
return noRouteChunks();
|
|
6190
|
+
}
|
|
6191
|
+
if (!Array.from(CLIENT_MODULE_CHUNKS).some(
|
|
6192
|
+
(exportName) => code.includes(exportName)
|
|
6193
|
+
)) {
|
|
6194
|
+
return noRouteChunks();
|
|
6195
|
+
}
|
|
6196
|
+
let [filename2] = id.split("?");
|
|
6197
|
+
return detectRouteChunks(code, cache, filename2);
|
|
5981
6198
|
}
|
|
5982
|
-
function
|
|
6199
|
+
function validateRouteChunks2({
|
|
5983
6200
|
id,
|
|
5984
|
-
|
|
6201
|
+
valid
|
|
5985
6202
|
}) {
|
|
5986
|
-
|
|
5987
|
-
|
|
6203
|
+
let invalidChunks = Object.entries(valid).filter(([_, isValid]) => !isValid).map(([chunkName]) => chunkName);
|
|
6204
|
+
if (invalidChunks.length === 0) {
|
|
6205
|
+
return;
|
|
6206
|
+
}
|
|
6207
|
+
let plural = invalidChunks.length > 1;
|
|
6208
|
+
throw new Error(
|
|
6209
|
+
[
|
|
6210
|
+
`Error splitting route module: ${id}`,
|
|
6211
|
+
invalidChunks.map((name) => `- ${name}`).join("\n"),
|
|
6212
|
+
`${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.`
|
|
6213
|
+
].join("\n\n")
|
|
6214
|
+
);
|
|
5988
6215
|
}
|
|
5989
6216
|
|
|
5990
6217
|
// vite/rsc/plugin.ts
|
|
@@ -6010,6 +6237,62 @@ function reactRouterRSCVitePlugin() {
|
|
|
6010
6237
|
newConfig.routes.root.file
|
|
6011
6238
|
);
|
|
6012
6239
|
}
|
|
6240
|
+
function isRootRouteModule(id) {
|
|
6241
|
+
return import_pathe6.default.normalize(id) === import_pathe6.default.normalize(rootRouteFile);
|
|
6242
|
+
}
|
|
6243
|
+
function getRouteIdForFile(file) {
|
|
6244
|
+
let normalizedFile = import_pathe6.default.normalize(file);
|
|
6245
|
+
let directMatch = routeIdByFile?.get(normalizedFile);
|
|
6246
|
+
if (directMatch) {
|
|
6247
|
+
return directMatch;
|
|
6248
|
+
}
|
|
6249
|
+
return Array.from(routeIdByFile ?? []).find(
|
|
6250
|
+
([routeFile]) => import_pathe6.default.normalize(routeFile).endsWith(normalizedFile)
|
|
6251
|
+
)?.[1];
|
|
6252
|
+
}
|
|
6253
|
+
function isMdxRouteModule(filename2) {
|
|
6254
|
+
let extension = import_pathe6.default.extname(filename2).toLowerCase();
|
|
6255
|
+
return extension === ".md" || extension === ".mdx";
|
|
6256
|
+
}
|
|
6257
|
+
function getTransformLanguage(filename2) {
|
|
6258
|
+
let extension = import_pathe6.default.extname(filename2).toLowerCase();
|
|
6259
|
+
switch (extension) {
|
|
6260
|
+
case ".ts":
|
|
6261
|
+
case ".cts":
|
|
6262
|
+
case ".mts":
|
|
6263
|
+
return "ts";
|
|
6264
|
+
case ".tsx":
|
|
6265
|
+
return "tsx";
|
|
6266
|
+
case ".js":
|
|
6267
|
+
case ".cjs":
|
|
6268
|
+
case ".mjs":
|
|
6269
|
+
case ".jsx":
|
|
6270
|
+
case ".md":
|
|
6271
|
+
case ".mdx":
|
|
6272
|
+
return "jsx";
|
|
6273
|
+
default:
|
|
6274
|
+
return void 0;
|
|
6275
|
+
}
|
|
6276
|
+
}
|
|
6277
|
+
async function transformToJs(code, filename2) {
|
|
6278
|
+
await preloadVite();
|
|
6279
|
+
let vite2 = getVite();
|
|
6280
|
+
let lang = getTransformLanguage(filename2);
|
|
6281
|
+
return ("transformWithOxc" in vite2 && typeof vite2.transformWithOxc === "function" ? await vite2.transformWithOxc(code, filename2, {
|
|
6282
|
+
lang,
|
|
6283
|
+
jsx: {
|
|
6284
|
+
runtime: "automatic",
|
|
6285
|
+
development: viteCommand !== "build",
|
|
6286
|
+
target: "esnext"
|
|
6287
|
+
}
|
|
6288
|
+
}) : await vite2.transformWithEsbuild(code, filename2, {
|
|
6289
|
+
loader: lang,
|
|
6290
|
+
target: "esnext",
|
|
6291
|
+
format: "esm",
|
|
6292
|
+
jsx: "automatic",
|
|
6293
|
+
jsxDev: viteCommand !== "build"
|
|
6294
|
+
})).code;
|
|
6295
|
+
}
|
|
6013
6296
|
return [
|
|
6014
6297
|
{
|
|
6015
6298
|
name: "react-router/rsc",
|
|
@@ -6035,12 +6318,10 @@ function reactRouterRSCVitePlugin() {
|
|
|
6035
6318
|
if (userConfig.serverBundles) errors.push("serverBundles");
|
|
6036
6319
|
if (userConfig.future?.v8_middleware === false)
|
|
6037
6320
|
errors.push("future.v8_middleware: false");
|
|
6038
|
-
if (userConfig.future?.v8_splitRouteModules)
|
|
6039
|
-
errors.push("future.v8_splitRouteModules");
|
|
6040
6321
|
if (userConfig.future?.v8_viteEnvironmentApi === false)
|
|
6041
6322
|
errors.push("future.v8_viteEnvironmentApi: false");
|
|
6042
|
-
if (userConfig.
|
|
6043
|
-
errors.push("
|
|
6323
|
+
if (userConfig.subResourceIntegrity)
|
|
6324
|
+
errors.push("subResourceIntegrity");
|
|
6044
6325
|
if (errors.length) {
|
|
6045
6326
|
return `RSC Framework Mode does not currently support the following React Router config:
|
|
6046
6327
|
${errors.map((x) => ` - ${x}`).join("\n")}
|
|
@@ -6199,27 +6480,6 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6199
6480
|
]
|
|
6200
6481
|
}
|
|
6201
6482
|
}
|
|
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
6483
|
}
|
|
6224
6484
|
};
|
|
6225
6485
|
},
|
|
@@ -6362,20 +6622,16 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6362
6622
|
}
|
|
6363
6623
|
}
|
|
6364
6624
|
},
|
|
6365
|
-
{
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
viteEnvironment: this.environment
|
|
6376
|
-
});
|
|
6377
|
-
}
|
|
6378
|
-
},
|
|
6625
|
+
virtualRouteModulesPlugin({
|
|
6626
|
+
environments: {
|
|
6627
|
+
client: ["client", "ssr"],
|
|
6628
|
+
server: ["rsc"]
|
|
6629
|
+
},
|
|
6630
|
+
getRouteIdForFile,
|
|
6631
|
+
isRootRouteModule,
|
|
6632
|
+
transformToJs,
|
|
6633
|
+
enforceSplitRouteModules: () => config.future.v8_splitRouteModules === "enforce"
|
|
6634
|
+
}),
|
|
6379
6635
|
{
|
|
6380
6636
|
name: "react-router/rsc/virtual-basename",
|
|
6381
6637
|
resolveId(id) {
|
|
@@ -6417,121 +6673,21 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6417
6673
|
async load(id) {
|
|
6418
6674
|
if (id !== virtual2.injectHmrRuntime.resolvedId) return;
|
|
6419
6675
|
return viteCommand === "serve" ? [
|
|
6420
|
-
`import
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6676
|
+
`if (import.meta.hot) {
|
|
6677
|
+
import.meta.hot.accept();
|
|
6678
|
+
import.meta.hot.on('rsc:update', () => {
|
|
6679
|
+
// Defer revalidation to the next animation frame so React Fast Refresh
|
|
6680
|
+
// can apply pending client component updates first. Without this delay,
|
|
6681
|
+
// the RSC payload (showing updated text) can arrive and be reconciled
|
|
6682
|
+
// against a DOM that still has the old text, causing a hydration mismatch.
|
|
6683
|
+
requestAnimationFrame(() => {
|
|
6684
|
+
__reactRouterDataRouter.revalidate()
|
|
6685
|
+
});
|
|
6686
|
+
})
|
|
6687
|
+
}`
|
|
6425
6688
|
].join("\n") : "";
|
|
6426
6689
|
}
|
|
6427
6690
|
},
|
|
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
6691
|
{
|
|
6536
6692
|
name: "react-router/rsc/virtual-react-router-serve-config",
|
|
6537
6693
|
resolveId(id) {
|
|
@@ -6655,7 +6811,6 @@ var virtual2 = {
|
|
|
6655
6811
|
routeConfig: create("unstable_rsc/routes"),
|
|
6656
6812
|
routeDiscovery: create("unstable_rsc/route-discovery"),
|
|
6657
6813
|
injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
|
|
6658
|
-
hmrRuntime: create("unstable_rsc/runtime"),
|
|
6659
6814
|
basename: create("unstable_rsc/basename"),
|
|
6660
6815
|
reactRouterServeConfig: create("unstable_rsc/react-router-serve-config")
|
|
6661
6816
|
};
|
|
@@ -6672,71 +6827,12 @@ function invalidateVirtualModules2(viteDevServer) {
|
|
|
6672
6827
|
function getRootDirectory(viteUserConfig) {
|
|
6673
6828
|
return viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
6674
6829
|
}
|
|
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
6830
|
var getClientBuildDirectory2 = (reactRouterConfig) => import_pathe6.default.join(reactRouterConfig.buildDirectory, "client");
|
|
6735
6831
|
function getPrerenderConcurrencyConfig2(reactRouterConfig) {
|
|
6736
6832
|
let concurrency = 1;
|
|
6737
6833
|
let { prerender: prerender2 } = reactRouterConfig;
|
|
6738
|
-
if (typeof prerender2 === "object" && "
|
|
6739
|
-
concurrency = prerender2.
|
|
6834
|
+
if (typeof prerender2 === "object" && "concurrency" in prerender2) {
|
|
6835
|
+
concurrency = prerender2.concurrency ?? 1;
|
|
6740
6836
|
}
|
|
6741
6837
|
return concurrency;
|
|
6742
6838
|
}
|