@react-router/dev 7.13.2 → 7.14.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 +76 -0
- package/dist/cli/index.js +75 -38
- package/dist/config/default-rsc-entries/entry.client.tsx +1 -3
- package/dist/config/default-rsc-entries/entry.rsc.tsx +3 -0
- package/dist/config/default-rsc-entries/entry.ssr.tsx +0 -1
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +2 -2
- package/dist/vite.js +469 -264
- package/package.json +9 -9
- package/rsc-types.d.ts +17 -0
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v7.
|
|
2
|
+
* @react-router/dev v7.14.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -111,6 +111,14 @@ function getVite() {
|
|
|
111
111
|
invariant(vite, "getVite() called before preloadVite()");
|
|
112
112
|
return vite;
|
|
113
113
|
}
|
|
114
|
+
function defineCompilerOptions(options) {
|
|
115
|
+
let vite2 = getVite();
|
|
116
|
+
return parseInt(vite2.version.split(".")[0], 10) >= 8 ? { oxc: options.oxc } : { esbuild: options.esbuild };
|
|
117
|
+
}
|
|
118
|
+
function defineOptimizeDepsCompilerOptions(options) {
|
|
119
|
+
let vite2 = getVite();
|
|
120
|
+
return parseInt(vite2.version.split(".")[0], 10) >= 8 ? { rolldownOptions: options.rolldown } : { esbuildOptions: options.esbuild };
|
|
121
|
+
}
|
|
114
122
|
|
|
115
123
|
// vite/ssr-externals.ts
|
|
116
124
|
var ssrExternals = isReactRouterRepo() ? [
|
|
@@ -566,7 +574,7 @@ async function resolveConfig({
|
|
|
566
574
|
unstable_previewServerPrerendering: userAndPresetConfigs.future?.unstable_previewServerPrerendering ?? false,
|
|
567
575
|
v8_middleware: userAndPresetConfigs.future?.v8_middleware ?? false,
|
|
568
576
|
v8_splitRouteModules: userAndPresetConfigs.future?.v8_splitRouteModules ?? false,
|
|
569
|
-
v8_viteEnvironmentApi: userAndPresetConfigs.future?.v8_viteEnvironmentApi ?? false
|
|
577
|
+
v8_viteEnvironmentApi: (userAndPresetConfigs.future?.v8_viteEnvironmentApi || userAndPresetConfigs.future?.unstable_previewServerPrerendering) ?? false
|
|
570
578
|
};
|
|
571
579
|
let allowedActionOrigins = userAndPresetConfigs.allowedActionOrigins ?? false;
|
|
572
580
|
let reactRouterConfig = deepFreeze({
|
|
@@ -1193,7 +1201,7 @@ function getRouteAnnotations({
|
|
|
1193
1201
|
module: Module
|
|
1194
1202
|
}>
|
|
1195
1203
|
` + "\n\n" + generate(matchesType).code + "\n\n" + import_dedent.default`
|
|
1196
|
-
type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }
|
|
1204
|
+
type Annotations = GetAnnotations<Info & { module: Module, matches: Matches }>;
|
|
1197
1205
|
|
|
1198
1206
|
export namespace Route {
|
|
1199
1207
|
// links
|
|
@@ -1230,11 +1238,20 @@ function getRouteAnnotations({
|
|
|
1230
1238
|
// HydrateFallback
|
|
1231
1239
|
export type HydrateFallbackProps = Annotations["HydrateFallbackProps"];
|
|
1232
1240
|
|
|
1241
|
+
// ServerHydrateFallback
|
|
1242
|
+
export type ServerHydrateFallbackProps = Annotations["ServerHydrateFallbackProps"];
|
|
1243
|
+
|
|
1233
1244
|
// Component
|
|
1234
1245
|
export type ComponentProps = Annotations["ComponentProps"];
|
|
1235
1246
|
|
|
1247
|
+
// ServerComponent
|
|
1248
|
+
export type ServerComponentProps = Annotations["ServerComponentProps"];
|
|
1249
|
+
|
|
1236
1250
|
// ErrorBoundary
|
|
1237
1251
|
export type ErrorBoundaryProps = Annotations["ErrorBoundaryProps"];
|
|
1252
|
+
|
|
1253
|
+
// ServerErrorBoundary
|
|
1254
|
+
export type ServerErrorBoundaryProps = Annotations["ServerErrorBoundaryProps"];
|
|
1238
1255
|
}
|
|
1239
1256
|
`;
|
|
1240
1257
|
return { filename: filename2, content };
|
|
@@ -2526,140 +2543,144 @@ function prerender(options) {
|
|
|
2526
2543
|
let viteConfig;
|
|
2527
2544
|
return {
|
|
2528
2545
|
name: "prerender",
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
const request = new Request(input);
|
|
2556
|
-
const url2 = new URL(request.url);
|
|
2557
|
-
if (url2.origin !== baseUrl.origin) {
|
|
2558
|
-
url2.hostname = baseUrl.hostname;
|
|
2559
|
-
url2.protocol = baseUrl.protocol;
|
|
2560
|
-
url2.port = baseUrl.port;
|
|
2561
|
-
}
|
|
2562
|
-
async function attempt(url3) {
|
|
2546
|
+
sharedDuringBuild: true,
|
|
2547
|
+
config: {
|
|
2548
|
+
order: "post",
|
|
2549
|
+
handler({ builder: { buildApp } = {} }) {
|
|
2550
|
+
return {
|
|
2551
|
+
builder: {
|
|
2552
|
+
async buildApp(builder) {
|
|
2553
|
+
await buildApp?.(builder);
|
|
2554
|
+
const rawRequests = typeof requests === "function" ? await requests() : requests;
|
|
2555
|
+
const prerenderRequests = rawRequests.map(
|
|
2556
|
+
normalizePrerenderRequest
|
|
2557
|
+
);
|
|
2558
|
+
if (prerenderRequests.length === 0) {
|
|
2559
|
+
return;
|
|
2560
|
+
}
|
|
2561
|
+
const prerenderConfig = typeof config === "function" ? await config() : config;
|
|
2562
|
+
const {
|
|
2563
|
+
buildDirectory = viteConfig.environments.client.build.outDir,
|
|
2564
|
+
concurrency = 1,
|
|
2565
|
+
retryCount = 0,
|
|
2566
|
+
retryDelay = 500,
|
|
2567
|
+
maxRedirects = 0,
|
|
2568
|
+
timeout = 1e4
|
|
2569
|
+
} = prerenderConfig ?? {};
|
|
2570
|
+
let ogIsBuildRequest = process.env.IS_RR_BUILD_REQUEST;
|
|
2571
|
+
process.env.IS_RR_BUILD_REQUEST = "yes";
|
|
2563
2572
|
try {
|
|
2564
|
-
const
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2573
|
+
const previewServer = await startPreviewServer(viteConfig);
|
|
2574
|
+
try {
|
|
2575
|
+
const baseUrl = getResolvedUrl(previewServer);
|
|
2576
|
+
async function prerenderRequest(input, metadata) {
|
|
2577
|
+
let attemptCount = 0;
|
|
2578
|
+
let redirectCount = 0;
|
|
2579
|
+
const request = new Request(input);
|
|
2580
|
+
const url2 = new URL(request.url);
|
|
2581
|
+
if (url2.origin !== baseUrl.origin) {
|
|
2582
|
+
url2.hostname = baseUrl.hostname;
|
|
2583
|
+
url2.protocol = baseUrl.protocol;
|
|
2584
|
+
url2.port = baseUrl.port;
|
|
2585
|
+
}
|
|
2586
|
+
async function attempt(url3) {
|
|
2587
|
+
try {
|
|
2588
|
+
const signal = AbortSignal.timeout(timeout);
|
|
2589
|
+
const prerenderReq = new Request(url3, request);
|
|
2590
|
+
const response = await fetch(prerenderReq, {
|
|
2591
|
+
redirect: "manual",
|
|
2592
|
+
signal
|
|
2593
|
+
});
|
|
2594
|
+
if (response.status >= 300 && response.status < 400 && response.headers.has("location") && ++redirectCount <= maxRedirects) {
|
|
2595
|
+
const location = response.headers.get("location");
|
|
2596
|
+
const responseURL = new URL(response.url);
|
|
2597
|
+
const locationUrl = new URL(location, response.url);
|
|
2598
|
+
if (responseURL.origin !== locationUrl.origin) {
|
|
2599
|
+
return await postProcess(
|
|
2600
|
+
request,
|
|
2601
|
+
response,
|
|
2602
|
+
metadata
|
|
2603
|
+
);
|
|
2604
|
+
}
|
|
2605
|
+
const redirectUrl = new URL(location, url3);
|
|
2606
|
+
return await attempt(redirectUrl);
|
|
2607
|
+
}
|
|
2608
|
+
if (response.status >= 500 && ++attemptCount <= retryCount) {
|
|
2609
|
+
await new Promise(
|
|
2610
|
+
(resolve6) => setTimeout(resolve6, retryDelay)
|
|
2611
|
+
);
|
|
2612
|
+
return attempt(url3);
|
|
2613
|
+
}
|
|
2614
|
+
return await postProcess(request, response, metadata);
|
|
2615
|
+
} catch (error) {
|
|
2616
|
+
if (++attemptCount <= retryCount) {
|
|
2617
|
+
await new Promise(
|
|
2618
|
+
(resolve6) => setTimeout(resolve6, retryDelay)
|
|
2619
|
+
);
|
|
2620
|
+
return attempt(url3);
|
|
2621
|
+
}
|
|
2622
|
+
handleError(
|
|
2623
|
+
request,
|
|
2624
|
+
error instanceof Error ? error : new Error(error?.toString() ?? "Unknown error"),
|
|
2625
|
+
metadata
|
|
2626
|
+
);
|
|
2627
|
+
return [];
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
return attempt(url2);
|
|
2631
|
+
}
|
|
2632
|
+
async function prerender2(input, metadata) {
|
|
2633
|
+
const result = await prerenderRequest(input, metadata);
|
|
2634
|
+
const { files, requests: requests2 } = normalizePostProcessResult(result);
|
|
2635
|
+
for (const file of files) {
|
|
2636
|
+
await writePrerenderFile(file, metadata);
|
|
2637
|
+
}
|
|
2638
|
+
for (const followUp of requests2) {
|
|
2639
|
+
const normalized = normalizePrerenderRequest(followUp);
|
|
2640
|
+
await prerender2(normalized.request, normalized.metadata);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
async function writePrerenderFile(file, metadata) {
|
|
2644
|
+
const normalizedPath = file.path.startsWith("/") ? file.path.slice(1) : file.path;
|
|
2645
|
+
const outputPath = import_node_path.default.join(
|
|
2646
|
+
buildDirectory,
|
|
2647
|
+
...normalizedPath.split("/")
|
|
2648
|
+
);
|
|
2649
|
+
await (0, import_promises2.mkdir)(import_node_path.default.dirname(outputPath), { recursive: true });
|
|
2650
|
+
await (0, import_promises2.writeFile)(outputPath, file.contents);
|
|
2651
|
+
const relativePath = import_node_path.default.relative(
|
|
2652
|
+
viteConfig.root,
|
|
2653
|
+
outputPath
|
|
2580
2654
|
);
|
|
2655
|
+
if (logFile) {
|
|
2656
|
+
logFile(relativePath, metadata);
|
|
2657
|
+
}
|
|
2658
|
+
return relativePath;
|
|
2581
2659
|
}
|
|
2582
|
-
const
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
return attempt(url3);
|
|
2590
|
-
}
|
|
2591
|
-
return await postProcess.call(
|
|
2592
|
-
pluginContext,
|
|
2593
|
-
request,
|
|
2594
|
-
response,
|
|
2595
|
-
metadata
|
|
2596
|
-
);
|
|
2597
|
-
} catch (error) {
|
|
2598
|
-
if (++attemptCount <= retryCount) {
|
|
2599
|
-
await new Promise(
|
|
2600
|
-
(resolve6) => setTimeout(resolve6, retryDelay)
|
|
2660
|
+
const pMap = await import("p-map");
|
|
2661
|
+
await pMap.default(
|
|
2662
|
+
prerenderRequests,
|
|
2663
|
+
async ({ request, metadata }) => {
|
|
2664
|
+
await prerender2(request, metadata);
|
|
2665
|
+
},
|
|
2666
|
+
{ concurrency }
|
|
2601
2667
|
);
|
|
2602
|
-
|
|
2668
|
+
if (finalize) {
|
|
2669
|
+
await finalize(buildDirectory);
|
|
2670
|
+
}
|
|
2671
|
+
} finally {
|
|
2672
|
+
await previewServer.close();
|
|
2603
2673
|
}
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
request,
|
|
2607
|
-
error instanceof Error ? error : new Error(error?.toString() ?? "Unknown error"),
|
|
2608
|
-
metadata
|
|
2609
|
-
);
|
|
2610
|
-
return [];
|
|
2674
|
+
} finally {
|
|
2675
|
+
process.env.IS_RR_BUILD_REQUEST = ogIsBuildRequest;
|
|
2611
2676
|
}
|
|
2612
2677
|
}
|
|
2613
|
-
return attempt(url2);
|
|
2614
|
-
}
|
|
2615
|
-
async function prerender2(input, metadata) {
|
|
2616
|
-
const result = await prerenderRequest(input, metadata);
|
|
2617
|
-
const { files, requests: requests2 } = normalizePostProcessResult(result);
|
|
2618
|
-
for (const file of files) {
|
|
2619
|
-
await writePrerenderFile(file, metadata);
|
|
2620
|
-
}
|
|
2621
|
-
for (const followUp of requests2) {
|
|
2622
|
-
const normalized = normalizePrerenderRequest(followUp);
|
|
2623
|
-
await prerender2(normalized.request, normalized.metadata);
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
async function writePrerenderFile(file, metadata) {
|
|
2627
|
-
const normalizedPath = file.path.startsWith("/") ? file.path.slice(1) : file.path;
|
|
2628
|
-
const outputPath = import_node_path.default.join(
|
|
2629
|
-
buildDirectory,
|
|
2630
|
-
...normalizedPath.split("/")
|
|
2631
|
-
);
|
|
2632
|
-
await (0, import_promises2.mkdir)(import_node_path.default.dirname(outputPath), { recursive: true });
|
|
2633
|
-
await (0, import_promises2.writeFile)(outputPath, file.contents);
|
|
2634
|
-
const relativePath = import_node_path.default.relative(viteConfig.root, outputPath);
|
|
2635
|
-
if (logFile) {
|
|
2636
|
-
logFile.call(pluginContext, relativePath, metadata);
|
|
2637
|
-
}
|
|
2638
|
-
return relativePath;
|
|
2639
|
-
}
|
|
2640
|
-
const pMap = await import("p-map");
|
|
2641
|
-
await pMap.default(
|
|
2642
|
-
prerenderRequests,
|
|
2643
|
-
async ({ request, metadata }) => {
|
|
2644
|
-
await prerender2(request, metadata);
|
|
2645
|
-
},
|
|
2646
|
-
{ concurrency }
|
|
2647
|
-
);
|
|
2648
|
-
if (finalize) {
|
|
2649
|
-
await finalize.call(pluginContext, buildDirectory);
|
|
2650
2678
|
}
|
|
2651
|
-
}
|
|
2652
|
-
await new Promise((resolve6, reject) => {
|
|
2653
|
-
previewServer.httpServer.close((err2) => {
|
|
2654
|
-
if (err2) {
|
|
2655
|
-
reject(err2);
|
|
2656
|
-
} else {
|
|
2657
|
-
resolve6();
|
|
2658
|
-
}
|
|
2659
|
-
});
|
|
2660
|
-
});
|
|
2661
|
-
}
|
|
2679
|
+
};
|
|
2662
2680
|
}
|
|
2681
|
+
},
|
|
2682
|
+
configResolved(resolvedConfig) {
|
|
2683
|
+
viteConfig = resolvedConfig;
|
|
2663
2684
|
}
|
|
2664
2685
|
};
|
|
2665
2686
|
}
|
|
@@ -3042,7 +3063,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3042
3063
|
let viteChildCompiler = null;
|
|
3043
3064
|
let cache = /* @__PURE__ */ new Map();
|
|
3044
3065
|
let reactRouterConfigLoader;
|
|
3045
|
-
let
|
|
3066
|
+
let typegenWatcherPromise2;
|
|
3046
3067
|
let logger;
|
|
3047
3068
|
let firstLoad = true;
|
|
3048
3069
|
let ctx;
|
|
@@ -3466,7 +3487,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3466
3487
|
rootDirectory = viteUserConfig.root ?? process.env.REACT_ROUTER_ROOT ?? process.cwd();
|
|
3467
3488
|
let mode = viteConfigEnv.mode;
|
|
3468
3489
|
if (viteCommand === "serve") {
|
|
3469
|
-
|
|
3490
|
+
typegenWatcherPromise2 = watch(rootDirectory, {
|
|
3470
3491
|
mode,
|
|
3471
3492
|
rsc: false,
|
|
3472
3493
|
// ignore `info` logs from typegen since they are redundant when Vite plugin logs are active
|
|
@@ -3526,10 +3547,18 @@ var reactRouterVitePlugin = () => {
|
|
|
3526
3547
|
}) ? ["react-router-dom"] : []
|
|
3527
3548
|
]
|
|
3528
3549
|
},
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3550
|
+
...defineCompilerOptions({
|
|
3551
|
+
oxc: {
|
|
3552
|
+
jsx: {
|
|
3553
|
+
runtime: "automatic",
|
|
3554
|
+
development: viteCommand !== "build"
|
|
3555
|
+
}
|
|
3556
|
+
},
|
|
3557
|
+
esbuild: {
|
|
3558
|
+
jsx: "automatic",
|
|
3559
|
+
jsxDev: viteCommand !== "build"
|
|
3560
|
+
}
|
|
3561
|
+
}),
|
|
3533
3562
|
resolve: {
|
|
3534
3563
|
dedupe: [
|
|
3535
3564
|
// https://react.dev/warnings/invalid-hook-call-warning#duplicate-react
|
|
@@ -3789,32 +3818,51 @@ var reactRouterVitePlugin = () => {
|
|
|
3789
3818
|
let cachedHandler = null;
|
|
3790
3819
|
async function getHandler() {
|
|
3791
3820
|
if (cachedHandler) return cachedHandler;
|
|
3792
|
-
let
|
|
3821
|
+
let bundledHandlers = [];
|
|
3793
3822
|
let buildManifest = ctx.buildManifest ?? (ctx.reactRouterConfig.serverBundles ? await getBuildManifest({
|
|
3794
3823
|
reactRouterConfig: ctx.reactRouterConfig,
|
|
3795
3824
|
rootDirectory: ctx.rootDirectory
|
|
3796
3825
|
}) : null);
|
|
3797
3826
|
if (buildManifest?.serverBundles) {
|
|
3827
|
+
let routesByServerBundleId = getRoutesByServerBundleId(buildManifest);
|
|
3798
3828
|
for (let bundle of Object.values(buildManifest.serverBundles)) {
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3829
|
+
let build = await import(url.pathToFileURL(path7.resolve(ctx.rootDirectory, bundle.file)).href);
|
|
3830
|
+
bundledHandlers.push({
|
|
3831
|
+
handler: (0, import_react_router2.createRequestHandler)(build, "production"),
|
|
3832
|
+
routes: createPrerenderRoutes(
|
|
3833
|
+
routesByServerBundleId[bundle.id] ?? {}
|
|
3834
|
+
)
|
|
3835
|
+
});
|
|
3802
3836
|
}
|
|
3803
3837
|
} else {
|
|
3804
3838
|
let serverEntryPath = path7.resolve(
|
|
3805
3839
|
getServerBuildDirectory(ctx.reactRouterConfig),
|
|
3806
3840
|
"index.js"
|
|
3807
3841
|
);
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
handlers.push((0, import_react_router2.createRequestHandler)(build, "production"));
|
|
3842
|
+
let build = await import(url.pathToFileURL(serverEntryPath).href);
|
|
3843
|
+
bundledHandlers.push({
|
|
3844
|
+
handler: (0, import_react_router2.createRequestHandler)(build, "production"),
|
|
3845
|
+
routes: null
|
|
3846
|
+
});
|
|
3814
3847
|
}
|
|
3815
3848
|
cachedHandler = async (request, loadContext) => {
|
|
3816
3849
|
let response;
|
|
3817
|
-
|
|
3850
|
+
let handlersToTry = bundledHandlers;
|
|
3851
|
+
if (buildManifest?.serverBundles) {
|
|
3852
|
+
let pathname = new URL(request.url).pathname;
|
|
3853
|
+
handlersToTry = bundledHandlers.map((entry, index) => ({
|
|
3854
|
+
entry,
|
|
3855
|
+
index,
|
|
3856
|
+
matchDepth: (0, import_react_router2.matchRoutes)(
|
|
3857
|
+
entry.routes ?? [],
|
|
3858
|
+
pathname,
|
|
3859
|
+
ctx.reactRouterConfig.basename
|
|
3860
|
+
)?.length ?? -1
|
|
3861
|
+
})).sort(
|
|
3862
|
+
(a, b) => b.matchDepth - a.matchDepth || a.index - b.index
|
|
3863
|
+
).map(({ entry }) => entry);
|
|
3864
|
+
}
|
|
3865
|
+
for (let { handler } of handlersToTry) {
|
|
3818
3866
|
response = await handler(request, loadContext);
|
|
3819
3867
|
if (response.status !== 404) {
|
|
3820
3868
|
return response;
|
|
@@ -3823,7 +3871,10 @@ var reactRouterVitePlugin = () => {
|
|
|
3823
3871
|
if (response) {
|
|
3824
3872
|
return response;
|
|
3825
3873
|
}
|
|
3826
|
-
|
|
3874
|
+
let url2 = new URL(request.url);
|
|
3875
|
+
throw new Error(
|
|
3876
|
+
"No handlers were found for the request: " + url2.pathname + url2.search
|
|
3877
|
+
);
|
|
3827
3878
|
};
|
|
3828
3879
|
return cachedHandler;
|
|
3829
3880
|
}
|
|
@@ -3977,7 +4028,7 @@ var reactRouterVitePlugin = () => {
|
|
|
3977
4028
|
async buildEnd() {
|
|
3978
4029
|
await viteChildCompiler?.close();
|
|
3979
4030
|
await reactRouterConfigLoader.close();
|
|
3980
|
-
let typegenWatcher = await
|
|
4031
|
+
let typegenWatcher = await typegenWatcherPromise2;
|
|
3981
4032
|
await typegenWatcher?.close();
|
|
3982
4033
|
}
|
|
3983
4034
|
},
|
|
@@ -4408,9 +4459,6 @@ var reactRouterVitePlugin = () => {
|
|
|
4408
4459
|
async requests() {
|
|
4409
4460
|
invariant(viteConfig);
|
|
4410
4461
|
let { future } = ctx.reactRouterConfig;
|
|
4411
|
-
if (future.v8_viteEnvironmentApi ? this.environment.name === "client" : !viteConfigEnv.isSsrBuild) {
|
|
4412
|
-
return [];
|
|
4413
|
-
}
|
|
4414
4462
|
if (!future.unstable_previewServerPrerendering) {
|
|
4415
4463
|
return [];
|
|
4416
4464
|
}
|
|
@@ -4603,7 +4651,9 @@ ${html}`
|
|
|
4603
4651
|
);
|
|
4604
4652
|
}
|
|
4605
4653
|
}
|
|
4606
|
-
let serverBuildDirectory =
|
|
4654
|
+
let serverBuildDirectory = getServerBuildDirectory(
|
|
4655
|
+
ctx.reactRouterConfig
|
|
4656
|
+
);
|
|
4607
4657
|
viteConfig.logger.info(
|
|
4608
4658
|
[
|
|
4609
4659
|
"Removing the server build in",
|
|
@@ -5629,6 +5679,7 @@ var import_es_module_lexer3 = require("es-module-lexer");
|
|
|
5629
5679
|
var Path5 = __toESM(require("pathe"));
|
|
5630
5680
|
var babel2 = __toESM(require("@babel/core"));
|
|
5631
5681
|
var import_picocolors5 = __toESM(require("picocolors"));
|
|
5682
|
+
var import_fs = require("fs");
|
|
5632
5683
|
var import_promises4 = require("fs/promises");
|
|
5633
5684
|
var import_pathe6 = __toESM(require("pathe"));
|
|
5634
5685
|
|
|
@@ -5685,39 +5736,27 @@ function createRouteId2(file, appDirectory) {
|
|
|
5685
5736
|
|
|
5686
5737
|
// vite/rsc/virtual-route-modules.ts
|
|
5687
5738
|
var import_es_module_lexer2 = require("es-module-lexer");
|
|
5688
|
-
var
|
|
5689
|
-
|
|
5690
|
-
|
|
5739
|
+
var SERVER_COMPONENT_EXPORTS = [
|
|
5740
|
+
"ServerComponent",
|
|
5741
|
+
"ServerLayout",
|
|
5742
|
+
"ServerHydrateFallback",
|
|
5743
|
+
"ServerErrorBoundary"
|
|
5744
|
+
];
|
|
5745
|
+
var SERVER_COMPONENT_EXPORTS_SET = new Set(SERVER_COMPONENT_EXPORTS);
|
|
5746
|
+
function isServerComponentExport(name) {
|
|
5747
|
+
return SERVER_COMPONENT_EXPORTS_SET.has(name);
|
|
5748
|
+
}
|
|
5749
|
+
var SERVER_ROUTE_EXPORTS = [
|
|
5750
|
+
...SERVER_COMPONENT_EXPORTS,
|
|
5691
5751
|
"loader",
|
|
5692
5752
|
"action",
|
|
5693
5753
|
"middleware",
|
|
5694
5754
|
"headers"
|
|
5695
5755
|
];
|
|
5696
|
-
var
|
|
5697
|
-
function
|
|
5698
|
-
return
|
|
5699
|
-
}
|
|
5700
|
-
var COMMON_COMPONENT_EXPORTS = [
|
|
5701
|
-
"ErrorBoundary",
|
|
5702
|
-
"HydrateFallback",
|
|
5703
|
-
"Layout"
|
|
5704
|
-
];
|
|
5705
|
-
var SERVER_FIRST_COMPONENT_EXPORTS = [
|
|
5706
|
-
...COMMON_COMPONENT_EXPORTS,
|
|
5707
|
-
...SERVER_ONLY_COMPONENT_EXPORTS
|
|
5708
|
-
];
|
|
5709
|
-
var SERVER_FIRST_COMPONENT_EXPORTS_SET = new Set(
|
|
5710
|
-
SERVER_FIRST_COMPONENT_EXPORTS
|
|
5711
|
-
);
|
|
5712
|
-
function isServerFirstComponentExport(name) {
|
|
5713
|
-
return SERVER_FIRST_COMPONENT_EXPORTS_SET.has(
|
|
5714
|
-
name
|
|
5715
|
-
);
|
|
5756
|
+
var SERVER_ROUTE_EXPORTS_SET = new Set(SERVER_ROUTE_EXPORTS);
|
|
5757
|
+
function isServerRouteExport(name) {
|
|
5758
|
+
return SERVER_ROUTE_EXPORTS_SET.has(name);
|
|
5716
5759
|
}
|
|
5717
|
-
var CLIENT_COMPONENT_EXPORTS = [
|
|
5718
|
-
...COMMON_COMPONENT_EXPORTS,
|
|
5719
|
-
"default"
|
|
5720
|
-
];
|
|
5721
5760
|
var CLIENT_NON_COMPONENT_EXPORTS2 = [
|
|
5722
5761
|
"clientAction",
|
|
5723
5762
|
"clientLoader",
|
|
@@ -5727,20 +5766,25 @@ var CLIENT_NON_COMPONENT_EXPORTS2 = [
|
|
|
5727
5766
|
"links",
|
|
5728
5767
|
"shouldRevalidate"
|
|
5729
5768
|
];
|
|
5730
|
-
var CLIENT_NON_COMPONENT_EXPORTS_SET = new Set(CLIENT_NON_COMPONENT_EXPORTS2);
|
|
5731
|
-
function isClientNonComponentExport(name) {
|
|
5732
|
-
return CLIENT_NON_COMPONENT_EXPORTS_SET.has(name);
|
|
5733
|
-
}
|
|
5734
5769
|
var CLIENT_ROUTE_EXPORTS2 = [
|
|
5735
5770
|
...CLIENT_NON_COMPONENT_EXPORTS2,
|
|
5736
|
-
|
|
5771
|
+
"default",
|
|
5772
|
+
"ErrorBoundary",
|
|
5773
|
+
"HydrateFallback",
|
|
5774
|
+
"Layout"
|
|
5737
5775
|
];
|
|
5738
5776
|
var CLIENT_ROUTE_EXPORTS_SET = new Set(CLIENT_ROUTE_EXPORTS2);
|
|
5739
5777
|
function isClientRouteExport(name) {
|
|
5740
5778
|
return CLIENT_ROUTE_EXPORTS_SET.has(name);
|
|
5741
5779
|
}
|
|
5780
|
+
var mutuallyExclusiveRouteExports = /* @__PURE__ */ new Map([
|
|
5781
|
+
["ErrorBoundary", "ServerErrorBoundary"],
|
|
5782
|
+
["HydrateFallback", "ServerHydrateFallback"],
|
|
5783
|
+
["Layout", "ServerLayout"],
|
|
5784
|
+
["default", "ServerComponent"]
|
|
5785
|
+
]);
|
|
5742
5786
|
var ROUTE_EXPORTS = [
|
|
5743
|
-
...
|
|
5787
|
+
...SERVER_ROUTE_EXPORTS,
|
|
5744
5788
|
...CLIENT_ROUTE_EXPORTS2
|
|
5745
5789
|
];
|
|
5746
5790
|
var ROUTE_EXPORTS_SET = new Set(ROUTE_EXPORTS);
|
|
@@ -5794,63 +5838,57 @@ async function createVirtualRouteModuleCode({
|
|
|
5794
5838
|
viteEnvironment
|
|
5795
5839
|
}) {
|
|
5796
5840
|
const isReactServer = hasReactServerCondition(viteEnvironment);
|
|
5797
|
-
const { staticExports,
|
|
5841
|
+
const { staticExports, hasClientExports } = parseRouteExports(routeSource);
|
|
5842
|
+
for (const exportName of staticExports) {
|
|
5843
|
+
if (mutuallyExclusiveRouteExports.has(exportName)) {
|
|
5844
|
+
const conflictingExport = mutuallyExclusiveRouteExports.get(exportName);
|
|
5845
|
+
if (staticExports.includes(conflictingExport)) {
|
|
5846
|
+
throw new Error(
|
|
5847
|
+
`Route module cannot export both "${exportName}" and "${conflictingExport}". Please choose one or the other.`
|
|
5848
|
+
);
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
5851
|
+
}
|
|
5798
5852
|
const clientModuleId = getVirtualClientModuleId(id);
|
|
5799
5853
|
const serverModuleId = getVirtualServerModuleId(id);
|
|
5800
5854
|
let code = "";
|
|
5801
|
-
if (
|
|
5802
|
-
|
|
5803
|
-
code += `import React from "react";
|
|
5855
|
+
if (isReactServer && staticExports.some(isServerComponentExport)) {
|
|
5856
|
+
code += `import React from "react";
|
|
5804
5857
|
`;
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
`;
|
|
5810
|
-
} else if (isReactServer && isServerFirstComponentExport(staticExport) && // Layout wraps all other component exports so doesn't need CSS injected
|
|
5811
|
-
staticExport !== "Layout") {
|
|
5812
|
-
code += `import { ${staticExport} as ${staticExport}WithoutCss } from "${serverModuleId}";
|
|
5858
|
+
}
|
|
5859
|
+
for (const staticExport of staticExports) {
|
|
5860
|
+
if (isReactServer && isServerComponentExport(staticExport)) {
|
|
5861
|
+
code += `import { ${staticExport} as ${staticExport}WithoutCss } from "${serverModuleId}";
|
|
5813
5862
|
`;
|
|
5814
|
-
|
|
5863
|
+
code += `export ${staticExport === "ServerComponent" ? "default " : " "}function ${staticExport.replace(/^Server/, "")}(props) {
|
|
5815
5864
|
`;
|
|
5816
|
-
|
|
5865
|
+
code += ` return React.createElement(React.Fragment, null,
|
|
5817
5866
|
`;
|
|
5818
|
-
|
|
5867
|
+
code += ` import.meta.viteRsc.loadCss(),
|
|
5819
5868
|
`;
|
|
5820
|
-
|
|
5869
|
+
code += ` React.createElement(${staticExport}WithoutCss, props),
|
|
5821
5870
|
`;
|
|
5822
|
-
|
|
5871
|
+
code += ` );
|
|
5823
5872
|
`;
|
|
5824
|
-
|
|
5873
|
+
code += `}
|
|
5825
5874
|
`;
|
|
5826
|
-
|
|
5827
|
-
|
|
5875
|
+
} else if (isReactServer && isServerRouteExport(staticExport)) {
|
|
5876
|
+
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5828
5877
|
`;
|
|
5829
|
-
|
|
5830
|
-
|
|
5878
|
+
} else if (isClientRouteExport(staticExport)) {
|
|
5879
|
+
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5831
5880
|
`;
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
if (viteCommand === "serve" && !hasClientExports) {
|
|
5835
|
-
code += `export { __ensureClientRouteModuleForHMR } from "${clientModuleId}";
|
|
5881
|
+
} else if (isCustomRouteExport(staticExport)) {
|
|
5882
|
+
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5836
5883
|
`;
|
|
5837
5884
|
}
|
|
5838
|
-
} else {
|
|
5839
|
-
for (const staticExport of staticExports) {
|
|
5840
|
-
if (isClientRouteExport(staticExport)) {
|
|
5841
|
-
code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5842
|
-
`;
|
|
5843
|
-
} else if (isReactServer && isServerOnlyRouteExport(staticExport)) {
|
|
5844
|
-
code += `export { ${staticExport} } from "${serverModuleId}";
|
|
5845
|
-
`;
|
|
5846
|
-
} else if (isCustomRouteExport(staticExport)) {
|
|
5847
|
-
code += `export { ${staticExport} } from "${isReactServer ? serverModuleId : clientModuleId}";
|
|
5848
|
-
`;
|
|
5849
|
-
}
|
|
5850
|
-
}
|
|
5851
5885
|
}
|
|
5852
|
-
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5886
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary") && !staticExports.includes("ServerErrorBoundary")) {
|
|
5853
5887
|
code += `export { ErrorBoundary } from "${clientModuleId}";
|
|
5888
|
+
`;
|
|
5889
|
+
}
|
|
5890
|
+
if (viteCommand === "serve" && !hasClientExports) {
|
|
5891
|
+
code += `export { __ensureClientRouteModuleForHMR } from "${clientModuleId}";
|
|
5854
5892
|
`;
|
|
5855
5893
|
}
|
|
5856
5894
|
return code;
|
|
@@ -5869,23 +5907,18 @@ function createVirtualServerRouteModuleCode({
|
|
|
5869
5907
|
].join("\n")
|
|
5870
5908
|
);
|
|
5871
5909
|
}
|
|
5872
|
-
const { staticExports
|
|
5910
|
+
const { staticExports } = parseRouteExports(routeSource);
|
|
5873
5911
|
const clientModuleId = getVirtualClientModuleId(id);
|
|
5874
5912
|
const serverRouteModuleAst = import_parser.parse(routeSource, {
|
|
5875
5913
|
sourceType: "module"
|
|
5876
5914
|
});
|
|
5877
|
-
removeExports(
|
|
5878
|
-
serverRouteModuleAst,
|
|
5879
|
-
isServerFirstRoute ? CLIENT_NON_COMPONENT_EXPORTS2 : CLIENT_ROUTE_EXPORTS2
|
|
5880
|
-
);
|
|
5915
|
+
removeExports(serverRouteModuleAst, CLIENT_ROUTE_EXPORTS2);
|
|
5881
5916
|
const generatorResult = generate(serverRouteModuleAst);
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
generatorResult.code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5917
|
+
for (const staticExport of staticExports) {
|
|
5918
|
+
if (isClientRouteExport(staticExport)) {
|
|
5919
|
+
generatorResult.code += "\n";
|
|
5920
|
+
generatorResult.code += `export { ${staticExport} } from "${clientModuleId}";
|
|
5887
5921
|
`;
|
|
5888
|
-
}
|
|
5889
5922
|
}
|
|
5890
5923
|
}
|
|
5891
5924
|
return generatorResult;
|
|
@@ -5896,15 +5929,14 @@ function createVirtualClientRouteModuleCode({
|
|
|
5896
5929
|
rootRouteFile,
|
|
5897
5930
|
viteCommand
|
|
5898
5931
|
}) {
|
|
5899
|
-
const { staticExports,
|
|
5900
|
-
const exportsToRemove = isServerFirstRoute ? [...SERVER_ONLY_ROUTE_EXPORTS2, ...CLIENT_COMPONENT_EXPORTS] : SERVER_ONLY_ROUTE_EXPORTS2;
|
|
5932
|
+
const { staticExports, hasClientExports } = parseRouteExports(routeSource);
|
|
5901
5933
|
const clientRouteModuleAst = import_parser.parse(routeSource, {
|
|
5902
5934
|
sourceType: "module"
|
|
5903
5935
|
});
|
|
5904
|
-
removeExports(clientRouteModuleAst,
|
|
5936
|
+
removeExports(clientRouteModuleAst, SERVER_ROUTE_EXPORTS);
|
|
5905
5937
|
const generatorResult = generate(clientRouteModuleAst);
|
|
5906
5938
|
generatorResult.code = '"use client";' + generatorResult.code;
|
|
5907
|
-
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary")) {
|
|
5939
|
+
if (isRootRouteFile({ id, rootRouteFile }) && !staticExports.includes("ErrorBoundary") && !staticExports.includes("ServerErrorBoundary")) {
|
|
5908
5940
|
const hasRootLayout = staticExports.includes("Layout");
|
|
5909
5941
|
generatorResult.code += `
|
|
5910
5942
|
import { createElement as __rr_createElement } from "react";
|
|
@@ -5918,7 +5950,7 @@ import { createElement as __rr_createElement } from "react";
|
|
|
5918
5950
|
generatorResult.code += `}
|
|
5919
5951
|
`;
|
|
5920
5952
|
}
|
|
5921
|
-
if (viteCommand === "serve" &&
|
|
5953
|
+
if (viteCommand === "serve" && !hasClientExports) {
|
|
5922
5954
|
generatorResult.code += `
|
|
5923
5955
|
export const __ensureClientRouteModuleForHMR = true;`;
|
|
5924
5956
|
}
|
|
@@ -5927,15 +5959,9 @@ export const __ensureClientRouteModuleForHMR = true;`;
|
|
|
5927
5959
|
function parseRouteExports(code) {
|
|
5928
5960
|
const [, exportSpecifiers] = (0, import_es_module_lexer2.parse)(code);
|
|
5929
5961
|
const staticExports = exportSpecifiers.map(({ n: name }) => name);
|
|
5930
|
-
const isServerFirstRoute = staticExports.some(
|
|
5931
|
-
(staticExport) => staticExport === "ServerComponent"
|
|
5932
|
-
);
|
|
5933
5962
|
return {
|
|
5934
5963
|
staticExports,
|
|
5935
|
-
|
|
5936
|
-
hasClientExports: staticExports.some(
|
|
5937
|
-
isServerFirstRoute ? isClientNonComponentExport : isClientRouteExport
|
|
5938
|
-
)
|
|
5964
|
+
hasClientExports: staticExports.some(isClientRouteExport)
|
|
5939
5965
|
};
|
|
5940
5966
|
}
|
|
5941
5967
|
function getVirtualClientModuleId(id) {
|
|
@@ -5962,12 +5988,14 @@ function isRootRouteFile({
|
|
|
5962
5988
|
}
|
|
5963
5989
|
|
|
5964
5990
|
// vite/rsc/plugin.ts
|
|
5991
|
+
var redirectStatusCodes2 = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
5992
|
+
var configLoaderPromise;
|
|
5993
|
+
var typegenWatcherPromise;
|
|
5965
5994
|
function reactRouterRSCVitePlugin() {
|
|
5966
5995
|
let runningWithinTheReactRouterMonoRepo = Boolean(
|
|
5967
5996
|
arguments && arguments.length === 1 && typeof arguments[0] === "object" && arguments[0] && "__runningWithinTheReactRouterMonoRepo" in arguments[0] && arguments[0].__runningWithinTheReactRouterMonoRepo === true
|
|
5968
5997
|
);
|
|
5969
5998
|
let configLoader;
|
|
5970
|
-
let typegenWatcherPromise;
|
|
5971
5999
|
let viteCommand;
|
|
5972
6000
|
let resolvedViteConfig;
|
|
5973
6001
|
let routeIdByFile;
|
|
@@ -5990,24 +6018,21 @@ function reactRouterRSCVitePlugin() {
|
|
|
5990
6018
|
await preloadVite();
|
|
5991
6019
|
viteCommand = command;
|
|
5992
6020
|
const rootDirectory = getRootDirectory(viteUserConfig);
|
|
5993
|
-
const watch2 = command === "serve";
|
|
6021
|
+
const watch2 = command === "serve" && process.env.IS_RR_BUILD_REQUEST !== "yes";
|
|
5994
6022
|
await loadDotenv({
|
|
5995
6023
|
rootDirectory,
|
|
5996
6024
|
viteUserConfig,
|
|
5997
6025
|
mode
|
|
5998
6026
|
});
|
|
5999
|
-
|
|
6027
|
+
configLoaderPromise ??= createConfigLoader({
|
|
6000
6028
|
rootDirectory,
|
|
6001
6029
|
mode,
|
|
6002
6030
|
watch: watch2,
|
|
6003
6031
|
validateConfig: (userConfig) => {
|
|
6004
6032
|
let errors = [];
|
|
6005
6033
|
if (userConfig.buildEnd) errors.push("buildEnd");
|
|
6006
|
-
if (userConfig.prerender) errors.push("prerender");
|
|
6007
6034
|
if (userConfig.presets?.length) errors.push("presets");
|
|
6008
|
-
if (userConfig.routeDiscovery) errors.push("routeDiscovery");
|
|
6009
6035
|
if (userConfig.serverBundles) errors.push("serverBundles");
|
|
6010
|
-
if (userConfig.ssr === false) errors.push("ssr: false");
|
|
6011
6036
|
if (userConfig.future?.v8_middleware === false)
|
|
6012
6037
|
errors.push("future.v8_middleware: false");
|
|
6013
6038
|
if (userConfig.future?.v8_splitRouteModules)
|
|
@@ -6023,6 +6048,7 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6023
6048
|
}
|
|
6024
6049
|
}
|
|
6025
6050
|
});
|
|
6051
|
+
configLoader = await configLoaderPromise;
|
|
6026
6052
|
const configResult = await configLoader.getConfig();
|
|
6027
6053
|
if (!configResult.ok) throw new Error(configResult.error);
|
|
6028
6054
|
updateConfig(configResult.value);
|
|
@@ -6065,9 +6091,16 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6065
6091
|
entryClientFilePath: entries.client,
|
|
6066
6092
|
reactRouterConfig: config
|
|
6067
6093
|
}),
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6094
|
+
...defineOptimizeDepsCompilerOptions({
|
|
6095
|
+
rolldown: {
|
|
6096
|
+
transform: {
|
|
6097
|
+
jsx: "react-jsx"
|
|
6098
|
+
}
|
|
6099
|
+
},
|
|
6100
|
+
esbuild: {
|
|
6101
|
+
jsx: "automatic"
|
|
6102
|
+
}
|
|
6103
|
+
}),
|
|
6071
6104
|
include: [
|
|
6072
6105
|
// Pre-bundle React dependencies to avoid React duplicates,
|
|
6073
6106
|
// even if React dependencies are not direct dependencies.
|
|
@@ -6089,10 +6122,18 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6089
6122
|
"react-router > set-cookie-parser"
|
|
6090
6123
|
]
|
|
6091
6124
|
},
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6125
|
+
...defineCompilerOptions({
|
|
6126
|
+
oxc: {
|
|
6127
|
+
jsx: {
|
|
6128
|
+
runtime: "automatic",
|
|
6129
|
+
development: viteCommand !== "build"
|
|
6130
|
+
}
|
|
6131
|
+
},
|
|
6132
|
+
esbuild: {
|
|
6133
|
+
jsx: "automatic",
|
|
6134
|
+
jsxDev: viteCommand !== "build"
|
|
6135
|
+
}
|
|
6136
|
+
}),
|
|
6096
6137
|
environments: {
|
|
6097
6138
|
client: {
|
|
6098
6139
|
build: {
|
|
@@ -6214,6 +6255,50 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6214
6255
|
}
|
|
6215
6256
|
);
|
|
6216
6257
|
},
|
|
6258
|
+
configurePreviewServer(previewServer) {
|
|
6259
|
+
const clientBuildDirectory = getClientBuildDirectory2(config);
|
|
6260
|
+
if ((config.prerender || config.ssr === false) && process.env.IS_RR_BUILD_REQUEST !== "yes") {
|
|
6261
|
+
previewServer.middlewares.use(async (req, res, next) => {
|
|
6262
|
+
try {
|
|
6263
|
+
const htmlFileBase = ((req.url || "/") + (req.url?.endsWith("/") ? "" : "/") + "index.html").slice(1);
|
|
6264
|
+
const htmlFilePath = import_pathe6.default.join(
|
|
6265
|
+
clientBuildDirectory,
|
|
6266
|
+
htmlFileBase
|
|
6267
|
+
);
|
|
6268
|
+
if ((0, import_fs.existsSync)(htmlFilePath)) {
|
|
6269
|
+
res.setHeader("Content-Type", "text/html");
|
|
6270
|
+
res.end(await (0, import_promises4.readFile)(htmlFilePath, "utf-8"));
|
|
6271
|
+
return;
|
|
6272
|
+
}
|
|
6273
|
+
next();
|
|
6274
|
+
} catch (error) {
|
|
6275
|
+
next(error);
|
|
6276
|
+
}
|
|
6277
|
+
});
|
|
6278
|
+
return () => {
|
|
6279
|
+
if (config.ssr === false) {
|
|
6280
|
+
previewServer.middlewares.use(async (req, res, next) => {
|
|
6281
|
+
try {
|
|
6282
|
+
res.statusCode = 404;
|
|
6283
|
+
const url2 = new URL(req.url || "/", `http://localhost`);
|
|
6284
|
+
const htmlFilePath = import_pathe6.default.join(
|
|
6285
|
+
clientBuildDirectory,
|
|
6286
|
+
url2.pathname.endsWith(".rsc") ? "__spa-fallback.rsc" : "__spa-fallback.html"
|
|
6287
|
+
);
|
|
6288
|
+
if ((0, import_fs.existsSync)(htmlFilePath)) {
|
|
6289
|
+
res.setHeader("Content-Type", "text/html");
|
|
6290
|
+
res.end(await (0, import_promises4.readFile)(htmlFilePath, "utf-8"));
|
|
6291
|
+
return;
|
|
6292
|
+
}
|
|
6293
|
+
res.end();
|
|
6294
|
+
} catch (error) {
|
|
6295
|
+
next(error);
|
|
6296
|
+
}
|
|
6297
|
+
});
|
|
6298
|
+
}
|
|
6299
|
+
};
|
|
6300
|
+
}
|
|
6301
|
+
},
|
|
6217
6302
|
async buildEnd() {
|
|
6218
6303
|
await configLoader.close();
|
|
6219
6304
|
}
|
|
@@ -6236,12 +6321,12 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6236
6321
|
configureServer: logExperimentalNotice
|
|
6237
6322
|
};
|
|
6238
6323
|
})(),
|
|
6239
|
-
{
|
|
6324
|
+
process.env.IS_RR_BUILD_REQUEST !== "yes" ? {
|
|
6240
6325
|
name: "react-router/rsc/typegen",
|
|
6241
6326
|
async config(viteUserConfig, { command, mode }) {
|
|
6242
6327
|
if (command === "serve") {
|
|
6243
6328
|
const vite2 = await import("vite");
|
|
6244
|
-
typegenWatcherPromise
|
|
6329
|
+
typegenWatcherPromise ??= watch(
|
|
6245
6330
|
getRootDirectory(viteUserConfig),
|
|
6246
6331
|
{
|
|
6247
6332
|
mode,
|
|
@@ -6258,7 +6343,7 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6258
6343
|
async buildEnd() {
|
|
6259
6344
|
(await typegenWatcherPromise)?.close();
|
|
6260
6345
|
}
|
|
6261
|
-
},
|
|
6346
|
+
} : null,
|
|
6262
6347
|
{
|
|
6263
6348
|
name: "react-router/rsc/virtual-route-config",
|
|
6264
6349
|
resolveId(id) {
|
|
@@ -6304,6 +6389,23 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6304
6389
|
}
|
|
6305
6390
|
}
|
|
6306
6391
|
},
|
|
6392
|
+
{
|
|
6393
|
+
name: "react-router/rsc/virtual-route-discovery",
|
|
6394
|
+
resolveId(id) {
|
|
6395
|
+
if (id === virtual2.routeDiscovery.id) {
|
|
6396
|
+
return virtual2.routeDiscovery.resolvedId;
|
|
6397
|
+
}
|
|
6398
|
+
},
|
|
6399
|
+
load(id) {
|
|
6400
|
+
if (id === virtual2.routeDiscovery.resolvedId) {
|
|
6401
|
+
return `export default ${JSON.stringify(
|
|
6402
|
+
config.ssr === false ? {
|
|
6403
|
+
mode: "initial"
|
|
6404
|
+
} : config.routeDiscovery ?? { mode: "lazy" }
|
|
6405
|
+
)};`;
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6408
|
+
},
|
|
6307
6409
|
{
|
|
6308
6410
|
name: "react-router/rsc/hmr/inject-runtime",
|
|
6309
6411
|
enforce: "pre",
|
|
@@ -6453,11 +6555,105 @@ ${errors.map((x) => ` - ${x}`).join("\n")}
|
|
|
6453
6555
|
}
|
|
6454
6556
|
},
|
|
6455
6557
|
validatePluginOrder(),
|
|
6456
|
-
warnOnClientSourceMaps()
|
|
6558
|
+
warnOnClientSourceMaps(),
|
|
6559
|
+
prerender({
|
|
6560
|
+
config() {
|
|
6561
|
+
return {
|
|
6562
|
+
buildDirectory: getClientBuildDirectory2(config),
|
|
6563
|
+
concurrency: getPrerenderConcurrencyConfig2(config)
|
|
6564
|
+
};
|
|
6565
|
+
},
|
|
6566
|
+
logFile: (path10) => logger.info(`Prerendered ${import_picocolors5.default.bold(path10)}`),
|
|
6567
|
+
async requests() {
|
|
6568
|
+
const prerenderPaths = new Set(
|
|
6569
|
+
await getPrerenderPaths(
|
|
6570
|
+
config.prerender,
|
|
6571
|
+
config.ssr,
|
|
6572
|
+
config.routes,
|
|
6573
|
+
true
|
|
6574
|
+
)
|
|
6575
|
+
);
|
|
6576
|
+
let basename3 = !config.basename || config.basename === "/" ? "/" : config.basename.endsWith("/") ? config.basename : config.basename + "/";
|
|
6577
|
+
if (config.ssr === false) {
|
|
6578
|
+
prerenderPaths.add("/__spa-fallback.html");
|
|
6579
|
+
}
|
|
6580
|
+
return Array.from(prerenderPaths).map(
|
|
6581
|
+
(prerenderPath) => `http://localhost${basename3}${prerenderPath.slice(1)}`
|
|
6582
|
+
);
|
|
6583
|
+
},
|
|
6584
|
+
async postProcess(request, response, metadata) {
|
|
6585
|
+
let url2 = new URL(request.url);
|
|
6586
|
+
let isRedirect = redirectStatusCodes2.has(response.status);
|
|
6587
|
+
if (!isRedirect && response.status !== 200 && response.status !== 202 && !(url2.pathname === "/__spa-fallback.html" && response.status === 404)) {
|
|
6588
|
+
throw new Error(
|
|
6589
|
+
`Prerender (data): Received a ${response.status} status code from \`entry.server.tsx\` while prerendering the \`${url2.pathname}\` path.
|
|
6590
|
+
${url2.pathname}`,
|
|
6591
|
+
{ cause: response }
|
|
6592
|
+
);
|
|
6593
|
+
}
|
|
6594
|
+
if (metadata?.manifest) {
|
|
6595
|
+
return [
|
|
6596
|
+
{
|
|
6597
|
+
path: url2.pathname,
|
|
6598
|
+
contents: await response.text()
|
|
6599
|
+
}
|
|
6600
|
+
];
|
|
6601
|
+
}
|
|
6602
|
+
let isHtml = response.headers.get("content-type")?.includes("text/html");
|
|
6603
|
+
let htmlResponse = isHtml ? isRedirect ? response : response.clone() : null;
|
|
6604
|
+
let location = response.headers.get("Location");
|
|
6605
|
+
let delay = response.status === 302 ? 2 : 0;
|
|
6606
|
+
let redirectBody = isRedirect ? `<!doctype html>
|
|
6607
|
+
<head>
|
|
6608
|
+
<title>Redirecting to: ${location}</title>
|
|
6609
|
+
<meta http-equiv="refresh" content="${delay};url=${location}">
|
|
6610
|
+
<meta name="robots" content="noindex">
|
|
6611
|
+
</head>
|
|
6612
|
+
<body>
|
|
6613
|
+
<a href="${location}">
|
|
6614
|
+
Redirecting from <code>${url2.pathname}</code> to <code>${location}</code>
|
|
6615
|
+
</a>
|
|
6616
|
+
</body>
|
|
6617
|
+
</html>` : "";
|
|
6618
|
+
let files = [
|
|
6619
|
+
{
|
|
6620
|
+
path: isHtml || redirectBody ? url2.pathname === "/__spa-fallback.html" ? "__spa-fallback.html" : (url2.pathname.endsWith("/") ? url2.pathname : url2.pathname + "/") + "index.html" : url2.pathname,
|
|
6621
|
+
contents: redirectBody || (isHtml ? await response.text() : new Uint8Array(await response.arrayBuffer()))
|
|
6622
|
+
}
|
|
6623
|
+
];
|
|
6624
|
+
if (htmlResponse) {
|
|
6625
|
+
let body = await htmlResponse.text();
|
|
6626
|
+
let matches = Array.from(
|
|
6627
|
+
body.matchAll(
|
|
6628
|
+
/<script>\(self\.__FLIGHT_DATA\|\|=\[\]\)\.push\(("(?:[^"\\]|\\.)*")\)<\/script>/gim
|
|
6629
|
+
)
|
|
6630
|
+
);
|
|
6631
|
+
if (matches.length) {
|
|
6632
|
+
let rscData = "";
|
|
6633
|
+
for (const match of matches) {
|
|
6634
|
+
rscData += JSON.parse(match[1]);
|
|
6635
|
+
}
|
|
6636
|
+
files.push({
|
|
6637
|
+
path: url2.pathname === "/" ? "_.rsc" : (url2.pathname === "/__spa-fallback.html" ? "__spa-fallback" : url2.pathname) + ".rsc",
|
|
6638
|
+
contents: rscData
|
|
6639
|
+
});
|
|
6640
|
+
}
|
|
6641
|
+
} else if (!url2.pathname.endsWith(".rsc")) {
|
|
6642
|
+
let dataUrl = new URL(url2);
|
|
6643
|
+
dataUrl.pathname += ".rsc";
|
|
6644
|
+
return {
|
|
6645
|
+
files,
|
|
6646
|
+
requests: [dataUrl.href]
|
|
6647
|
+
};
|
|
6648
|
+
}
|
|
6649
|
+
return files;
|
|
6650
|
+
}
|
|
6651
|
+
})
|
|
6457
6652
|
];
|
|
6458
6653
|
}
|
|
6459
6654
|
var virtual2 = {
|
|
6460
6655
|
routeConfig: create("unstable_rsc/routes"),
|
|
6656
|
+
routeDiscovery: create("unstable_rsc/route-discovery"),
|
|
6461
6657
|
injectHmrRuntime: create("unstable_rsc/inject-hmr-runtime"),
|
|
6462
6658
|
hmrRuntime: create("unstable_rsc/runtime"),
|
|
6463
6659
|
basename: create("unstable_rsc/basename"),
|
|
@@ -6535,6 +6731,15 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
6535
6731
|
});
|
|
6536
6732
|
});
|
|
6537
6733
|
}`;
|
|
6734
|
+
var getClientBuildDirectory2 = (reactRouterConfig) => import_pathe6.default.join(reactRouterConfig.buildDirectory, "client");
|
|
6735
|
+
function getPrerenderConcurrencyConfig2(reactRouterConfig) {
|
|
6736
|
+
let concurrency = 1;
|
|
6737
|
+
let { prerender: prerender2 } = reactRouterConfig;
|
|
6738
|
+
if (typeof prerender2 === "object" && "unstable_concurrency" in prerender2) {
|
|
6739
|
+
concurrency = prerender2.unstable_concurrency ?? 1;
|
|
6740
|
+
}
|
|
6741
|
+
return concurrency;
|
|
6742
|
+
}
|
|
6538
6743
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6539
6744
|
0 && (module.exports = {
|
|
6540
6745
|
reactRouter,
|