@rangojs/router 0.27.0 → 0.29.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/dist/bin/rango.js +1 -1
- package/dist/types/__internal.d.ts +7 -1
- package/dist/types/browser/action-fence.d.ts +2 -1
- package/dist/types/browser/event-controller.d.ts +8 -2
- package/dist/types/browser/history-state.d.ts +3 -9
- package/dist/types/browser/navigation-store.d.ts +8 -6
- package/dist/types/browser/partial-update.d.ts +11 -0
- package/dist/types/browser/react/filter-segment-order.d.ts +2 -2
- package/dist/types/browser/react/use-action.d.ts +7 -2
- package/dist/types/browser/react/use-handle.d.ts +19 -16
- package/dist/types/browser/react/use-link-status.d.ts +5 -2
- package/dist/types/browser/segment-reconciler.d.ts +32 -4
- package/dist/types/browser/types.d.ts +24 -5
- package/dist/types/browser/wire-protocol.d.ts +26 -0
- package/dist/types/cache/cache-key-utils.d.ts +11 -5
- package/dist/types/cache/cache-scope.d.ts +34 -22
- package/dist/types/cache/cf/cf-cache-constants.d.ts +2 -2
- package/dist/types/cache/cf/cf-cache-store.d.ts +47 -65
- package/dist/types/cache/cf/cf-kv-utils.d.ts +1 -1
- package/dist/types/cache/handle-snapshot.d.ts +9 -4
- package/dist/types/cache/segment-codec.d.ts +14 -0
- package/dist/types/cache/shell-snapshot.d.ts +1 -1
- package/dist/types/cache/taint.d.ts +5 -3
- package/dist/types/cache/types.d.ts +7 -3
- package/dist/types/cache/vercel/vercel-cache-store.d.ts +8 -6
- package/dist/types/prefetch-markers.d.ts +5 -14
- package/dist/types/prerender/store.d.ts +31 -0
- package/dist/types/prerender/warm-request.d.ts +3 -3
- package/dist/types/prerender.d.ts +2 -2
- package/dist/types/route-name.d.ts +5 -0
- package/dist/types/router/error-handling.d.ts +11 -5
- package/dist/types/router/instrument.d.ts +4 -3
- package/dist/types/router/intercept-resolution.d.ts +25 -9
- package/dist/types/router/match-context.d.ts +6 -11
- package/dist/types/router/match-handlers.d.ts +2 -6
- package/dist/types/router/match-middleware/background-revalidation.d.ts +13 -22
- package/dist/types/router/match-middleware/cache-lookup.d.ts +34 -86
- package/dist/types/router/match-middleware/segment-resolution.d.ts +8 -6
- package/dist/types/router/navigation-snapshot.d.ts +7 -0
- package/dist/types/router/prerender-match.d.ts +21 -6
- package/dist/types/router/preview-match.d.ts +2 -7
- package/dist/types/router/request-classification.d.ts +5 -0
- package/dist/types/router/router-context.d.ts +7 -46
- package/dist/types/router/router-interfaces.d.ts +8 -14
- package/dist/types/router/segment-resolution/helpers.d.ts +19 -3
- package/dist/types/router/segment-resolution/loader-cache.d.ts +3 -3
- package/dist/types/router/segment-resolution/loader-mask.d.ts +4 -4
- package/dist/types/router/segment-resolution/prefetch-deferral.d.ts +20 -18
- package/dist/types/router/segment-resolution/resolution-pass.d.ts +95 -0
- package/dist/types/router/segment-resolution/revalidation.d.ts +82 -31
- package/dist/types/router/segment-resolution/streamed-handler-boundary.d.ts +2 -0
- package/dist/types/router/segment-resolution.d.ts +1 -2
- package/dist/types/router/segment-wrappers.d.ts +11 -48
- package/dist/types/router/telemetry.d.ts +2 -0
- package/dist/types/router/types.d.ts +11 -1
- package/dist/types/rsc/full-payload.d.ts +2 -2
- package/dist/types/rsc/handler-context.d.ts +6 -6
- package/dist/types/rsc/json-route-result.d.ts +5 -9
- package/dist/types/rsc/request-stages.d.ts +203 -0
- package/dist/types/rsc/response-cache-serve.d.ts +7 -12
- package/dist/types/rsc/response-route-handler.d.ts +2 -2
- package/dist/types/rsc/routine-plan.d.ts +1 -1
- package/dist/types/rsc/server-action.d.ts +2 -2
- package/dist/types/rsc/shell-capture-constants.d.ts +1 -1
- package/dist/types/rsc/shell-capture.d.ts +132 -15
- package/dist/types/rsc/shell-serve.d.ts +37 -12
- package/dist/types/server/context.d.ts +9 -8
- package/dist/types/server/handle-store.d.ts +16 -0
- package/dist/types/server/render-pass.d.ts +72 -0
- package/dist/types/server/request-context.d.ts +53 -104
- package/dist/types/server/rewrite-trail.d.ts +2 -2
- package/dist/types/testing/dispatch.d.ts +35 -18
- package/dist/types/testing/render-route.d.ts +43 -8
- package/dist/types/testing/serve-shell-request.d.ts +8 -1
- package/dist/types/types/cache-types.d.ts +6 -3
- package/dist/types/types/error-types.d.ts +30 -3
- package/dist/types/types/handler-context.d.ts +9 -1
- package/dist/types/types/segments.d.ts +1 -1
- package/dist/types/vite/discovery/build-discovery-phase.d.ts +40 -0
- package/dist/types/vite/discovery/build-env.d.ts +22 -0
- package/dist/types/vite/discovery/bundle-scan-phase.d.ts +12 -0
- package/dist/types/vite/discovery/dev-prerender-cache.d.ts +3 -2
- package/dist/types/vite/discovery/dev-server-phase.d.ts +26 -0
- package/dist/types/vite/discovery/discovery-errors.d.ts +1 -1
- package/dist/types/vite/discovery/state.d.ts +12 -0
- package/dist/types/vite/plugins/version-plugin.d.ts +1 -1
- package/dist/types/vite/plugins/virtual-entries.d.ts +1 -1
- package/dist/types/vite/router-discovery.d.ts +8 -47
- package/dist/types/vite/temp-rsc-server.d.ts +39 -0
- package/dist/types/vite/utils/prerender-utils.d.ts +9 -0
- package/dist/types/wire-params.d.ts +39 -0
- package/dist/vite/index.js +3822 -3727
- package/package.json +1 -1
- package/skills/cache-guide/SKILL.md +8 -5
- package/skills/caching/SKILL.md +37 -18
- package/skills/client-urls/SKILL.md +4 -2
- package/skills/document-cache/SKILL.md +13 -1
- package/skills/handler-use/SKILL.md +1 -1
- package/skills/hooks/SKILL.md +1 -1
- package/skills/hooks/data.md +8 -1
- package/skills/hooks/handle-and-actions.md +33 -2
- package/skills/hooks/navigation.md +121 -15
- package/skills/hooks/state.md +6 -4
- package/skills/hooks/urls.md +16 -5
- package/skills/intercept/SKILL.md +23 -7
- package/skills/middleware/SKILL.md +18 -0
- package/skills/observability/SKILL.md +30 -0
- package/skills/ppr/SKILL.md +18 -3
- package/skills/prerender/SKILL.md +39 -15
- package/skills/rango/SKILL.md +5 -1
- package/skills/server-actions/SKILL.md +15 -1
- package/skills/testing/client-components.md +25 -18
- package/skills/testing/response-routes.md +6 -4
- package/skills/testing/serve-shell-request.md +7 -7
- package/skills/use-cache/SKILL.md +46 -8
- package/skills/view-transitions/SKILL.md +1 -1
- package/src/__internal.ts +7 -1
- package/src/browser/action-fence.ts +2 -1
- package/src/browser/connection-warmup.ts +3 -1
- package/src/browser/event-controller.ts +37 -13
- package/src/browser/history-state.ts +6 -12
- package/src/browser/navigation-bridge.ts +59 -26
- package/src/browser/navigation-client.ts +20 -25
- package/src/browser/navigation-store.ts +25 -27
- package/src/browser/navigation-transaction.ts +4 -1
- package/src/browser/network-error-handler.ts +4 -0
- package/src/browser/partial-update.ts +33 -6
- package/src/browser/prefetch/cache.ts +2 -1
- package/src/browser/prefetch/fetch.ts +8 -16
- package/src/browser/prefetch/queue.ts +4 -4
- package/src/browser/react/NavigationProvider.tsx +2 -1
- package/src/browser/react/filter-segment-order.ts +2 -2
- package/src/browser/react/use-action.ts +24 -48
- package/src/browser/react/use-handle.ts +22 -18
- package/src/browser/react/use-link-status.ts +48 -60
- package/src/browser/react/use-navigation.ts +92 -41
- package/src/browser/rsc-router.tsx +1 -0
- package/src/browser/segment-reconciler.ts +109 -53
- package/src/browser/server-action-bridge.ts +81 -61
- package/src/browser/types.ts +25 -5
- package/src/browser/wire-protocol.ts +43 -0
- package/src/cache/cache-key-utils.ts +11 -5
- package/src/cache/cache-runtime.ts +132 -75
- package/src/cache/cache-scope.ts +110 -64
- package/src/cache/cf/cf-cache-constants.ts +2 -2
- package/src/cache/cf/cf-cache-store.ts +486 -874
- package/src/cache/cf/cf-kv-utils.ts +1 -1
- package/src/cache/document-cache.ts +64 -46
- package/src/cache/handle-snapshot.ts +19 -7
- package/src/cache/read-through-swr.ts +20 -18
- package/src/cache/segment-codec.ts +55 -0
- package/src/cache/shell-snapshot.ts +2 -2
- package/src/cache/tag-invalidation.ts +6 -2
- package/src/cache/taint.ts +5 -3
- package/src/cache/types.ts +7 -3
- package/src/cache/vercel/vercel-cache-store.ts +243 -310
- package/src/handles/pushed-by.ts +1 -1
- package/src/prefetch-markers.ts +5 -16
- package/src/prerender/store.ts +76 -0
- package/src/prerender/warm-request.ts +8 -4
- package/src/prerender.ts +2 -2
- package/src/route-name.ts +8 -0
- package/src/router/error-handling.ts +22 -10
- package/src/router/instrument.ts +4 -3
- package/src/router/intercept-resolution.ts +82 -75
- package/src/router/loader-resolution.ts +5 -4
- package/src/router/match-api.ts +5 -5
- package/src/router/match-context.ts +23 -12
- package/src/router/match-handlers.ts +8 -20
- package/src/router/match-middleware/background-revalidation.ts +46 -57
- package/src/router/match-middleware/cache-lookup.ts +677 -726
- package/src/router/match-middleware/cache-store.ts +4 -8
- package/src/router/match-middleware/intercept-resolution.ts +3 -23
- package/src/router/match-middleware/segment-resolution.ts +34 -61
- package/src/router/middleware.ts +69 -11
- package/src/router/navigation-snapshot.ts +14 -4
- package/src/router/prerender-match.ts +100 -44
- package/src/router/preview-match.ts +6 -41
- package/src/router/request-classification.ts +13 -7
- package/src/router/route-snapshot.ts +2 -5
- package/src/router/router-context.ts +10 -95
- package/src/router/router-interfaces.ts +8 -14
- package/src/router/segment-resolution/helpers.ts +49 -13
- package/src/router/segment-resolution/loader-cache.ts +15 -9
- package/src/router/segment-resolution/loader-mask.ts +5 -5
- package/src/router/segment-resolution/prefetch-deferral.ts +30 -27
- package/src/router/segment-resolution/resolution-pass.ts +139 -0
- package/src/router/segment-resolution/revalidation.ts +939 -789
- package/src/router/segment-resolution/streamed-handler-boundary.ts +3 -0
- package/src/router/segment-resolution.ts +4 -13
- package/src/router/segment-wrappers.ts +51 -269
- package/src/router/telemetry.ts +5 -0
- package/src/router/types.ts +11 -1
- package/src/router.ts +19 -17
- package/src/rsc/full-payload.ts +6 -5
- package/src/rsc/handler-context.ts +8 -14
- package/src/rsc/handler.ts +126 -507
- package/src/rsc/json-route-result.ts +5 -9
- package/src/rsc/loader-fetch.ts +6 -5
- package/src/rsc/progressive-enhancement.ts +5 -0
- package/src/rsc/request-stages.ts +759 -0
- package/src/rsc/response-cache-serve.ts +10 -14
- package/src/rsc/response-route-handler.ts +13 -5
- package/src/rsc/rewrite-passes.ts +2 -1
- package/src/rsc/routine-plan.ts +1 -1
- package/src/rsc/rsc-rendering.ts +164 -349
- package/src/rsc/server-action.ts +87 -113
- package/src/rsc/shell-capture-constants.ts +1 -1
- package/src/rsc/shell-capture.ts +275 -227
- package/src/rsc/shell-serve.ts +121 -18
- package/src/rsc/ssr-setup.ts +5 -4
- package/src/segment-system.tsx +3 -3
- package/src/server/context.ts +22 -25
- package/src/server/handle-store.ts +55 -0
- package/src/server/render-pass.ts +291 -0
- package/src/server/request-context.ts +75 -115
- package/src/server/rewrite-trail.ts +6 -4
- package/src/ssr/index.tsx +1 -1
- package/src/testing/dispatch.ts +226 -710
- package/src/testing/e2e/page-helpers.ts +2 -2
- package/src/testing/render-route.tsx +199 -13
- package/src/testing/serve-shell-request.ts +36 -40
- package/src/types/cache-types.ts +6 -3
- package/src/types/error-types.ts +30 -3
- package/src/types/handler-context.ts +12 -1
- package/src/types/segments.ts +1 -1
- package/src/vite/discovery/build-discovery-phase.ts +204 -0
- package/src/vite/discovery/build-env.ts +148 -0
- package/src/vite/discovery/bundle-scan-phase.ts +128 -0
- package/src/vite/discovery/dev-prerender-cache.ts +8 -3
- package/src/vite/discovery/dev-server-phase.ts +1776 -0
- package/src/vite/discovery/discover-routers.ts +1 -1
- package/src/vite/discovery/discovery-errors.ts +1 -1
- package/src/vite/discovery/prerender-collection.ts +24 -39
- package/src/vite/discovery/state.ts +15 -0
- package/src/vite/plugins/version-plugin.ts +1 -1
- package/src/vite/plugins/virtual-entries.ts +1 -1
- package/src/vite/router-discovery.ts +29 -2428
- package/src/vite/temp-rsc-server.ts +223 -0
- package/src/vite/utils/prerender-utils.ts +47 -0
- package/src/wire-params.ts +40 -0
- package/dist/types/router/segment-resolution/fresh.d.ts +0 -72
- package/src/router/segment-resolution/fresh.ts +0 -945
|
@@ -63,7 +63,6 @@
|
|
|
63
63
|
*
|
|
64
64
|
* Handler Context:
|
|
65
65
|
* - handlerContext: Context passed to loaders
|
|
66
|
-
* - loaderPromises: Memoized loader promises
|
|
67
66
|
*
|
|
68
67
|
* Intercepts:
|
|
69
68
|
* - interceptResult: Detected intercept (if soft navigation)
|
|
@@ -118,16 +117,8 @@ import type {
|
|
|
118
117
|
import type { HandlerContext, ResolvedSegment } from "../types.js";
|
|
119
118
|
import type { RouteMatchResult } from "./pattern-matching.js";
|
|
120
119
|
import type { InterceptResult } from "./router-context.js";
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
* Action context passed to matchPartial
|
|
124
|
-
*/
|
|
125
|
-
export interface ActionContext {
|
|
126
|
-
actionId?: string;
|
|
127
|
-
actionUrl?: URL;
|
|
128
|
-
actionResult?: any;
|
|
129
|
-
formData?: FormData;
|
|
130
|
-
}
|
|
120
|
+
import type { ResolutionPassInput } from "./segment-resolution/resolution-pass.js";
|
|
121
|
+
import type { ActionContext } from "./types.js";
|
|
131
122
|
|
|
132
123
|
/**
|
|
133
124
|
* Match context containing all state for the match pipeline
|
|
@@ -145,6 +136,8 @@ export interface MatchContext<TEnv = any> {
|
|
|
145
136
|
clientSegmentIds: string[];
|
|
146
137
|
clientSegmentSet: Set<string>;
|
|
147
138
|
stale: boolean;
|
|
139
|
+
/** NavigationSnapshot.heldBoundary: the walk stops above it. */
|
|
140
|
+
heldBoundary?: string;
|
|
148
141
|
|
|
149
142
|
// Previous navigation state
|
|
150
143
|
prevUrl: URL;
|
|
@@ -160,7 +153,6 @@ export interface MatchContext<TEnv = any> {
|
|
|
160
153
|
|
|
161
154
|
// Handler context (for loaders)
|
|
162
155
|
handlerContext: HandlerContext<any, TEnv>;
|
|
163
|
-
loaderPromises: Map<string, Promise<any>>;
|
|
164
156
|
|
|
165
157
|
// Route map for server-side ctx.reverse() resolution
|
|
166
158
|
routeMap: Record<string, string>;
|
|
@@ -214,6 +206,25 @@ export function rendersLive(
|
|
|
214
206
|
return ctx.isAction || ctx.stale;
|
|
215
207
|
}
|
|
216
208
|
|
|
209
|
+
/** This match as the input of a revalidating resolution pass (resolution-pass.ts). */
|
|
210
|
+
export function resolutionPassInput<TEnv>(
|
|
211
|
+
ctx: MatchContext<TEnv>,
|
|
212
|
+
): ResolutionPassInput<TEnv> {
|
|
213
|
+
return {
|
|
214
|
+
context: ctx.handlerContext,
|
|
215
|
+
client: ctx.clientSegmentSet,
|
|
216
|
+
params: ctx.matched.params,
|
|
217
|
+
prevParams: ctx.prevParams,
|
|
218
|
+
request: ctx.request,
|
|
219
|
+
prevUrl: ctx.prevUrl,
|
|
220
|
+
nextUrl: ctx.url,
|
|
221
|
+
routeKey: ctx.routeKey,
|
|
222
|
+
actionContext: ctx.actionContext,
|
|
223
|
+
stale: ctx.stale,
|
|
224
|
+
heldBoundary: ctx.heldBoundary,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
217
228
|
/**
|
|
218
229
|
* Mutable state that flows through the pipeline
|
|
219
230
|
*/
|
|
@@ -13,14 +13,10 @@ import {
|
|
|
13
13
|
type InterceptEntry,
|
|
14
14
|
type InterceptSelectorContext,
|
|
15
15
|
} from "../server/context.js";
|
|
16
|
-
import type { MatchApiDeps } from "./types.js";
|
|
16
|
+
import type { ActionContext, MatchApiDeps } from "./types.js";
|
|
17
17
|
import type { RouterContext } from "./router-context.js";
|
|
18
18
|
import { runWithRouterContext } from "./router-context.js";
|
|
19
|
-
import {
|
|
20
|
-
type ActionContext,
|
|
21
|
-
type MatchContext,
|
|
22
|
-
createPipelineState,
|
|
23
|
-
} from "./match-context.js";
|
|
19
|
+
import { type MatchContext, createPipelineState } from "./match-context.js";
|
|
24
20
|
import { createMatchPartialPipeline } from "./match-pipelines.js";
|
|
25
21
|
import { collectMatchResult } from "./match-result.js";
|
|
26
22
|
import {
|
|
@@ -194,11 +190,8 @@ export interface MatchHandlers<TEnv = any> {
|
|
|
194
190
|
handler: MiddlewareFn;
|
|
195
191
|
params: Record<string, string>;
|
|
196
192
|
}>;
|
|
197
|
-
responseType?: string;
|
|
198
|
-
handler?: Function;
|
|
199
193
|
params?: Record<string, string>;
|
|
200
|
-
|
|
201
|
-
manifestEntry?: EntryData;
|
|
194
|
+
routeKey?: string;
|
|
202
195
|
} | null>;
|
|
203
196
|
}
|
|
204
197
|
|
|
@@ -259,12 +252,7 @@ export function createMatchHandlers<TEnv = any>(
|
|
|
259
252
|
async function createMatchContextForPartial(
|
|
260
253
|
request: Request,
|
|
261
254
|
env: TEnv,
|
|
262
|
-
actionContext?:
|
|
263
|
-
actionId?: string;
|
|
264
|
-
actionUrl?: URL;
|
|
265
|
-
actionResult?: any;
|
|
266
|
-
formData?: FormData;
|
|
267
|
-
},
|
|
255
|
+
actionContext?: ActionContext,
|
|
268
256
|
): Promise<MatchContext<TEnv> | null> {
|
|
269
257
|
return _createMatchContextForPartial(
|
|
270
258
|
request,
|
|
@@ -277,13 +265,13 @@ export function createMatchHandlers<TEnv = any>(
|
|
|
277
265
|
|
|
278
266
|
async function match(request: Request, env: TEnv): Promise<MatchResult> {
|
|
279
267
|
// Silence telemetry for the PPR background shell capture: it re-runs match()
|
|
280
|
-
// under a derived request context
|
|
268
|
+
// under a derived request context with _shellCaptureState (shell-capture.ts
|
|
281
269
|
// attemptCapture), re-using the foreground Request — a second request.start/
|
|
282
270
|
// cache.decision/request.end stamped with the same WeakMap-keyed requestId
|
|
283
271
|
// would double-count dashboards. Derived here (inside the capture's active
|
|
284
272
|
// request-context ALS) so the read sees the derived context, not module state.
|
|
285
273
|
const emitTelemetry =
|
|
286
|
-
hasTelemetry && !_getRequestContext()?.
|
|
274
|
+
hasTelemetry && !_getRequestContext()?._shellCaptureState?.run;
|
|
287
275
|
const requestId = emitTelemetry ? getRequestId(request) : undefined;
|
|
288
276
|
return runWithRouterLogContext({ request, transaction: "match" }, () => {
|
|
289
277
|
const routerCtx = buildRouterContext();
|
|
@@ -409,9 +397,9 @@ export function createMatchHandlers<TEnv = any>(
|
|
|
409
397
|
actionContext?: ActionContext,
|
|
410
398
|
): Promise<MatchResult | null> {
|
|
411
399
|
// See match() above: the PPR shell capture re-runs matchPartial() under a
|
|
412
|
-
//
|
|
400
|
+
// _shellCaptureState context and must stay invisible to the sink.
|
|
413
401
|
const emitTelemetry =
|
|
414
|
-
hasTelemetry && !_getRequestContext()?.
|
|
402
|
+
hasTelemetry && !_getRequestContext()?._shellCaptureState?.run;
|
|
415
403
|
const partialRequestId = emitTelemetry ? getRequestId(request) : undefined;
|
|
416
404
|
return runWithRouterLogContext(
|
|
417
405
|
{ request, transaction: "matchPartial" },
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
* |
|
|
37
37
|
* v
|
|
38
38
|
* +---------------------------+
|
|
39
|
-
* |
|
|
39
|
+
* | FRESH segment pass | Fresh resolution (no revalidation)
|
|
40
40
|
* | + resolveIntercepts() | Ensures complete components
|
|
41
41
|
* +---------------------------+
|
|
42
42
|
* |
|
|
@@ -94,14 +94,17 @@
|
|
|
94
94
|
* FRESH RESOLUTION (NO REVALIDATION)
|
|
95
95
|
* ===================================
|
|
96
96
|
*
|
|
97
|
-
* Both full and partial requests
|
|
97
|
+
* Both full and partial requests resolve with a FRESH pass (without
|
|
98
98
|
* revalidation logic) to ensure all segments have complete components.
|
|
99
99
|
* Using revalidation-aware resolution would produce null components
|
|
100
|
-
* for skipped segments, which would corrupt the cache entry.
|
|
100
|
+
* for skipped segments, which would corrupt the cache entry. Under an
|
|
101
|
+
* intercept the walk still skips the intercepted route's entry, as the MISS
|
|
102
|
+
* does: an intercept: record never holds the route's page.
|
|
101
103
|
*/
|
|
102
104
|
import type { ResolvedSegment } from "../../types.js";
|
|
103
105
|
import type { MatchContext, MatchPipelineState } from "../match-context.js";
|
|
104
106
|
import { getRouterContext, type RouterContext } from "../router-context.js";
|
|
107
|
+
import { interceptRecordKey } from "../intercept-resolution.js";
|
|
105
108
|
import type { CacheScope } from "../../cache/cache-scope.js";
|
|
106
109
|
import type { GeneratorMiddleware } from "./cache-lookup.js";
|
|
107
110
|
import { debugLog, debugWarn, getOrCreateRequestId } from "../logging.js";
|
|
@@ -109,12 +112,16 @@ import { INTERNAL_RANGO_DEBUG } from "../../internal-debug.js";
|
|
|
109
112
|
import { getContext } from "../../server/context.js";
|
|
110
113
|
import { executionStart } from "../../cache/tag-invalidation.js";
|
|
111
114
|
import {
|
|
112
|
-
bindRes,
|
|
113
115
|
createRequestContext,
|
|
114
|
-
|
|
116
|
+
runAsBackgroundWork,
|
|
115
117
|
type RequestContext,
|
|
116
118
|
} from "../../server/request-context.js";
|
|
119
|
+
import { deriveRenderPass } from "../../server/render-pass.js";
|
|
117
120
|
import { recordUse } from "../segment-resolution/prefetch-deferral.js";
|
|
121
|
+
import {
|
|
122
|
+
freshPassInput,
|
|
123
|
+
heldNothingPassInput,
|
|
124
|
+
} from "../segment-resolution/resolution-pass.js";
|
|
118
125
|
|
|
119
126
|
/**
|
|
120
127
|
* Re-render a cached route in the background and write it with
|
|
@@ -129,25 +136,14 @@ import { recordUse } from "../segment-resolution/prefetch-deferral.js";
|
|
|
129
136
|
* MAX_REVALIDATION_INTERVAL, as after a refresh that throws.
|
|
130
137
|
*
|
|
131
138
|
* Runs on a DERIVED request context that owns the per-render state the
|
|
132
|
-
* foreground reads while it is still producing the page
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* - _metricsStore: undefined, and the DSL store below has `metrics` unset
|
|
141
|
-
* (track() reads that one), so nothing lands on the foreground's perf
|
|
142
|
-
* timeline. ctx.Store.run closes over ctx.Store, so the derived store
|
|
143
|
-
* needs its own run.
|
|
144
|
-
* - response writes (headers, cookies, status, onResponse callbacks) go to
|
|
145
|
-
* a throwaway context (whose status gates the write, above) and are
|
|
146
|
-
* dropped: a layout above the cache() boundary is outside the header
|
|
147
|
-
* guard and an error boundary sets a status, so they would otherwise
|
|
148
|
-
* reach the live response.
|
|
149
|
-
* runWithRequestContext also re-establishes the request ALS, which a waitUntil
|
|
150
|
-
* task on workerd loses; the DSL store is a different ALS (build context).
|
|
139
|
+
* foreground reads while it is still producing the page:
|
|
140
|
+
* RENDER_PASS_FIELDS["background-revalidation"] (server/render-pass.ts) lists
|
|
141
|
+
* each field and why. The DSL store below has `metrics` unset too (track()
|
|
142
|
+
* reads that one), so nothing lands on the foreground's perf timeline;
|
|
143
|
+
* ctx.Store.run closes over ctx.Store, so the derived store needs its own run.
|
|
144
|
+
* runAsBackgroundWork also re-establishes the request ALS, which a waitUntil
|
|
145
|
+
* task on workerd loses, and marks the pass's onError reports `background`;
|
|
146
|
+
* the DSL store is a different ALS (build context).
|
|
151
147
|
*/
|
|
152
148
|
export async function rerenderAndCacheRoute<TEnv>(
|
|
153
149
|
ctx: MatchContext<TEnv>,
|
|
@@ -157,8 +153,7 @@ export async function rerenderAndCacheRoute<TEnv>(
|
|
|
157
153
|
): Promise<number> {
|
|
158
154
|
const start = executionStart();
|
|
159
155
|
const handleStore = routerCtx.createHandleStore();
|
|
160
|
-
// Response writes land in a throwaway context nothing merges or drains.
|
|
161
|
-
// mutators are closures over its own stub, and they keep the same guards.
|
|
156
|
+
// Response writes land in a throwaway context nothing merges or drains.
|
|
162
157
|
const sink = createRequestContext({
|
|
163
158
|
env: ctx.env,
|
|
164
159
|
request: ctx.request,
|
|
@@ -166,26 +161,10 @@ export async function rerenderAndCacheRoute<TEnv>(
|
|
|
166
161
|
variables: {},
|
|
167
162
|
themeConfig: requestCtx._themeConfig,
|
|
168
163
|
});
|
|
169
|
-
const renderCtx
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
_metricsStore: undefined,
|
|
174
|
-
_renderErrors: [],
|
|
175
|
-
_recoveredHandlerErrors: undefined,
|
|
176
|
-
_onResponseCallbacks: [],
|
|
177
|
-
header: sink.header,
|
|
178
|
-
setCookie: sink.setCookie,
|
|
179
|
-
deleteCookie: sink.deleteCookie,
|
|
180
|
-
setStatus: sink.setStatus,
|
|
181
|
-
_setStatus: sink._setStatus,
|
|
182
|
-
setTheme: sink.setTheme,
|
|
183
|
-
_rotateStateCookie: sink._rotateStateCookie,
|
|
184
|
-
_setKeepCacheDirective: sink._setKeepCacheDirective,
|
|
185
|
-
},
|
|
186
|
-
);
|
|
187
|
-
// ctx.res reads the sink's stub, not the live request's.
|
|
188
|
-
bindRes(renderCtx, () => sink.res);
|
|
164
|
+
const renderCtx = deriveRenderPass(requestCtx, "background-revalidation", {
|
|
165
|
+
handleStore,
|
|
166
|
+
sink,
|
|
167
|
+
});
|
|
189
168
|
const store = Object.assign(Object.create(ctx.Store), { metrics: undefined });
|
|
190
169
|
const runInStore = <T>(fn: () => T): T =>
|
|
191
170
|
getContext().runWithStore(
|
|
@@ -194,7 +173,7 @@ export async function rerenderAndCacheRoute<TEnv>(
|
|
|
194
173
|
store.parent,
|
|
195
174
|
fn,
|
|
196
175
|
);
|
|
197
|
-
return
|
|
176
|
+
return runAsBackgroundWork(renderCtx, async () => {
|
|
198
177
|
const handlerContext = routerCtx.createHandlerContext(
|
|
199
178
|
ctx.matched.params,
|
|
200
179
|
ctx.request,
|
|
@@ -210,26 +189,36 @@ export async function rerenderAndCacheRoute<TEnv>(
|
|
|
210
189
|
const loaderPromises = new Map<string, Promise<any>>();
|
|
211
190
|
routerCtx.setupLoaderAccess(handlerContext, loaderPromises);
|
|
212
191
|
|
|
213
|
-
const segments = await runInStore(() =>
|
|
192
|
+
const { segments } = await runInStore(() =>
|
|
214
193
|
routerCtx.resolveAllSegments(
|
|
194
|
+
freshPassInput(handlerContext, ctx.routeKey, ctx.matched.params, {
|
|
195
|
+
skipLoaders: true,
|
|
196
|
+
partialRequest: !ctx.isFullMatch,
|
|
197
|
+
}),
|
|
215
198
|
ctx.entries,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
199
|
+
// Under an intercept the route's own entry is skipped, as on a MISS.
|
|
200
|
+
{
|
|
201
|
+
interceptResult: ctx.interceptResult,
|
|
202
|
+
localRouteName: ctx.localRouteName,
|
|
203
|
+
pathname: handlerContext.pathname,
|
|
204
|
+
},
|
|
221
205
|
),
|
|
222
206
|
);
|
|
223
207
|
if (ctx.interceptResult) {
|
|
224
208
|
segments.push(
|
|
225
209
|
...(await runInStore(() =>
|
|
226
210
|
routerCtx.resolveInterceptEntry(
|
|
211
|
+
// Nothing held: render fresh. Its loaders are skipped as the
|
|
212
|
+
// route's are: the record drops them.
|
|
213
|
+
heldNothingPassInput(
|
|
214
|
+
handlerContext,
|
|
215
|
+
ctx.interceptResult!.intercept.routeName,
|
|
216
|
+
ctx.matched.params,
|
|
217
|
+
{ skipLoaders: true },
|
|
218
|
+
),
|
|
227
219
|
ctx.interceptResult!.intercept,
|
|
228
220
|
ctx.interceptResult!.entry,
|
|
229
|
-
ctx.matched.params,
|
|
230
|
-
handlerContext,
|
|
231
221
|
true, // belongsToRoute
|
|
232
|
-
undefined, // no revalidationContext: render fresh
|
|
233
222
|
// A handler error rejects, so the failure is never cached.
|
|
234
223
|
{ background: true },
|
|
235
224
|
),
|
|
@@ -251,7 +240,7 @@ export async function rerenderAndCacheRoute<TEnv>(
|
|
|
251
240
|
ctx.pathname,
|
|
252
241
|
ctx.matched.params,
|
|
253
242
|
segments,
|
|
254
|
-
ctx.
|
|
243
|
+
interceptRecordKey(ctx.interceptResult),
|
|
255
244
|
start,
|
|
256
245
|
);
|
|
257
246
|
return segments.length;
|