@rangojs/router 0.0.0-experimental.eb0645d3 → 0.0.0-experimental.f1468e3c
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 +8 -0
- package/README.md +126 -16
- package/dist/bin/rango.js +319 -95
- package/dist/testing/vitest.js +82 -0
- package/dist/vite/index.js +2724 -1053
- package/package.json +68 -14
- package/skills/api-client/SKILL.md +211 -0
- package/skills/breadcrumbs/SKILL.md +64 -2
- package/skills/bundle-analysis/SKILL.md +159 -0
- package/skills/cache-guide/SKILL.md +224 -32
- package/skills/caching/SKILL.md +279 -17
- package/skills/composability/SKILL.md +27 -3
- package/skills/css/SKILL.md +76 -0
- package/skills/debug-manifest/SKILL.md +4 -2
- package/skills/document-cache/SKILL.md +78 -55
- package/skills/handler-use/SKILL.md +11 -9
- package/skills/hooks/SKILL.md +243 -29
- package/skills/host-router/SKILL.md +83 -23
- package/skills/i18n/SKILL.md +276 -0
- package/skills/intercept/SKILL.md +68 -19
- package/skills/layout/SKILL.md +13 -9
- package/skills/links/SKILL.md +190 -23
- package/skills/loader/SKILL.md +235 -9
- package/skills/middleware/SKILL.md +18 -10
- package/skills/migrate-nextjs/SKILL.md +43 -19
- package/skills/migrate-react-router/SKILL.md +8 -2
- package/skills/mime-routes/SKILL.md +28 -1
- package/skills/observability/SKILL.md +172 -0
- package/skills/parallel/SKILL.md +18 -7
- package/skills/prerender/SKILL.md +65 -60
- package/skills/rango/SKILL.md +251 -24
- package/skills/react-compiler/SKILL.md +168 -0
- package/skills/response-routes/SKILL.md +115 -48
- package/skills/route/SKILL.md +46 -5
- package/skills/router-setup/SKILL.md +30 -8
- package/skills/scripts/SKILL.md +179 -0
- package/skills/server-actions/SKILL.md +775 -0
- package/skills/tailwind/SKILL.md +27 -3
- package/skills/testing/SKILL.md +130 -0
- package/skills/testing/bindings.md +103 -0
- package/skills/testing/cache-prerender.md +127 -0
- package/skills/testing/client-components.md +124 -0
- package/skills/testing/e2e-parity.md +125 -0
- package/skills/testing/flight.md +91 -0
- package/skills/testing/handles.md +129 -0
- package/skills/testing/loader.md +128 -0
- package/skills/testing/middleware.md +99 -0
- package/skills/testing/render-handler.md +122 -0
- package/skills/testing/response-routes.md +95 -0
- package/skills/testing/reverse-and-types.md +84 -0
- package/skills/testing/server-actions.md +107 -0
- package/skills/testing/server-tree.md +128 -0
- package/skills/testing/setup.md +123 -0
- package/skills/typesafety/SKILL.md +322 -29
- package/skills/use-cache/SKILL.md +57 -14
- package/skills/view-transitions/SKILL.md +337 -0
- package/src/__augment-tests__/augment.ts +81 -0
- package/src/__augment-tests__/augmented.check.ts +116 -0
- package/src/__internal.ts +0 -65
- package/src/browser/action-coordinator.ts +53 -36
- package/src/browser/action-fence.ts +47 -0
- package/src/browser/app-shell.ts +39 -0
- package/src/browser/connection-warmup.ts +134 -0
- package/src/browser/cookie-name.ts +140 -0
- package/src/browser/event-controller.ts +192 -150
- package/src/browser/history-state.ts +21 -0
- package/src/browser/index.ts +3 -3
- package/src/browser/invalidate-client-cache.ts +52 -0
- package/src/browser/navigation-bridge.ts +94 -25
- package/src/browser/navigation-client.ts +121 -84
- package/src/browser/navigation-store-handle.ts +38 -0
- package/src/browser/navigation-store.ts +115 -67
- package/src/browser/navigation-transaction.ts +9 -59
- package/src/browser/network-error-handler.ts +34 -7
- package/src/browser/partial-update.ts +147 -128
- package/src/browser/prefetch/cache.ts +107 -56
- package/src/browser/prefetch/fetch.ts +204 -34
- package/src/browser/prefetch/queue.ts +6 -3
- package/src/browser/rango-state.ts +158 -76
- package/src/browser/react/Link.tsx +30 -7
- package/src/browser/react/NavigationProvider.tsx +283 -118
- package/src/browser/react/ScrollRestoration.tsx +10 -6
- package/src/browser/react/deferred-handle-resolution.ts +75 -0
- package/src/browser/react/filter-segment-order.ts +66 -7
- package/src/browser/react/index.ts +0 -48
- package/src/browser/react/location-state-shared.ts +178 -8
- package/src/browser/react/location-state.ts +39 -14
- package/src/browser/react/use-action.ts +6 -15
- package/src/browser/react/use-handle.ts +17 -14
- package/src/browser/react/use-href.tsx +8 -1
- package/src/browser/react/use-link-status.ts +33 -8
- package/src/browser/react/use-navigation.ts +10 -5
- package/src/browser/react/use-params.ts +11 -11
- package/src/browser/react/use-reverse.ts +106 -0
- package/src/browser/react/use-router.ts +25 -3
- package/src/browser/react/use-search-params.ts +0 -5
- package/src/browser/react/use-segments.ts +11 -21
- package/src/browser/response-adapter.ts +99 -8
- package/src/browser/rsc-router.tsx +91 -24
- package/src/browser/scroll-restoration.ts +30 -17
- package/src/browser/segment-structure-assert.ts +2 -2
- package/src/browser/server-action-bridge.ts +214 -55
- package/src/browser/types.ts +80 -9
- package/src/browser/validate-redirect-origin.ts +43 -16
- package/src/build/collect-fallback-refs.ts +107 -0
- package/src/build/generate-manifest.ts +60 -35
- package/src/build/generate-route-types.ts +2 -1
- package/src/build/index.ts +8 -2
- package/src/build/prefix-tree-utils.ts +123 -0
- package/src/build/route-trie.ts +117 -14
- package/src/build/route-types/ast-route-extraction.ts +15 -8
- package/src/build/route-types/codegen.ts +16 -5
- package/src/build/route-types/include-resolution.ts +117 -23
- package/src/build/route-types/param-extraction.ts +6 -3
- package/src/build/route-types/per-module-writer.ts +22 -6
- package/src/build/route-types/router-processing.ts +55 -28
- package/src/build/route-types/scan-filter.ts +1 -1
- package/src/build/route-types/source-scan.ts +216 -0
- package/src/build/runtime-discovery.ts +9 -20
- package/src/cache/cache-error.ts +104 -0
- package/src/cache/cache-key-utils.ts +29 -13
- package/src/cache/cache-policy.ts +108 -34
- package/src/cache/cache-runtime.ts +224 -41
- package/src/cache/cache-scope.ts +188 -82
- package/src/cache/cache-tag.ts +103 -0
- package/src/cache/cf/cf-base64.ts +33 -0
- package/src/cache/cf/cf-cache-constants.ts +127 -0
- package/src/cache/cf/cf-cache-store.ts +1989 -378
- package/src/cache/cf/cf-cache-types.ts +349 -0
- package/src/cache/cf/cf-kv-utils.ts +46 -0
- package/src/cache/cf/cf-tag-marker-memo.ts +105 -0
- package/src/cache/cf/index.ts +6 -16
- package/src/cache/document-cache.ts +89 -21
- package/src/cache/handle-snapshot.ts +70 -0
- package/src/cache/index.ts +10 -20
- package/src/cache/memory-segment-store.ts +136 -37
- package/src/cache/profile-registry.ts +46 -31
- package/src/cache/read-through-swr.ts +56 -12
- package/src/cache/segment-codec.ts +9 -17
- package/src/cache/tag-invalidation.ts +230 -0
- package/src/cache/types.ts +37 -100
- package/src/client.rsc.tsx +44 -21
- package/src/client.tsx +36 -61
- package/src/cloudflare/index.ts +11 -0
- package/src/cloudflare/tracing.ts +109 -0
- package/src/component-utils.ts +19 -0
- package/src/components/DefaultDocument.tsx +8 -2
- package/src/context-var.ts +18 -6
- package/src/decode-loader-results.ts +52 -0
- package/src/defer.ts +196 -0
- package/src/deps/ssr.ts +0 -1
- package/src/encode-kv.ts +49 -0
- package/src/errors.ts +30 -4
- package/src/escape-script.ts +52 -0
- package/src/handle.ts +31 -23
- package/src/handles/MetaTags.tsx +62 -19
- package/src/handles/Scripts.tsx +183 -0
- package/src/handles/breadcrumbs.ts +37 -8
- package/src/handles/is-thenable.ts +19 -0
- package/src/handles/meta.ts +51 -40
- package/src/handles/script.ts +244 -0
- package/src/host/cookie-handler.ts +9 -60
- package/src/host/errors.ts +0 -24
- package/src/host/index.ts +8 -2
- package/src/host/pattern-matcher.ts +23 -52
- package/src/host/router.ts +107 -99
- package/src/host/testing.ts +40 -27
- package/src/host/types.ts +37 -4
- package/src/host/utils.ts +1 -1
- package/src/href-client.ts +137 -22
- package/src/index.rsc.ts +96 -12
- package/src/index.ts +94 -14
- package/src/internal-debug.ts +11 -10
- package/src/loader-store.ts +500 -0
- package/src/loader.rsc.ts +20 -13
- package/src/loader.ts +12 -11
- package/src/missing-id-error.ts +68 -0
- package/src/outlet-context.ts +1 -1
- package/src/outlet-provider.tsx +1 -5
- package/src/prerender/param-hash.ts +16 -16
- package/src/prerender/store.ts +32 -37
- package/src/prerender.ts +61 -6
- package/src/redirect-origin.ts +100 -0
- package/src/regex-escape.ts +8 -0
- package/src/render-error-thrower.tsx +20 -0
- package/src/response-utils.ts +34 -0
- package/src/reverse.ts +65 -40
- package/src/root-error-boundary.tsx +1 -19
- package/src/route-content-wrapper.tsx +19 -77
- package/src/route-definition/dsl-helpers.ts +304 -309
- package/src/route-definition/helper-factories.ts +28 -140
- package/src/route-definition/helpers-types.ts +82 -55
- package/src/route-definition/index.ts +1 -2
- package/src/route-definition/redirect.ts +44 -11
- package/src/route-definition/resolve-handler-use.ts +12 -1
- package/src/route-definition/use-item-types.ts +29 -0
- package/src/route-map-builder.ts +0 -16
- package/src/route-types.ts +19 -46
- package/src/router/basename.ts +14 -0
- package/src/router/content-negotiation.ts +73 -25
- package/src/router/error-handling.ts +45 -18
- package/src/router/find-match.ts +44 -23
- package/src/router/handler-context.ts +27 -43
- package/src/router/instrument.ts +350 -0
- package/src/router/intercept-resolution.ts +39 -20
- package/src/router/lazy-includes.ts +10 -47
- package/src/router/loader-resolution.ts +155 -72
- package/src/router/logging.ts +0 -6
- package/src/router/manifest.ts +18 -29
- package/src/router/match-api.ts +9 -24
- package/src/router/match-context.ts +0 -22
- package/src/router/match-handlers.ts +58 -58
- package/src/router/match-middleware/background-revalidation.ts +40 -24
- package/src/router/match-middleware/cache-lookup.ts +159 -285
- package/src/router/match-middleware/cache-store.ts +64 -52
- package/src/router/match-middleware/intercept-resolution.ts +0 -22
- package/src/router/match-middleware/segment-resolution.ts +0 -22
- package/src/router/match-pipelines.ts +1 -42
- package/src/router/match-result.ts +44 -74
- package/src/router/metrics.ts +0 -34
- package/src/router/middleware-types.ts +7 -134
- package/src/router/middleware.ts +247 -166
- package/src/router/navigation-snapshot.ts +0 -51
- package/src/router/params-util.ts +23 -0
- package/src/router/pattern-matching.ts +85 -94
- package/src/router/prefetch-cache-ttl.ts +51 -0
- package/src/router/prerender-match.ts +104 -65
- package/src/router/preview-match.ts +3 -1
- package/src/router/request-classification.ts +28 -62
- package/src/router/revalidation.ts +123 -73
- package/src/router/route-snapshot.ts +0 -1
- package/src/router/router-context.ts +3 -28
- package/src/router/router-interfaces.ts +83 -35
- package/src/router/router-options.ts +136 -5
- package/src/router/router-registry.ts +2 -5
- package/src/router/segment-resolution/fresh.ts +97 -84
- package/src/router/segment-resolution/helpers.ts +86 -6
- package/src/router/segment-resolution/loader-cache.ts +76 -39
- package/src/router/segment-resolution/revalidation.ts +272 -320
- package/src/router/segment-resolution/static-store.ts +19 -5
- package/src/router/segment-resolution/streamed-handler-telemetry.ts +52 -0
- package/src/router/segment-resolution/view-transition-default.ts +56 -0
- package/src/router/segment-resolution.ts +5 -1
- package/src/router/segment-wrappers.ts +6 -5
- package/src/router/state-cookie-name.ts +33 -0
- package/src/router/substitute-pattern-params.ts +56 -0
- package/src/router/telemetry-otel.ts +161 -199
- package/src/router/telemetry.ts +96 -19
- package/src/router/timeout.ts +0 -20
- package/src/router/tracing.ts +206 -0
- package/src/router/trie-matching.ts +162 -64
- package/src/router/types.ts +9 -63
- package/src/router/url-params.ts +0 -5
- package/src/router.ts +110 -55
- package/src/rsc/handler-context.ts +3 -2
- package/src/rsc/handler.ts +264 -220
- package/src/rsc/helpers.ts +100 -6
- package/src/rsc/index.ts +2 -5
- package/src/rsc/json-route-result.ts +38 -0
- package/src/rsc/loader-fetch.ts +114 -38
- package/src/rsc/manifest-init.ts +28 -41
- package/src/rsc/origin-guard.ts +39 -25
- package/src/rsc/progressive-enhancement.ts +117 -11
- package/src/rsc/redirect-guard.ts +99 -0
- package/src/rsc/response-cache-serve.ts +238 -0
- package/src/rsc/response-error.ts +79 -12
- package/src/rsc/response-route-handler.ts +88 -188
- package/src/rsc/rsc-rendering.ts +98 -76
- package/src/rsc/runtime-warnings.ts +23 -10
- package/src/rsc/server-action.ts +281 -117
- package/src/rsc/ssr-setup.ts +16 -0
- package/src/rsc/transition-gate.ts +89 -0
- package/src/rsc/types.ts +23 -5
- package/src/runtime-env.ts +18 -0
- package/src/search-params.ts +35 -30
- package/src/segment-loader-promise.ts +31 -4
- package/src/segment-system.tsx +254 -143
- package/src/serialize.ts +243 -0
- package/src/server/context.ts +163 -51
- package/src/server/cookie-parse.ts +32 -0
- package/src/server/cookie-store.ts +80 -5
- package/src/server/handle-store.ts +21 -38
- package/src/server/loader-registry.ts +33 -42
- package/src/server/request-context.ts +287 -178
- package/src/ssr/index.tsx +21 -16
- package/src/static-handler.ts +10 -13
- package/src/testing/cache-status.ts +162 -0
- package/src/testing/collect-handle.ts +40 -0
- package/src/testing/dispatch.ts +701 -0
- package/src/testing/dom.entry.ts +22 -0
- package/src/testing/e2e/fixture.ts +188 -0
- package/src/testing/e2e/index.ts +128 -0
- package/src/testing/e2e/matchers.ts +35 -0
- package/src/testing/e2e/page-helpers.ts +272 -0
- package/src/testing/e2e/parity.ts +387 -0
- package/src/testing/e2e/server.ts +195 -0
- package/src/testing/flight-matchers.ts +97 -0
- package/src/testing/flight-normalize.ts +11 -0
- package/src/testing/flight-runtime.d.ts +57 -0
- package/src/testing/flight-tree.ts +682 -0
- package/src/testing/flight.entry.ts +52 -0
- package/src/testing/flight.ts +257 -0
- package/src/testing/generated-routes.ts +183 -0
- package/src/testing/index.ts +105 -0
- package/src/testing/internal/context.ts +371 -0
- package/src/testing/internal/flight-client-globals.ts +30 -0
- package/src/testing/internal/seed-vars.ts +54 -0
- package/src/testing/render-handler.ts +357 -0
- package/src/testing/render-route.tsx +581 -0
- package/src/testing/run-loader.ts +385 -0
- package/src/testing/run-middleware.ts +205 -0
- package/src/testing/run-transition-when.ts +164 -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 +305 -0
- package/src/theme/ThemeProvider.tsx +20 -58
- package/src/theme/ThemeScript.tsx +7 -9
- package/src/theme/constants.ts +52 -13
- package/src/theme/index.ts +0 -7
- package/src/theme/theme-context.ts +1 -5
- package/src/theme/theme-script.ts +22 -21
- package/src/theme/use-theme.ts +0 -3
- package/src/types/boundaries.ts +0 -35
- package/src/types/cache-types.ts +13 -4
- package/src/types/error-types.ts +30 -90
- package/src/types/global-namespace.ts +54 -41
- package/src/types/handler-context.ts +110 -62
- package/src/types/index.ts +3 -10
- package/src/types/loader-types.ts +11 -9
- package/src/types/request-scope.ts +112 -0
- package/src/types/route-config.ts +6 -50
- package/src/types/route-entry.ts +0 -6
- package/src/types/segments.ts +135 -14
- package/src/urls/include-helper.ts +9 -56
- package/src/urls/index.ts +1 -11
- package/src/urls/path-helper-types.ts +29 -12
- package/src/urls/path-helper.ts +17 -106
- package/src/urls/pattern-types.ts +36 -19
- package/src/urls/response-types.ts +22 -29
- package/src/urls/type-extraction.ts +58 -139
- package/src/urls/urls-function.ts +1 -19
- package/src/use-loader.tsx +292 -107
- package/src/vite/debug.ts +185 -0
- package/src/vite/discovery/bundle-postprocess.ts +8 -7
- package/src/vite/discovery/discover-routers.ts +126 -85
- 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 +96 -68
- 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 +44 -0
- package/src/vite/discovery/virtual-module-codegen.ts +14 -34
- package/src/vite/index.ts +2 -0
- package/src/vite/inject-client-debug.ts +36 -0
- package/src/vite/plugin-types.ts +126 -8
- package/src/vite/plugins/cjs-to-esm.ts +16 -19
- package/src/vite/plugins/client-ref-dedup.ts +16 -11
- package/src/vite/plugins/client-ref-hashing.ts +28 -15
- package/src/vite/plugins/cloudflare-protocol-stub.ts +1 -21
- package/src/vite/plugins/expose-action-id.ts +48 -95
- package/src/vite/plugins/expose-id-utils.ts +88 -55
- package/src/vite/plugins/expose-ids/export-analysis.ts +101 -34
- package/src/vite/plugins/expose-ids/handler-transform.ts +11 -90
- package/src/vite/plugins/expose-ids/loader-transform.ts +14 -24
- package/src/vite/plugins/expose-ids/router-transform.ts +118 -29
- package/src/vite/plugins/expose-internal-ids.ts +505 -486
- package/src/vite/plugins/performance-tracks.ts +26 -25
- package/src/vite/plugins/refresh-cmd.ts +1 -1
- package/src/vite/plugins/use-cache-transform.ts +73 -83
- package/src/vite/plugins/version-injector.ts +40 -29
- package/src/vite/plugins/version-plugin.ts +37 -40
- package/src/vite/plugins/virtual-entries.ts +39 -25
- package/src/vite/rango.ts +109 -118
- package/src/vite/router-discovery.ts +718 -119
- package/src/vite/utils/ast-handler-extract.ts +26 -35
- package/src/vite/utils/banner.ts +1 -1
- package/src/vite/utils/bundle-analysis.ts +10 -15
- package/src/vite/utils/client-chunks.ts +184 -0
- package/src/vite/utils/directive-prologue.ts +40 -0
- package/src/vite/utils/forward-user-plugins.ts +171 -0
- package/src/vite/utils/manifest-utils.ts +4 -59
- package/src/vite/utils/package-resolution.ts +20 -52
- package/src/vite/utils/prerender-utils.ts +54 -39
- package/src/vite/utils/shared-utils.ts +90 -41
- package/src/browser/action-response-classifier.ts +0 -99
- package/src/browser/react/use-client-cache.ts +0 -58
- package/src/browser/shallow.ts +0 -40
- package/src/handles/index.ts +0 -7
- package/src/network-error-thrower.tsx +0 -23
- package/src/router/middleware-cookies.ts +0 -55
package/src/types/index.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
// Global namespace (must be imported for side effects: `declare global`)
|
|
2
1
|
export type {
|
|
3
2
|
GetRegisteredRoutes,
|
|
4
3
|
DefaultHandlerRouteMap,
|
|
5
4
|
DefaultReverseRouteMap,
|
|
6
5
|
DefaultEnv,
|
|
7
6
|
} from "./global-namespace.js";
|
|
8
|
-
// Ensure the global namespace declaration is evaluated
|
|
9
7
|
import "./global-namespace.js";
|
|
10
8
|
|
|
11
|
-
// Route configuration
|
|
12
9
|
export type {
|
|
13
10
|
DocumentProps,
|
|
14
11
|
ExtractParams,
|
|
@@ -19,7 +16,6 @@ export type {
|
|
|
19
16
|
ResolvedRouteMap,
|
|
20
17
|
} from "./route-config.js";
|
|
21
18
|
|
|
22
|
-
// Boundaries (error/notFound)
|
|
23
19
|
export type {
|
|
24
20
|
ErrorInfo,
|
|
25
21
|
ErrorBoundaryFallbackProps,
|
|
@@ -32,7 +28,6 @@ export type {
|
|
|
32
28
|
} from "./boundaries.js";
|
|
33
29
|
export { isLoaderDataResult } from "./boundaries.js";
|
|
34
30
|
|
|
35
|
-
// Handler context and related types
|
|
36
31
|
export type {
|
|
37
32
|
MiddlewareFn,
|
|
38
33
|
ScopedRouteMap,
|
|
@@ -42,6 +37,7 @@ export type {
|
|
|
42
37
|
GenericParams,
|
|
43
38
|
RevalidateParams,
|
|
44
39
|
ShouldRevalidateFn,
|
|
40
|
+
ActionRef,
|
|
45
41
|
RouteKeys,
|
|
46
42
|
ExtractRouteParams,
|
|
47
43
|
HandlersForRouteMap,
|
|
@@ -49,10 +45,11 @@ export type {
|
|
|
49
45
|
Middleware,
|
|
50
46
|
} from "./handler-context.js";
|
|
51
47
|
|
|
52
|
-
// Segments
|
|
53
48
|
export type {
|
|
54
49
|
ViewTransitionClass,
|
|
55
50
|
TransitionConfig,
|
|
51
|
+
TransitionWhenFn,
|
|
52
|
+
TransitionWhenContext,
|
|
56
53
|
ResolvedSegment,
|
|
57
54
|
SegmentMetadata,
|
|
58
55
|
SlotState,
|
|
@@ -60,10 +57,8 @@ export type {
|
|
|
60
57
|
MatchResult,
|
|
61
58
|
} from "./segments.js";
|
|
62
59
|
|
|
63
|
-
// Route entries
|
|
64
60
|
export type { LazyIncludeContext, RouteEntry } from "./route-entry.js";
|
|
65
61
|
|
|
66
|
-
// Loader types
|
|
67
62
|
export type {
|
|
68
63
|
LoaderContext,
|
|
69
64
|
LoaderFn,
|
|
@@ -72,7 +67,6 @@ export type {
|
|
|
72
67
|
LoaderDefinition,
|
|
73
68
|
} from "./loader-types.js";
|
|
74
69
|
|
|
75
|
-
// Cache types
|
|
76
70
|
export type {
|
|
77
71
|
CacheContext,
|
|
78
72
|
CacheOptions,
|
|
@@ -80,7 +74,6 @@ export type {
|
|
|
80
74
|
EntryCacheConfig,
|
|
81
75
|
} from "./cache-types.js";
|
|
82
76
|
|
|
83
|
-
// Error handling types
|
|
84
77
|
export type {
|
|
85
78
|
ErrorPhase,
|
|
86
79
|
OnErrorContext,
|
|
@@ -3,11 +3,13 @@ import type { Handle } from "../handle.js";
|
|
|
3
3
|
import type { MiddlewareFn } from "../router/middleware.js";
|
|
4
4
|
import type { ScopedReverseFunction } from "../reverse.js";
|
|
5
5
|
import type { SearchSchema, ResolveSearchSchema } from "../search-params.js";
|
|
6
|
+
import type { UseItems, LoaderUseItem } from "../route-types.js";
|
|
6
7
|
import type {
|
|
7
8
|
DefaultEnv,
|
|
8
9
|
DefaultReverseRouteMap,
|
|
9
10
|
DefaultVars,
|
|
10
11
|
} from "./global-namespace.js";
|
|
12
|
+
import type { RequestScope } from "./request-scope.js";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Context passed to loader functions during execution
|
|
@@ -39,7 +41,7 @@ export type LoaderContext<
|
|
|
39
41
|
TEnv = DefaultEnv,
|
|
40
42
|
TBody = unknown,
|
|
41
43
|
TSearch extends SearchSchema = {},
|
|
42
|
-
> = {
|
|
44
|
+
> = RequestScope<TEnv> & {
|
|
43
45
|
params: TParams;
|
|
44
46
|
/**
|
|
45
47
|
* Route params extracted from the URL pattern match (server-side only).
|
|
@@ -48,12 +50,7 @@ export type LoaderContext<
|
|
|
48
50
|
* resource scoping.
|
|
49
51
|
*/
|
|
50
52
|
routeParams: Record<string, string>;
|
|
51
|
-
request: Request;
|
|
52
|
-
searchParams: URLSearchParams;
|
|
53
53
|
search: {} extends TSearch ? {} : ResolveSearchSchema<TSearch>;
|
|
54
|
-
pathname: string;
|
|
55
|
-
url: URL;
|
|
56
|
-
env: TEnv;
|
|
57
54
|
get: {
|
|
58
55
|
<T>(contextVar: ContextVar<T>): T | undefined;
|
|
59
56
|
} & (<K extends keyof DefaultVars>(key: K) => DefaultVars[K]);
|
|
@@ -75,9 +72,12 @@ export type LoaderContext<
|
|
|
75
72
|
* **Experimental.** Wait for all non-loader segments to settle.
|
|
76
73
|
*
|
|
77
74
|
* After the returned promise resolves, handle data is available via
|
|
78
|
-
* `ctx.use(handle)`.
|
|
79
|
-
* trees
|
|
80
|
-
*
|
|
75
|
+
* `ctx.use(handle)`. Supported in DSL loaders, including on streaming
|
|
76
|
+
* trees that use `loading()` — the barrier waits for the streaming
|
|
77
|
+
* handlers to finish pushing before it resolves. Throws if called from a
|
|
78
|
+
* handler-invoked loader, or if a handler is already awaiting this loader
|
|
79
|
+
* via `ctx.use()` (that would deadlock — use a loader-to-loader
|
|
80
|
+
* dependency instead).
|
|
81
81
|
*
|
|
82
82
|
* @example
|
|
83
83
|
* ```typescript
|
|
@@ -207,4 +207,6 @@ export type LoaderDefinition<
|
|
|
207
207
|
__brand: "loader";
|
|
208
208
|
$$id: string; // Injected by Vite plugin (exposeInternalIds) - unique identifier
|
|
209
209
|
fn?: LoaderFn<T, TParams, any>; // Optional - server-side only, stored in registry for RSC
|
|
210
|
+
/** Composable default DSL items merged when the loader is mounted. */
|
|
211
|
+
use?: () => UseItems<LoaderUseItem>;
|
|
210
212
|
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { DefaultEnv } from "./global-namespace.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal subset of Cloudflare Workers' ExecutionContext that the router
|
|
5
|
+
* uses. Defined locally so the package does not depend on
|
|
6
|
+
* `@cloudflare/workers-types`. Consumers that want the full type can cast.
|
|
7
|
+
*
|
|
8
|
+
* On non-Cloudflare runtimes (Node, dev server, tests), this is undefined
|
|
9
|
+
* — portable apps should prefer `ctx.waitUntil(...)`, which degrades
|
|
10
|
+
* gracefully. `ctx.executionContext` is the escape hatch for libraries
|
|
11
|
+
* (MCP, Durable Object routing, etc.) that type their arguments as the
|
|
12
|
+
* raw ExecutionContext.
|
|
13
|
+
*/
|
|
14
|
+
export interface ExecutionContext {
|
|
15
|
+
waitUntil(promise: Promise<any>): void;
|
|
16
|
+
passThroughOnException(): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Fallback `waitUntil` body used when no Cloudflare `ExecutionContext`
|
|
21
|
+
* is available (Node, dev, tests). Runs the work fire-and-forget and
|
|
22
|
+
* logs errors so they don't silently swallow.
|
|
23
|
+
*
|
|
24
|
+
* Exported so every `waitUntil` call site degrades identically instead
|
|
25
|
+
* of inventing its own fallback policy.
|
|
26
|
+
*/
|
|
27
|
+
export function fireAndForgetWaitUntil(fn: () => Promise<void>): void {
|
|
28
|
+
// Defer fn() invocation to a microtask so a SYNCHRONOUS throw in a non-async
|
|
29
|
+
// callback (e.g. `() => { somethingThatThrows(); return p; }`) becomes a
|
|
30
|
+
// rejected promise we catch here, not an exception that escapes into the
|
|
31
|
+
// request flow. waitUntil is fire-and-forget: a background-task failure must
|
|
32
|
+
// never break the response.
|
|
33
|
+
Promise.resolve()
|
|
34
|
+
.then(fn)
|
|
35
|
+
.catch((err) => console.error("[waitUntil] Background task failed:", err));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Fields present on every user-facing request context.
|
|
40
|
+
*
|
|
41
|
+
* @template TEnv - Platform bindings type (Cloudflare env, etc.).
|
|
42
|
+
*/
|
|
43
|
+
export interface RequestScope<TEnv = DefaultEnv> {
|
|
44
|
+
/**
|
|
45
|
+
* The original incoming Request object (transport URL intact).
|
|
46
|
+
* Use `url` / `searchParams` for application logic — those have
|
|
47
|
+
* internal `_rsc*` params stripped. `request` preserves the raw URL
|
|
48
|
+
* when you need original headers, method, or body.
|
|
49
|
+
*/
|
|
50
|
+
request: Request;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The request URL with internal `_rsc*` transport params stripped.
|
|
54
|
+
* Use this for routing, link generation, and display.
|
|
55
|
+
*/
|
|
56
|
+
url: URL;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The original request URL with all parameters intact, including
|
|
60
|
+
* internal `_rsc*` transport params. Use `url` for application logic
|
|
61
|
+
* — this is only needed for advanced cases like debugging or custom
|
|
62
|
+
* cache keying.
|
|
63
|
+
*/
|
|
64
|
+
originalUrl: URL;
|
|
65
|
+
|
|
66
|
+
/** URL pathname (same as `url.pathname`). */
|
|
67
|
+
pathname: string;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Query parameters from the URL (system params like `_rsc*` are
|
|
71
|
+
* filtered). Always a standard `URLSearchParams` instance.
|
|
72
|
+
*/
|
|
73
|
+
searchParams: URLSearchParams;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Platform bindings (DB, KV, secrets, etc.). On Cloudflare Workers
|
|
77
|
+
* these are the `env` object passed to the Worker's `fetch()` handler.
|
|
78
|
+
*/
|
|
79
|
+
env: TEnv;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Schedule work to run after the response is sent.
|
|
83
|
+
* On Cloudflare Workers, delegates to `executionContext.waitUntil()`.
|
|
84
|
+
* On Node / dev / tests, runs as fire-and-forget with error logging.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* ctx.waitUntil(async () => {
|
|
89
|
+
* await cacheStore.set(key, data, ttl);
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
waitUntil(fn: () => Promise<void>): void;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Raw Cloudflare Workers `ExecutionContext`, when running on a
|
|
97
|
+
* Cloudflare-compatible runtime. Undefined elsewhere.
|
|
98
|
+
*
|
|
99
|
+
* Escape hatch for libraries that type their arguments as
|
|
100
|
+
* `ExecutionContext` (MCP `fetch`, `routeAgentRequest`, etc.).
|
|
101
|
+
* For the common "do work after the response" case, prefer
|
|
102
|
+
* `ctx.waitUntil(...)` — it is platform-neutral.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* path.any("/mcp", (ctx) =>
|
|
107
|
+
* emailMcp.fetch(ctx.request, ctx.env, ctx.executionContext!),
|
|
108
|
+
* );
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
executionContext?: ExecutionContext;
|
|
112
|
+
}
|
|
@@ -7,47 +7,24 @@ export type DocumentProps = {
|
|
|
7
7
|
children: ReactNode;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Parse constraint values into a union type
|
|
12
|
-
* "a|b|c" -> "a" | "b" | "c"
|
|
13
|
-
*/
|
|
14
10
|
type ParseConstraint<T extends string> =
|
|
15
11
|
T extends `${infer First}|${infer Rest}` ? First | ParseConstraint<Rest> : T;
|
|
16
12
|
|
|
17
|
-
/**
|
|
18
|
-
* Extract param info from a param segment
|
|
19
|
-
*
|
|
20
|
-
* Handles:
|
|
21
|
-
* - :param -> { name: "param", optional: false, type: string }
|
|
22
|
-
* - :param? -> { name: "param", optional: true, type: string }
|
|
23
|
-
* - :param(a|b) -> { name: "param", optional: false, type: "a" | "b" }
|
|
24
|
-
* - :param(a|b)? -> { name: "param", optional: true, type: "a" | "b" }
|
|
25
|
-
*/
|
|
26
13
|
type ExtractParamInfo<T extends string> =
|
|
27
|
-
// Optional + constrained (with optional suffix): :param(a|b)?suffix
|
|
28
14
|
T extends `${infer Name}(${infer Constraint})?${string}`
|
|
29
15
|
? { name: Name; optional: true; type: ParseConstraint<Constraint> }
|
|
30
|
-
:
|
|
31
|
-
T extends `${infer Name}(${infer Constraint})${string}`
|
|
16
|
+
: T extends `${infer Name}(${infer Constraint})${string}`
|
|
32
17
|
? { name: Name; optional: false; type: ParseConstraint<Constraint> }
|
|
33
|
-
:
|
|
34
|
-
T extends `${infer Name}?${string}`
|
|
18
|
+
: T extends `${infer Name}?${string}`
|
|
35
19
|
? { name: Name; optional: true; type: string }
|
|
36
|
-
:
|
|
37
|
-
T extends `${infer Name}.${string}`
|
|
20
|
+
: T extends `${infer Name}.${string}`
|
|
38
21
|
? { name: Name; optional: false; type: string }
|
|
39
|
-
:
|
|
40
|
-
T extends `${infer Name}-${string}`
|
|
22
|
+
: T extends `${infer Name}-${string}`
|
|
41
23
|
? { name: Name; optional: false; type: string }
|
|
42
|
-
:
|
|
43
|
-
T extends `${infer Name}~${string}`
|
|
24
|
+
: T extends `${infer Name}~${string}`
|
|
44
25
|
? { name: Name; optional: false; type: string }
|
|
45
|
-
:
|
|
46
|
-
{ name: T; optional: false; type: string };
|
|
26
|
+
: { name: T; optional: false; type: string };
|
|
47
27
|
|
|
48
|
-
/**
|
|
49
|
-
* Build param object from info
|
|
50
|
-
*/
|
|
51
28
|
type ParamFromInfo<Info> = Info extends {
|
|
52
29
|
name: infer N extends string;
|
|
53
30
|
optional: true;
|
|
@@ -62,10 +39,6 @@ type ParamFromInfo<Info> = Info extends {
|
|
|
62
39
|
? { [K in N]: V }
|
|
63
40
|
: never;
|
|
64
41
|
|
|
65
|
-
/**
|
|
66
|
-
* Merge two param objects preserving optionality
|
|
67
|
-
* Uses Pick to preserve the modifiers from source types
|
|
68
|
-
*/
|
|
69
42
|
type MergeParams<A, B> = Pick<A, keyof A> & Pick<B, keyof B> extends infer O
|
|
70
43
|
? { [K in keyof O]: O[K] }
|
|
71
44
|
: never;
|
|
@@ -109,17 +82,11 @@ export type ExtractParams<
|
|
|
109
82
|
*/
|
|
110
83
|
export type TrailingSlashMode = "never" | "always" | "ignore";
|
|
111
84
|
|
|
112
|
-
/**
|
|
113
|
-
* Route configuration object (alternative to string path)
|
|
114
|
-
*/
|
|
115
85
|
export type RouteConfig = {
|
|
116
86
|
path: string;
|
|
117
87
|
trailingSlash?: TrailingSlashMode;
|
|
118
88
|
};
|
|
119
89
|
|
|
120
|
-
/**
|
|
121
|
-
* Route definition options (global defaults)
|
|
122
|
-
*/
|
|
123
90
|
export type RouteDefinitionOptions = {
|
|
124
91
|
trailingSlash?: TrailingSlashMode;
|
|
125
92
|
};
|
|
@@ -128,11 +95,6 @@ export type RouteDefinition = {
|
|
|
128
95
|
[key: string]: string | RouteConfig | RouteDefinition;
|
|
129
96
|
};
|
|
130
97
|
|
|
131
|
-
/**
|
|
132
|
-
* Recursively flatten nested routes with depth limit to prevent infinite recursion
|
|
133
|
-
* Transforms: { products: { detail: "/product/:slug" } } => { "products.detail": "/product/:slug" }
|
|
134
|
-
* Also handles RouteConfig objects: { api: { path: "/api" } } => { "api": "/api" }
|
|
135
|
-
*/
|
|
136
98
|
type FlattenRoutes<
|
|
137
99
|
T extends RouteDefinition,
|
|
138
100
|
Prefix extends string = "",
|
|
@@ -153,18 +115,12 @@ type FlattenRoutes<
|
|
|
153
115
|
: never;
|
|
154
116
|
}[keyof T];
|
|
155
117
|
|
|
156
|
-
/**
|
|
157
|
-
* Union to intersection helper
|
|
158
|
-
*/
|
|
159
118
|
type UnionToIntersection<U> = (
|
|
160
119
|
U extends unknown ? (k: U) => void : never
|
|
161
120
|
) extends (k: infer I) => void
|
|
162
121
|
? I
|
|
163
122
|
: never;
|
|
164
123
|
|
|
165
|
-
/**
|
|
166
|
-
* Resolved route map - flattened route definitions with full paths
|
|
167
|
-
*/
|
|
168
124
|
export type ResolvedRouteMap<T extends RouteDefinition> = UnionToIntersection<
|
|
169
125
|
FlattenRoutes<T>
|
|
170
126
|
>;
|
package/src/types/route-entry.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { AllUseItems } from "../route-types.js";
|
|
2
2
|
import type { TrailingSlashMode, ResolvedRouteMap } from "./route-config.js";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Context captured for lazy include evaluation
|
|
6
|
-
*/
|
|
7
4
|
export interface LazyIncludeContext {
|
|
8
5
|
urlPrefix: string;
|
|
9
6
|
namePrefix: string | undefined;
|
|
@@ -25,9 +22,6 @@ export interface LazyIncludeContext {
|
|
|
25
22
|
includeScope?: string;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
/**
|
|
29
|
-
* Internal route entry stored in router
|
|
30
|
-
*/
|
|
31
25
|
export interface RouteEntry<TEnv = any> {
|
|
32
26
|
prefix: string;
|
|
33
27
|
/**
|
package/src/types/segments.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import type { ErrorInfo, NotFoundInfo } from "./boundaries.js";
|
|
3
|
+
import type { RevalidateParams, HandlerContext } from "./handler-context.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* CSS class(es) for a ViewTransition phase.
|
|
@@ -8,9 +9,102 @@ import type { ErrorInfo, NotFoundInfo } from "./boundaries.js";
|
|
|
8
9
|
*/
|
|
9
10
|
export type ViewTransitionClass = Record<string, string> | string;
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The context a transition({ when }) predicate receives.
|
|
14
|
+
*
|
|
15
|
+
* It mirrors the {@link ShouldRevalidateFn} args a `revalidate()` predicate
|
|
16
|
+
* gets — the same navigation/action metadata — so the two read the same shape,
|
|
17
|
+
* plus `get`/`env` for post-handler reads. There is no full `HandlerContext`
|
|
18
|
+
* here: the gate runs at the RSC-payload layer with the request context, not a
|
|
19
|
+
* handler context, so handler-only sugar (`search`/`build`/`dev`/`headers`) is
|
|
20
|
+
* absent by design. `get` is the way to read what the handler/middleware set
|
|
21
|
+
* via `ctx.set(...)` this request.
|
|
22
|
+
*
|
|
23
|
+
* Field availability (all source fields are optional — never fabricated):
|
|
24
|
+
* - `currentUrl` / `currentParams` / `fromRouteName` (the navigation SOURCE) are
|
|
25
|
+
* populated on soft navigations and action-success revalidations. They are
|
|
26
|
+
* undefined on an initial full document load and on action-error / no-JS error
|
|
27
|
+
* paths that skip the navigation snapshot — there is no prior page to name.
|
|
28
|
+
* - `nextUrl` / `nextParams` / `get` / `env` / `method` are always present;
|
|
29
|
+
* `toRouteName` is present only when the target route is named (undefined for
|
|
30
|
+
* unnamed/auto-generated routes, like `fromRouteName`).
|
|
31
|
+
* - `actionId` / `actionUrl` / `actionResult` / `formData` are populated only
|
|
32
|
+
* when a server action triggered the render; `method` is "POST" then, "GET"
|
|
33
|
+
* otherwise. On no-JS (progressive-enhancement) action paths `actionId` may be
|
|
34
|
+
* undefined when React cannot surface the action's stable id: the success
|
|
35
|
+
* re-render still sets `actionUrl`/`formData` for a recognized action, but the
|
|
36
|
+
* error-boundary re-render exposes `actionUrl` only when `actionId` resolved.
|
|
37
|
+
* Malformed form bodies that fail before action detection expose no action
|
|
38
|
+
* fields. Treat `actionId` as "the action, if known", not as "was this an
|
|
39
|
+
* action".
|
|
40
|
+
*
|
|
41
|
+
* PREFETCH / CACHE CAVEAT (read this before gating on the source): the gate runs
|
|
42
|
+
* server-side during resolution. A PREFETCHED navigation renders at prefetch
|
|
43
|
+
* time, so `currentUrl`/`currentParams`/`fromRouteName` reflect the page the
|
|
44
|
+
* prefetch fired from, NOT necessarily the page the user actually navigates from
|
|
45
|
+
* — the decision is baked into the stored Flight payload and replayed verbatim.
|
|
46
|
+
* A `cache()`/prerender hit replays the stored transition with the predicate NOT
|
|
47
|
+
* re-run at all. So a source-sensitive predicate can be frozen to prefetch-time
|
|
48
|
+
* or store-time state. This is accepted (~99% of navigations match), but if your
|
|
49
|
+
* gate must reflect the exact click-time source, source-scope the prefetch
|
|
50
|
+
* (`<Link prefetchKey=":source">`) and do not `cache()` that segment.
|
|
51
|
+
*/
|
|
52
|
+
export type TransitionWhenContext<
|
|
53
|
+
TParams = Record<string, string>,
|
|
54
|
+
TEnv = unknown,
|
|
55
|
+
> = Partial<
|
|
56
|
+
Pick<
|
|
57
|
+
RevalidateParams<TParams, TEnv>,
|
|
58
|
+
"currentUrl" | "currentParams" | "fromRouteName"
|
|
59
|
+
>
|
|
60
|
+
> &
|
|
61
|
+
Pick<
|
|
62
|
+
RevalidateParams<TParams, TEnv>,
|
|
63
|
+
| "nextUrl"
|
|
64
|
+
| "nextParams"
|
|
65
|
+
| "toRouteName"
|
|
66
|
+
| "actionId"
|
|
67
|
+
| "actionUrl"
|
|
68
|
+
| "actionResult"
|
|
69
|
+
| "formData"
|
|
70
|
+
| "method"
|
|
71
|
+
> &
|
|
72
|
+
Pick<HandlerContext<any, TEnv>, "get" | "env">;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Predicate that gates whether a transition() applies for the current request.
|
|
76
|
+
*
|
|
77
|
+
* Evaluated server-side AFTER the route's handler runs (so `get(...)` can read
|
|
78
|
+
* handler/middleware-set state) and outside any cache scope. Return false to
|
|
79
|
+
* drop this segment's transition for the request; return true to apply it. The
|
|
80
|
+
* context ({@link TransitionWhenContext}) carries the same navigation/action
|
|
81
|
+
* metadata a `revalidate()` predicate sees plus `get`/`env`. If it throws, the
|
|
82
|
+
* error is reported to the router's onError (phase "rendering") and the
|
|
83
|
+
* transition is dropped (the navigation does not hold).
|
|
84
|
+
*
|
|
85
|
+
* Distinct from intercept()'s `when` config selector, which runs at MATCH time
|
|
86
|
+
* over `{ from, to, params, segments, … }`; a transition `when` runs
|
|
87
|
+
* post-handler over the resolved payload.
|
|
88
|
+
*
|
|
89
|
+
* Scope: dropping a transition removes only THIS segment's contribution to the
|
|
90
|
+
* navigation's hold. The startTransition hold is navigation-wide — it engages if
|
|
91
|
+
* any matched segment still has a transition — so `when: false` makes the
|
|
92
|
+
* navigation stream its loading fallback only when no other matched segment
|
|
93
|
+
* keeps a transition (the common case: a single transition on the route).
|
|
94
|
+
*
|
|
95
|
+
* Evaluated on every fresh (cache-miss) resolution; it is NOT re-run when a
|
|
96
|
+
* segment is replayed from the runtime cache or a build-time prerender, and a
|
|
97
|
+
* prefetched navigation freezes it to prefetch-time state — see the caveat on
|
|
98
|
+
* {@link TransitionWhenContext}.
|
|
99
|
+
*/
|
|
100
|
+
export type TransitionWhenFn = (ctx: TransitionWhenContext) => boolean;
|
|
101
|
+
|
|
11
102
|
/**
|
|
12
103
|
* Configuration for React's <ViewTransition> component.
|
|
13
|
-
*
|
|
104
|
+
*
|
|
105
|
+
* The phase fields (enter/exit/update/share/default/name) map directly to
|
|
106
|
+
* ViewTransitionProps (minus children/ref/callbacks). The `viewTransition`
|
|
107
|
+
* field is router-specific and is stripped before the config reaches React.
|
|
14
108
|
*/
|
|
15
109
|
export interface TransitionConfig {
|
|
16
110
|
enter?: ViewTransitionClass;
|
|
@@ -19,19 +113,34 @@ export interface TransitionConfig {
|
|
|
19
113
|
share?: ViewTransitionClass;
|
|
20
114
|
default?: ViewTransitionClass;
|
|
21
115
|
name?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Whether the router wraps this segment's content in its own
|
|
118
|
+
* <ViewTransition> boundary.
|
|
119
|
+
*
|
|
120
|
+
* - "auto" (default): the router places the boundary, producing the
|
|
121
|
+
* router-owned cross-fade described by the phase fields above.
|
|
122
|
+
* - false: the router places no boundary. The navigation commit is still
|
|
123
|
+
* driven through startTransition (so loaders hold instead of flashing a
|
|
124
|
+
* skeleton, and consumer-placed <ViewTransition> elements still animate),
|
|
125
|
+
* but the router contributes no cross-fade of its own.
|
|
126
|
+
*
|
|
127
|
+
* When unset, inherits the createRouter({ viewTransition }) default.
|
|
128
|
+
*/
|
|
129
|
+
viewTransition?: "auto" | false;
|
|
130
|
+
/**
|
|
131
|
+
* Optional server-side predicate that gates this transition per request. When
|
|
132
|
+
* present and it returns false (evaluated post-handler), the router drops this
|
|
133
|
+
* segment's transition for the request, so the navigation streams its loading
|
|
134
|
+
* fallback instead of holding. The predicate is server-only and never
|
|
135
|
+
* serialized to the client; only its resolved effect (transition kept or
|
|
136
|
+
* dropped) crosses. See {@link TransitionWhenFn}.
|
|
137
|
+
*/
|
|
138
|
+
when?: TransitionWhenFn;
|
|
22
139
|
}
|
|
23
140
|
|
|
24
141
|
/**
|
|
25
142
|
* Resolved segment with component
|
|
26
143
|
*
|
|
27
|
-
* Segment types:
|
|
28
|
-
* - layout: Wraps child content via <Outlet />
|
|
29
|
-
* - route: The leaf content for a URL
|
|
30
|
-
* - parallel: Named slots rendered via <ParallelOutlet name="@slot" />
|
|
31
|
-
* - loader: Data segment (no visual rendering, carries loaderData)
|
|
32
|
-
* - error: Error fallback segment (replaces failed segment with error UI)
|
|
33
|
-
* - notFound: Not found fallback segment (replaces segment when data not found)
|
|
34
|
-
*
|
|
35
144
|
* @internal This type is an implementation detail and may change without notice.
|
|
36
145
|
*/
|
|
37
146
|
export interface ResolvedSegment {
|
|
@@ -62,13 +171,16 @@ export interface ResolvedSegment {
|
|
|
62
171
|
notFoundInfo?: NotFoundInfo; // For notFound segments: the not found information
|
|
63
172
|
// Mount path from include() scope, used for MountContext.Provider wrapping
|
|
64
173
|
mountPath?: string;
|
|
174
|
+
/**
|
|
175
|
+
* @internal Server-side marker: true when the segment's handler actually ran
|
|
176
|
+
* this request (not skipped via the revalidate cache path). Used by
|
|
177
|
+
* match-result.ts to populate `MatchResult.resolvedIds` for client-side
|
|
178
|
+
* handle-bucket cleanup. Stripped from the wire payload before serialization
|
|
179
|
+
* — never reaches the client.
|
|
180
|
+
*/
|
|
181
|
+
_handlerRan?: boolean;
|
|
65
182
|
}
|
|
66
183
|
|
|
67
|
-
/**
|
|
68
|
-
* Segment metadata (without component)
|
|
69
|
-
*
|
|
70
|
-
* @internal This type is an implementation detail and may change without notice.
|
|
71
|
-
*/
|
|
72
184
|
export interface SegmentMetadata {
|
|
73
185
|
id: string;
|
|
74
186
|
type: "layout" | "route" | "parallel" | "loader" | "error" | "notFound";
|
|
@@ -116,6 +228,15 @@ export interface MatchResult {
|
|
|
116
228
|
segments: ResolvedSegment[];
|
|
117
229
|
matched: string[];
|
|
118
230
|
diff: string[];
|
|
231
|
+
/**
|
|
232
|
+
* Every segment id whose handler actually ran on the server this request,
|
|
233
|
+
* including ones with `component === null` that get filtered out of
|
|
234
|
+
* `segments`/`diff` to avoid wasted bytes. Drives the client's handle-
|
|
235
|
+
* cleanup pass — a slot that re-resolves and pushes nothing must clear
|
|
236
|
+
* its previous handle bucket, but `diff` doesn't carry it because the
|
|
237
|
+
* segment payload doesn't either. A superset of `diff`.
|
|
238
|
+
*/
|
|
239
|
+
resolvedIds: string[];
|
|
119
240
|
/**
|
|
120
241
|
* Merged route params from all matched segments
|
|
121
242
|
* Available for use by the handler after route matching
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { AllUseItems, IncludeItem } from "../route-types.js";
|
|
2
2
|
import {
|
|
3
|
-
getContext,
|
|
4
|
-
runWithPrefixes,
|
|
5
3
|
getUrlPrefix,
|
|
6
4
|
getNamePrefix,
|
|
5
|
+
requireDslContext,
|
|
7
6
|
} from "../server/context";
|
|
8
7
|
import {
|
|
9
8
|
INTERNAL_INCLUDE_SCOPE_PREFIX,
|
|
@@ -26,28 +25,10 @@ function allocateInternalIncludeScopeId(
|
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
|
-
*
|
|
30
|
-
* This expands the include into actual route registrations
|
|
31
|
-
*/
|
|
32
|
-
function processIncludeItem(item: IncludeItem): AllUseItems[] {
|
|
33
|
-
const { prefix, patterns } = item;
|
|
34
|
-
const namePrefix =
|
|
35
|
-
(item as IncludeItem & { _lazyContext?: { namePrefix?: string } })
|
|
36
|
-
._lazyContext?.namePrefix ?? item.options?.name;
|
|
37
|
-
|
|
38
|
-
// Execute the nested patterns' handler with URL and name prefixes
|
|
39
|
-
// The urlPrefix being set tells nested urls() to skip RootLayout wrapping
|
|
40
|
-
return runWithPrefixes(prefix, namePrefix, () => {
|
|
41
|
-
// Call the nested patterns' handler - this registers routes with prefixed patterns/names
|
|
42
|
-
return (patterns as UrlPatterns).handler();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Recursively process items, expanding any IncludeItems
|
|
48
|
-
* Returns items with IncludeItems expanded into actual route items
|
|
28
|
+
* Recursively walk items, recursing into layout children.
|
|
49
29
|
*
|
|
50
|
-
*
|
|
30
|
+
* All includes are lazy and kept as-is; the router expands them on the first
|
|
31
|
+
* matching request.
|
|
51
32
|
*/
|
|
52
33
|
export function processItems(items: readonly AllUseItems[]): AllUseItems[] {
|
|
53
34
|
const result: AllUseItems[] = [];
|
|
@@ -56,28 +37,8 @@ export function processItems(items: readonly AllUseItems[]): AllUseItems[] {
|
|
|
56
37
|
if (!item) continue;
|
|
57
38
|
|
|
58
39
|
if (item.type === "include") {
|
|
59
|
-
|
|
60
|
-
_expanded?: AllUseItems[];
|
|
61
|
-
lazy?: boolean;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Lazy includes are NOT expanded here - kept for router to handle
|
|
65
|
-
if (includeItem.lazy) {
|
|
66
|
-
result.push(item);
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Eager includes are already expanded during include() call
|
|
71
|
-
if (includeItem._expanded) {
|
|
72
|
-
// Items were expanded immediately - just process them recursively
|
|
73
|
-
result.push(...processItems(includeItem._expanded));
|
|
74
|
-
} else {
|
|
75
|
-
// Fallback for legacy include items without _expanded
|
|
76
|
-
const expanded = processIncludeItem(item as IncludeItem);
|
|
77
|
-
result.push(...processItems(expanded));
|
|
78
|
-
}
|
|
40
|
+
result.push(item);
|
|
79
41
|
} else if (item.type === "layout" && (item as any).uses) {
|
|
80
|
-
// Process nested items in layout
|
|
81
42
|
const layoutItem = item as any;
|
|
82
43
|
layoutItem.uses = processItems(layoutItem.uses);
|
|
83
44
|
result.push(layoutItem);
|
|
@@ -92,13 +53,9 @@ export function processItems(items: readonly AllUseItems[]): AllUseItems[] {
|
|
|
92
53
|
/**
|
|
93
54
|
* Create include() helper for composing URL patterns
|
|
94
55
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* With `lazy: true`, patterns are NOT expanded at definition time. Instead,
|
|
100
|
-
* they're evaluated on first request that matches the prefix. This improves
|
|
101
|
-
* cold start time for apps with many routes.
|
|
56
|
+
* All includes are lazy: the nested patterns are NOT expanded at definition
|
|
57
|
+
* time. Instead they are evaluated on the first request that matches the
|
|
58
|
+
* prefix, which improves cold start time for apps with many routes.
|
|
102
59
|
*/
|
|
103
60
|
export function createIncludeHelper<TEnv>(): IncludeFn<TEnv> {
|
|
104
61
|
return (
|
|
@@ -106,9 +63,7 @@ export function createIncludeHelper<TEnv>(): IncludeFn<TEnv> {
|
|
|
106
63
|
patterns: UrlPatterns<TEnv>,
|
|
107
64
|
options?: IncludeOptions,
|
|
108
65
|
): IncludeItem => {
|
|
109
|
-
const
|
|
110
|
-
const ctx = store.getStore();
|
|
111
|
-
if (!ctx) throw new Error("include() must be called inside urls()");
|
|
66
|
+
const { ctx } = requireDslContext("include() must be called inside urls()");
|
|
112
67
|
|
|
113
68
|
const explicitName = options?.name;
|
|
114
69
|
const hasExplicitName = hasExplicitNameOption(options);
|
|
@@ -184,8 +139,6 @@ export function createIncludeHelper<TEnv>(): IncludeFn<TEnv> {
|
|
|
184
139
|
? (parentRootScoped ?? false)
|
|
185
140
|
: parentRootScoped;
|
|
186
141
|
|
|
187
|
-
// All includes are lazy - patterns are evaluated on first matching request
|
|
188
|
-
// This improves cold start time significantly for large route sets
|
|
189
142
|
return {
|
|
190
143
|
type: "include",
|
|
191
144
|
name,
|