@rangojs/router 0.27.0 → 0.28.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/event-controller.d.ts +2 -1
- package/dist/types/browser/history-state.d.ts +3 -9
- package/dist/types/browser/navigation-store.d.ts +8 -6
- package/dist/types/browser/react/filter-segment-order.d.ts +2 -2
- package/dist/types/browser/segment-reconciler.d.ts +6 -4
- package/dist/types/browser/types.d.ts +2 -1
- package/dist/types/browser/wire-protocol.d.ts +25 -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/tag-invalidation.d.ts +10 -0
- 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 +4 -4
- 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 +4 -11
- package/dist/types/router/match-handlers.d.ts +2 -6
- package/dist/types/router/match-middleware/background-revalidation.d.ts +10 -20
- 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/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/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 +93 -0
- package/dist/types/router/segment-resolution/revalidation.d.ts +82 -31
- 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 +10 -0
- 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 +24 -104
- package/dist/types/server/rewrite-trail.d.ts +2 -2
- package/dist/types/testing/dispatch.d.ts +35 -18
- package/dist/types/types/cache-types.d.ts +6 -3
- package/dist/types/types/error-types.d.ts +9 -1
- 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 +34 -0
- package/dist/vite/index.js +3809 -3710
- package/package.json +1 -1
- package/skills/cache-guide/SKILL.md +8 -5
- package/skills/caching/SKILL.md +37 -18
- package/skills/document-cache/SKILL.md +13 -1
- package/skills/handler-use/SKILL.md +1 -1
- package/skills/intercept/SKILL.md +17 -7
- package/skills/middleware/SKILL.md +18 -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 +8 -1
- package/skills/testing/response-routes.md +6 -4
- package/skills/use-cache/SKILL.md +46 -8
- package/src/__internal.ts +7 -1
- package/src/browser/connection-warmup.ts +3 -1
- package/src/browser/event-controller.ts +5 -3
- package/src/browser/history-state.ts +6 -12
- package/src/browser/navigation-bridge.ts +14 -13
- package/src/browser/navigation-client.ts +18 -25
- package/src/browser/navigation-store.ts +25 -27
- package/src/browser/navigation-transaction.ts +4 -1
- 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/rsc-router.tsx +1 -0
- package/src/browser/segment-reconciler.ts +66 -53
- package/src/browser/server-action-bridge.ts +50 -57
- package/src/browser/types.ts +2 -1
- package/src/browser/wire-protocol.ts +41 -0
- package/src/cache/cache-key-utils.ts +11 -5
- package/src/cache/cache-runtime.ts +110 -50
- 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 +34 -13
- package/src/cache/handle-snapshot.ts +19 -7
- package/src/cache/segment-codec.ts +55 -0
- package/src/cache/shell-snapshot.ts +2 -2
- package/src/cache/tag-invalidation.ts +21 -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 +4 -4
- package/src/router/instrument.ts +4 -3
- package/src/router/intercept-resolution.ts +77 -75
- package/src/router/loader-resolution.ts +5 -4
- package/src/router/match-api.ts +4 -5
- package/src/router/match-context.ts +20 -12
- package/src/router/match-handlers.ts +8 -20
- package/src/router/match-middleware/background-revalidation.ts +41 -53
- package/src/router/match-middleware/cache-lookup.ts +675 -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 +4 -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/loader-cache.ts +14 -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 +137 -0
- package/src/router/segment-resolution/revalidation.ts +897 -776
- 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 +10 -0
- package/src/router.ts +12 -13
- 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 +757 -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 +212 -169
- 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 +26 -115
- package/src/server/rewrite-trail.ts +6 -4
- package/src/ssr/index.tsx +1 -1
- package/src/testing/dispatch.ts +223 -710
- package/src/testing/e2e/page-helpers.ts +2 -2
- package/src/testing/serve-shell-request.ts +23 -36
- package/src/types/cache-types.ts +6 -3
- package/src/types/error-types.ts +9 -1
- 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 +35 -0
- package/dist/types/router/segment-resolution/fresh.d.ts +0 -72
- package/src/router/segment-resolution/fresh.ts +0 -945
|
@@ -25,12 +25,12 @@ export declare function recordRewriteHop(reqCtx: TrailContext, from: URL, to: UR
|
|
|
25
25
|
export declare function recordRewriteShell(reqCtx: TrailContext, audience: RewriteShell | undefined): void;
|
|
26
26
|
/** The last hop's `rewrite(...).shell()` choice; undefined: none. */
|
|
27
27
|
export declare function rewriteShellAudience(reqCtx: TrailContext | undefined): RewriteShell | undefined;
|
|
28
|
-
type AudienceContext = Pick<RequestContext<any>, "
|
|
28
|
+
type AudienceContext = Pick<RequestContext<any>, "_shellCaptureState" | "_documentCacheRender" | "res">;
|
|
29
29
|
/**
|
|
30
30
|
* A render other visitors may be served: a PPR shell capture, or a render
|
|
31
31
|
* the document cache stores (its response opted in before next()). It shows
|
|
32
32
|
* no visitor theme, and no visitor URL unless it is a visitor-keyed shell
|
|
33
|
-
* capture (`
|
|
33
|
+
* capture (`_shellCaptureState.forVisitor`).
|
|
34
34
|
*/
|
|
35
35
|
export declare function rendersForSharedAudience(reqCtx: AudienceContext): boolean;
|
|
36
36
|
/**
|
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
* dispatch — in-process request -> Response for unit/integration tests,
|
|
3
3
|
* WITHOUT the Flight RSC runtime.
|
|
4
4
|
*
|
|
5
|
-
* dispatch runs the
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* dispatch runs the production handler's request stages
|
|
6
|
+
* (rsc/request-stages.ts: classify, the terminal plans, the global middleware
|
|
7
|
+
* passes, the response route and the response's finalization) so that
|
|
8
|
+
* redirects, 404s, reloads, response routes (path.json / path.text /
|
|
9
|
+
* path.html / ...), and middleware short-circuits behave exactly as in
|
|
10
|
+
* production. It deliberately
|
|
8
11
|
* does NOT render React Server Components: there is no Flight stream, no SSR,
|
|
9
12
|
* and no DOM. Hit an RSC (component) route and dispatch throws a clear error
|
|
10
13
|
* directing you to renderToFlightString/renderServerTree/renderHandler or an e2e test.
|
|
@@ -17,19 +20,20 @@
|
|
|
17
20
|
* so a global auth middleware can 401/redirect them and middleware-set
|
|
18
21
|
* cookies/headers merge onto the 308/404 the way createResponseWithMergedHeaders
|
|
19
22
|
* merges them in production.
|
|
20
|
-
* - Response routes (non-RSC)
|
|
23
|
+
* - Response routes (non-RSC), served by production's handleResponseRoute
|
|
24
|
+
* (rsc/response-route-handler.ts) -> serialized Response
|
|
21
25
|
* - json: JSON.stringify(result) (bare value) with application/json
|
|
22
26
|
* - text/html/xml/md: String(result) with the mapped MIME type
|
|
23
|
-
* - handler returning or throwing a Response: re-wrapped
|
|
24
|
-
*
|
|
25
|
-
*
|
|
27
|
+
* - handler returning or throwing a Response: re-wrapped (stub
|
|
28
|
+
* headers/cookies merged, Set-Cookie preserved, WebSocket upgrade passed
|
|
29
|
+
* through without reconstruction)
|
|
26
30
|
* - handler throwing a non-Response error: typed 500 / RouterError
|
|
27
|
-
* status
|
|
28
|
-
*
|
|
31
|
+
* status (RFC 9457 problem+json body with application/problem+json for
|
|
32
|
+
* json routes, text/plain message otherwise)
|
|
29
33
|
* - content-negotiated route: Vary: Accept appended
|
|
30
34
|
* - cached response route (cache({...})): getResponse/putResponse
|
|
31
|
-
* hit/SWR/tag write, resolved from the matched entry tree
|
|
32
|
-
*
|
|
35
|
+
* hit/SWR/tag write, resolved from the matched entry tree. The write is
|
|
36
|
+
* scheduled via ctx.waitUntil
|
|
33
37
|
* (a microtask without an executionContext), so a HIT-asserting test must
|
|
34
38
|
* flush microtasks between the seeding dispatch and the asserting one.
|
|
35
39
|
* - Global middleware (router.use(...)) AND route-level middleware, with full
|
|
@@ -38,10 +42,17 @@
|
|
|
38
42
|
* global middleware runs first (so an auth gate can still 401/redirect),
|
|
39
43
|
* then — if it passes through — an X-RSC-Reload is returned. Route-level
|
|
40
44
|
* middleware is skipped on a partial, exactly as production skips it.
|
|
41
|
-
* - A middleware redirect (3xx + Location) on a partial/action request
|
|
42
|
-
* (?_rsc_partial / ?_rsc_action)
|
|
43
|
-
*
|
|
45
|
+
* - A global middleware redirect (3xx + Location) on a partial/action request
|
|
46
|
+
* (?_rsc_partial / ?_rsc_action), and a findMatch() redirect on a partial
|
|
47
|
+
* request: a 204 + X-RSC-Redirect, so fetch() does not auto-follow the 3xx —
|
|
44
48
|
* identical to production's no-location-state path.
|
|
49
|
+
* - The terminal plans production answers inside the global chain
|
|
50
|
+
* (terminalPlanResponse): a `_rsc_v` version mismatch and a `_rsc_rid` app
|
|
51
|
+
* switch reload (X-RSC-Reload), and an action (?_rsc_action) a rewrite moved
|
|
52
|
+
* to a target that is not a page route throws production's error.
|
|
53
|
+
* - Route params and name are set inside the global chain, after classify, by
|
|
54
|
+
* the stage production's executeRequest runs (recordPlanRoute): global
|
|
55
|
+
* middleware sees them after next(), not before it.
|
|
45
56
|
* - The open-redirect guard (rsc/redirect-guard.ts) on full (browser-followed)
|
|
46
57
|
* redirects: a cross-origin Location is rewritten to the basename root unless
|
|
47
58
|
* redirect(url, { external: true }) opted out, mirroring production's single
|
|
@@ -60,7 +71,9 @@
|
|
|
60
71
|
* after finalizeResponse (segmentCount 0 / cacheHit false — dispatch renders no
|
|
61
72
|
* RSC segments and holds no match-cache state), and a thrown non-Response error
|
|
62
73
|
* emits request.error with phase "routing". All three carry the same requestId
|
|
63
|
-
* (getRequestId)
|
|
74
|
+
* (getRequestId), as does a response-route timeout on a rewritten pass
|
|
75
|
+
* (runRequestPasses carries the id to each pass's request, as in
|
|
76
|
+
* production). Emission is gated entirely on a configured sink; with none,
|
|
64
77
|
* dispatch does zero new work and stays byte-identical for existing callers.
|
|
65
78
|
* Lets a consumer unit-test their sink wiring in-process instead of only at e2e.
|
|
66
79
|
* - Response-route `renderStartMs` timeouts and `onTimeout`: dispatch races the
|
|
@@ -96,9 +109,13 @@
|
|
|
96
109
|
* request.start/end/error lifecycle above; cover cache/loader telemetry with an
|
|
97
110
|
* e2e test driving a real RSC request.
|
|
98
111
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* route
|
|
112
|
+
* Each pass is classified with the handler's classify stage
|
|
113
|
+
* (router/request-classification.ts classifyRequest), which runs content
|
|
114
|
+
* negotiation and resolves route middleware from the matched entry tree, so
|
|
115
|
+
* dispatch's route-middleware collection is exactly the router's, not a
|
|
116
|
+
* re-implementation. The origin guard is not run: it gates only the action,
|
|
117
|
+
* loader and PE-form plans, which classify gives a component route only, and
|
|
118
|
+
* dispatch throws on those before the pass's middleware.
|
|
102
119
|
*/
|
|
103
120
|
import type { Rango } from "../router/router-interfaces.js";
|
|
104
121
|
/**
|
|
@@ -130,9 +130,12 @@ export interface CacheOptions<TEnv = unknown> {
|
|
|
130
130
|
*/
|
|
131
131
|
condition?: (ctx: import("../server/request-context.js").RequestContext<TEnv>) => boolean;
|
|
132
132
|
/**
|
|
133
|
-
* Custom cache key function
|
|
134
|
-
*
|
|
135
|
-
*
|
|
133
|
+
* Custom cache key function. Replaces the URL part of the default key
|
|
134
|
+
* (host, path, params, search) AND bypasses the store's keyGenerator. The
|
|
135
|
+
* request kind stays: a document request, a navigation and each intercept
|
|
136
|
+
* navigation keep their own record under one result, so the result decides
|
|
137
|
+
* which requests of one kind share a record. It is stored namespaced
|
|
138
|
+
* (`key:` plus its URI encoding, then the kind), so no value it returns
|
|
136
139
|
* names another route's record; a nested cache() keys its records within
|
|
137
140
|
* this partition.
|
|
138
141
|
*
|
|
@@ -69,7 +69,15 @@ export interface OnErrorContext<TEnv = any> {
|
|
|
69
69
|
env?: TEnv;
|
|
70
70
|
/** Duration from request start to error (milliseconds) */
|
|
71
71
|
duration?: number;
|
|
72
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Whether this is a partial/navigation request, on an error the segment
|
|
74
|
+
* walk catches (a handler that throws, a DSL loader that rejects): `true`
|
|
75
|
+
* for a navigation, unset for a document. An error in the background
|
|
76
|
+
* re-render of a `cache()` record (a stale HIT's refresh, the write of a
|
|
77
|
+
* navigation that kept a layout mounted) reports the request that started
|
|
78
|
+
* it. A streamed (`loading()`) handler's rejection does not carry it, in
|
|
79
|
+
* either render; the `routing` phase reports `false`.
|
|
80
|
+
*/
|
|
73
81
|
isPartial?: boolean;
|
|
74
82
|
/** Whether an error boundary caught the error */
|
|
75
83
|
handledByBoundary?: boolean;
|
|
@@ -342,7 +342,7 @@ export type InternalHandlerContext<TParams = {}, TEnv = DefaultEnv, TSearch exte
|
|
|
342
342
|
_reverseScope?: import("../server/context.js").ReverseScope;
|
|
343
343
|
/**
|
|
344
344
|
* @internal The on-demand overlay holds a "removed" marker for this request
|
|
345
|
-
* (
|
|
345
|
+
* (readPrerenderSource, cache-lookup.ts); gateOnDemandProducer reads it. On
|
|
346
346
|
* this context, not the request's: withCacheLookup documents that the
|
|
347
347
|
* request ALS can be lost mid-pipeline on workerd.
|
|
348
348
|
*/
|
|
@@ -390,6 +390,14 @@ export type InternalHandlerContext<TParams = {}, TEnv = DefaultEnv, TSearch exte
|
|
|
390
390
|
* request is a fill. See router/segment-resolution/prefetch-deferral.ts.
|
|
391
391
|
*/
|
|
392
392
|
_prefetchDeferral?: import("../router/segment-resolution/prefetch-deferral.js").PrefetchDeferral;
|
|
393
|
+
/**
|
|
394
|
+
* @internal DSL loaders registered and not started, by `$$id`: a prefetch
|
|
395
|
+
* deferred them, or a pass that skips loaders (`skipLoaders`) did not run
|
|
396
|
+
* them. A reader's ctx.use() starts one through its registration
|
|
397
|
+
* (registerDeferredLoader, startDeferredLoader in
|
|
398
|
+
* router/segment-resolution/prefetch-deferral.ts).
|
|
399
|
+
*/
|
|
400
|
+
_deferredLoaders?: Map<string, import("../router/segment-resolution/prefetch-deferral.js").DeferredLoader>;
|
|
393
401
|
/**
|
|
394
402
|
* @internal Whether a loader was started in this request: a run of it (a
|
|
395
403
|
* handler's or another loader's ctx.use()) or its cache() binding. A
|
|
@@ -151,7 +151,7 @@ export interface ResolvedSegment {
|
|
|
151
151
|
loaderData?: any;
|
|
152
152
|
/**
|
|
153
153
|
* True when this loader was awaited before first flush
|
|
154
|
-
* (loader(Def, { ssr: false })). Stamped by
|
|
154
|
+
* (loader(Def, { ssr: false })). Stamped by resolveOwnerLoaders on
|
|
155
155
|
* document AND shell-capture renders — capture bakes flagged loaders and
|
|
156
156
|
* awaits the same lane. Feeds segment-system's settled-value delivery and
|
|
157
157
|
* the dev SSR suspension warning (ssr-suspension-warning.ts).
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build discovery phase: the discovery plugin's buildStart, buildApp (post)
|
|
3
|
+
* and buildEnd hooks.
|
|
4
|
+
*
|
|
5
|
+
* buildStart discovers routers through a temp RSC server and writes the
|
|
6
|
+
* generated route types. When PPR shell candidates exist, it defers closing
|
|
7
|
+
* that server, and releasing the buildEnv, as a PAIR: the buildApp post hook
|
|
8
|
+
* releases them after the shell capture (success), buildEnd after an
|
|
9
|
+
* environment build failure (abort).
|
|
10
|
+
*/
|
|
11
|
+
import type { Rolldown, ViteBuilder } from "vite";
|
|
12
|
+
import type { DiscoveryState } from "./state.js";
|
|
13
|
+
/**
|
|
14
|
+
* buildStart. Build mode: create a temporary Vite dev server to access the
|
|
15
|
+
* RSC environment's module runner, then discover routers and generate
|
|
16
|
+
* manifests. The manifest data is stored for the virtual module's load hook.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildDiscoveryPhase(s: DiscoveryState, context: Rolldown.PluginContext): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* buildApp (post). Post-build phases, after EVERY environment bundle is
|
|
21
|
+
* written.
|
|
22
|
+
*
|
|
23
|
+
* 1. Cache versions (router-versions-phase.ts): hashes the server output as
|
|
24
|
+
* postprocessBundle left it and writes the per-router table into the
|
|
25
|
+
* built version module. First, because phase 2 stamps its entries with
|
|
26
|
+
* these versions and reads the same RSC out dir.
|
|
27
|
+
* 2. PPR shell capture (producer B, #699): the shell prelude embeds built
|
|
28
|
+
* client asset URLs (bootstrap entry), which do not exist at buildStart.
|
|
29
|
+
* The kept temp server and the buildEnv were deferred AS A PAIR in
|
|
30
|
+
* buildStart's finally; this finally is the pair's success-path owner
|
|
31
|
+
* (buildEndPhase owns the aborted-build path) — the phase itself is a pure
|
|
32
|
+
* producer and tears down only the globals it installs.
|
|
33
|
+
*/
|
|
34
|
+
export declare function postBuildPhase(s: DiscoveryState, builder: ViteBuilder): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* buildEnd. An environment build failure aborts the builder before the
|
|
37
|
+
* buildApp post hook — never leak the kept temp server (open handles hang
|
|
38
|
+
* the CLI) or the deferred buildEnv (a live miniflare proxy).
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildEndPhase(s: DiscoveryState, error: Error | undefined): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time env (rango({ buildEnv })): resolution of the option and the
|
|
3
|
+
* lifetime of the resolved bindings on DiscoveryState. Acquired by dev
|
|
4
|
+
* discovery (dev-server-phase.ts) and build discovery
|
|
5
|
+
* (build-discovery-phase.ts).
|
|
6
|
+
*/
|
|
7
|
+
import type { BuildEnvOption, BuildEnvFactoryContext, BuildEnvResult } from "../plugin-types.js";
|
|
8
|
+
import type { DiscoveryState } from "./state.js";
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the buildEnv option into a concrete { env, dispose? } result.
|
|
11
|
+
* Handles all four input shapes: false, "auto", factory, plain object.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveBuildEnv(option: BuildEnvOption | undefined, factoryCtx: BuildEnvFactoryContext): Promise<BuildEnvResult | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Acquire build-time env bindings and store on discovery state.
|
|
16
|
+
* Returns true if env was acquired, false if buildEnv is disabled.
|
|
17
|
+
*/
|
|
18
|
+
export declare function acquireBuildEnv(s: DiscoveryState, command: "serve" | "build", mode: string): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Release build-time env resources and clear state.
|
|
21
|
+
*/
|
|
22
|
+
export declare function releaseBuildEnv(s: DiscoveryState): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundle scan phase: the discovery plugin's generateBundle hook.
|
|
3
|
+
*
|
|
4
|
+
* Records the inputs of the per-router cache versions (build-versions.ts) for
|
|
5
|
+
* every environment and, during the RSC build, the RSC entry filename and the
|
|
6
|
+
* chunks holding Prerender/Static handler exports. closeBundle
|
|
7
|
+
* (bundle-postprocess.ts) uses them for handler code eviction and prerender
|
|
8
|
+
* data injection.
|
|
9
|
+
*/
|
|
10
|
+
import type { Rolldown } from "vite";
|
|
11
|
+
import type { DiscoveryState } from "./state.js";
|
|
12
|
+
export declare function bundleScanPhase(s: DiscoveryState, context: Rolldown.PluginContext, bundle: any): void;
|
|
@@ -34,8 +34,9 @@ export interface DevPrerenderPayloadBodies {
|
|
|
34
34
|
/** `intercept != 1` response: the route's own segments + handles. */
|
|
35
35
|
main: string;
|
|
36
36
|
/**
|
|
37
|
-
* `intercept=1` response:
|
|
38
|
-
*
|
|
37
|
+
* `intercept=1` response: the build's intercept variant
|
|
38
|
+
* (interceptVariantSegments, prerender/store.ts) with the producer's handle
|
|
39
|
+
* string for it. Falls back to `main` byte-for-byte when the route has no
|
|
39
40
|
* intercept segments — mirroring the endpoint's historical behavior.
|
|
40
41
|
*/
|
|
41
42
|
intercept: string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev server phase: the discovery plugin's configureServer hook.
|
|
3
|
+
*
|
|
4
|
+
* Runs dev discovery (the Node RSC runner, or a temp Node server under
|
|
5
|
+
* Cloudflare, whose RSC env has no runner), serves the dev /__rsc_prerender
|
|
6
|
+
* and /__rsc_shell endpoints, and watches route files to regenerate the
|
|
7
|
+
* generated route types and re-run runtime discovery on HMR.
|
|
8
|
+
*/
|
|
9
|
+
import type { ViteDevServer } from "vite";
|
|
10
|
+
import { type DiscoveryState } from "./state.js";
|
|
11
|
+
/** The slice of a Vite environment module graph the route-file watcher reads. */
|
|
12
|
+
interface ModulesByFileGraph {
|
|
13
|
+
getModulesByFile(file: string): ReadonlySet<unknown> | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether the dev route-file watcher ignores `file`: it sits in a directory
|
|
17
|
+
* every discovery scan skips (isInSkippedScanDir) and the RSC graph has not
|
|
18
|
+
* loaded it. See docs/manifests.md, "A reload no file of the app asked for".
|
|
19
|
+
*/
|
|
20
|
+
export declare function isFileOutsideApp(root: string, file: string, rscGraph: ModulesByFileGraph | undefined): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* configureServer. Dev mode: discover routers and populate manifest in
|
|
23
|
+
* memory. Skipped in build mode (buildDiscoveryPhase handles it).
|
|
24
|
+
*/
|
|
25
|
+
export declare function devServerPhase(s: DiscoveryState, server: ViteDevServer): void;
|
|
26
|
+
export {};
|
|
@@ -95,7 +95,7 @@ export interface DiscoveryFailureReport {
|
|
|
95
95
|
* - a transient artifact of a Vite dependency re-optimization racing with boot
|
|
96
96
|
* discovery (a module read before the entry import resolves to the
|
|
97
97
|
* pre-optimize copy of the runner graph while createRouter() populated the
|
|
98
|
-
* post-optimize copy — see
|
|
98
|
+
* post-optimize copy — see dev-server-phase.ts).
|
|
99
99
|
*
|
|
100
100
|
* We can only tell them apart when the caller observed the dep optimizer's
|
|
101
101
|
* `browserHash` change across the discovery attempt (`reoptimizeObserved`): a
|
|
@@ -117,6 +117,9 @@ export interface DiscoveryState {
|
|
|
117
117
|
resolvedEntryPath: string | undefined;
|
|
118
118
|
projectRoot: string;
|
|
119
119
|
isBuildMode: boolean;
|
|
120
|
+
/** Vite's resolved command and mode (configResolved), for resolveBuildEnv. */
|
|
121
|
+
viteCommand: "serve" | "build";
|
|
122
|
+
viteMode: string;
|
|
120
123
|
userResolveAlias: any;
|
|
121
124
|
/**
|
|
122
125
|
* Data-only slice of the user's resolved config (resolve.* incl. native
|
|
@@ -199,6 +202,15 @@ export interface DiscoveryState {
|
|
|
199
202
|
devDiscoveryEpoch?: number;
|
|
200
203
|
devServerOrigin: string | null;
|
|
201
204
|
devServer: any;
|
|
205
|
+
/**
|
|
206
|
+
* Dev: the pending transition({ when }) definition error, re-sent as the
|
|
207
|
+
* Vite error overlay until a discovery succeeds (dev-server-phase.ts).
|
|
208
|
+
*/
|
|
209
|
+
transitionWhenOverlay: {
|
|
210
|
+
message: string;
|
|
211
|
+
stack: string;
|
|
212
|
+
plugin: string;
|
|
213
|
+
} | null;
|
|
202
214
|
selfWrittenGenFiles: Map<string, {
|
|
203
215
|
at: number;
|
|
204
216
|
hash: string;
|
|
@@ -10,7 +10,7 @@ import { type Plugin } from "vite";
|
|
|
10
10
|
* Build: exports a placeholder for the per-router versions table. The module
|
|
11
11
|
* holds nothing that varies between builds; the table is written into the
|
|
12
12
|
* built chunk after the server output is hashed (the buildApp post hook in
|
|
13
|
-
*
|
|
13
|
+
* discovery/build-discovery-phase.ts). See docs/design/per-app-cache-version.md.
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
16
|
export declare function createVersionPlugin(): Plugin;
|
|
@@ -47,7 +47,7 @@ export declare function getVirtualVersionContent(version: string): string;
|
|
|
47
47
|
/**
|
|
48
48
|
* Free identifier the production version module ships in place of the table.
|
|
49
49
|
* The versions are hashes of the built server code, so they cannot be part of
|
|
50
|
-
* it: the buildApp post hook (
|
|
50
|
+
* it: the buildApp post hook (discovery/build-discovery-phase.ts) replaces this token in the
|
|
51
51
|
* written chunk once the hashes are final (runRouterVersionsPhase,
|
|
52
52
|
* discovery/router-versions-phase.ts). An unreplaced token throws a ReferenceError
|
|
53
53
|
* when the module evaluates, so a build that skipped the step cannot serve
|
|
@@ -2,55 +2,16 @@
|
|
|
2
2
|
* Router Discovery Plugin
|
|
3
3
|
*
|
|
4
4
|
* Vite plugin that discovers router instances at dev/build time via the RSC
|
|
5
|
-
* environment.
|
|
6
|
-
*
|
|
5
|
+
* environment. Its hooks call the phase modules over one DiscoveryState:
|
|
6
|
+
* discovery/dev-server-phase.ts (configureServer),
|
|
7
|
+
* discovery/build-discovery-phase.ts (buildStart, buildApp post, buildEnd) and
|
|
8
|
+
* discovery/bundle-scan-phase.ts (generateBundle). Route types generation,
|
|
9
|
+
* virtual module codegen and bundle post-processing live in their own
|
|
10
|
+
* discovery/ modules.
|
|
7
11
|
*/
|
|
8
|
-
import type { Plugin
|
|
9
|
-
import { VIRTUAL_ROUTES_MANIFEST_ID, type
|
|
12
|
+
import type { Plugin } from "vite";
|
|
13
|
+
import { VIRTUAL_ROUTES_MANIFEST_ID, type PluginOptions } from "./discovery/state.js";
|
|
10
14
|
export { VIRTUAL_ROUTES_MANIFEST_ID };
|
|
11
|
-
/** The slice of a Vite environment module graph the route-file watcher reads. */
|
|
12
|
-
interface ModulesByFileGraph {
|
|
13
|
-
getModulesByFile(file: string): ReadonlySet<unknown> | undefined;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Whether the dev route-file watcher ignores `file`: it sits in a directory
|
|
17
|
-
* every discovery scan skips (isInSkippedScanDir) and the RSC graph has not
|
|
18
|
-
* loaded it. See docs/manifests.md, "A reload no file of the app asked for".
|
|
19
|
-
*/
|
|
20
|
-
export declare function isFileOutsideApp(root: string, file: string, rscGraph: ModulesByFileGraph | undefined): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Create a minimal Vite server for router discovery.
|
|
23
|
-
*
|
|
24
|
-
* Both dev-mode prerender and build-mode discovery need a temp RSC server
|
|
25
|
-
* to import user router files via module runner. This factory centralizes
|
|
26
|
-
* the shared config and the mode-specific differences:
|
|
27
|
-
* - Dev: path-based IDs (no forceBuild), separate cacheDir
|
|
28
|
-
* - Build: hashed IDs (forceBuild), hashClientRefs for production bundles
|
|
29
|
-
*
|
|
30
|
-
* Returns the ViteDevServer instance. Callers access .environments.rsc as needed.
|
|
31
|
-
* @internal Exported for tests.
|
|
32
|
-
*/
|
|
33
|
-
export declare function createTempRscServer(state: DiscoveryState, options?: {
|
|
34
|
-
forceBuild?: boolean;
|
|
35
|
-
cacheDir?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Serve the REAL rango SSR entry (getVirtualEntrySSR) for
|
|
38
|
-
* "virtual:entry-ssr" instead of the discovery stub, so the dev
|
|
39
|
-
* /__rsc_shell endpoint can drive captureShellHTML in this server's SSR
|
|
40
|
-
* realm. Dev-correct by construction: the entry's bootstrap resolves to
|
|
41
|
-
* plugin-rsc's stable virtual browser-entry URL, which the MAIN dev
|
|
42
|
-
* server serves to the browser. Loaded lazily — discovery never imports
|
|
43
|
-
* the SSR entry, so the temp server stays as light as before until a
|
|
44
|
-
* shell capture actually runs.
|
|
45
|
-
*/
|
|
46
|
-
realSsrEntry?: boolean;
|
|
47
|
-
}): Promise<ViteDevServer>;
|
|
48
|
-
import type { BuildEnvOption, BuildEnvFactoryContext, BuildEnvResult } from "./plugin-types.js";
|
|
49
|
-
/**
|
|
50
|
-
* Resolve the buildEnv option into a concrete { env, dispose? } result.
|
|
51
|
-
* Handles all four input shapes: false, "auto", factory, plain object.
|
|
52
|
-
*/
|
|
53
|
-
export declare function resolveBuildEnv(option: BuildEnvOption | undefined, factoryCtx: BuildEnvFactoryContext): Promise<BuildEnvResult | null>;
|
|
54
15
|
/**
|
|
55
16
|
* Plugin that discovers router instances at dev/build time via the RSC environment.
|
|
56
17
|
*
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The discovery temp RSC server: a minimal Vite server whose module runner
|
|
3
|
+
* imports the user's router files. Shared by dev discovery
|
|
4
|
+
* (discovery/dev-server-phase.ts) and build discovery
|
|
5
|
+
* (discovery/build-discovery-phase.ts).
|
|
6
|
+
*
|
|
7
|
+
* Sits in src/vite/, not src/vite/discovery/: the loader hook URL below
|
|
8
|
+
* resolves against this module's import.meta.url, and the published bundle
|
|
9
|
+
* (dist/vite/index.js) ships the hook at the same relative path.
|
|
10
|
+
*/
|
|
11
|
+
import type { ViteDevServer } from "vite";
|
|
12
|
+
import type { DiscoveryState } from "./discovery/state.js";
|
|
13
|
+
/**
|
|
14
|
+
* Create a minimal Vite server for router discovery.
|
|
15
|
+
*
|
|
16
|
+
* Both dev-mode prerender and build-mode discovery need a temp RSC server
|
|
17
|
+
* to import user router files via module runner. This factory centralizes
|
|
18
|
+
* the shared config and the mode-specific differences:
|
|
19
|
+
* - Dev: path-based IDs (no forceBuild), separate cacheDir
|
|
20
|
+
* - Build: hashed IDs (forceBuild), hashClientRefs for production bundles
|
|
21
|
+
*
|
|
22
|
+
* Returns the ViteDevServer instance. Callers access .environments.rsc as needed.
|
|
23
|
+
* @internal Exported for tests.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createTempRscServer(state: DiscoveryState, options?: {
|
|
26
|
+
forceBuild?: boolean;
|
|
27
|
+
cacheDir?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Serve the REAL rango SSR entry (getVirtualEntrySSR) for
|
|
30
|
+
* "virtual:entry-ssr" instead of the discovery stub, so the dev
|
|
31
|
+
* /__rsc_shell endpoint can drive captureShellHTML in this server's SSR
|
|
32
|
+
* realm. Dev-correct by construction: the entry's bootstrap resolves to
|
|
33
|
+
* plugin-rsc's stable virtual browser-entry URL, which the MAIN dev
|
|
34
|
+
* server serves to the browser. Loaded lazily — discovery never imports
|
|
35
|
+
* the SSR entry, so the temp server stays as light as before until a
|
|
36
|
+
* shell capture actually runs.
|
|
37
|
+
*/
|
|
38
|
+
realSsrEntry?: boolean;
|
|
39
|
+
}): Promise<ViteDevServer>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LiveIntercept } from "../../router/prerender-match.js";
|
|
1
2
|
export declare function encodePathParam(value: unknown): string;
|
|
2
3
|
/**
|
|
3
4
|
* `ctx.reverse` of a build-time `getParams()`. Substitutes like the dev-mode
|
|
@@ -25,6 +26,14 @@ export declare function notifyOnError(registry: Map<string, any>, error: unknown
|
|
|
25
26
|
* URL / handler name for the log line; `elapsed` is the per-entry duration string.
|
|
26
27
|
*/
|
|
27
28
|
export declare function resolvePrerenderError(registry: Map<string, any>, error: any, onError: "fail" | "warn", label: string, elapsed: string, phase: "prerender" | "static", routeKey?: string, pathname?: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Warn once per router, route and slot (`warned` holds the keys already
|
|
31
|
+
* warned) that an intercept over a Prerender() route renders live: the build
|
|
32
|
+
* did not bake it (matchForPrerender `liveIntercepts`), so its handler runs
|
|
33
|
+
* per request and one that needs BuildContext fails there. A route in an
|
|
34
|
+
* unnamed include() has an internal key; the warning names its URL instead.
|
|
35
|
+
*/
|
|
36
|
+
export declare function warnLiveIntercepts(warned: Set<string>, routerId: string, routeName: string, urlPath: string, liveIntercepts: readonly LiveIntercept[] | undefined): void;
|
|
28
37
|
/** Build scratch space, relative to the project root. Never shipped. */
|
|
29
38
|
export declare const RANGO_BUILD_DIR = "node_modules/.rangojs-router-build";
|
|
30
39
|
export declare function resetStagedBuildAssets(projectRoot: string): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The router's `_rsc_*` query parameter names, shared by the browser and the
|
|
3
|
+
* server graph (dependency free): the one module that spells them
|
|
4
|
+
* (tools/check-internals.mjs rule rsc-param-literal). The browser writes the
|
|
5
|
+
* partial-request set through browser/wire-protocol.ts writePartialParams.
|
|
6
|
+
*/
|
|
7
|
+
export declare const WIRE: {
|
|
8
|
+
/** A navigation or prefetch: `true`. */
|
|
9
|
+
readonly partial: "_rsc_partial";
|
|
10
|
+
/** The mounted segment ids, comma-joined. */
|
|
11
|
+
readonly segments: "_rsc_segments";
|
|
12
|
+
/** A JS server action's id, in place of `partial`. */
|
|
13
|
+
readonly action: "_rsc_action";
|
|
14
|
+
/** The client's build version (version-mismatch reload). */
|
|
15
|
+
readonly version: "_rsc_v";
|
|
16
|
+
/** The client's router id (app-switch reload). */
|
|
17
|
+
readonly routerId: "_rsc_rid";
|
|
18
|
+
/** The rewrite target of the page on screen (#1144). */
|
|
19
|
+
readonly rewriteTarget: "_rsc_rt";
|
|
20
|
+
/** A stale request: `true` (router/navigation-snapshot.ts). */
|
|
21
|
+
readonly stale: "_rsc_stale";
|
|
22
|
+
/** A fill request (docs/design/prefetch-false.md): `1`. */
|
|
23
|
+
readonly fill: "_rsc_fill";
|
|
24
|
+
/** A loader fetch's loader id (rsc/loader-fetch.ts). */
|
|
25
|
+
readonly loader: "_rsc_loader";
|
|
26
|
+
/** A loader fetch's params, JSON: a query param, or a form field on a POST. */
|
|
27
|
+
readonly loaderParams: "_rsc_loader_params";
|
|
28
|
+
/** The forced-MISS marker of a degraded PPR shell reload (rsc/shell-serve.ts). */
|
|
29
|
+
readonly shellMiss: "_rsc_shell";
|
|
30
|
+
/** A connection warmup HEAD request (browser/connection-warmup.ts). */
|
|
31
|
+
readonly warmup: "_rsc_warmup";
|
|
32
|
+
};
|
|
33
|
+
/** The prefix every name in WIRE starts with. */
|
|
34
|
+
export declare const WIRE_PREFIX = "_rsc_";
|