@rangojs/router 0.0.0-experimental.debug-cache-fix → 0.0.0-experimental.dfdb0387
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/README.md +76 -18
- package/dist/bin/rango.js +130 -47
- package/dist/vite/index.js +702 -231
- package/package.json +2 -2
- package/skills/cache-guide/SKILL.md +32 -0
- package/skills/caching/SKILL.md +8 -0
- package/skills/links/SKILL.md +3 -1
- package/skills/loader/SKILL.md +53 -43
- package/skills/middleware/SKILL.md +2 -0
- package/skills/prerender/SKILL.md +110 -68
- package/skills/route/SKILL.md +31 -0
- package/skills/router-setup/SKILL.md +87 -2
- package/skills/typesafety/SKILL.md +10 -0
- package/src/__internal.ts +1 -1
- package/src/browser/app-version.ts +14 -0
- package/src/browser/navigation-bridge.ts +16 -3
- package/src/browser/navigation-client.ts +98 -46
- package/src/browser/navigation-store.ts +43 -8
- package/src/browser/partial-update.ts +32 -5
- package/src/browser/prefetch/cache.ts +16 -6
- package/src/browser/prefetch/fetch.ts +52 -6
- package/src/browser/prefetch/queue.ts +61 -29
- package/src/browser/prefetch/resource-ready.ts +77 -0
- package/src/browser/react/Link.tsx +67 -8
- package/src/browser/react/NavigationProvider.tsx +13 -4
- package/src/browser/react/context.ts +7 -2
- package/src/browser/react/use-handle.ts +9 -58
- package/src/browser/react/use-router.ts +21 -8
- package/src/browser/rsc-router.tsx +26 -3
- package/src/browser/scroll-restoration.ts +10 -8
- package/src/browser/segment-reconciler.ts +26 -0
- package/src/browser/server-action-bridge.ts +8 -6
- package/src/browser/types.ts +27 -5
- package/src/build/generate-manifest.ts +6 -6
- package/src/build/generate-route-types.ts +3 -0
- package/src/build/route-types/include-resolution.ts +8 -1
- package/src/build/route-types/router-processing.ts +211 -72
- package/src/build/route-types/scan-filter.ts +8 -1
- package/src/cache/cache-scope.ts +12 -14
- package/src/cache/taint.ts +55 -0
- package/src/client.tsx +2 -56
- package/src/context-var.ts +72 -2
- package/src/handle.ts +40 -0
- package/src/index.rsc.ts +3 -1
- package/src/index.ts +12 -0
- package/src/prerender/store.ts +5 -4
- package/src/prerender.ts +138 -77
- package/src/reverse.ts +22 -1
- package/src/route-definition/dsl-helpers.ts +42 -19
- package/src/route-definition/helpers-types.ts +10 -6
- package/src/route-definition/index.ts +3 -0
- package/src/route-definition/redirect.ts +9 -1
- package/src/route-definition/resolve-handler-use.ts +149 -0
- package/src/route-types.ts +11 -0
- package/src/router/content-negotiation.ts +100 -1
- package/src/router/handler-context.ts +79 -23
- package/src/router/intercept-resolution.ts +9 -4
- package/src/router/loader-resolution.ts +156 -21
- package/src/router/match-api.ts +124 -189
- package/src/router/match-middleware/cache-lookup.ts +26 -7
- package/src/router/match-middleware/segment-resolution.ts +53 -0
- package/src/router/match-result.ts +82 -4
- package/src/router/middleware-types.ts +6 -8
- package/src/router/middleware.ts +2 -5
- package/src/router/navigation-snapshot.ts +182 -0
- package/src/router/prerender-match.ts +110 -10
- package/src/router/preview-match.ts +30 -102
- package/src/router/request-classification.ts +310 -0
- package/src/router/route-snapshot.ts +245 -0
- package/src/router/router-interfaces.ts +36 -4
- package/src/router/router-options.ts +37 -11
- package/src/router/segment-resolution/fresh.ts +80 -9
- package/src/router/segment-resolution/helpers.ts +29 -24
- package/src/router/segment-resolution/revalidation.ts +91 -8
- package/src/router/types.ts +1 -0
- package/src/router.ts +54 -5
- package/src/rsc/handler.ts +472 -372
- package/src/rsc/loader-fetch.ts +23 -3
- package/src/rsc/manifest-init.ts +5 -1
- package/src/rsc/progressive-enhancement.ts +14 -2
- package/src/rsc/rsc-rendering.ts +10 -1
- package/src/rsc/server-action.ts +8 -0
- package/src/rsc/ssr-setup.ts +2 -2
- package/src/rsc/types.ts +9 -1
- package/src/server/context.ts +50 -1
- package/src/server/handle-store.ts +19 -0
- package/src/server/loader-registry.ts +9 -8
- package/src/server/request-context.ts +175 -15
- package/src/ssr/index.tsx +3 -0
- package/src/static-handler.ts +18 -6
- package/src/types/cache-types.ts +4 -4
- package/src/types/handler-context.ts +37 -19
- package/src/types/loader-types.ts +36 -9
- package/src/types/route-entry.ts +1 -1
- package/src/types/segments.ts +1 -0
- package/src/urls/path-helper-types.ts +9 -2
- package/src/urls/path-helper.ts +47 -12
- package/src/urls/pattern-types.ts +12 -0
- package/src/urls/response-types.ts +16 -6
- package/src/use-loader.tsx +77 -5
- package/src/vite/discovery/bundle-postprocess.ts +30 -33
- package/src/vite/discovery/discover-routers.ts +5 -1
- package/src/vite/discovery/prerender-collection.ts +128 -74
- package/src/vite/discovery/state.ts +13 -4
- package/src/vite/index.ts +4 -0
- package/src/vite/plugin-types.ts +60 -5
- package/src/vite/plugins/expose-id-utils.ts +12 -0
- package/src/vite/plugins/expose-ids/handler-transform.ts +30 -0
- package/src/vite/plugins/expose-internal-ids.ts +257 -40
- package/src/vite/plugins/performance-tracks.ts +88 -0
- package/src/vite/plugins/refresh-cmd.ts +88 -26
- package/src/vite/rango.ts +19 -2
- package/src/vite/router-discovery.ts +178 -37
- package/src/vite/utils/prerender-utils.ts +18 -0
- package/src/vite/utils/shared-utils.ts +3 -2
package/src/rsc/handler.ts
CHANGED
|
@@ -14,10 +14,11 @@ import {
|
|
|
14
14
|
runWithRequestContext,
|
|
15
15
|
setRequestContextParams,
|
|
16
16
|
requireRequestContext,
|
|
17
|
+
getRequestContext,
|
|
18
|
+
_getRequestContext,
|
|
17
19
|
createRequestContext,
|
|
18
20
|
} from "../server/request-context.js";
|
|
19
21
|
import * as rscDeps from "@vitejs/plugin-rsc/rsc";
|
|
20
|
-
|
|
21
22
|
import type {
|
|
22
23
|
RscPayload,
|
|
23
24
|
CreateRSCHandlerOptions,
|
|
@@ -82,6 +83,11 @@ import {
|
|
|
82
83
|
mayNeedSSR,
|
|
83
84
|
SSR_SETUP_VAR,
|
|
84
85
|
} from "./ssr-setup.js";
|
|
86
|
+
import {
|
|
87
|
+
classifyRequest,
|
|
88
|
+
type RequestPlan,
|
|
89
|
+
type ExecutableRequestPlan,
|
|
90
|
+
} from "../router/request-classification.js";
|
|
85
91
|
|
|
86
92
|
/**
|
|
87
93
|
* Create an RSC request handler.
|
|
@@ -161,10 +167,13 @@ export function createRSCHandler<
|
|
|
161
167
|
phase: ErrorPhase,
|
|
162
168
|
context: Parameters<typeof invokeOnError<TEnv>>[3],
|
|
163
169
|
): void {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
// Guard: abort signal handlers fire asynchronously outside the ALS
|
|
171
|
+
// request scope, so the context may be gone. Skip dedup in that
|
|
172
|
+
// case — the error is from a cancelled stream, not a real failure.
|
|
173
|
+
const reqCtx = _getRequestContext();
|
|
174
|
+
if (error != null && typeof error === "object" && reqCtx) {
|
|
175
|
+
if (reqCtx._reportedErrors.has(error)) return;
|
|
176
|
+
reqCtx._reportedErrors.add(error);
|
|
168
177
|
}
|
|
169
178
|
invokeOnError(router.onError, error, phase, context, "RSC");
|
|
170
179
|
}
|
|
@@ -452,6 +461,9 @@ export function createRSCHandler<
|
|
|
452
461
|
// - Server components during rendering
|
|
453
462
|
// - Error boundaries
|
|
454
463
|
// - Streaming
|
|
464
|
+
// Store basename on request context (scoped per-request via existing ALS)
|
|
465
|
+
requestContext._basename = router.basename;
|
|
466
|
+
|
|
455
467
|
return runWithRequestContext(requestContext, async () => {
|
|
456
468
|
// Core handler logic (wrapped by middleware)
|
|
457
469
|
const coreHandler = async (): Promise<Response> => {
|
|
@@ -527,7 +539,9 @@ export function createRSCHandler<
|
|
|
527
539
|
});
|
|
528
540
|
};
|
|
529
541
|
|
|
530
|
-
// Core request handling logic (separated for middleware wrapping)
|
|
542
|
+
// Core request handling logic (separated for middleware wrapping).
|
|
543
|
+
// Uses the classify → execute model: classifyRequest produces a RequestPlan,
|
|
544
|
+
// then execution dispatches on the plan mode.
|
|
531
545
|
async function coreRequestHandler(
|
|
532
546
|
request: Request,
|
|
533
547
|
env: TEnv,
|
|
@@ -535,71 +549,112 @@ export function createRSCHandler<
|
|
|
535
549
|
variables: Record<string, any>,
|
|
536
550
|
nonce: string | undefined,
|
|
537
551
|
): Promise<Response> {
|
|
538
|
-
const previewStart = performance.now();
|
|
539
|
-
const preview = await router.previewMatch(request, { env });
|
|
540
|
-
const previewDur = performance.now() - previewStart;
|
|
541
552
|
const handlerTiming: string[] = variables.__handlerTiming || [];
|
|
542
|
-
|
|
543
|
-
//
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
+
|
|
554
|
+
// Debug manifest endpoint: handled before classification since it
|
|
555
|
+
// doesn't need a route match and needs trie access from the closure.
|
|
556
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
557
|
+
if (
|
|
558
|
+
url.searchParams.has("__debug_manifest") &&
|
|
559
|
+
(isDev || router.allowDebugManifest)
|
|
560
|
+
) {
|
|
561
|
+
const trie = getRouterTrie(router.id) ?? getRouteTrie();
|
|
562
|
+
const routeManifest = getRequiredRouteMap();
|
|
563
|
+
const { extractAncestryFromTrie } =
|
|
564
|
+
await import("../build/route-trie.js");
|
|
565
|
+
return new Response(
|
|
566
|
+
JSON.stringify(
|
|
567
|
+
{
|
|
568
|
+
routerId: router.id,
|
|
569
|
+
routeManifest,
|
|
570
|
+
routeAncestry: trie ? extractAncestryFromTrie(trie) : {},
|
|
571
|
+
routeTrie: trie,
|
|
572
|
+
precomputedEntries: getPrecomputedEntries(),
|
|
573
|
+
},
|
|
574
|
+
null,
|
|
575
|
+
2,
|
|
553
576
|
),
|
|
554
|
-
|
|
555
|
-
|
|
577
|
+
{
|
|
578
|
+
headers: { "Content-Type": "application/json" },
|
|
579
|
+
},
|
|
556
580
|
);
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// ---- 1. Classify ----
|
|
584
|
+
// classifyRequest may throw RouteNotFoundError for unknown routes.
|
|
585
|
+
// In that case, fall through to a full-render plan so the pipeline
|
|
586
|
+
// can render the 404 page via the existing error handling path.
|
|
587
|
+
const classifyStart = performance.now();
|
|
588
|
+
let plan: RequestPlan<TEnv>;
|
|
589
|
+
try {
|
|
590
|
+
plan = await classifyRequest<TEnv>(request, url, {
|
|
591
|
+
findMatch: router.findMatch,
|
|
592
|
+
routerVersion: version,
|
|
593
|
+
routerId: router.id,
|
|
594
|
+
});
|
|
595
|
+
} catch (error) {
|
|
596
|
+
if (
|
|
597
|
+
error instanceof RouteNotFoundError ||
|
|
598
|
+
(error instanceof Error && error.name === "RouteNotFoundError")
|
|
599
|
+
) {
|
|
600
|
+
// Let the render path handle 404 — match()/matchPartial() will
|
|
601
|
+
// re-throw RouteNotFoundError and the catch block in
|
|
602
|
+
// executeRenderWithMiddleware renders the not-found page.
|
|
603
|
+
plan = {
|
|
604
|
+
mode: "full-render",
|
|
605
|
+
route: {
|
|
606
|
+
matched: null as any,
|
|
607
|
+
manifestEntry: null as any,
|
|
608
|
+
entries: [],
|
|
609
|
+
routeKey: "",
|
|
610
|
+
localRouteName: "",
|
|
611
|
+
params: {},
|
|
612
|
+
routeMiddleware: [],
|
|
613
|
+
cacheScope: null,
|
|
614
|
+
isPassthrough: false,
|
|
615
|
+
},
|
|
616
|
+
negotiated: false,
|
|
617
|
+
};
|
|
618
|
+
} else {
|
|
619
|
+
throw error;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
const classifyDur = performance.now() - classifyStart;
|
|
623
|
+
handlerTiming.push(`handler-classify;dur=${classifyDur.toFixed(2)}`);
|
|
624
|
+
|
|
625
|
+
// ---- 2. Terminal plans (no execution needed) ----
|
|
626
|
+
if (plan.mode === "redirect") {
|
|
627
|
+
// Redirects are handled by the pipeline (match/matchPartial),
|
|
628
|
+
// but for partial requests we short-circuit with a Flight redirect.
|
|
629
|
+
if (url.searchParams.has("_rsc_partial")) {
|
|
630
|
+
return createRedirectFlightResponse(plan.redirectUrl);
|
|
566
631
|
}
|
|
567
|
-
|
|
632
|
+
// Full requests: let the pipeline handle the redirect via match()
|
|
633
|
+
// which returns { redirect: url }. Fall through to full-render.
|
|
568
634
|
}
|
|
569
635
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
if (mayNeedSSR(request, url)) {
|
|
574
|
-
variables[SSR_SETUP_VAR] = startSSRSetup(
|
|
575
|
-
handlerCtx,
|
|
576
|
-
request,
|
|
577
|
-
env,
|
|
578
|
-
url,
|
|
579
|
-
router.debugPerformance
|
|
580
|
-
? () => requireRequestContext()._metricsStore
|
|
581
|
-
: undefined,
|
|
636
|
+
if (plan.mode === "version-mismatch") {
|
|
637
|
+
console.log(
|
|
638
|
+
`[RSC] Version mismatch: client=${url.searchParams.get("_rsc_v")}, server=${version}. Forcing reload.`,
|
|
582
639
|
);
|
|
640
|
+
return createResponseWithMergedHeaders(null, {
|
|
641
|
+
status: 200,
|
|
642
|
+
headers: {
|
|
643
|
+
"X-RSC-Reload": plan.reloadUrl,
|
|
644
|
+
"content-type": "text/x-component;charset=utf-8",
|
|
645
|
+
},
|
|
646
|
+
});
|
|
583
647
|
}
|
|
584
648
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
// PE form submissions before any execution. Regular page navigations
|
|
595
|
-
// (GET without _rsc_loader/_rsc_action) are not affected.
|
|
596
|
-
const originPhase: OriginCheckPhase | null = isAction
|
|
597
|
-
? "action"
|
|
598
|
-
: isLoaderFetch
|
|
599
|
-
? "loader"
|
|
600
|
-
: request.method === "POST"
|
|
601
|
-
? "pe-form"
|
|
602
|
-
: null;
|
|
649
|
+
// ---- 3. Origin guard (gate for action/loader/PE modes) ----
|
|
650
|
+
const originPhase: OriginCheckPhase | null =
|
|
651
|
+
plan.mode === "action"
|
|
652
|
+
? "action"
|
|
653
|
+
: plan.mode === "loader"
|
|
654
|
+
? "loader"
|
|
655
|
+
: plan.mode === "pe-render"
|
|
656
|
+
? "pe-form"
|
|
657
|
+
: null;
|
|
603
658
|
if (originPhase) {
|
|
604
659
|
const originResult = await checkRequestOrigin(
|
|
605
660
|
request,
|
|
@@ -649,13 +704,33 @@ export function createRSCHandler<
|
|
|
649
704
|
}
|
|
650
705
|
}
|
|
651
706
|
|
|
652
|
-
//
|
|
707
|
+
// ---- 4. Execute ----
|
|
708
|
+
return executeRequest(
|
|
709
|
+
plan as ExecutableRequestPlan<TEnv>,
|
|
710
|
+
request,
|
|
711
|
+
env,
|
|
712
|
+
url,
|
|
713
|
+
variables,
|
|
714
|
+
nonce,
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// Execute a classified request plan. Dispatches to the appropriate handler
|
|
719
|
+
// based on plan.mode. Lives in the createRSCHandler closure for access to
|
|
720
|
+
// handlerCtx, router, callOnError, etc.
|
|
721
|
+
// Only receives executable plans (version-mismatch is handled above).
|
|
722
|
+
async function executeRequest(
|
|
723
|
+
plan: ExecutableRequestPlan<TEnv>,
|
|
724
|
+
request: Request,
|
|
725
|
+
env: TEnv,
|
|
726
|
+
url: URL,
|
|
727
|
+
variables: Record<string, any>,
|
|
728
|
+
nonce: string | undefined,
|
|
729
|
+
): Promise<Response> {
|
|
730
|
+
// Common setup
|
|
653
731
|
const handleStore = requireRequestContext()._handleStore;
|
|
654
732
|
|
|
655
733
|
// Wire up error reporting for late streaming-handle failures
|
|
656
|
-
// (LateHandlePushError: handle pushed after stream completion).
|
|
657
|
-
// Without this, these errors are only caught by React's error boundary
|
|
658
|
-
// and never reach the router's onError callback or telemetry.
|
|
659
734
|
handleStore.onError = (error: Error) => {
|
|
660
735
|
const reqCtx = requireRequestContext();
|
|
661
736
|
callOnError(error, "handler", {
|
|
@@ -685,37 +760,106 @@ export function createRSCHandler<
|
|
|
685
760
|
};
|
|
686
761
|
|
|
687
762
|
// Set route params early so all execution paths can access ctx.params.
|
|
688
|
-
|
|
689
|
-
|
|
763
|
+
// Also store the classified snapshot so match/matchPartial can reuse it
|
|
764
|
+
// instead of calling resolveRoute again.
|
|
765
|
+
if (plan.mode !== "redirect") {
|
|
766
|
+
setRequestContextParams(plan.route.params, plan.route.routeKey);
|
|
767
|
+
requireRequestContext()._classifiedRoute = plan.route;
|
|
690
768
|
}
|
|
691
769
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
//
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
routeMiddleware:
|
|
770
|
+
const routeReverse = createReverseFunction(getRequiredRouteMap());
|
|
771
|
+
|
|
772
|
+
// ---- Response route: skip entire RSC pipeline ----
|
|
773
|
+
if (plan.mode === "response") {
|
|
774
|
+
// Build ResponseRouteMatch from plan fields. handleResponseRoute
|
|
775
|
+
// expects a flat object with params at the top level.
|
|
776
|
+
const responseMatch: ResponseRouteMatch = {
|
|
777
|
+
responseType: plan.responseType,
|
|
778
|
+
handler: plan.handler,
|
|
779
|
+
params: plan.route.params,
|
|
780
|
+
negotiated: plan.negotiated,
|
|
781
|
+
manifestEntry: plan.manifestEntry,
|
|
782
|
+
routeMiddleware: plan.routeMiddleware,
|
|
783
|
+
};
|
|
784
|
+
const responseOutcome = await withTimeout(
|
|
785
|
+
handleResponseRoute(
|
|
786
|
+
handlerCtx,
|
|
787
|
+
responseMatch,
|
|
788
|
+
request,
|
|
789
|
+
env,
|
|
790
|
+
url,
|
|
791
|
+
variables,
|
|
792
|
+
),
|
|
793
|
+
router.timeouts.renderStartMs,
|
|
794
|
+
"render-start",
|
|
795
|
+
);
|
|
796
|
+
if (responseOutcome.timedOut) {
|
|
797
|
+
return handleTimeoutResponse(
|
|
798
|
+
request,
|
|
799
|
+
env,
|
|
800
|
+
url,
|
|
801
|
+
"render-start",
|
|
802
|
+
responseOutcome.durationMs,
|
|
803
|
+
plan.route.routeKey,
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
const response = responseOutcome.result;
|
|
807
|
+
if (plan.negotiated) {
|
|
808
|
+
response.headers.append("Vary", "Accept");
|
|
809
|
+
}
|
|
810
|
+
return response;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// SSR setup: kick off in parallel for modes that need HTML rendering.
|
|
814
|
+
// Placed after response-route short-circuit so response/mime routes
|
|
815
|
+
// never pay for SSR work.
|
|
816
|
+
if (plan.mode !== "loader" && mayNeedSSR(request, url)) {
|
|
817
|
+
variables[SSR_SETUP_VAR] = startSSRSetup(
|
|
818
|
+
handlerCtx,
|
|
819
|
+
request,
|
|
820
|
+
env,
|
|
821
|
+
url,
|
|
822
|
+
router.debugPerformance
|
|
823
|
+
? () => requireRequestContext()._metricsStore
|
|
824
|
+
: undefined,
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// ---- Loader fetch ----
|
|
829
|
+
if (plan.mode === "loader") {
|
|
830
|
+
return handleLoaderFetch(
|
|
831
|
+
handlerCtx,
|
|
832
|
+
request,
|
|
833
|
+
env,
|
|
834
|
+
url,
|
|
705
835
|
variables,
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
836
|
+
plan.route.params,
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
// ---- Progressive enhancement ----
|
|
841
|
+
if (plan.mode === "pe-render") {
|
|
842
|
+
const peResult = await handleProgressiveEnhancement(
|
|
843
|
+
handlerCtx,
|
|
844
|
+
request,
|
|
845
|
+
env,
|
|
846
|
+
url,
|
|
847
|
+
false, // isAction = false for PE
|
|
848
|
+
handleStore,
|
|
849
|
+
nonce,
|
|
850
|
+
{
|
|
851
|
+
routeMiddleware: plan.route.routeMiddleware,
|
|
852
|
+
variables,
|
|
853
|
+
routeReverse,
|
|
854
|
+
},
|
|
855
|
+
);
|
|
856
|
+
if (peResult) return peResult;
|
|
857
|
+
// PE handler returned null (not a PE form) — fall through to render
|
|
711
858
|
}
|
|
712
859
|
|
|
713
|
-
//
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
// the revalidation pass (identical to a normal render).
|
|
717
|
-
let actionContinuation: ActionContinuation | undefined;
|
|
718
|
-
if (isAction && actionId) {
|
|
860
|
+
// ---- Action: execute action, then revalidate wrapped in route middleware ----
|
|
861
|
+
if (plan.mode === "action") {
|
|
862
|
+
let actionContinuation: ActionContinuation | undefined;
|
|
719
863
|
try {
|
|
720
864
|
const actionOutcome = await withTimeout(
|
|
721
865
|
executeServerAction(
|
|
@@ -723,7 +867,7 @@ export function createRSCHandler<
|
|
|
723
867
|
request,
|
|
724
868
|
env,
|
|
725
869
|
url,
|
|
726
|
-
actionId,
|
|
870
|
+
plan.actionId,
|
|
727
871
|
handleStore,
|
|
728
872
|
),
|
|
729
873
|
router.timeouts.actionMs,
|
|
@@ -736,8 +880,8 @@ export function createRSCHandler<
|
|
|
736
880
|
url,
|
|
737
881
|
"action",
|
|
738
882
|
actionOutcome.durationMs,
|
|
739
|
-
|
|
740
|
-
actionId,
|
|
883
|
+
plan.route.routeKey,
|
|
884
|
+
plan.actionId,
|
|
741
885
|
);
|
|
742
886
|
}
|
|
743
887
|
const result = actionOutcome.result;
|
|
@@ -749,341 +893,297 @@ export function createRSCHandler<
|
|
|
749
893
|
request,
|
|
750
894
|
url,
|
|
751
895
|
env,
|
|
752
|
-
actionId,
|
|
896
|
+
actionId: plan.actionId,
|
|
753
897
|
handledByBoundary: false,
|
|
754
898
|
});
|
|
755
899
|
console.error(`[RSC] Action error:`, error);
|
|
756
900
|
throw error;
|
|
757
901
|
}
|
|
758
|
-
}
|
|
759
902
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
903
|
+
// Revalidation render wrapped in route middleware.
|
|
904
|
+
// Actions from client-side navigation include _rsc_partial — preserve
|
|
905
|
+
// the partial flag so the revalidation returns a Flight stream, not HTML.
|
|
906
|
+
// App-switch is already excluded by classifyRequest (would be full-render).
|
|
907
|
+
const isPartialAction = url.searchParams.has("_rsc_partial");
|
|
908
|
+
return executeRenderWithMiddleware(
|
|
909
|
+
plan.route.routeMiddleware,
|
|
910
|
+
plan.negotiated,
|
|
911
|
+
plan.route.routeKey,
|
|
912
|
+
routeReverse,
|
|
764
913
|
request,
|
|
765
914
|
env,
|
|
766
915
|
url,
|
|
767
916
|
variables,
|
|
768
917
|
nonce,
|
|
769
|
-
preview?.params,
|
|
770
|
-
preview?.routeKey,
|
|
771
918
|
handleStore,
|
|
919
|
+
isPartialAction,
|
|
772
920
|
actionContinuation,
|
|
773
921
|
);
|
|
774
|
-
|
|
775
|
-
response.headers.append("Vary", "Accept");
|
|
776
|
-
}
|
|
777
|
-
return response;
|
|
778
|
-
};
|
|
779
|
-
|
|
780
|
-
// Wrap the render path (with or without route middleware) in a
|
|
781
|
-
// renderStartMs timeout so slow renders are caught before output.
|
|
782
|
-
const executeRender = async (): Promise<Response> => {
|
|
783
|
-
if (preview?.routeMiddleware && preview.routeMiddleware.length > 0) {
|
|
784
|
-
const mwResponse = await executeMiddleware(
|
|
785
|
-
buildRouteMiddlewareEntries<TEnv>(preview.routeMiddleware),
|
|
786
|
-
request,
|
|
787
|
-
env,
|
|
788
|
-
variables,
|
|
789
|
-
renderHandler,
|
|
790
|
-
routeReverse,
|
|
791
|
-
);
|
|
792
|
-
|
|
793
|
-
if (
|
|
794
|
-
url.searchParams.has("_rsc_partial") ||
|
|
795
|
-
url.searchParams.has("_rsc_action")
|
|
796
|
-
) {
|
|
797
|
-
const intercepted = interceptRedirectForPartial(
|
|
798
|
-
mwResponse,
|
|
799
|
-
createRedirectFlightResponse,
|
|
800
|
-
);
|
|
801
|
-
if (intercepted) return intercepted;
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
return finalizeResponse(mwResponse);
|
|
805
|
-
}
|
|
922
|
+
}
|
|
806
923
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
924
|
+
// ---- Full render / Partial render (or PE that fell through) ----
|
|
925
|
+
if (plan.mode === "full-render" || plan.mode === "partial-render") {
|
|
926
|
+
const isPartial = plan.mode === "partial-render";
|
|
927
|
+
return executeRenderWithMiddleware(
|
|
928
|
+
plan.route.routeMiddleware,
|
|
929
|
+
plan.negotiated,
|
|
930
|
+
plan.route.routeKey,
|
|
931
|
+
routeReverse,
|
|
932
|
+
request,
|
|
933
|
+
env,
|
|
934
|
+
url,
|
|
935
|
+
variables,
|
|
936
|
+
nonce,
|
|
937
|
+
handleStore,
|
|
938
|
+
isPartial,
|
|
939
|
+
);
|
|
940
|
+
}
|
|
810
941
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
942
|
+
// PE that fell through (handleProgressiveEnhancement returned null)
|
|
943
|
+
// falls back to full render
|
|
944
|
+
if (plan.mode === "pe-render") {
|
|
945
|
+
return executeRenderWithMiddleware(
|
|
946
|
+
plan.route.routeMiddleware,
|
|
947
|
+
false,
|
|
948
|
+
plan.route.routeKey,
|
|
949
|
+
routeReverse,
|
|
818
950
|
request,
|
|
819
951
|
env,
|
|
820
952
|
url,
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
953
|
+
variables,
|
|
954
|
+
nonce,
|
|
955
|
+
handleStore,
|
|
956
|
+
false,
|
|
824
957
|
);
|
|
825
958
|
}
|
|
826
|
-
|
|
959
|
+
|
|
960
|
+
// Redirect plan that wasn't handled above (full-page redirect — let
|
|
961
|
+
// the pipeline handle it via match() which returns { redirect: url })
|
|
962
|
+
return executeRenderWithMiddleware(
|
|
963
|
+
plan.route.routeMiddleware,
|
|
964
|
+
false,
|
|
965
|
+
plan.route.routeKey,
|
|
966
|
+
routeReverse,
|
|
967
|
+
request,
|
|
968
|
+
env,
|
|
969
|
+
url,
|
|
970
|
+
variables,
|
|
971
|
+
nonce,
|
|
972
|
+
handleStore,
|
|
973
|
+
false,
|
|
974
|
+
);
|
|
827
975
|
}
|
|
828
976
|
|
|
829
|
-
//
|
|
830
|
-
//
|
|
831
|
-
//
|
|
832
|
-
async function
|
|
977
|
+
// Shared render execution: wraps handleRscRendering (or revalidateAfterAction)
|
|
978
|
+
// in route middleware and timeout handling. Consolidates the pattern used by
|
|
979
|
+
// action-revalidate, full-render, and partial-render modes.
|
|
980
|
+
async function executeRenderWithMiddleware(
|
|
981
|
+
routeMiddleware: import("../router/middleware-types.js").CollectedMiddleware[],
|
|
982
|
+
negotiated: boolean,
|
|
983
|
+
routeKey: string,
|
|
984
|
+
routeReverse: ReturnType<typeof createReverseFunction>,
|
|
833
985
|
request: Request,
|
|
834
986
|
env: TEnv,
|
|
835
987
|
url: URL,
|
|
836
988
|
variables: Record<string, any>,
|
|
837
989
|
nonce: string | undefined,
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
handleStore?: ReturnType<typeof requireRequestContext>["_handleStore"],
|
|
990
|
+
handleStore: ReturnType<typeof requireRequestContext>["_handleStore"],
|
|
991
|
+
isPartial: boolean,
|
|
841
992
|
actionContinuation?: ActionContinuation,
|
|
842
993
|
): Promise<Response> {
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
994
|
+
const renderHandler = async (): Promise<Response> => {
|
|
995
|
+
try {
|
|
996
|
+
let response: Response;
|
|
997
|
+
if (actionContinuation) {
|
|
998
|
+
response = await revalidateAfterAction(
|
|
999
|
+
handlerCtx,
|
|
1000
|
+
request,
|
|
1001
|
+
env,
|
|
1002
|
+
url,
|
|
1003
|
+
handleStore,
|
|
1004
|
+
actionContinuation,
|
|
1005
|
+
);
|
|
1006
|
+
} else {
|
|
1007
|
+
response = await handleRscRendering(
|
|
1008
|
+
handlerCtx,
|
|
1009
|
+
request,
|
|
1010
|
+
env,
|
|
1011
|
+
url,
|
|
1012
|
+
isPartial,
|
|
1013
|
+
handleStore,
|
|
1014
|
+
nonce,
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
if (negotiated) {
|
|
1018
|
+
response.headers.append("Vary", "Accept");
|
|
1019
|
+
}
|
|
1020
|
+
return response;
|
|
1021
|
+
} catch (error) {
|
|
1022
|
+
// Check if middleware/handler returned Response
|
|
1023
|
+
if (error instanceof Response) {
|
|
1024
|
+
// During partial (client-side navigation), a 200 Response from a handler
|
|
1025
|
+
// means the route serves raw content (JSON, text, etc.), not JSX.
|
|
1026
|
+
// Signal the browser to hard-navigate so it renders the raw response.
|
|
1027
|
+
if (isPartial && error.status === 200) {
|
|
1028
|
+
console.warn(
|
|
1029
|
+
`[RSC] Route handler at ${url.pathname} returned a Response during client-side navigation. ` +
|
|
1030
|
+
`Falling back to hard navigation. Use data-external on the <Link> to avoid the extra round-trip.`,
|
|
1031
|
+
);
|
|
1032
|
+
return createResponseWithMergedHeaders(null, {
|
|
1033
|
+
status: 200,
|
|
1034
|
+
headers: {
|
|
1035
|
+
"X-RSC-Reload": stripInternalParams(url).toString(),
|
|
1036
|
+
"content-type": "text/x-component;charset=utf-8",
|
|
1037
|
+
},
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
854
1040
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
if (referer) {
|
|
862
|
-
try {
|
|
863
|
-
const refererUrl = new URL(referer);
|
|
864
|
-
if (refererUrl.origin === url.origin) {
|
|
865
|
-
reloadUrl = referer;
|
|
866
|
-
}
|
|
867
|
-
} catch {
|
|
868
|
-
// Malformed referer, fall back to cleanUrl
|
|
1041
|
+
if (isPartial) {
|
|
1042
|
+
const intercepted = interceptRedirectForPartial(
|
|
1043
|
+
error,
|
|
1044
|
+
createRedirectFlightResponse,
|
|
1045
|
+
);
|
|
1046
|
+
if (intercepted) return intercepted;
|
|
869
1047
|
}
|
|
1048
|
+
|
|
1049
|
+
return error;
|
|
870
1050
|
}
|
|
871
|
-
}
|
|
872
1051
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
const isDev = process.env.NODE_ENV !== "production";
|
|
885
|
-
if (
|
|
886
|
-
url.searchParams.has("__debug_manifest") &&
|
|
887
|
-
(isDev || router.allowDebugManifest)
|
|
888
|
-
) {
|
|
889
|
-
const trie = getRouterTrie(router.id) ?? getRouteTrie();
|
|
890
|
-
const routeManifest = getRequiredRouteMap();
|
|
891
|
-
const { extractAncestryFromTrie } =
|
|
892
|
-
await import("../build/route-trie.js");
|
|
893
|
-
return new Response(
|
|
894
|
-
JSON.stringify(
|
|
895
|
-
{
|
|
896
|
-
routerId: router.id,
|
|
897
|
-
routeManifest,
|
|
898
|
-
routeAncestry: trie ? extractAncestryFromTrie(trie) : {},
|
|
899
|
-
routeTrie: trie,
|
|
900
|
-
precomputedEntries: getPrecomputedEntries(),
|
|
901
|
-
},
|
|
902
|
-
null,
|
|
903
|
-
2,
|
|
904
|
-
),
|
|
905
|
-
{
|
|
906
|
-
headers: { "Content-Type": "application/json" },
|
|
907
|
-
},
|
|
908
|
-
);
|
|
909
|
-
}
|
|
1052
|
+
// Render 404 page for unmatched routes
|
|
1053
|
+
const isRouteNotFound =
|
|
1054
|
+
error instanceof RouteNotFoundError ||
|
|
1055
|
+
(error instanceof Error && error.name === "RouteNotFoundError");
|
|
1056
|
+
if (isRouteNotFound) {
|
|
1057
|
+
callOnError(error, "routing", {
|
|
1058
|
+
request,
|
|
1059
|
+
url,
|
|
1060
|
+
env,
|
|
1061
|
+
handledByBoundary: true,
|
|
1062
|
+
});
|
|
910
1063
|
|
|
911
|
-
|
|
1064
|
+
const notFoundOption = router.notFound;
|
|
1065
|
+
const notFoundComponent =
|
|
1066
|
+
typeof notFoundOption === "function"
|
|
1067
|
+
? notFoundOption({ pathname: url.pathname })
|
|
1068
|
+
: (notFoundOption ?? createElement("h1", null, "Not Found"));
|
|
1069
|
+
|
|
1070
|
+
const notFoundSegment = {
|
|
1071
|
+
id: "notFound",
|
|
1072
|
+
namespace: "notFound",
|
|
1073
|
+
type: "route" as const,
|
|
1074
|
+
index: 0,
|
|
1075
|
+
component: notFoundComponent,
|
|
1076
|
+
params: {},
|
|
1077
|
+
};
|
|
1078
|
+
|
|
1079
|
+
const payload: RscPayload = {
|
|
1080
|
+
metadata: {
|
|
1081
|
+
pathname: url.pathname,
|
|
1082
|
+
routerId: router.id,
|
|
1083
|
+
basename: router.basename,
|
|
1084
|
+
segments: [notFoundSegment],
|
|
1085
|
+
matched: [],
|
|
1086
|
+
diff: [],
|
|
1087
|
+
isPartial: false,
|
|
1088
|
+
rootLayout: router.rootLayout,
|
|
1089
|
+
handles: handleStore.stream(),
|
|
1090
|
+
version,
|
|
1091
|
+
themeConfig: router.themeConfig,
|
|
1092
|
+
warmupEnabled: router.warmupEnabled,
|
|
1093
|
+
initialTheme: requireRequestContext().theme,
|
|
1094
|
+
},
|
|
1095
|
+
};
|
|
912
1096
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
}
|
|
1097
|
+
const rscStream = renderToReadableStream(payload, {
|
|
1098
|
+
onError: (error: unknown) => {
|
|
1099
|
+
callOnError(error, "rendering", { request, url, env });
|
|
1100
|
+
},
|
|
1101
|
+
});
|
|
919
1102
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
handlerCtx,
|
|
926
|
-
request,
|
|
927
|
-
env,
|
|
928
|
-
url,
|
|
929
|
-
store,
|
|
930
|
-
actionContinuation,
|
|
931
|
-
);
|
|
932
|
-
}
|
|
1103
|
+
const isRscRequest =
|
|
1104
|
+
isPartial ||
|
|
1105
|
+
(!request.headers.get("accept")?.includes("text/html") &&
|
|
1106
|
+
!url.searchParams.has("__html")) ||
|
|
1107
|
+
url.searchParams.has("__rsc");
|
|
933
1108
|
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
handlerCtx,
|
|
941
|
-
request,
|
|
942
|
-
env,
|
|
943
|
-
url,
|
|
944
|
-
variables,
|
|
945
|
-
routeParams,
|
|
946
|
-
);
|
|
947
|
-
}
|
|
1109
|
+
if (isRscRequest) {
|
|
1110
|
+
return createResponseWithMergedHeaders(rscStream, {
|
|
1111
|
+
status: 404,
|
|
1112
|
+
headers: { "content-type": "text/x-component;charset=utf-8" },
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
948
1115
|
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
request,
|
|
956
|
-
env,
|
|
957
|
-
url,
|
|
958
|
-
isPartial,
|
|
959
|
-
store,
|
|
960
|
-
nonce,
|
|
961
|
-
);
|
|
962
|
-
} catch (error) {
|
|
963
|
-
// Check if middleware/handler returned Response
|
|
964
|
-
if (error instanceof Response) {
|
|
965
|
-
// During partial (client-side navigation), a 200 Response from a handler
|
|
966
|
-
// means the route serves raw content (JSON, text, etc.), not JSX.
|
|
967
|
-
// Signal the browser to hard-navigate so it renders the raw response.
|
|
968
|
-
// Only for 200 — redirects (3xx) work already because the browser follows
|
|
969
|
-
// them automatically to a URL that serves Flight data.
|
|
970
|
-
if (isPartial && error.status === 200) {
|
|
971
|
-
console.warn(
|
|
972
|
-
`[RSC] Route handler at ${url.pathname} returned a Response during client-side navigation. ` +
|
|
973
|
-
`Falling back to hard navigation. Use data-external on the <Link> to avoid the extra round-trip.`,
|
|
1116
|
+
const [ssrModule, streamMode] = await getSSRSetup(
|
|
1117
|
+
handlerCtx,
|
|
1118
|
+
request,
|
|
1119
|
+
env,
|
|
1120
|
+
url,
|
|
1121
|
+
requireRequestContext()._metricsStore,
|
|
974
1122
|
);
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
"X-RSC-Reload": stripInternalParams(url).toString(),
|
|
979
|
-
"content-type": "text/x-component;charset=utf-8",
|
|
980
|
-
},
|
|
1123
|
+
const htmlStream = await ssrModule.renderHTML(rscStream, {
|
|
1124
|
+
nonce,
|
|
1125
|
+
streamMode,
|
|
981
1126
|
});
|
|
982
|
-
}
|
|
983
1127
|
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
);
|
|
989
|
-
if (intercepted) return intercepted;
|
|
1128
|
+
return createResponseWithMergedHeaders(htmlStream, {
|
|
1129
|
+
status: 404,
|
|
1130
|
+
headers: { "content-type": "text/html;charset=utf-8" },
|
|
1131
|
+
});
|
|
990
1132
|
}
|
|
991
1133
|
|
|
992
|
-
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
// Render 404 page for unmatched routes
|
|
996
|
-
// Check both instanceof and error.name for cross-bundle compatibility
|
|
997
|
-
const isRouteNotFound =
|
|
998
|
-
error instanceof RouteNotFoundError ||
|
|
999
|
-
(error instanceof Error && error.name === "RouteNotFoundError");
|
|
1000
|
-
if (isRouteNotFound) {
|
|
1134
|
+
// Report unhandled errors
|
|
1001
1135
|
callOnError(error, "routing", {
|
|
1002
1136
|
request,
|
|
1003
1137
|
url,
|
|
1004
1138
|
env,
|
|
1005
|
-
handledByBoundary:
|
|
1139
|
+
handledByBoundary: false,
|
|
1006
1140
|
});
|
|
1141
|
+
console.error(`[RSC] Error:`, error);
|
|
1142
|
+
throw error;
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1007
1145
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
: (notFoundOption ?? createElement("h1", null, "Not Found"));
|
|
1014
|
-
|
|
1015
|
-
// Create a simple segment for the 404 page
|
|
1016
|
-
const notFoundSegment = {
|
|
1017
|
-
id: "notFound",
|
|
1018
|
-
namespace: "notFound",
|
|
1019
|
-
type: "route" as const,
|
|
1020
|
-
index: 0,
|
|
1021
|
-
component: notFoundComponent,
|
|
1022
|
-
params: {},
|
|
1023
|
-
};
|
|
1024
|
-
|
|
1025
|
-
const payload: RscPayload = {
|
|
1026
|
-
metadata: {
|
|
1027
|
-
pathname: url.pathname,
|
|
1028
|
-
segments: [notFoundSegment],
|
|
1029
|
-
matched: [],
|
|
1030
|
-
diff: [],
|
|
1031
|
-
isPartial: false,
|
|
1032
|
-
rootLayout: router.rootLayout,
|
|
1033
|
-
handles: store.stream(),
|
|
1034
|
-
version,
|
|
1035
|
-
themeConfig: router.themeConfig,
|
|
1036
|
-
warmupEnabled: router.warmupEnabled,
|
|
1037
|
-
initialTheme: requireRequestContext().theme,
|
|
1038
|
-
// No routeName for not-found routes
|
|
1039
|
-
},
|
|
1040
|
-
};
|
|
1041
|
-
|
|
1042
|
-
const rscStream = renderToReadableStream(payload);
|
|
1043
|
-
|
|
1044
|
-
// Determine if this is an RSC request or HTML request.
|
|
1045
|
-
// Partial requests are always RSC (see main isRscRequest comment).
|
|
1046
|
-
const isRscRequest =
|
|
1047
|
-
isPartial ||
|
|
1048
|
-
(!request.headers.get("accept")?.includes("text/html") &&
|
|
1049
|
-
!url.searchParams.has("__html")) ||
|
|
1050
|
-
url.searchParams.has("__rsc");
|
|
1051
|
-
|
|
1052
|
-
if (isRscRequest) {
|
|
1053
|
-
return createResponseWithMergedHeaders(rscStream, {
|
|
1054
|
-
status: 404,
|
|
1055
|
-
headers: { "content-type": "text/x-component;charset=utf-8" },
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
// Delegate to SSR for HTML response (reuse early setup if available)
|
|
1060
|
-
const [ssrModule, streamMode] = await getSSRSetup(
|
|
1061
|
-
handlerCtx,
|
|
1146
|
+
// Wrap the render path in a renderStartMs timeout
|
|
1147
|
+
const executeRender = async (): Promise<Response> => {
|
|
1148
|
+
if (routeMiddleware.length > 0) {
|
|
1149
|
+
const mwResponse = await executeMiddleware(
|
|
1150
|
+
buildRouteMiddlewareEntries<TEnv>(routeMiddleware),
|
|
1062
1151
|
request,
|
|
1063
1152
|
env,
|
|
1064
|
-
|
|
1065
|
-
|
|
1153
|
+
variables,
|
|
1154
|
+
renderHandler,
|
|
1155
|
+
routeReverse,
|
|
1066
1156
|
);
|
|
1067
|
-
const htmlStream = await ssrModule.renderHTML(rscStream, {
|
|
1068
|
-
nonce,
|
|
1069
|
-
streamMode,
|
|
1070
|
-
});
|
|
1071
1157
|
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1158
|
+
if (isPartial || actionContinuation) {
|
|
1159
|
+
const intercepted = interceptRedirectForPartial(
|
|
1160
|
+
mwResponse,
|
|
1161
|
+
createRedirectFlightResponse,
|
|
1162
|
+
);
|
|
1163
|
+
if (intercepted) return intercepted;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
return finalizeResponse(mwResponse);
|
|
1076
1167
|
}
|
|
1077
1168
|
|
|
1078
|
-
|
|
1079
|
-
|
|
1169
|
+
return renderHandler();
|
|
1170
|
+
};
|
|
1171
|
+
|
|
1172
|
+
const renderOutcome = await withTimeout(
|
|
1173
|
+
executeRender(),
|
|
1174
|
+
router.timeouts.renderStartMs,
|
|
1175
|
+
"render-start",
|
|
1176
|
+
);
|
|
1177
|
+
if (renderOutcome.timedOut) {
|
|
1178
|
+
return handleTimeoutResponse(
|
|
1080
1179
|
request,
|
|
1081
|
-
url,
|
|
1082
1180
|
env,
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1181
|
+
url,
|
|
1182
|
+
"render-start",
|
|
1183
|
+
renderOutcome.durationMs,
|
|
1184
|
+
routeKey,
|
|
1185
|
+
);
|
|
1087
1186
|
}
|
|
1187
|
+
return renderOutcome.result;
|
|
1088
1188
|
}
|
|
1089
1189
|
}
|