@rangojs/router 0.0.0-experimental.20 → 0.0.0-experimental.204030a9
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/AGENTS.md +4 -0
- package/README.md +242 -55
- package/dist/bin/rango.js +277 -99
- package/dist/vite/index.js +2929 -1132
- package/dist/vite/index.js.bak +5448 -0
- package/dist/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/package.json +68 -21
- package/skills/breadcrumbs/SKILL.md +252 -0
- package/skills/bundle-analysis/SKILL.md +159 -0
- package/skills/cache-guide/SKILL.md +243 -21
- package/skills/caching/SKILL.md +159 -10
- package/skills/composability/SKILL.md +27 -2
- package/skills/document-cache/SKILL.md +78 -55
- package/skills/handler-use/SKILL.md +364 -0
- package/skills/hooks/SKILL.md +262 -51
- package/skills/host-router/SKILL.md +243 -0
- package/skills/i18n/SKILL.md +276 -0
- package/skills/intercept/SKILL.md +46 -4
- package/skills/layout/SKILL.md +28 -7
- package/skills/links/SKILL.md +249 -17
- package/skills/loader/SKILL.md +291 -31
- package/skills/middleware/SKILL.md +49 -12
- package/skills/migrate-nextjs/SKILL.md +562 -0
- package/skills/migrate-react-router/SKILL.md +769 -0
- package/skills/mime-routes/SKILL.md +27 -0
- package/skills/observability/SKILL.md +137 -0
- package/skills/parallel/SKILL.md +197 -6
- package/skills/prerender/SKILL.md +125 -102
- package/skills/rango/SKILL.md +242 -23
- package/skills/react-compiler/SKILL.md +168 -0
- package/skills/response-routes/SKILL.md +66 -9
- package/skills/route/SKILL.md +91 -8
- package/skills/router-setup/SKILL.md +98 -8
- package/skills/server-actions/SKILL.md +751 -0
- package/skills/streams-and-websockets/SKILL.md +283 -0
- package/skills/testing/SKILL.md +511 -188
- package/skills/typesafety/SKILL.md +354 -50
- package/skills/use-cache/SKILL.md +34 -5
- package/skills/view-transitions/SKILL.md +294 -0
- package/src/__augment-tests__/augment.ts +81 -0
- package/src/__augment-tests__/augmented.check.ts +117 -0
- package/src/__internal.ts +92 -0
- package/src/browser/action-coordinator.ts +53 -36
- package/src/browser/app-shell.ts +52 -0
- package/src/browser/app-version.ts +14 -0
- package/src/browser/event-controller.ts +91 -70
- package/src/browser/history-state.ts +21 -0
- package/src/browser/index.ts +3 -3
- package/src/browser/link-interceptor.ts +4 -0
- package/src/browser/navigation-bridge.ts +183 -18
- package/src/browser/navigation-client.ts +187 -57
- package/src/browser/navigation-store.ts +75 -17
- package/src/browser/navigation-transaction.ts +21 -37
- package/src/browser/partial-update.ts +143 -40
- package/src/browser/prefetch/cache.ts +275 -28
- package/src/browser/prefetch/fetch.ts +191 -46
- package/src/browser/prefetch/policy.ts +6 -0
- package/src/browser/prefetch/queue.ts +123 -20
- package/src/browser/prefetch/resource-ready.ts +77 -0
- package/src/browser/rango-state.ts +53 -13
- package/src/browser/react/Link.tsx +98 -14
- package/src/browser/react/NavigationProvider.tsx +110 -33
- package/src/browser/react/context.ts +7 -2
- package/src/browser/react/filter-segment-order.ts +51 -7
- package/src/browser/react/index.ts +3 -0
- package/src/browser/react/location-state-shared.ts +175 -4
- package/src/browser/react/location-state.ts +39 -13
- package/src/browser/react/use-handle.ts +23 -64
- package/src/browser/react/use-navigation.ts +22 -2
- package/src/browser/react/use-params.ts +20 -8
- package/src/browser/react/use-reverse.ts +106 -0
- package/src/browser/react/use-router.ts +43 -10
- package/src/browser/react/use-segments.ts +11 -8
- package/src/browser/response-adapter.ts +25 -0
- package/src/browser/rsc-router.tsx +200 -75
- package/src/browser/scroll-restoration.ts +46 -39
- package/src/browser/segment-reconciler.ts +36 -9
- package/src/browser/segment-structure-assert.ts +2 -2
- package/src/browser/server-action-bridge.ts +31 -36
- package/src/browser/types.ts +81 -5
- package/src/build/collect-fallback-refs.ts +107 -0
- package/src/build/generate-manifest.ts +65 -40
- package/src/build/generate-route-types.ts +5 -0
- package/src/build/index.ts +2 -0
- package/src/build/route-trie.ts +69 -26
- package/src/build/route-types/codegen.ts +4 -4
- package/src/build/route-types/include-resolution.ts +9 -2
- package/src/build/route-types/per-module-writer.ts +7 -4
- package/src/build/route-types/router-processing.ts +278 -88
- package/src/build/route-types/scan-filter.ts +9 -2
- package/src/build/route-types/source-scan.ts +118 -0
- package/src/build/runtime-discovery.ts +9 -20
- package/src/cache/cache-runtime.ts +15 -11
- package/src/cache/cache-scope.ts +76 -49
- package/src/cache/cf/cf-cache-store.ts +501 -18
- package/src/cache/cf/index.ts +5 -1
- package/src/cache/document-cache.ts +17 -7
- package/src/cache/index.ts +1 -0
- package/src/cache/taint.ts +55 -0
- package/src/client.rsc.tsx +5 -1
- package/src/client.tsx +95 -284
- package/src/context-var.ts +72 -2
- package/src/debug.ts +2 -2
- package/src/decode-loader-results.ts +36 -0
- package/src/errors.ts +30 -1
- package/src/handle.ts +65 -12
- package/src/handles/breadcrumbs.ts +66 -0
- package/src/handles/index.ts +1 -0
- package/src/host/index.ts +2 -5
- package/src/host/router.ts +129 -57
- package/src/host/types.ts +31 -2
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +140 -20
- package/src/index.rsc.ts +15 -40
- package/src/index.ts +92 -76
- package/src/loader-store.ts +500 -0
- package/src/loader.rsc.ts +2 -5
- package/src/loader.ts +3 -10
- package/src/missing-id-error.ts +68 -0
- package/src/outlet-context.ts +1 -1
- package/src/prerender/store.ts +57 -15
- package/src/prerender.ts +141 -80
- package/src/response-utils.ts +37 -0
- package/src/reverse.ts +65 -15
- package/src/route-content-wrapper.tsx +6 -28
- package/src/route-definition/dsl-helpers.ts +435 -260
- package/src/route-definition/helper-factories.ts +29 -139
- package/src/route-definition/helpers-types.ts +110 -34
- package/src/route-definition/index.ts +3 -3
- package/src/route-definition/redirect.ts +11 -3
- package/src/route-definition/resolve-handler-use.ts +155 -0
- package/src/route-definition/use-item-types.ts +32 -0
- package/src/route-map-builder.ts +7 -1
- package/src/route-types.ts +37 -41
- package/src/router/basename.ts +14 -0
- package/src/router/content-negotiation.ts +113 -1
- package/src/router/error-handling.ts +1 -1
- package/src/router/find-match.ts +4 -2
- package/src/router/handler-context.ts +105 -39
- package/src/router/intercept-resolution.ts +15 -22
- package/src/router/lazy-includes.ts +12 -9
- package/src/router/loader-resolution.ts +175 -23
- package/src/router/logging.ts +5 -2
- package/src/router/manifest.ts +31 -16
- package/src/router/match-api.ts +129 -193
- package/src/router/match-handlers.ts +63 -20
- package/src/router/match-middleware/background-revalidation.ts +30 -2
- package/src/router/match-middleware/cache-lookup.ts +136 -106
- package/src/router/match-middleware/cache-store.ts +54 -10
- package/src/router/match-middleware/intercept-resolution.ts +9 -7
- package/src/router/match-middleware/segment-resolution.ts +61 -5
- package/src/router/match-result.ts +124 -18
- package/src/router/metrics.ts +239 -14
- package/src/router/middleware-types.ts +61 -31
- package/src/router/middleware.ts +226 -124
- package/src/router/navigation-snapshot.ts +182 -0
- package/src/router/pattern-matching.ts +118 -19
- package/src/router/prerender-match.ts +114 -10
- package/src/router/preview-match.ts +32 -102
- package/src/router/request-classification.ts +286 -0
- package/src/router/revalidation.ts +85 -9
- package/src/router/route-snapshot.ts +245 -0
- package/src/router/router-context.ts +6 -1
- package/src/router/router-interfaces.ts +91 -29
- package/src/router/router-options.ts +89 -19
- package/src/router/router-registry.ts +2 -5
- package/src/router/segment-resolution/fresh.ts +240 -23
- package/src/router/segment-resolution/helpers.ts +30 -25
- package/src/router/segment-resolution/loader-cache.ts +1 -0
- package/src/router/segment-resolution/revalidation.ts +483 -289
- package/src/router/segment-resolution/view-transition-default.ts +36 -0
- package/src/router/segment-wrappers.ts +2 -0
- package/src/router/substitute-pattern-params.ts +56 -0
- package/src/router/telemetry.ts +99 -0
- package/src/router/trie-matching.ts +38 -15
- package/src/router/types.ts +9 -0
- package/src/router/url-params.ts +49 -0
- package/src/router.ts +120 -32
- package/src/rsc/handler-context.ts +2 -2
- package/src/rsc/handler.ts +524 -370
- package/src/rsc/helpers.ts +91 -43
- package/src/rsc/index.ts +1 -21
- package/src/rsc/loader-fetch.ts +23 -3
- package/src/rsc/manifest-init.ts +5 -1
- package/src/rsc/origin-guard.ts +28 -10
- package/src/rsc/progressive-enhancement.ts +39 -10
- package/src/rsc/response-route-handler.ts +46 -53
- package/src/rsc/rsc-rendering.ts +69 -89
- package/src/rsc/runtime-warnings.ts +9 -10
- package/src/rsc/server-action.ts +39 -47
- package/src/rsc/ssr-setup.ts +144 -0
- package/src/rsc/types.ts +19 -3
- package/src/search-params.ts +20 -17
- package/src/segment-content-promise.ts +67 -0
- package/src/segment-loader-promise.ts +122 -0
- package/src/segment-system.tsx +219 -67
- package/src/serialize.ts +243 -0
- package/src/server/context.ts +285 -63
- package/src/server/cookie-store.ts +28 -4
- package/src/server/handle-store.ts +19 -0
- package/src/server/loader-registry.ts +9 -8
- package/src/server/request-context.ts +228 -65
- package/src/server.ts +6 -0
- package/src/ssr/index.tsx +9 -1
- package/src/static-handler.ts +19 -7
- package/src/testing/cache-status.ts +166 -0
- package/src/testing/collect-handle.ts +63 -0
- package/src/testing/dispatch.ts +440 -0
- package/src/testing/dom.entry.ts +22 -0
- package/src/testing/e2e/fixture.ts +154 -0
- package/src/testing/e2e/index.ts +149 -0
- package/src/testing/e2e/matchers.ts +51 -0
- package/src/testing/e2e/page-helpers.ts +272 -0
- package/src/testing/e2e/parity.ts +306 -0
- package/src/testing/e2e/server.ts +183 -0
- package/src/testing/flight-matchers.ts +104 -0
- package/src/testing/flight-runtime.d.ts +21 -0
- package/src/testing/flight.entry.ts +22 -0
- package/src/testing/flight.ts +182 -0
- package/src/testing/generated-routes.ts +223 -0
- package/src/testing/index.ts +98 -0
- package/src/testing/internal/context.ts +151 -0
- package/src/testing/render-route.tsx +536 -0
- package/src/testing/run-loader.ts +296 -0
- package/src/testing/run-middleware.ts +170 -0
- package/src/testing/vitest-stubs/cloudflare-email.ts +9 -0
- package/src/testing/vitest-stubs/cloudflare-workers.ts +21 -0
- package/src/testing/vitest-stubs/plugin-rsc.ts +16 -0
- package/src/testing/vitest-stubs/version.ts +5 -0
- package/src/testing/vitest.ts +112 -0
- package/src/theme/index.ts +4 -13
- package/src/types/cache-types.ts +4 -4
- package/src/types/global-namespace.ts +39 -26
- package/src/types/handler-context.ts +197 -79
- package/src/types/index.ts +1 -0
- package/src/types/loader-types.ts +41 -15
- package/src/types/request-scope.ts +126 -0
- package/src/types/route-config.ts +17 -8
- package/src/types/route-entry.ts +19 -1
- package/src/types/segments.ts +37 -6
- package/src/urls/include-helper.ts +34 -67
- package/src/urls/index.ts +0 -3
- package/src/urls/path-helper-types.ts +50 -9
- package/src/urls/path-helper.ts +63 -63
- package/src/urls/pattern-types.ts +48 -19
- package/src/urls/response-types.ts +25 -22
- package/src/urls/type-extraction.ts +26 -116
- package/src/urls/urls-function.ts +1 -5
- package/src/use-loader.tsx +487 -44
- package/src/vite/debug.ts +185 -0
- package/src/vite/discovery/bundle-postprocess.ts +63 -91
- package/src/vite/discovery/discover-routers.ts +106 -53
- package/src/vite/discovery/discovery-errors.ts +194 -0
- package/src/vite/discovery/gate-state.ts +171 -0
- package/src/vite/discovery/prerender-collection.ts +222 -107
- package/src/vite/discovery/route-types-writer.ts +40 -84
- package/src/vite/discovery/self-gen-tracking.ts +27 -1
- package/src/vite/discovery/state.ts +50 -13
- package/src/vite/discovery/virtual-module-codegen.ts +13 -23
- package/src/vite/index.ts +10 -3
- package/src/vite/plugin-types.ts +111 -72
- package/src/vite/plugins/cjs-to-esm.ts +8 -7
- package/src/vite/plugins/client-ref-dedup.ts +16 -0
- package/src/vite/plugins/client-ref-hashing.ts +28 -5
- package/src/vite/plugins/cloudflare-protocol-loader-hook.d.mts +23 -0
- package/src/vite/plugins/cloudflare-protocol-loader-hook.mjs +76 -0
- package/src/vite/plugins/cloudflare-protocol-stub.ts +214 -0
- package/src/vite/plugins/expose-action-id.ts +55 -33
- package/src/vite/plugins/expose-id-utils.ts +24 -8
- package/src/vite/plugins/expose-ids/export-analysis.ts +100 -20
- package/src/vite/plugins/expose-ids/handler-transform.ts +12 -35
- package/src/vite/plugins/expose-ids/loader-transform.ts +3 -5
- package/src/vite/plugins/expose-ids/router-transform.ts +20 -3
- package/src/vite/plugins/expose-internal-ids.ts +544 -317
- package/src/vite/plugins/performance-tracks.ts +92 -0
- package/src/vite/plugins/refresh-cmd.ts +127 -0
- package/src/vite/plugins/use-cache-transform.ts +65 -50
- package/src/vite/plugins/version-injector.ts +39 -23
- package/src/vite/plugins/version-plugin.ts +72 -3
- package/src/vite/plugins/virtual-entries.ts +2 -2
- package/src/vite/rango.ts +265 -226
- package/src/vite/router-discovery.ts +924 -137
- package/src/vite/utils/ast-handler-extract.ts +15 -15
- package/src/vite/utils/banner.ts +4 -4
- package/src/vite/utils/bundle-analysis.ts +4 -2
- package/src/vite/utils/client-chunks.ts +190 -0
- package/src/vite/utils/forward-user-plugins.ts +193 -0
- package/src/vite/utils/manifest-utils.ts +21 -5
- package/src/vite/utils/package-resolution.ts +41 -1
- package/src/vite/utils/prerender-utils.ts +98 -5
- package/src/vite/utils/shared-utils.ts +109 -27
- package/src/browser/action-response-classifier.ts +0 -99
- package/src/route-definition/route-function.ts +0 -119
package/src/router.ts
CHANGED
|
@@ -19,11 +19,12 @@ import {
|
|
|
19
19
|
import MapRootLayout from "./server/root-layout.js";
|
|
20
20
|
import type { AllUseItems } from "./route-types.js";
|
|
21
21
|
import type { UrlPatterns } from "./urls.js";
|
|
22
|
+
import type { UrlBuilder } from "./urls/pattern-types.js";
|
|
23
|
+
import { urls } from "./urls.js";
|
|
22
24
|
import {
|
|
23
|
-
EntryData,
|
|
24
|
-
InterceptSelectorContext,
|
|
25
|
+
type EntryData,
|
|
25
26
|
getContext,
|
|
26
|
-
|
|
27
|
+
RangoContext,
|
|
27
28
|
type MetricsStore,
|
|
28
29
|
} from "./server/context";
|
|
29
30
|
import { createHandleStore, type HandleStore } from "./server/handle-store.js";
|
|
@@ -55,6 +56,7 @@ import { buildDebugManifest } from "./router/debug-manifest.js";
|
|
|
55
56
|
|
|
56
57
|
import type { SegmentResolutionDeps, MatchApiDeps } from "./router/types.js";
|
|
57
58
|
import { createHandlerContext } from "./router/handler-context.js";
|
|
59
|
+
import { normalizeBasename } from "./router/basename.js";
|
|
58
60
|
import {
|
|
59
61
|
setupLoaderAccess,
|
|
60
62
|
setupLoaderAccessSilent,
|
|
@@ -89,13 +91,10 @@ import {
|
|
|
89
91
|
RouterRegistry,
|
|
90
92
|
nextRouterAutoId,
|
|
91
93
|
} from "./router/router-registry.js";
|
|
94
|
+
import type { RangoOptions, RootLayoutProps } from "./router/router-options.js";
|
|
92
95
|
import type {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
} from "./router/router-options.js";
|
|
96
|
-
import type {
|
|
97
|
-
RSCRouter,
|
|
98
|
-
RSCRouterInternal,
|
|
96
|
+
Rango,
|
|
97
|
+
RangoInternal,
|
|
99
98
|
RouterRequestInput,
|
|
100
99
|
} from "./router/router-interfaces.js";
|
|
101
100
|
|
|
@@ -114,25 +113,26 @@ import {
|
|
|
114
113
|
// Re-export public types and values from extracted modules
|
|
115
114
|
export { RSC_ROUTER_BRAND, RouterRegistry } from "./router/router-registry.js";
|
|
116
115
|
export type {
|
|
117
|
-
|
|
116
|
+
RangoOptions,
|
|
118
117
|
RootLayoutProps,
|
|
119
118
|
SSRStreamMode,
|
|
120
119
|
SSROptions,
|
|
121
120
|
ResolveStreamingContext,
|
|
122
121
|
} from "./router/router-options.js";
|
|
123
122
|
export type {
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
Rango,
|
|
124
|
+
RangoInternal,
|
|
126
125
|
RouterRequestInput,
|
|
127
126
|
} from "./router/router-interfaces.js";
|
|
128
127
|
export { toInternal } from "./router/router-interfaces.js";
|
|
129
128
|
|
|
130
129
|
export function createRouter<TEnv = any>(
|
|
131
|
-
options:
|
|
132
|
-
):
|
|
130
|
+
options: RangoOptions<TEnv> = {},
|
|
131
|
+
): Rango<TEnv, {}> {
|
|
133
132
|
const {
|
|
134
133
|
id: userProvidedId,
|
|
135
134
|
$$id: injectedId,
|
|
135
|
+
basename: basenameOption,
|
|
136
136
|
debugPerformance = false,
|
|
137
137
|
document: documentOption,
|
|
138
138
|
defaultErrorBoundary,
|
|
@@ -147,7 +147,7 @@ export function createRouter<TEnv = any>(
|
|
|
147
147
|
$$sourceFile: injectedSourceFile,
|
|
148
148
|
nonce,
|
|
149
149
|
version,
|
|
150
|
-
|
|
150
|
+
prefetchCacheTTL: prefetchCacheTTLOption,
|
|
151
151
|
warmup: warmupOption,
|
|
152
152
|
allowDebugManifest: allowDebugManifestOption = false,
|
|
153
153
|
telemetry: telemetrySink,
|
|
@@ -156,8 +156,24 @@ export function createRouter<TEnv = any>(
|
|
|
156
156
|
timeouts: timeoutsOption,
|
|
157
157
|
onTimeout,
|
|
158
158
|
originCheck: originCheckOption,
|
|
159
|
+
viewTransition: viewTransitionOption = "auto",
|
|
160
|
+
debugCacheSignal: debugCacheSignalOption = false,
|
|
159
161
|
} = options;
|
|
160
162
|
|
|
163
|
+
// Debug cache signal gate (DEVELOPMENT/TEST ONLY). Enabled by the
|
|
164
|
+
// debugCacheSignal option OR the RANGO_TEST_SIGNALS=1 env flag. When off,
|
|
165
|
+
// no X-Rango-Cache header is emitted and output is byte-identical.
|
|
166
|
+
const cacheSignalEnabled =
|
|
167
|
+
debugCacheSignalOption ||
|
|
168
|
+
(typeof process !== "undefined" &&
|
|
169
|
+
(process as { env?: Record<string, string | undefined> }).env
|
|
170
|
+
?.RANGO_TEST_SIGNALS === "1");
|
|
171
|
+
|
|
172
|
+
// Normalize basename: ensure leading slash, strip trailing slash.
|
|
173
|
+
// A bare "/" is equivalent to no basename. Shared with the testing
|
|
174
|
+
// primitives via normalizeBasename so they can never drift.
|
|
175
|
+
const basename = normalizeBasename(basenameOption);
|
|
176
|
+
|
|
161
177
|
// Resolve telemetry sink (no-op when not configured)
|
|
162
178
|
const telemetry = resolveSink(telemetrySink);
|
|
163
179
|
|
|
@@ -200,11 +216,17 @@ export function createRouter<TEnv = any>(
|
|
|
200
216
|
const routerId =
|
|
201
217
|
userProvidedId ?? injectedId ?? `router_${nextRouterAutoId()}`;
|
|
202
218
|
|
|
203
|
-
// Resolve prefetch cache
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
219
|
+
// Resolve prefetch cache TTL (default: 300 seconds / 5 minutes)
|
|
220
|
+
// Clamp to a non-negative integer for valid Cache-Control max-age.
|
|
221
|
+
const rawTTL =
|
|
222
|
+
prefetchCacheTTLOption !== undefined ? prefetchCacheTTLOption : 300;
|
|
223
|
+
const prefetchCacheTTLSeconds =
|
|
224
|
+
rawTTL === false ? 0 : Math.max(0, Math.floor(rawTTL));
|
|
225
|
+
const prefetchCacheTTL = prefetchCacheTTLSeconds * 1000;
|
|
226
|
+
const prefetchCacheControl: string | false =
|
|
227
|
+
prefetchCacheTTLSeconds === 0
|
|
228
|
+
? false
|
|
229
|
+
: `private, max-age=${prefetchCacheTTLSeconds}`;
|
|
208
230
|
|
|
209
231
|
// Resolve warmup enabled flag (default: true)
|
|
210
232
|
const warmupEnabled = warmupOption !== false;
|
|
@@ -357,8 +379,18 @@ export function createRouter<TEnv = any>(
|
|
|
357
379
|
return precomputedByPrefix;
|
|
358
380
|
}
|
|
359
381
|
|
|
360
|
-
// Wrapper to pass debugPerformance to external createMetricsStore
|
|
361
|
-
|
|
382
|
+
// Wrapper to pass debugPerformance to external createMetricsStore.
|
|
383
|
+
// Also checks per-request flag set by ctx.debugPerformance() in middleware.
|
|
384
|
+
const getMetricsStore = () => {
|
|
385
|
+
const reqCtx = _getRequestContext();
|
|
386
|
+
const enabled = debugPerformance || !!reqCtx?._debugPerformance;
|
|
387
|
+
if (!enabled) return undefined;
|
|
388
|
+
if (!reqCtx) {
|
|
389
|
+
return createMetricsStore(true);
|
|
390
|
+
}
|
|
391
|
+
reqCtx._metricsStore ??= createMetricsStore(true);
|
|
392
|
+
return reqCtx._metricsStore;
|
|
393
|
+
};
|
|
362
394
|
|
|
363
395
|
// Wrapper to pass defaults to error/notFound boundary finders
|
|
364
396
|
const findNearestErrorBoundary = (entry: EntryData | null) =>
|
|
@@ -510,7 +542,9 @@ export function createRouter<TEnv = any>(
|
|
|
510
542
|
trackHandler,
|
|
511
543
|
findNearestErrorBoundary,
|
|
512
544
|
findNearestNotFoundBoundary,
|
|
545
|
+
notFoundComponent: notFound,
|
|
513
546
|
callOnError,
|
|
547
|
+
viewTransitionDefault: viewTransitionOption,
|
|
514
548
|
};
|
|
515
549
|
|
|
516
550
|
// Match API dependencies
|
|
@@ -544,6 +578,7 @@ export function createRouter<TEnv = any>(
|
|
|
544
578
|
mergedRouteMap,
|
|
545
579
|
nextMountIndex: () => mountIndex++,
|
|
546
580
|
getPrecomputedByPrefix,
|
|
581
|
+
routerId,
|
|
547
582
|
};
|
|
548
583
|
|
|
549
584
|
function evaluateLazyEntry(entry: RouteEntry<TEnv>): void {
|
|
@@ -597,6 +632,8 @@ export function createRouter<TEnv = any>(
|
|
|
597
632
|
params: Record<string, string>,
|
|
598
633
|
buildVars?: Record<string, any>,
|
|
599
634
|
isPassthroughRoute?: boolean,
|
|
635
|
+
buildEnv?: TEnv,
|
|
636
|
+
devMode?: boolean,
|
|
600
637
|
) {
|
|
601
638
|
return _matchForPrerender(
|
|
602
639
|
pathname,
|
|
@@ -604,6 +641,8 @@ export function createRouter<TEnv = any>(
|
|
|
604
641
|
prerenderDeps,
|
|
605
642
|
buildVars,
|
|
606
643
|
isPassthroughRoute,
|
|
644
|
+
buildEnv,
|
|
645
|
+
devMode,
|
|
607
646
|
);
|
|
608
647
|
}
|
|
609
648
|
|
|
@@ -611,12 +650,16 @@ export function createRouter<TEnv = any>(
|
|
|
611
650
|
handler: Function,
|
|
612
651
|
handlerId: string,
|
|
613
652
|
routeName?: string,
|
|
653
|
+
buildEnv?: TEnv,
|
|
654
|
+
devMode?: boolean,
|
|
614
655
|
) {
|
|
615
656
|
return _renderStaticSegment<TEnv>(
|
|
616
657
|
handler,
|
|
617
658
|
handlerId,
|
|
618
659
|
mergedRouteMap,
|
|
619
660
|
routeName,
|
|
661
|
+
buildEnv,
|
|
662
|
+
devMode,
|
|
620
663
|
);
|
|
621
664
|
}
|
|
622
665
|
|
|
@@ -629,6 +672,7 @@ export function createRouter<TEnv = any>(
|
|
|
629
672
|
findMatch,
|
|
630
673
|
findInterceptForRoute,
|
|
631
674
|
telemetry: telemetrySink,
|
|
675
|
+
cacheSignalEnabled,
|
|
632
676
|
});
|
|
633
677
|
|
|
634
678
|
const { match, matchPartial, matchError, previewMatch } = matchHandlers;
|
|
@@ -638,11 +682,18 @@ export function createRouter<TEnv = any>(
|
|
|
638
682
|
* The type system tracks accumulated routes through the builder chain
|
|
639
683
|
* Initial TRoutes is {} (empty) to avoid poisoning accumulated types with Record<string, string>
|
|
640
684
|
*/
|
|
641
|
-
const router:
|
|
685
|
+
const router: RangoInternal<TEnv, {}> = {
|
|
642
686
|
__brand: RSC_ROUTER_BRAND,
|
|
643
687
|
id: routerId,
|
|
688
|
+
basename,
|
|
689
|
+
|
|
690
|
+
routes(patternsOrBuilder: UrlPatterns<TEnv> | UrlBuilder<TEnv>): any {
|
|
691
|
+
// Wrap builder functions in urls() automatically
|
|
692
|
+
const urlPatterns: UrlPatterns<TEnv> =
|
|
693
|
+
typeof patternsOrBuilder === "function"
|
|
694
|
+
? (urls(patternsOrBuilder) as UrlPatterns<TEnv>)
|
|
695
|
+
: patternsOrBuilder;
|
|
644
696
|
|
|
645
|
-
routes(urlPatterns: UrlPatterns<TEnv>): any {
|
|
646
697
|
// Store reference for runtime manifest generation
|
|
647
698
|
storedUrlPatterns = urlPatterns;
|
|
648
699
|
const currentMountIndex = mountIndex++;
|
|
@@ -673,13 +724,13 @@ export function createRouter<TEnv = any>(
|
|
|
673
724
|
errorBoundary: [],
|
|
674
725
|
notFoundBoundary: [],
|
|
675
726
|
layout: [],
|
|
676
|
-
parallel:
|
|
727
|
+
parallel: {},
|
|
677
728
|
intercept: [],
|
|
678
729
|
loader: [],
|
|
679
730
|
};
|
|
680
731
|
|
|
681
732
|
let handlerResult: AllUseItems[] = [];
|
|
682
|
-
|
|
733
|
+
RangoContext.run(
|
|
683
734
|
{
|
|
684
735
|
manifest,
|
|
685
736
|
patterns: routePatterns,
|
|
@@ -690,6 +741,10 @@ export function createRouter<TEnv = any>(
|
|
|
690
741
|
counters: {},
|
|
691
742
|
mountIndex: currentMountIndex,
|
|
692
743
|
cacheProfiles: resolvedCacheProfiles,
|
|
744
|
+
// basename sets the initial URL prefix so all path() patterns
|
|
745
|
+
// are registered with the prefix (e.g. "/admin" + "/users" = "/admin/users").
|
|
746
|
+
// No namePrefix — route names stay unprefixed.
|
|
747
|
+
...(basename ? { urlPrefix: basename } : {}),
|
|
693
748
|
},
|
|
694
749
|
() => {
|
|
695
750
|
handlerResult = urlPatterns.handler() as AllUseItems[];
|
|
@@ -709,7 +764,7 @@ export function createRouter<TEnv = any>(
|
|
|
709
764
|
if (entry.type === "route" && entry.isPrerender) {
|
|
710
765
|
if (!prerenderRouteKeys) prerenderRouteKeys = new Set();
|
|
711
766
|
prerenderRouteKeys.add(name);
|
|
712
|
-
if (entry.
|
|
767
|
+
if (entry.isPassthrough === true) {
|
|
713
768
|
if (!passthroughRouteKeys) passthroughRouteKeys = new Set();
|
|
714
769
|
passthroughRouteKeys.add(name);
|
|
715
770
|
}
|
|
@@ -735,6 +790,7 @@ export function createRouter<TEnv = any>(
|
|
|
735
790
|
trailingSlash: trailingSlashConfig,
|
|
736
791
|
handler: urlPatterns.handler,
|
|
737
792
|
mountIndex: currentMountIndex,
|
|
793
|
+
routerId,
|
|
738
794
|
cacheProfiles: resolvedCacheProfiles,
|
|
739
795
|
...(prerenderRouteKeys ? { prerenderRouteKeys } : {}),
|
|
740
796
|
...(passthroughRouteKeys ? { passthroughRouteKeys } : {}),
|
|
@@ -754,6 +810,7 @@ export function createRouter<TEnv = any>(
|
|
|
754
810
|
trailingSlash: trailingSlashConfig,
|
|
755
811
|
handler: urlPatterns.handler,
|
|
756
812
|
mountIndex: currentMountIndex,
|
|
813
|
+
routerId,
|
|
757
814
|
cacheProfiles: resolvedCacheProfiles,
|
|
758
815
|
...(prerenderRouteKeys ? { prerenderRouteKeys } : {}),
|
|
759
816
|
...(passthroughRouteKeys ? { passthroughRouteKeys } : {}),
|
|
@@ -797,6 +854,7 @@ export function createRouter<TEnv = any>(
|
|
|
797
854
|
trailingSlash: trailingSlashConfig,
|
|
798
855
|
handler: urlPatterns.handler,
|
|
799
856
|
mountIndex: mountIndex++,
|
|
857
|
+
routerId,
|
|
800
858
|
// Lazy evaluation fields
|
|
801
859
|
lazy: true,
|
|
802
860
|
lazyPatterns: lazyInclude.patterns,
|
|
@@ -835,8 +893,18 @@ export function createRouter<TEnv = any>(
|
|
|
835
893
|
patternOrMiddleware: string | MiddlewareFn<TEnv>,
|
|
836
894
|
middleware?: MiddlewareFn<TEnv>,
|
|
837
895
|
): any {
|
|
838
|
-
//
|
|
839
|
-
|
|
896
|
+
// Auto-prefix pattern with basename so router-level middleware
|
|
897
|
+
// patterns are router-relative (e.g. "/users/*" matches "/app/users/*").
|
|
898
|
+
if (basename && typeof patternOrMiddleware === "string") {
|
|
899
|
+
const pattern = patternOrMiddleware;
|
|
900
|
+
const prefixed =
|
|
901
|
+
pattern === "/*" || pattern === "*"
|
|
902
|
+
? `${basename}/*`
|
|
903
|
+
: `${basename}${pattern}`;
|
|
904
|
+
addMiddleware(prefixed, middleware, null);
|
|
905
|
+
} else {
|
|
906
|
+
addMiddleware(patternOrMiddleware, middleware, null);
|
|
907
|
+
}
|
|
840
908
|
return router;
|
|
841
909
|
},
|
|
842
910
|
|
|
@@ -869,12 +937,16 @@ export function createRouter<TEnv = any>(
|
|
|
869
937
|
// Expose resolved cache profiles for per-request resolution
|
|
870
938
|
cacheProfiles: resolvedCacheProfiles,
|
|
871
939
|
|
|
872
|
-
// Expose prefetch cache
|
|
940
|
+
// Expose prefetch cache settings
|
|
873
941
|
prefetchCacheControl,
|
|
942
|
+
prefetchCacheTTL,
|
|
874
943
|
|
|
875
944
|
// Expose warmup enabled flag for handler and client
|
|
876
945
|
warmupEnabled,
|
|
877
946
|
|
|
947
|
+
// Expose router-wide performance debugging for request-level metrics setup
|
|
948
|
+
debugPerformance,
|
|
949
|
+
|
|
878
950
|
// Expose debug manifest flag for handler
|
|
879
951
|
allowDebugManifest: allowDebugManifestOption,
|
|
880
952
|
|
|
@@ -933,6 +1005,16 @@ export function createRouter<TEnv = any>(
|
|
|
933
1005
|
// Expose source file for per-router type generation
|
|
934
1006
|
__sourceFile,
|
|
935
1007
|
|
|
1008
|
+
// Expose basename for runtime manifest generation
|
|
1009
|
+
__basename: basename,
|
|
1010
|
+
|
|
1011
|
+
// Expose router-level boundary defaults for build-time clientChunks
|
|
1012
|
+
// discovery (so a "use client" default boundary lands in app-fallback).
|
|
1013
|
+
// These are createRouter options, never pushed onto EntryData.
|
|
1014
|
+
__defaultErrorBoundary: defaultErrorBoundary,
|
|
1015
|
+
__defaultNotFoundBoundary: defaultNotFoundBoundary,
|
|
1016
|
+
__notFound: notFound,
|
|
1017
|
+
|
|
936
1018
|
// RSC request handler (lazily created on first call)
|
|
937
1019
|
fetch: (() => {
|
|
938
1020
|
// Handler is created on first call and reused
|
|
@@ -966,6 +1048,10 @@ export function createRouter<TEnv = any>(
|
|
|
966
1048
|
};
|
|
967
1049
|
})(),
|
|
968
1050
|
|
|
1051
|
+
// Low-level route matching for request classification
|
|
1052
|
+
findMatch: (pathname: string, metricsStore?: any) =>
|
|
1053
|
+
findMatch(pathname, metricsStore),
|
|
1054
|
+
|
|
969
1055
|
// Debug utility for manifest inspection
|
|
970
1056
|
debugManifest: () => buildDebugManifest<TEnv>(routesEntries),
|
|
971
1057
|
};
|
|
@@ -974,8 +1060,10 @@ export function createRouter<TEnv = any>(
|
|
|
974
1060
|
RouterRegistry.set(routerId, router);
|
|
975
1061
|
|
|
976
1062
|
// If urls option was provided, auto-register them
|
|
977
|
-
if (urlsOption) {
|
|
978
|
-
return router.routes(urlsOption) as
|
|
1063
|
+
if (typeof urlsOption === "function") {
|
|
1064
|
+
return router.routes(urlsOption) as Rango<TEnv, {}>;
|
|
1065
|
+
} else if (urlsOption) {
|
|
1066
|
+
return router.routes(urlsOption) as Rango<TEnv, {}>;
|
|
979
1067
|
}
|
|
980
1068
|
|
|
981
1069
|
return router;
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
* RSC rendering) so they can be standalone modules without closure coupling.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { RangoInternal } from "../router/router-interfaces.js";
|
|
10
10
|
import type { ErrorPhase } from "../types.js";
|
|
11
11
|
import type { InvokeOnErrorContext } from "../router/error-handling.js";
|
|
12
12
|
import type { RSCDependencies, LoadSSRModule } from "./types.js";
|
|
13
13
|
import type { SSRStreamMode } from "../router/router-options.js";
|
|
14
14
|
|
|
15
15
|
export interface HandlerContext<TEnv = unknown> {
|
|
16
|
-
router:
|
|
16
|
+
router: RangoInternal<TEnv, any>;
|
|
17
17
|
version: string;
|
|
18
18
|
renderToReadableStream: RSCDependencies["renderToReadableStream"];
|
|
19
19
|
decodeReply: RSCDependencies["decodeReply"];
|