@rangojs/router 0.22.1 → 0.24.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 +10 -4
- package/dist/testing/vitest.js +31 -1
- package/dist/types/browser/defer.d.ts +48 -0
- package/dist/types/browser/document-revealed.d.ts +17 -0
- package/dist/types/browser/event-controller.d.ts +7 -1
- package/dist/types/browser/merge-segment-loaders.d.ts +5 -2
- package/dist/types/browser/navigation-transaction.d.ts +21 -7
- package/dist/types/browser/partial-update.d.ts +39 -8
- package/dist/types/browser/react/NavigationProvider.d.ts +19 -5
- package/dist/types/browser/react/context.d.ts +3 -2
- package/dist/types/browser/react/filter-segment-order.d.ts +7 -0
- package/dist/types/browser/response-adapter.d.ts +7 -0
- package/dist/types/browser/types.d.ts +24 -10
- package/dist/types/browser/validate-redirect-origin.d.ts +11 -0
- package/dist/types/build/generate-route-types.d.ts +1 -1
- package/dist/types/build/route-types/router-processing.d.ts +1 -1
- package/dist/types/build/route-types/scan-filter.d.ts +22 -2
- package/dist/types/cache/cf/cf-cache-store.d.ts +16 -1
- package/dist/types/cache/cf/cf-cache-types.d.ts +23 -2
- package/dist/types/cache/document-cache-policy.d.ts +24 -0
- package/dist/types/cache/document-cache.d.ts +2 -10
- package/dist/types/client-urls/client-urls.d.ts +1 -1
- package/dist/types/client-urls/hoisted-revalidate.d.ts +13 -0
- package/dist/types/client-urls/navigation.d.ts +0 -37
- package/dist/types/client-urls/revalidate-registry.d.ts +4 -0
- package/dist/types/client-urls/server-projection.d.ts +29 -1
- package/dist/types/client-urls/types.d.ts +34 -69
- package/dist/types/client.d.ts +0 -1
- package/dist/types/context-var.d.ts +12 -0
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/handles/deferred-resolution.d.ts +2 -1
- package/dist/types/handles/pushed-by.d.ts +31 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.rsc.d.ts +2 -0
- package/dist/types/loader-store.d.ts +8 -0
- package/dist/types/prefetch-markers.d.ts +11 -0
- package/dist/types/response-utils.d.ts +7 -0
- package/dist/types/reverse.d.ts +8 -8
- package/dist/types/route-definition/helpers-types.d.ts +27 -0
- package/dist/types/route-definition/rewrite.d.ts +56 -0
- package/dist/types/route-map-builder.d.ts +7 -2
- package/dist/types/router/basename.d.ts +7 -0
- package/dist/types/router/handler-context.d.ts +1 -5
- package/dist/types/router/internal-params.d.ts +8 -0
- package/dist/types/router/is-action.d.ts +2 -1
- package/dist/types/router/middleware-types.d.ts +15 -0
- package/dist/types/router/revalidation.d.ts +1 -2
- package/dist/types/router/route-trie-builder.d.ts +10 -0
- package/dist/types/router/segment-resolution/loader-mask.d.ts +3 -2
- package/dist/types/router/segment-resolution/mask-nested.d.ts +4 -2
- package/dist/types/router/segment-resolution/prefetch-deferral.d.ts +264 -0
- package/dist/types/rsc/full-payload.d.ts +11 -0
- package/dist/types/rsc/handler.d.ts +33 -0
- package/dist/types/rsc/helpers.d.ts +8 -0
- package/dist/types/rsc/loader-fetch.d.ts +16 -0
- package/dist/types/rsc/rewrite-passes.d.ts +74 -0
- package/dist/types/rsc/ssr-setup.d.ts +3 -1
- package/dist/types/server/context.d.ts +21 -1
- package/dist/types/server/handle-store.d.ts +9 -1
- package/dist/types/server/request-context.d.ts +52 -2
- package/dist/types/server/rewrite-trail.d.ts +49 -0
- package/dist/types/server/slot-accessors.d.ts +29 -0
- package/dist/types/server.d.ts +1 -0
- package/dist/types/testing/flight.entry.d.ts +1 -1
- package/dist/types/testing/index.d.ts +4 -4
- package/dist/types/testing/internal/action-id.d.ts +10 -1
- package/dist/types/testing/internal/client-urls-projection.d.ts +16 -0
- package/dist/types/testing/internal/test-action.d.ts +8 -0
- package/dist/types/testing/render-route.d.ts +8 -0
- package/dist/types/testing/run-loader.d.ts +2 -1
- package/dist/types/testing/run-middleware.d.ts +20 -0
- package/dist/types/testing/run-revalidate.d.ts +74 -0
- package/dist/types/testing/run-transition-when.d.ts +2 -3
- package/dist/types/testing/serve-shell-request.d.ts +40 -1
- package/dist/types/testing/vitest.d.ts +11 -0
- package/dist/types/thenable-status.d.ts +6 -0
- package/dist/types/types/boundaries.d.ts +9 -0
- package/dist/types/types/handler-context.d.ts +14 -0
- package/dist/types/types/loader-types.d.ts +30 -0
- package/dist/types/types/request-scope.d.ts +7 -0
- package/dist/types/types/segments.d.ts +21 -4
- package/dist/types/urls/path-helper-types.d.ts +25 -4
- package/dist/types/urls/type-extraction.d.ts +6 -2
- package/dist/types/vite/discovery/discover-routers.d.ts +9 -0
- package/dist/types/vite/discovery/state.d.ts +14 -4
- package/dist/types/vite/plugins/client-urls-revalidate-hoist.d.ts +54 -0
- package/dist/types/vite/plugins/hoist/literal.d.ts +83 -0
- package/dist/types/vite/plugins/hoist/scope.d.ts +40 -0
- package/dist/types/vite/plugins/hoist/source.d.ts +41 -0
- package/dist/types/vite/plugins/transition-when-hoist.d.ts +8 -11
- package/dist/types/vite/router-discovery.d.ts +10 -0
- package/dist/vite/index.js +974 -379
- package/package.json +1 -1
- package/skills/caching/SKILL.md +54 -5
- package/skills/catalog.json +3 -3
- package/skills/client-urls/SKILL.md +197 -24
- package/skills/cloudflare/SKILL.md +14 -9
- package/skills/hooks/SKILL.md +16 -3
- package/skills/hooks/data.md +3 -1
- package/skills/links/SKILL.md +24 -0
- package/skills/loader/SKILL.md +199 -2
- package/skills/middleware/SKILL.md +183 -2
- package/skills/migrate-nextjs/SKILL.md +2 -2
- package/skills/migrate-react-router/SKILL.md +10 -7
- package/skills/migrate-react-router/data-and-actions.md +1 -1
- package/skills/ppr/SKILL.md +22 -0
- package/skills/prerender/SKILL.md +22 -8
- package/skills/rango/SKILL.md +13 -7
- package/skills/route/SKILL.md +139 -0
- package/skills/server-actions/SKILL.md +27 -0
- package/skills/testing/SKILL.md +3 -2
- package/skills/testing/client-components.md +2 -1
- package/skills/testing/middleware.md +31 -10
- package/skills/testing/predicates.md +67 -32
- package/skills/testing/response-routes.md +1 -0
- package/skills/testing/serve-shell-request.md +107 -19
- package/skills/testing/setup.md +2 -2
- package/skills/typesafety/route-types.md +2 -2
- package/skills/use-cache/SKILL.md +4 -2
- package/skills/view-transitions/SKILL.md +26 -0
- package/src/__augment-tests__/augmented.check.ts +20 -0
- package/src/browser/defer.ts +82 -0
- package/src/browser/document-revealed.ts +52 -0
- package/src/browser/event-controller.ts +46 -32
- package/src/browser/merge-segment-loaders.ts +31 -18
- package/src/browser/navigation-bridge.ts +82 -16
- package/src/browser/navigation-client.ts +48 -36
- package/src/browser/navigation-store.ts +13 -0
- package/src/browser/navigation-transaction.ts +25 -8
- package/src/browser/partial-update.ts +554 -146
- package/src/browser/prefetch/fetch.ts +2 -1
- package/src/browser/react/Link.tsx +7 -9
- package/src/browser/react/NavigationProvider.tsx +88 -49
- package/src/browser/react/context.ts +3 -2
- package/src/browser/react/filter-segment-order.ts +13 -2
- package/src/browser/react/use-router.ts +2 -4
- package/src/browser/response-adapter.ts +20 -0
- package/src/browser/rsc-router.tsx +17 -45
- package/src/browser/server-action-bridge.ts +25 -63
- package/src/browser/types.ts +24 -10
- package/src/browser/validate-redirect-origin.ts +16 -0
- package/src/build/generate-route-types.ts +1 -0
- package/src/build/route-types/router-processing.ts +3 -6
- package/src/build/route-types/scan-filter.ts +45 -11
- package/src/cache/cf/cf-cache-store.ts +59 -21
- package/src/cache/cf/cf-cache-types.ts +24 -2
- package/src/cache/document-cache-policy.ts +131 -0
- package/src/cache/document-cache.ts +21 -107
- package/src/client-urls/client-urls.ts +22 -6
- package/src/client-urls/hoisted-revalidate.ts +25 -0
- package/src/client-urls/navigation.ts +0 -96
- package/src/client-urls/revalidate-registry.ts +30 -0
- package/src/client-urls/server-projection.ts +151 -65
- package/src/client-urls/types.ts +39 -71
- package/src/client.tsx +9 -5
- package/src/context-var.ts +32 -2
- package/src/errors.ts +34 -0
- package/src/handles/deferred-resolution.ts +28 -5
- package/src/handles/pushed-by.ts +148 -0
- package/src/index.rsc.ts +8 -0
- package/src/index.ts +7 -0
- package/src/loader-store.ts +18 -7
- package/src/prefetch-markers.ts +13 -0
- package/src/response-utils.ts +19 -0
- package/src/reverse.ts +17 -14
- package/src/route-content-wrapper.tsx +18 -4
- package/src/route-definition/dsl-helpers.ts +27 -4
- package/src/route-definition/helpers-types.ts +27 -1
- package/src/route-definition/redirect.ts +2 -15
- package/src/route-definition/rewrite.ts +146 -0
- package/src/route-map-builder.ts +14 -11
- package/src/router/basename.ts +20 -0
- package/src/router/handler-context.ts +3 -13
- package/src/router/intercept-resolution.ts +35 -16
- package/src/router/internal-params.ts +16 -0
- package/src/router/is-action.ts +2 -1
- package/src/router/loader-resolution.ts +85 -4
- package/src/router/match-api.ts +36 -1
- package/src/router/match-middleware/background-revalidation.ts +16 -4
- package/src/router/match-middleware/cache-lookup.ts +35 -7
- package/src/router/match-middleware/cache-store.ts +15 -1
- package/src/router/match-middleware/intercept-resolution.ts +4 -2
- package/src/router/match-result.ts +14 -2
- package/src/router/middleware-types.ts +16 -0
- package/src/router/middleware.ts +127 -49
- package/src/router/navigation-snapshot.ts +2 -1
- package/src/router/revalidation.ts +1 -1
- package/src/router/route-trie-builder.ts +28 -1
- package/src/router/segment-resolution/fresh.ts +22 -18
- package/src/router/segment-resolution/loader-cache.ts +2 -1
- package/src/router/segment-resolution/loader-mask.ts +5 -3
- package/src/router/segment-resolution/loader-snapshot.ts +18 -4
- package/src/router/segment-resolution/mask-nested.ts +8 -4
- package/src/router/segment-resolution/prefetch-deferral.ts +583 -0
- package/src/router/segment-resolution/revalidation.ts +215 -82
- package/src/rsc/full-payload.ts +37 -5
- package/src/rsc/handler.ts +82 -55
- package/src/rsc/helpers.ts +24 -0
- package/src/rsc/loader-fetch.ts +79 -24
- package/src/rsc/response-cache-serve.ts +18 -2
- package/src/rsc/response-route-handler.ts +4 -7
- package/src/rsc/rewrite-passes.ts +203 -0
- package/src/rsc/rsc-rendering.ts +54 -9
- package/src/rsc/shell-capture.ts +2 -1
- package/src/rsc/ssr-setup.ts +11 -5
- package/src/segment-loader-promise.ts +23 -20
- package/src/segment-system.tsx +60 -26
- package/src/server/context.ts +39 -5
- package/src/server/cookie-parse.ts +36 -12
- package/src/server/cookie-store.ts +7 -3
- package/src/server/handle-store.ts +152 -25
- package/src/server/request-context.ts +175 -64
- package/src/server/request-headers.ts +4 -14
- package/src/server/rewrite-trail.ts +190 -0
- package/src/server/slot-accessors.ts +57 -0
- package/src/server.ts +4 -0
- package/src/ssr/index.tsx +118 -16
- package/src/testing/action-form.ts +2 -11
- package/src/testing/dispatch.ts +138 -67
- package/src/testing/e2e/page-helpers.ts +3 -1
- package/src/testing/flight.entry.ts +1 -0
- package/src/testing/index.ts +7 -3
- package/src/testing/internal/action-id.ts +16 -1
- package/src/testing/internal/client-urls-projection.ts +70 -0
- package/src/testing/internal/test-action.ts +25 -0
- package/src/testing/render-route.tsx +16 -3
- package/src/testing/run-loader.ts +4 -1
- package/src/testing/run-middleware.ts +56 -11
- package/src/testing/run-revalidate.ts +142 -0
- package/src/testing/run-transition-when.ts +7 -8
- package/src/testing/serve-shell-request.ts +131 -8
- package/src/testing/vitest.ts +67 -1
- package/src/thenable-status.ts +11 -0
- package/src/types/boundaries.ts +12 -0
- package/src/types/handler-context.ts +14 -0
- package/src/types/loader-types.ts +30 -0
- package/src/types/request-scope.ts +8 -0
- package/src/types/segments.ts +26 -4
- package/src/urls/path-helper-types.ts +27 -5
- package/src/urls/type-extraction.ts +30 -10
- package/src/use-loader.tsx +18 -13
- package/src/vite/discovery/client-urls-projection.ts +20 -21
- package/src/vite/discovery/discover-routers.ts +94 -26
- package/src/vite/discovery/state.ts +28 -4
- package/src/vite/discovery/virtual-module-codegen.ts +22 -17
- package/src/vite/plugins/client-urls-revalidate-hoist.ts +564 -0
- package/src/vite/plugins/expose-internal-ids.ts +2 -3
- package/src/vite/plugins/hoist/literal.ts +417 -0
- package/src/vite/plugins/hoist/scope.ts +370 -0
- package/src/vite/plugins/hoist/source.ts +84 -0
- package/src/vite/plugins/transition-when-hoist.ts +113 -779
- package/src/vite/rango.ts +2 -0
- package/src/vite/router-discovery.ts +116 -53
- package/dist/types/client-urls/revalidate-chain.d.ts +0 -33
- package/dist/types/client-urls/revalidation-protocol.d.ts +0 -25
- package/dist/types/testing/run-client-revalidate.d.ts +0 -43
- package/src/client-urls/revalidate-chain.ts +0 -83
- package/src/client-urls/revalidation-protocol.ts +0 -56
- package/src/testing/run-client-revalidate.ts +0 -92
|
@@ -13,16 +13,8 @@
|
|
|
13
13
|
* 4. If miss → run handler, cache if response has cache headers
|
|
14
14
|
*/
|
|
15
15
|
import type { MiddlewareFn, MiddlewareContext } from "../router/middleware.js";
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
* Whether this cache will store the response the current render produces, as
|
|
19
|
-
* far as the render can tell: the middleware runs it (a MISS or a stale
|
|
20
|
-
* refresh) and the response stub already opts in. payloadInitialTheme
|
|
21
|
-
* (rsc/full-payload.ts) then renders the no-cookie default theme (#978). A
|
|
22
|
-
* Cache-Control written after next() is not on the stub yet; for that render
|
|
23
|
-
* shouldCacheResponse refuses a payload marked `_payloadVisitorTheme`.
|
|
24
|
-
*/
|
|
25
|
-
export declare function documentCacheStoresRender(reqCtx: Pick<RequestContext, "_documentCacheRender" | "res">): boolean;
|
|
16
|
+
import { documentCacheStoresRender } from "./document-cache-policy.js";
|
|
17
|
+
export { documentCacheStoresRender };
|
|
26
18
|
export interface DocumentCacheOptions<TEnv = any> {
|
|
27
19
|
/**
|
|
28
20
|
* Skip caching for specific paths (e.g., API routes)
|
|
@@ -2,4 +2,4 @@ import type { ClientUrlBuilder, ClientUrlPatterns } from "./types.js";
|
|
|
2
2
|
import type { ExtractRoutes } from "../urls/type-extraction.js";
|
|
3
3
|
import type { ClientUrlItems } from "./types.js";
|
|
4
4
|
export declare function clientUrls<const TItems extends ClientUrlItems>(builder: ClientUrlBuilder<TItems>): ClientUrlPatterns<ExtractRoutes<TItems>>;
|
|
5
|
-
export type {
|
|
5
|
+
export type { ClientTransitionConfig, ClientUrlBuilder, ClientUrlHelpers, ClientUrlInterceptRecord, ClientUrlItem, ClientUrlItemInput, ClientUrlItems, ClientLayoutFn, ClientPathOptions, ClientUrlLoaderRecord, ClientPathFn, ClientUrlPatterns, ClientUrlRouteRecord, ClientUrlUse, } from "./types.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The value the build leaves in place of a clientUrls() `revalidate()`
|
|
3
|
+
* predicate in the browser and SSR copies of a "use client" module
|
|
4
|
+
* (vite/plugins/client-urls-revalidate-hoist.ts): the predicate itself moves
|
|
5
|
+
* to a server module, registered under the same content key
|
|
6
|
+
* (revalidate-registry.ts). The projection carries the key; the materialized
|
|
7
|
+
* loader stub calls the registered predicate.
|
|
8
|
+
*/
|
|
9
|
+
export declare const HOISTED_REVALIDATE_KEY = "$$rangoRevalidate";
|
|
10
|
+
export interface HoistedRevalidateRef {
|
|
11
|
+
readonly $$rangoRevalidate: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function isHoistedRevalidateRef(value: unknown): value is HoistedRevalidateRef;
|
|
@@ -46,41 +46,4 @@ export declare function registerClientUrlGroup(definition: ClientUrlPatterns, mo
|
|
|
46
46
|
export declare function beginClientUrlNavigation(targetUrl: URL, signal: AbortSignal,
|
|
47
47
|
/** Builds the entry state; called only when the group presents the target. */
|
|
48
48
|
buildState?: () => unknown, decideTransition?: (destination: ClientUrlDestination) => boolean): ClientUrlNavigationPresentation | null;
|
|
49
|
-
/**
|
|
50
|
-
* Run the held clientUrls route's per-loader revalidate() predicates and
|
|
51
|
-
* encode their decisions for the request header. Predicates are CLIENT code
|
|
52
|
-
* (declared in the "use client" definition module); only decisions cross the
|
|
53
|
-
* wire — the synthesized per-loader revalidate() on every materialized stub
|
|
54
|
-
* (server-projection.ts) reads them back by loader $$id.
|
|
55
|
-
*
|
|
56
|
-
* Decisions exist only for the loaders the client currently HOLDS: the local
|
|
57
|
-
* match of currentUrl. They matter when the server would re-evaluate those
|
|
58
|
-
* held loader segments — same-route param/search navs, actions, and stale
|
|
59
|
-
* restores. Cross-route targets render new segments unconditionally, so a
|
|
60
|
-
* decision would be ignored; we still compute against the current route since
|
|
61
|
-
* only its held segments are addressable.
|
|
62
|
-
*
|
|
63
|
-
* Returns null when no group is active, the current location is not a client
|
|
64
|
-
* route, or no predicate produced a decision that differs from the locked
|
|
65
|
-
* default — the server then applies defaults, which is also the behavior for
|
|
66
|
-
* requests that cannot carry decisions (no-JS, PE, prefetch, document loads).
|
|
67
|
-
*/
|
|
68
|
-
export declare function collectClientRevalidationDecisions(options: {
|
|
69
|
-
currentUrl: URL;
|
|
70
|
-
nextUrl: URL;
|
|
71
|
-
/**
|
|
72
|
-
* True only when the decisions ride the action POST itself — the one
|
|
73
|
-
* request the server evaluates with actionContext (locked default true).
|
|
74
|
-
* Action-triggered refetch GETs (partial-update terminals) pass false:
|
|
75
|
-
* the server gives those navigation defaults, and the delta gate below
|
|
76
|
-
* must diff against the default the SERVER will use, or a force decision
|
|
77
|
-
* on the refetch would be silently swallowed as "equals default".
|
|
78
|
-
*/
|
|
79
|
-
actionRequest: boolean;
|
|
80
|
-
/** Action TRUTH for the predicates' isAction() matcher; may be true on
|
|
81
|
-
* refetch GETs where actionRequest is false. */
|
|
82
|
-
isAction: boolean;
|
|
83
|
-
actionId?: string;
|
|
84
|
-
stale: boolean;
|
|
85
|
-
}): string | null;
|
|
86
49
|
export declare function clearClientUrlNavigationRegistry(): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ShouldRevalidateFn } from "../types.js";
|
|
2
|
+
export declare function registerClientUrlRevalidators(fns: Readonly<Record<string, ShouldRevalidateFn<any, any>>>): void;
|
|
3
|
+
export declare function getClientUrlRevalidator(key: string): ShouldRevalidateFn<any, any> | undefined;
|
|
4
|
+
export declare function clearClientUrlRevalidators(): void;
|
|
@@ -32,6 +32,16 @@ export interface ClientUrlProjectionRoute {
|
|
|
32
32
|
* document renders await them before first flush. Absent (= none) in
|
|
33
33
|
* projections serialized before the option existed. */
|
|
34
34
|
readonly awaitedLoaderIndices?: readonly number[];
|
|
35
|
+
/** Indices into loaderIds of loaders declared loader(Def, { prefetch:
|
|
36
|
+
* false }); materialization passes the option through to the server
|
|
37
|
+
* loader(), so a prefetch of the route defers them. Absent (= none) in
|
|
38
|
+
* projections serialized before the option existed. */
|
|
39
|
+
readonly deferrableLoaderIndices?: readonly number[];
|
|
40
|
+
/** Per loader (aligned with loaderIds), the keys of its hoisted
|
|
41
|
+
* revalidate() predicates in declaration order; materialization attaches
|
|
42
|
+
* the registered predicates (revalidate-registry.ts). Absent when no
|
|
43
|
+
* loader declares one. */
|
|
44
|
+
readonly loaderRevalidate?: readonly (readonly string[])[];
|
|
35
45
|
/** Data-only transition config (never `when`); absent in projections
|
|
36
46
|
* serialized before transition support. */
|
|
37
47
|
readonly transition?: Readonly<ClientTransitionConfig>;
|
|
@@ -54,7 +64,25 @@ export interface ClientUrlProjection {
|
|
|
54
64
|
* must treat missing as empty. */
|
|
55
65
|
readonly intercepts?: readonly ClientUrlProjectionIntercept[];
|
|
56
66
|
}
|
|
57
|
-
|
|
67
|
+
/** Options for {@link serializeClientUrlPatterns}. */
|
|
68
|
+
export interface SerializeClientUrlPatternsOptions {
|
|
69
|
+
/**
|
|
70
|
+
* The definition was loaded through the rango Vite plugin (route
|
|
71
|
+
* discovery), which moves every revalidate() predicate to the server and
|
|
72
|
+
* leaves a marker: a plain function then is a site the build could not
|
|
73
|
+
* see, and fails loudly.
|
|
74
|
+
*/
|
|
75
|
+
readonly hoisted?: boolean;
|
|
76
|
+
}
|
|
77
|
+
export declare function serializeClientUrlPatterns(patterns: ClientUrlPatterns, options?: SerializeClientUrlPatternsOptions): ClientUrlProjection;
|
|
78
|
+
/**
|
|
79
|
+
* The projection of a clientUrls() module from its namespace, or undefined
|
|
80
|
+
* when its default export is not a clientUrls() definition. Discovery
|
|
81
|
+
* (vite/discovery/client-urls-projection.ts) and the testing "use client"
|
|
82
|
+
* transform (testing/internal/client-urls-projection.ts) both project a
|
|
83
|
+
* module through it.
|
|
84
|
+
*/
|
|
85
|
+
export declare function projectClientUrlsModule(namespace: Readonly<Record<string, unknown>>, options?: SerializeClientUrlPatternsOptions): ClientUrlProjection | undefined;
|
|
58
86
|
export declare function isClientUrlPatterns(value: unknown): value is ClientUrlPatterns;
|
|
59
87
|
export declare function isClientUrlReference(value: unknown): value is ClientUrlReference;
|
|
60
88
|
/**
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from "react";
|
|
2
|
-
import type {
|
|
2
|
+
import type { LoaderDefinition, LoaderOptions, ShouldRevalidateFn, TransitionConfig } from "../types.js";
|
|
3
|
+
import type { DefaultEnv } from "../types/global-namespace.js";
|
|
4
|
+
import type { HoistedRevalidateRef } from "./hoisted-revalidate.js";
|
|
3
5
|
import type { TrieMatchResult } from "../router/trie-matching.js";
|
|
4
6
|
import type { PathOptions } from "../urls/pattern-types.js";
|
|
5
7
|
import type { SearchSchema } from "../search-params.js";
|
|
@@ -18,67 +20,14 @@ export type ClientUrlUse = () => ClientUrlItems;
|
|
|
18
20
|
export type ClientPathOptions<TName extends string = string, TSearch extends SearchSchema = SearchSchema> = Pick<PathOptions<TName, TSearch>, "name" | "search" | "trailingSlash" | "ppr">;
|
|
19
21
|
export type ClientPathFn = <const TPattern extends string, const TName extends string = UnnamedRoute, const TSearch extends SearchSchema = {}>(pattern: TPattern, component: ComponentType, optionsOrUse?: ClientPathOptions<TName, TSearch> | ClientUrlUse, use?: ClientUrlUse) => ClientUrlItem & TypedRouteItem<TName, TPattern, unknown, TSearch>;
|
|
20
22
|
export type ClientLayoutFn = <const TItems extends ClientUrlItems>(component: ComponentType, children: () => TItems) => ClientUrlItem & TypedLayoutItem<ExtractRoutes<TItems>>;
|
|
21
|
-
/**
|
|
22
|
-
* Arguments a clientUrls() revalidate() predicate receives. A client-computable
|
|
23
|
-
* subset of the server ShouldRevalidateFn args — the predicate RUNS IN THE
|
|
24
|
-
* BROWSER (it is declared in a "use client" module and never crosses the
|
|
25
|
-
* projection boundary); only its decision is sent to the server. There is no
|
|
26
|
-
* `context` — no server handler context exists where this executes. `isAction`
|
|
27
|
-
* is the same callable matcher as on the server, not a boolean.
|
|
28
|
-
*/
|
|
29
|
-
export interface ClientRevalidateArgs {
|
|
30
|
-
/** Full URL of the page being navigated away from (current location). */
|
|
31
|
-
readonly currentUrl: URL;
|
|
32
|
-
/** Full URL of the navigation target (equals currentUrl for actions). */
|
|
33
|
-
readonly nextUrl: URL;
|
|
34
|
-
/** Route params of the held client route (definition-local match). */
|
|
35
|
-
readonly currentParams: Record<string, string>;
|
|
36
|
-
/** Route params for the navigation target (definition-local match). */
|
|
37
|
-
readonly nextParams: Record<string, string>;
|
|
38
|
-
/**
|
|
39
|
-
* The current default decision for this loader, computed client-side with
|
|
40
|
-
* the same rules the server applies to the request the decisions ride on:
|
|
41
|
-
* `true` when they ride the action POST itself, otherwise `true` when
|
|
42
|
-
* params/search changed. (An action-triggered refetch GET gets navigation
|
|
43
|
-
* defaults — matching the server — even though `isAction()` is true.)
|
|
44
|
-
* Earlier predicates' `{ defaultShouldRevalidate }` verdicts thread into
|
|
45
|
-
* this value, exactly like the server chain. Return it for default
|
|
46
|
-
* behavior plus your own conditions.
|
|
47
|
-
*/
|
|
48
|
-
readonly defaultShouldRevalidate: boolean;
|
|
49
|
-
/** True when this is a stale history-entry background revalidation. */
|
|
50
|
-
readonly stale: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Same {@link IsActionFn} the server `revalidate()` predicate receives.
|
|
53
|
-
* In the browser the match is against the action stub's hashed `$$id`
|
|
54
|
-
* (the id the action request carries) — not the RSC file-path `$id`.
|
|
55
|
-
*/
|
|
56
|
-
readonly isAction: IsActionFn;
|
|
57
|
-
/**
|
|
58
|
-
* The triggering server action's id, when this is an action. In the
|
|
59
|
-
* browser this is the hashed `hash#export` form (`$$id`), not the RSC
|
|
60
|
-
* file-path `src/...#export`. Prefer `isAction(ref)` — a substring of
|
|
61
|
-
* `path#export` will not match here in production.
|
|
62
|
-
*/
|
|
63
|
-
readonly actionId?: string;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Client-run per-loader predicate, with the same chain semantics as the
|
|
67
|
-
* server's `revalidate()` (src/router/revalidation.ts): a boolean is a HARD
|
|
68
|
-
* decision that short-circuits the rest of the chain; a
|
|
69
|
-
* `{ defaultShouldRevalidate }` object updates the running suggestion, which
|
|
70
|
-
* later predicates receive as their `defaultShouldRevalidate`; `void` /
|
|
71
|
-
* `null` / `undefined` defers to the current suggestion — so
|
|
72
|
-
* `isAction(CartActions) || undefined` defers to the locked default.
|
|
73
|
-
* Predicates must be synchronous; the object form requires a boolean value.
|
|
74
|
-
*/
|
|
75
|
-
export type ClientRevalidateFn = (args: ClientRevalidateArgs) => boolean | {
|
|
76
|
-
defaultShouldRevalidate: boolean;
|
|
77
|
-
} | null | void;
|
|
78
23
|
export interface ClientUrlLoaderRecord {
|
|
79
24
|
readonly loader: LoaderDefinition<any, any>;
|
|
80
|
-
/**
|
|
81
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Per-loader revalidate() predicates, run on the server; empty = the
|
|
27
|
+
* router's defaults. Under the rango Vite plugin the browser and SSR copies
|
|
28
|
+
* hold the marker the build left in place of each hoisted predicate.
|
|
29
|
+
*/
|
|
30
|
+
readonly revalidate: readonly (ShouldRevalidateFn<any, DefaultEnv> | HoistedRevalidateRef)[];
|
|
82
31
|
/**
|
|
83
32
|
* loader(Def, { ssr: false }): document renders await this loader before
|
|
84
33
|
* first flush (see {@link LoaderOptions}). Projected into the server tree,
|
|
@@ -86,6 +35,14 @@ export interface ClientUrlLoaderRecord {
|
|
|
86
35
|
* regardless.
|
|
87
36
|
*/
|
|
88
37
|
readonly ssr?: false;
|
|
38
|
+
/**
|
|
39
|
+
* loader(Def, { prefetch: false }): a prefetch of the route defers this
|
|
40
|
+
* loader and the click that adopts it runs it in its fill request (see
|
|
41
|
+
* {@link LoaderOptions}). Projected onto the materialized stub. Inside
|
|
42
|
+
* intercept() it is not recorded: intercept loaders ignore the flag, as in
|
|
43
|
+
* urls().
|
|
44
|
+
*/
|
|
45
|
+
readonly prefetch?: false;
|
|
89
46
|
}
|
|
90
47
|
/**
|
|
91
48
|
* The TransitionConfig subset a clientUrls() route may declare: ViewTransition
|
|
@@ -124,8 +81,7 @@ export interface ClientUrlHelpers {
|
|
|
124
81
|
readonly layout: ClientLayoutFn;
|
|
125
82
|
/**
|
|
126
83
|
* Attach a projected loader. The optional use callback may contain
|
|
127
|
-
* revalidate() only
|
|
128
|
-
* the function) is sent with the revalidation request.
|
|
84
|
+
* revalidate() only: a per-loader predicate the server runs, as in urls().
|
|
129
85
|
*
|
|
130
86
|
* Pass `{ ssr: false }` — the same knob as loading(fallback, { ssr:
|
|
131
87
|
* false }) — to await this loader before first flush on DOCUMENT requests
|
|
@@ -135,18 +91,27 @@ export interface ClientUrlHelpers {
|
|
|
135
91
|
* route the flag BAKES: the loader executes at shell capture and its
|
|
136
92
|
* settled return freezes into the shell (nested promises stay live
|
|
137
93
|
* holes).
|
|
94
|
+
*
|
|
95
|
+
* Pass `{ prefetch: false }` to keep this loader out of the route's
|
|
96
|
+
* prefetches (see {@link LoaderOptions}): an in-group click still shows
|
|
97
|
+
* the destination at once, commits the adopted prefetch with the other
|
|
98
|
+
* loaders' data, and runs only the flagged loaders in its one fill
|
|
99
|
+
* request. A `layout()` loader with the flag is flagged on every route
|
|
100
|
+
* below it. Inside intercept() the flag is accepted and ignored, as in
|
|
101
|
+
* urls().
|
|
138
102
|
*/
|
|
139
|
-
readonly loader: <TData>(definition: LoaderDefinition<TData>, optionsOrUse?: LoaderOptions | ClientUrlUse, use?: ClientUrlUse) => ClientUrlItem;
|
|
103
|
+
readonly loader: <TData>(definition: LoaderDefinition<TData>, optionsOrUse?: Pick<LoaderOptions, "ssr" | "prefetch"> | ClientUrlUse, use?: ClientUrlUse) => ClientUrlItem;
|
|
140
104
|
readonly loading: (component: ReactNode) => ClientUrlItem;
|
|
141
105
|
/**
|
|
142
106
|
* Per-loader revalidation predicate, valid inside a loader() use callback
|
|
143
|
-
* only.
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
107
|
+
* only. It runs ON THE SERVER with the same arguments as a urls() loader's
|
|
108
|
+
* revalidate() (`actionResult`, `formData`, `context`, `isAction`, route
|
|
109
|
+
* names, ...): the build moves it out of this "use client" module. It may
|
|
110
|
+
* reference imports and globals only; a binding of this module, `this`,
|
|
111
|
+
* `import()`, a browser global, an `async` function or an import from a
|
|
112
|
+
* "use client" module fails the build with its file and line.
|
|
148
113
|
*/
|
|
149
|
-
readonly revalidate: (fn:
|
|
114
|
+
readonly revalidate: (fn: ShouldRevalidateFn<any, DefaultEnv>) => ClientUrlItem;
|
|
150
115
|
/**
|
|
151
116
|
* Declare an intercept for a named route in THIS definition. The target is
|
|
152
117
|
* dot-local (`.detail`); scoping is module-local — only navigations whose
|
package/dist/types/client.d.ts
CHANGED
|
@@ -191,4 +191,3 @@ export { useReverse } from "./browser/react/use-reverse.js";
|
|
|
191
191
|
export type { ScopedReverseFunction, LocalReverseFunction } from "./reverse.js";
|
|
192
192
|
export type { LoaderDefinition } from "./types.js";
|
|
193
193
|
export type { ActionRef, IsActionFn } from "./types.js";
|
|
194
|
-
export type { ClientRevalidateArgs, ClientRevalidateFn, } from "./client-urls/types.js";
|
|
@@ -68,6 +68,18 @@ export declare function isNonCacheable(variables: any, keyOrVar: string | Contex
|
|
|
68
68
|
* Accepts either a string key (legacy) or a ContextVar token (typed).
|
|
69
69
|
*/
|
|
70
70
|
export declare function contextGet(variables: any, keyOrVar: string | ContextVar<any>): any;
|
|
71
|
+
/**
|
|
72
|
+
* Keys that must never be used as string variable names, nor as a fetchable
|
|
73
|
+
* loader's request params (rsc/loader-fetch.ts).
|
|
74
|
+
*/
|
|
75
|
+
export declare const FORBIDDEN_KEYS: ReadonlySet<string>;
|
|
76
|
+
/**
|
|
77
|
+
* `target[key] = value` as an own data property, `__proto__` included: that
|
|
78
|
+
* assignment would call Object.prototype's setter and replace the target's
|
|
79
|
+
* prototype, which Flight refuses to serialize (#1109). Loader data parsed
|
|
80
|
+
* from JSON, cookie names and the like can carry the key.
|
|
81
|
+
*/
|
|
82
|
+
export declare function assignOwn(target: Record<string, unknown>, key: string, value: unknown): void;
|
|
71
83
|
export interface ContextSetOptions {
|
|
72
84
|
/**
|
|
73
85
|
* When false, marks this specific write as non-cacheable.
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -176,6 +176,16 @@ export declare class Skip extends Error {
|
|
|
176
176
|
* Type guard to check if a thrown value is a Skip signal.
|
|
177
177
|
*/
|
|
178
178
|
export declare function isSkip(value: unknown): value is Skip;
|
|
179
|
+
/**
|
|
180
|
+
* A request middleware rewrote (`throw rewrite()`) more than `maxHops` times,
|
|
181
|
+
* or to the URL it was on. Reported through `onError` (phase "routing") and
|
|
182
|
+
* answered with 508. `trail` lists the URLs, the visitor's first.
|
|
183
|
+
*/
|
|
184
|
+
export declare class RewriteLoopError extends Error {
|
|
185
|
+
name: "RewriteLoopError";
|
|
186
|
+
readonly trail: readonly string[];
|
|
187
|
+
constructor(trail: readonly string[], maxHops: number);
|
|
188
|
+
}
|
|
179
189
|
/**
|
|
180
190
|
* Thrown by the partial updater when the server responds with a redirect payload
|
|
181
191
|
* that carries location state. Caught by navigate() to re-navigate to the
|
|
@@ -212,6 +222,11 @@ export declare class InvalidHandlerError extends Error {
|
|
|
212
222
|
* ```
|
|
213
223
|
*/
|
|
214
224
|
export declare function invariant(condition: any, message: string): asserts condition;
|
|
225
|
+
/**
|
|
226
|
+
* Rejects a boolean-only DSL option that holds anything else (undefined
|
|
227
|
+
* passes), as an invariant.
|
|
228
|
+
*/
|
|
229
|
+
export declare function assertBooleanOption(value: unknown, option: string, effect: string): void;
|
|
215
230
|
/**
|
|
216
231
|
* Sanitize errors for production - prevents leaking sensitive information
|
|
217
232
|
*
|
|
@@ -24,7 +24,8 @@ export declare function deferredHandleNames(data: HandleData): Set<string>;
|
|
|
24
24
|
* thenables). A rejected deferred is dropped, and a deferred that resolves to
|
|
25
25
|
* `null`/`undefined` is dropped (the `.defer({ else })` skip semantics), so a
|
|
26
26
|
* nullish deferred slot never reaches a collector. Sync (non-thenable) values —
|
|
27
|
-
* including a legitimate sync `null` push — pass through unchanged.
|
|
27
|
+
* including a legitimate sync `null` push — pass through unchanged. A
|
|
28
|
+
* pushedBy record (pushed-by.ts) loses the entries of the dropped values.
|
|
28
29
|
*/
|
|
29
30
|
export declare function resolveDeferredHandleValues(data: HandleData): Promise<HandleData>;
|
|
30
31
|
/**
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HandleData } from "../server/handle-store.js";
|
|
2
|
+
/** The snapshot key holding `handleName`'s pushedBy record. */
|
|
3
|
+
export declare function pushedByKey(handleName: string): string;
|
|
4
|
+
/** True for a pushedBy record's key, false for a handle's. */
|
|
5
|
+
export declare function isPushedByKey(name: string): boolean;
|
|
6
|
+
/** `data` without its pushedBy records, as a reader outside the router sees it. */
|
|
7
|
+
export declare function withoutPushedBy(data: HandleData): HandleData;
|
|
8
|
+
/**
|
|
9
|
+
* `target` with the buckets of the segments in `ids` taken from `source`.
|
|
10
|
+
* A pushedBy record is a snapshot key like a handle's, so a bucket's values
|
|
11
|
+
* and the record of the runs that pushed them always come from the same
|
|
12
|
+
* snapshot. New containers; the value arrays are shared, as cloneHandleData
|
|
13
|
+
* (navigation-store.ts) shares them.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withSegmentHandles(target: HandleData, source: HandleData, ids: ReadonlySet<string>): HandleData;
|
|
16
|
+
/**
|
|
17
|
+
* The handle data after a partial response's snapshot `incoming` (each stream
|
|
18
|
+
* yield holds everything the response pushed so far). A segment outside
|
|
19
|
+
* `segmentOrder` loses its buckets. In the others a value stands for the run
|
|
20
|
+
* that pushed it: the segment's handler, or a loader `matched` registers on
|
|
21
|
+
* the segment (`${shortCode}D${index}.${$$id}`, a loader's pushes being filed
|
|
22
|
+
* under its shortCode; an id it does not register, a dependency or a loader a
|
|
23
|
+
* handler read, counts as the handler's). A run that has values in the
|
|
24
|
+
* response, or ran for it (`resolvedIds`: the handlers and loaders that ran),
|
|
25
|
+
* replaces its values with the ones it delivered, nothing when it delivered
|
|
26
|
+
* none. The other runs keep theirs in place, and the response's values take
|
|
27
|
+
* the position of the first value they replace (the end when they replace
|
|
28
|
+
* none). New containers throughout: an object a reader was handed (a history
|
|
29
|
+
* entry's data) is never written to.
|
|
30
|
+
*/
|
|
31
|
+
export declare function mergePartialHandleData(current: HandleData, incoming: HandleData, segmentOrder: readonly string[], matched: readonly string[], resolvedIds: readonly string[] | undefined): HandleData;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export declare function createRouter(): never;
|
|
|
32
32
|
* Error-throwing stub for server-only `redirect` function.
|
|
33
33
|
*/
|
|
34
34
|
export declare function redirect(): never;
|
|
35
|
+
/**
|
|
36
|
+
* Error-throwing stub for server-only `rewrite` function.
|
|
37
|
+
*/
|
|
38
|
+
export declare function rewrite(): never;
|
|
35
39
|
export { createHandle, isHandle, type Handle } from "./handle.js";
|
|
36
40
|
export { DEFAULT_DEFER_TIMEOUT_MS, type DeferOptions, type HandlePush, type HandlePushFn, } from "./defer.js";
|
|
37
41
|
export { createVar, type ContextVar } from "./context-var.js";
|
|
@@ -14,6 +14,8 @@ export type { RangoOptions, SSRStreamMode, SSROptions, ResolveStreamingContext,
|
|
|
14
14
|
export type { OriginCheckConfig, OriginCheckContext, OriginCheckPhase, } from "./rsc/origin-guard.js";
|
|
15
15
|
export type { ShellCaptureDebug, ShellCaptureDebugEvent, } from "./rsc/shell-capture.js";
|
|
16
16
|
export { createLoader, redirect, type RouteHelpers, type RouteHandlers, layout, cache, middleware, revalidate, loader, loading, parallel, intercept, errorBoundary, notFoundBoundary, transition, } from "./route-definition.js";
|
|
17
|
+
export { rewrite, type Rewrite, type RewriteFunction, } from "./route-definition/rewrite.js";
|
|
18
|
+
export { RewriteLoopError } from "./errors.js";
|
|
17
19
|
export type { RouteUseItem, LayoutUseItem, AllUseItems, UseItems, HandlerUseItem, } from "./route-types.js";
|
|
18
20
|
export { createHandle, isHandle, type Handle } from "./handle.js";
|
|
19
21
|
export { DEFAULT_DEFER_TIMEOUT_MS, type DeferOptions, type HandlePush, type HandlePushFn, } from "./defer.js";
|
|
@@ -215,6 +215,14 @@ export declare class LoaderStore {
|
|
|
215
215
|
* awaited before flush. Released as the stream settles, either way.
|
|
216
216
|
*/
|
|
217
217
|
trackPendingStream(loaderId: string, stream: Promise<unknown>): void;
|
|
218
|
+
/**
|
|
219
|
+
* Stop tracking a stream. trackPendingStream does it as the stream settles;
|
|
220
|
+
* an abandoned fill's hole (browser/partial-update.ts releaseHoles) never
|
|
221
|
+
* settles, and
|
|
222
|
+
* left tracked it would pin the family's held readers on every later
|
|
223
|
+
* transition.
|
|
224
|
+
*/
|
|
225
|
+
releasePendingStream(loaderId: string, stream: Promise<unknown>): void;
|
|
218
226
|
/** True while any navigation stream for `loaderId` is still pending. */
|
|
219
227
|
isStreamPending(loaderId: string): boolean;
|
|
220
228
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire markers of `prefetch: false` (docs/design/prefetch-false.md):
|
|
3
|
+
* shared by the browser that sends them and the server that reads them
|
|
4
|
+
* (router/segment-resolution/prefetch-deferral.ts requestKind). Dependency
|
|
5
|
+
* free, like segment-fragments.ts: the browser must not import the server
|
|
6
|
+
* module that reads them.
|
|
7
|
+
*/
|
|
8
|
+
/** Request header of a `<Link>` prefetch (browser/prefetch/fetch.ts). */
|
|
9
|
+
export declare const PREFETCH_HEADER = "X-Rango-Prefetch";
|
|
10
|
+
/** Query param of a fill request (browser/navigation-client.ts). */
|
|
11
|
+
export declare const FILL_PARAM = "_rsc_fill";
|
|
@@ -33,3 +33,10 @@ export declare function isWebSocketUpgradeResponse(response: Response): boolean;
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function appendVaryAccept(response: Response): void;
|
|
35
35
|
export declare function isRedirectResponse(response: Response): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Set a header on a response the router hands to the host, skipping a
|
|
38
|
+
* WebSocket upgrade (its headers are not to be touched) and swallowing the
|
|
39
|
+
* TypeError of immutable headers (a passed-through platform Response):
|
|
40
|
+
* instrumentation and debug headers never fail a request.
|
|
41
|
+
*/
|
|
42
|
+
export declare function trySetHeader(response: Response, name: string, value: string): void;
|
package/dist/types/reverse.d.ts
CHANGED
|
@@ -93,31 +93,31 @@ export type ReverseFunction<TRoutes> = {
|
|
|
93
93
|
* reverse("typo") // ✗ Compile error (not in global routes)
|
|
94
94
|
* ```
|
|
95
95
|
*/
|
|
96
|
-
export type ScopedReverseFunction<TLocalRoutes, TGlobalRoutes = TLocalRoutes> = {
|
|
96
|
+
export type ScopedReverseFunction<TLocalRoutes, TGlobalRoutes = TLocalRoutes, TResult = string> = {
|
|
97
97
|
/**
|
|
98
98
|
* Global route without params
|
|
99
99
|
*/
|
|
100
|
-
<TName extends keyof TGlobalRoutes & string>(name: IsEmptyObject<ExtractParams<RoutePatternFor<TGlobalRoutes, TName>>> extends true ? TName : never):
|
|
100
|
+
<TName extends keyof TGlobalRoutes & string>(name: IsEmptyObject<ExtractParams<RoutePatternFor<TGlobalRoutes, TName>>> extends true ? TName : never): TResult;
|
|
101
101
|
/**
|
|
102
102
|
* Global route with params
|
|
103
103
|
*/
|
|
104
|
-
<TName extends keyof TGlobalRoutes & string>(name: TName, params: ExtractParams<RoutePatternFor<TGlobalRoutes, TName>>):
|
|
104
|
+
<TName extends keyof TGlobalRoutes & string>(name: TName, params: ExtractParams<RoutePatternFor<TGlobalRoutes, TName>>): TResult;
|
|
105
105
|
/**
|
|
106
106
|
* Global route with params and search
|
|
107
107
|
*/
|
|
108
|
-
<TName extends keyof TGlobalRoutes & string>(name: TName, params: ExtractParams<RoutePatternFor<TGlobalRoutes, TName>>, search: ResolveSearchSchema<ExtractSearchSchema<TGlobalRoutes, TName>>):
|
|
108
|
+
<TName extends keyof TGlobalRoutes & string>(name: TName, params: ExtractParams<RoutePatternFor<TGlobalRoutes, TName>>, search: ResolveSearchSchema<ExtractSearchSchema<TGlobalRoutes, TName>>): TResult;
|
|
109
109
|
/**
|
|
110
110
|
* Dot-prefixed local route without params
|
|
111
111
|
*/
|
|
112
|
-
<TName extends keyof TLocalRoutes & string>(name: IsEmptyObject<ExtractParams<RoutePatternFor<TLocalRoutes, TName>>> extends true ? `.${TName}` : never):
|
|
112
|
+
<TName extends keyof TLocalRoutes & string>(name: IsEmptyObject<ExtractParams<RoutePatternFor<TLocalRoutes, TName>>> extends true ? `.${TName}` : never): TResult;
|
|
113
113
|
/**
|
|
114
114
|
* Dot-prefixed local route with params
|
|
115
115
|
*/
|
|
116
|
-
<TName extends keyof TLocalRoutes & string>(name: `.${TName}`, params: ExtractParams<RoutePatternFor<TLocalRoutes, TName>>):
|
|
116
|
+
<TName extends keyof TLocalRoutes & string>(name: `.${TName}`, params: ExtractParams<RoutePatternFor<TLocalRoutes, TName>>): TResult;
|
|
117
117
|
/**
|
|
118
118
|
* Dot-prefixed local route with params and search
|
|
119
119
|
*/
|
|
120
|
-
<TName extends keyof TLocalRoutes & string>(name: `.${TName}`, params: ExtractParams<RoutePatternFor<TLocalRoutes, TName>>, search: ResolveSearchSchema<ExtractSearchSchema<TLocalRoutes, TName>>):
|
|
120
|
+
<TName extends keyof TLocalRoutes & string>(name: `.${TName}`, params: ExtractParams<RoutePatternFor<TLocalRoutes, TName>>, search: ResolveSearchSchema<ExtractSearchSchema<TLocalRoutes, TName>>): TResult;
|
|
121
121
|
};
|
|
122
122
|
/**
|
|
123
123
|
* Reverse function that resolves global route names only: no include() scope,
|
|
@@ -147,7 +147,7 @@ export type ScopedReverseFunction<TLocalRoutes, TGlobalRoutes = TLocalRoutes> =
|
|
|
147
147
|
* reverse(".post", { slug: "hello" }) // compile error: no include() scope
|
|
148
148
|
* ```
|
|
149
149
|
*/
|
|
150
|
-
export type GlobalReverseFunction<TGlobalRoutes> = string extends keyof TGlobalRoutes ? <TName extends string>(name: Exclude<TName, `.${string}`>, params?: Record<string, string>, search?: Record<string, unknown>) =>
|
|
150
|
+
export type GlobalReverseFunction<TGlobalRoutes, TResult = string> = string extends keyof TGlobalRoutes ? <TName extends string>(name: Exclude<TName, `.${string}`>, params?: Record<string, string>, search?: Record<string, unknown>) => TResult : ScopedReverseFunction<{}, TGlobalRoutes, TResult>;
|
|
151
151
|
/**
|
|
152
152
|
* Extract local routes type from UrlPatterns
|
|
153
153
|
* Used with scopedReverse() to get the routes type from patterns
|
|
@@ -226,6 +226,16 @@ export type RouteHelpers<T extends RouteDefinition, TEnv> = {
|
|
|
226
226
|
* loader(RecommendationsLoader), // still streams behind loading()
|
|
227
227
|
* ```
|
|
228
228
|
*
|
|
229
|
+
* Pass `{ prefetch: false }` to keep the loader out of prefetches: a
|
|
230
|
+
* prefetch skips it and the click that adopts the prefetch fetches it in
|
|
231
|
+
* one follow-up request (see {@link LoaderOptions}). Only on a segment the
|
|
232
|
+
* client does not have yet: a loader the client already holds runs in the
|
|
233
|
+
* prefetch when it revalidates.
|
|
234
|
+
*
|
|
235
|
+
* ```typescript
|
|
236
|
+
* loader(ReviewsLoader, { prefetch: false }),
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
229
239
|
* @param loaderDef - Loader created with createLoader()
|
|
230
240
|
* @param optionsOrUse - Delivery options, or the use() callback when passing none
|
|
231
241
|
* @param use - Optional callback for loader-specific revalidation rules
|
|
@@ -239,13 +249,30 @@ export type RouteHelpers<T extends RouteDefinition, TEnv> = {
|
|
|
239
249
|
*
|
|
240
250
|
* // Skip loading on SSR, only show on client navigation
|
|
241
251
|
* loading(<Skeleton />, { ssr: false })
|
|
252
|
+
*
|
|
253
|
+
* // Keep everything behind this fallback out of prefetches
|
|
254
|
+
* loading(<Skeleton />, { prefetch: false })
|
|
242
255
|
* ```
|
|
243
256
|
* @param component - The loading UI to show during navigation
|
|
244
257
|
* @param options - Configuration options
|
|
245
258
|
* @param options.ssr - If false, skip showing loading on document requests (SSR)
|
|
259
|
+
* @param options.prefetch - If false, the flag applies when this entry's
|
|
260
|
+
* segment is new to the client. A prefetch then skips the whole unit: the
|
|
261
|
+
* handler, its loaders, its orphan layouts and parallel slots and, for a
|
|
262
|
+
* layout, every deeper entry; the click that adopts the prefetch shows
|
|
263
|
+
* this fallback and fetches them in one follow-up request, which reads
|
|
264
|
+
* cache() and "use cache" as any request does (a prefetch reads neither
|
|
265
|
+
* for skipped work). A segment the client already holds is never
|
|
266
|
+
* deferred: a prefetch renders it as usual when it revalidates, and what
|
|
267
|
+
* is below it follows its own flags. To keep a child out of prefetches
|
|
268
|
+
* while moving inside a section, flag the child's own loading(). An entry
|
|
269
|
+
* whose handler output is stored (cache(), ppr, Prerender/Static) is
|
|
270
|
+
* served as usual and only its loaders are skipped. Loaders behind the
|
|
271
|
+
* fallback cannot call ctx.rendered().
|
|
246
272
|
*/
|
|
247
273
|
loading: (component: ReactNode | (() => ReactNode), options?: {
|
|
248
274
|
ssr?: boolean;
|
|
275
|
+
prefetch?: boolean;
|
|
249
276
|
}) => LoadingItem;
|
|
250
277
|
/**
|
|
251
278
|
* Attach an error boundary to catch errors in this segment and children
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `throw rewrite(target)`: middleware renders another route at the same URL.
|
|
3
|
+
*
|
|
4
|
+
* The value only: what middleware throws and how the router recognizes it.
|
|
5
|
+
* The pass loop that honors it lives in rsc/rewrite-passes.ts, the hop trail
|
|
6
|
+
* in server/rewrite-trail.ts.
|
|
7
|
+
*/
|
|
8
|
+
import type { GlobalReverseFunction } from "../reverse.js";
|
|
9
|
+
import type { DefaultReverseRouteMap } from "../types/global-namespace.js";
|
|
10
|
+
/** The target as written: a path, or a global route name with its params. */
|
|
11
|
+
export type RewriteTarget = {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly params?: Record<string, string>;
|
|
16
|
+
readonly search?: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
export declare function describeRewriteTarget(target: RewriteTarget): string;
|
|
19
|
+
/**
|
|
20
|
+
* The value `rewrite()` returns, thrown by middleware. An Error, so a throw
|
|
21
|
+
* where a rewrite is not supported fails loudly with the rule in its message.
|
|
22
|
+
*/
|
|
23
|
+
export declare class Rewrite extends Error {
|
|
24
|
+
name: "Rewrite";
|
|
25
|
+
readonly target: RewriteTarget;
|
|
26
|
+
constructor(target: RewriteTarget);
|
|
27
|
+
}
|
|
28
|
+
/** Whether `value` is a Rewrite thrown by `rewrite()` (ctx.isRewrite). */
|
|
29
|
+
export declare function isRewrite(value: unknown): value is Rewrite;
|
|
30
|
+
/**
|
|
31
|
+
* `rewrite(path)` or `rewrite(name, params?, search?)`: a path in this app
|
|
32
|
+
* (basename-prefixed like `redirect()`, may carry `?search`), or a global
|
|
33
|
+
* route name with the params and search `ctx.reverse` takes.
|
|
34
|
+
*/
|
|
35
|
+
export type RewriteFunction<TRoutes = DefaultReverseRouteMap> = ((path: `/${string}`) => Rewrite) & GlobalReverseFunction<TRoutes, Rewrite>;
|
|
36
|
+
/**
|
|
37
|
+
* Render another route at the same URL. Throw it from middleware, before
|
|
38
|
+
* `await next()`:
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* router.use(async (ctx, next) => {
|
|
42
|
+
* if (!locked || ctx.pathname === "/maintenance") return next();
|
|
43
|
+
* throw rewrite("maintenance");
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* The request runs again as the target (global middleware, route
|
|
48
|
+
* middleware, render) with the same request context: values set before the
|
|
49
|
+
* throw stay readable. `ctx.url` is the target; `ctx.rewrittenFrom` is the
|
|
50
|
+
* visitor's URL. See the `/middleware` skill.
|
|
51
|
+
*/
|
|
52
|
+
export declare const rewrite: RewriteFunction;
|
|
53
|
+
/** A dispatch site that cannot honor a rewrite. */
|
|
54
|
+
export type RewriteSite = "mutation" | "loader-fetch" | "intercept";
|
|
55
|
+
/** The error a rewrite becomes at a site that cannot honor it. */
|
|
56
|
+
export declare function rewriteNotSupported(rewrite: Rewrite, site: RewriteSite): Error;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* See docs/manifests.md for the full data flow.
|
|
9
9
|
*/
|
|
10
|
+
import { type TrieNode } from "./router/route-trie-builder.js";
|
|
10
11
|
/**
|
|
11
12
|
* Register routes into the global route map.
|
|
12
13
|
* Routes are merged with any existing registered routes.
|
|
@@ -71,10 +72,14 @@ export declare function clearAllRouterData(): void;
|
|
|
71
72
|
export declare function setRouterManifest(routerId: string, manifest: Record<string, string>): void;
|
|
72
73
|
/** @internal */
|
|
73
74
|
export declare function getRouterManifest(routerId: string): Record<string, string> | undefined;
|
|
74
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Install a router's trie. A trie that arrives as JSON (the build manifest)
|
|
77
|
+
* or across the dev runner boundary gets null-prototype static maps first.
|
|
78
|
+
*/
|
|
79
|
+
export declare function setRouterTrie(routerId: string, trie: TrieNode): void;
|
|
75
80
|
export declare function markRouterTrieAuthoritative(routerId: string): void;
|
|
76
81
|
export declare function isRouterTrieAuthoritative(routerId: string): boolean;
|
|
77
|
-
export declare function getRouterTrie(routerId: string):
|
|
82
|
+
export declare function getRouterTrie(routerId: string): TrieNode | undefined;
|
|
78
83
|
export declare function setRouterPrecomputedEntries(routerId: string, entries: Array<{
|
|
79
84
|
staticPrefix: string;
|
|
80
85
|
routes: Record<string, string>;
|
|
@@ -8,3 +8,10 @@
|
|
|
8
8
|
* createRouter() accepts and observe the same redirect() prefixing).
|
|
9
9
|
*/
|
|
10
10
|
export declare function normalizeBasename(basename?: string): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Prefix a root-relative path with the basename unless it already carries it
|
|
13
|
+
* (the basename followed by "/", "?", "#" or the end), so "/admin?tab=x" and
|
|
14
|
+
* "/admin#frag" under basename "/admin" are not prefixed twice. Shared by
|
|
15
|
+
* redirect(), rewrite() and useRouter().
|
|
16
|
+
*/
|
|
17
|
+
export declare function prefixBasename(path: string, basename?: string): string;
|