@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/cache-types.ts
CHANGED
|
@@ -78,6 +78,14 @@ export interface CacheOptions<TEnv = unknown> {
|
|
|
78
78
|
* - Loader-specific caching strategies
|
|
79
79
|
* - Hot data in fast cache, cold data in larger/slower cache
|
|
80
80
|
*
|
|
81
|
+
* Tag invalidation caveat: a per-boundary store becomes reachable by
|
|
82
|
+
* `updateTag()` / `revalidateTag()` once this boundary is resolved in the
|
|
83
|
+
* current process. If the store is *durable* (shared across processes) and the
|
|
84
|
+
* very first request to a fresh worker is an `updateTag`/`revalidateTag` for a
|
|
85
|
+
* tag held only in this store - before this boundary is matched - that
|
|
86
|
+
* invalidation can miss it. For data you invalidate by tag, prefer the
|
|
87
|
+
* app-level store (always reachable), or ensure the boundary is warmed.
|
|
88
|
+
*
|
|
81
89
|
* @example
|
|
82
90
|
* ```typescript
|
|
83
91
|
* const kvStore = new CloudflareKVStore(env.CACHE_KV);
|
|
@@ -145,10 +153,11 @@ export interface CacheOptions<TEnv = unknown> {
|
|
|
145
153
|
* Tags for cache invalidation.
|
|
146
154
|
* Can be a static array or a function that returns tags.
|
|
147
155
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
156
|
+
* The built-in `MemorySegmentCacheStore` and `CFCacheStore` index by tag.
|
|
157
|
+
* Invalidate on demand with `updateTag(...tags)` (awaitable, read-your-own-writes;
|
|
158
|
+
* for server actions) or `revalidateTag(...tags)` (background hard-purge, not
|
|
159
|
+
* awaited; for route handlers / webhooks). For `CFCacheStore`, distributed
|
|
160
|
+
* invalidation requires a `kv` namespace (markers live in that same namespace).
|
|
152
161
|
*
|
|
153
162
|
* @example
|
|
154
163
|
* ```typescript
|
package/src/types/error-types.ts
CHANGED
|
@@ -14,19 +14,19 @@
|
|
|
14
14
|
* - "unknown": Fallback for unclassified errors (not currently invoked)
|
|
15
15
|
*/
|
|
16
16
|
export type ErrorPhase =
|
|
17
|
-
| "routing"
|
|
18
|
-
| "manifest"
|
|
19
|
-
| "middleware"
|
|
20
|
-
| "loader"
|
|
21
|
-
| "handler"
|
|
22
|
-
| "rendering"
|
|
23
|
-
| "action"
|
|
24
|
-
| "revalidation"
|
|
25
|
-
| "cache"
|
|
26
|
-
| "prerender"
|
|
27
|
-
| "static"
|
|
28
|
-
| "origin"
|
|
29
|
-
| "unknown";
|
|
17
|
+
| "routing"
|
|
18
|
+
| "manifest"
|
|
19
|
+
| "middleware"
|
|
20
|
+
| "loader"
|
|
21
|
+
| "handler"
|
|
22
|
+
| "rendering"
|
|
23
|
+
| "action"
|
|
24
|
+
| "revalidation"
|
|
25
|
+
| "cache"
|
|
26
|
+
| "prerender"
|
|
27
|
+
| "static"
|
|
28
|
+
| "origin"
|
|
29
|
+
| "unknown";
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Comprehensive context passed to onError callback
|
|
@@ -59,103 +59,43 @@ export type ErrorPhase =
|
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
61
|
export interface OnErrorContext<TEnv = any> {
|
|
62
|
-
/**
|
|
63
|
-
* The error that occurred
|
|
64
|
-
*/
|
|
65
62
|
error: Error;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Phase where the error occurred
|
|
69
|
-
*/
|
|
70
63
|
phase: ErrorPhase;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The original request
|
|
74
|
-
*/
|
|
75
64
|
request: Request;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Parsed URL from the request
|
|
79
|
-
*/
|
|
80
65
|
url: URL;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Request pathname
|
|
84
|
-
*/
|
|
85
66
|
pathname: string;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* HTTP method
|
|
89
|
-
*/
|
|
90
67
|
method: string;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Matched route key (if available)
|
|
94
|
-
* e.g., "shop.products.detail"
|
|
95
|
-
*/
|
|
68
|
+
/** Matched route key (if available) e.g., "shop.products.detail" */
|
|
96
69
|
routeKey?: string;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Route params (if available)
|
|
100
|
-
* e.g., { slug: "headphones" }
|
|
101
|
-
*/
|
|
70
|
+
/** Route params (if available) e.g., { slug: "headphones" } */
|
|
102
71
|
params?: Record<string, string>;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Segment ID where error occurred (if available)
|
|
106
|
-
* e.g., "M1L0" for a layout, "M1R0" for a route
|
|
107
|
-
*/
|
|
72
|
+
/** Segment ID where error occurred (if available) e.g., "M1L0" for a layout, "M1R0" for a route */
|
|
108
73
|
segmentId?: string;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Segment type where error occurred (if available)
|
|
112
|
-
*/
|
|
74
|
+
/** Segment type where error occurred (if available) */
|
|
113
75
|
segmentType?: "layout" | "route" | "parallel" | "loader" | "middleware";
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Loader name (if error occurred in a loader)
|
|
117
|
-
*/
|
|
76
|
+
/** Loader name (if error occurred in a loader) */
|
|
118
77
|
loaderName?: string;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Middleware name/id (if error occurred in middleware)
|
|
122
|
-
*/
|
|
78
|
+
/** Middleware name/id (if error occurred in middleware) */
|
|
123
79
|
middlewareId?: string;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Action ID (if error occurred during server action)
|
|
127
|
-
* e.g., "src/actions.ts#addToCart"
|
|
128
|
-
*/
|
|
80
|
+
/** Action ID (if error occurred during server action) e.g., "src/actions.ts#addToCart" */
|
|
129
81
|
actionId?: string;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Environment/bindings (platform context)
|
|
133
|
-
*/
|
|
82
|
+
/** Environment/bindings (platform context) */
|
|
134
83
|
env?: TEnv;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Duration from request start to error (milliseconds)
|
|
138
|
-
*/
|
|
84
|
+
/** Duration from request start to error (milliseconds) */
|
|
139
85
|
duration?: number;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Whether this is a partial/navigation request
|
|
143
|
-
*/
|
|
86
|
+
/** Whether this is a partial/navigation request */
|
|
144
87
|
isPartial?: boolean;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Whether an error boundary caught the error
|
|
148
|
-
* If true, the error was handled and a fallback UI was rendered
|
|
149
|
-
*/
|
|
88
|
+
/** Whether an error boundary caught the error */
|
|
150
89
|
handledByBoundary?: boolean;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Stack trace (if available)
|
|
154
|
-
*/
|
|
90
|
+
/** Stack trace (if available) */
|
|
155
91
|
stack?: string;
|
|
156
92
|
|
|
157
93
|
/**
|
|
158
|
-
* Additional metadata specific to the error phase
|
|
94
|
+
* Additional metadata specific to the error phase. For the `cache` phase,
|
|
95
|
+
* `metadata.category` is a `CacheErrorCategory` (exported from
|
|
96
|
+
* `@rangojs/router/cache`) identifying the failure kind, e.g. `cache-read`
|
|
97
|
+
* (transient outage, degraded to a miss) vs `cache-corrupt` (faulty entry
|
|
98
|
+
* self-healed) vs `cache-invalidate` (a failed background revalidateTag).
|
|
159
99
|
*/
|
|
160
100
|
metadata?: Record<string, unknown>;
|
|
161
101
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* ```typescript
|
|
8
8
|
* // In env.ts or env.d.ts
|
|
9
9
|
* declare global {
|
|
10
|
-
* namespace
|
|
10
|
+
* namespace Rango {
|
|
11
11
|
* interface Env extends AppBindings {}
|
|
12
12
|
* interface Vars extends AppVariables {}
|
|
13
13
|
* }
|
|
@@ -18,39 +18,41 @@
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
declare global {
|
|
21
|
-
namespace
|
|
21
|
+
namespace Rango {
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
23
|
-
interface Env {
|
|
24
|
-
// Empty by default - users augment with their bindings (e.g., { DB: D1Database })
|
|
25
|
-
}
|
|
23
|
+
interface Env {}
|
|
26
24
|
|
|
27
25
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
28
|
-
interface Vars {
|
|
29
|
-
// Empty by default - users augment with their variables (e.g., { user?: User })
|
|
30
|
-
}
|
|
26
|
+
interface Vars {}
|
|
31
27
|
|
|
32
28
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
33
|
-
interface RegisteredRoutes {
|
|
34
|
-
// Empty by default - users augment with their merged route maps for type-safe href()
|
|
35
|
-
// Values are string (pattern) for RSC routes, or { path: string; response: T } for response routes
|
|
36
|
-
}
|
|
29
|
+
interface RegisteredRoutes {}
|
|
37
30
|
|
|
38
31
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
39
|
-
interface GeneratedRouteMap {
|
|
40
|
-
// Empty by default - populated by generated named-routes.gen.ts
|
|
41
|
-
// Maps route names to URL pattern strings for Handler<"routeName"> support
|
|
42
|
-
}
|
|
32
|
+
interface GeneratedRouteMap {}
|
|
43
33
|
}
|
|
44
34
|
}
|
|
45
35
|
|
|
46
36
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
37
|
+
* Route map for path-validation surfaces (`href`, `ValidPaths`, `PathResponse`).
|
|
38
|
+
*
|
|
39
|
+
* Resolution order:
|
|
40
|
+
* 1. `RegisteredRoutes` — manual `extends typeof router.routeMap`; richest map,
|
|
41
|
+
* the only one carrying response-route payload metadata.
|
|
42
|
+
* 2. `GeneratedRouteMap` — auto-wired by `router.named-routes.gen.ts`; path +
|
|
43
|
+
* search only. Lets `rango generate` alone enable `href()`/`ValidPaths` path
|
|
44
|
+
* checking without a manual `RegisteredRoutes` declaration.
|
|
45
|
+
* 3. `Record<string, string>` — permissive fallback when nothing is registered.
|
|
46
|
+
*
|
|
47
|
+
* Referencing `GeneratedRouteMap` here is cycle-safe: it is declared in the
|
|
48
|
+
* standalone gen file with no imports, unlike `RegisteredRoutes extends typeof
|
|
49
|
+
* router.routeMap`.
|
|
50
50
|
*/
|
|
51
|
-
export type GetRegisteredRoutes = keyof
|
|
52
|
-
?
|
|
53
|
-
|
|
51
|
+
export type GetRegisteredRoutes = keyof Rango.RegisteredRoutes extends never
|
|
52
|
+
? keyof Rango.GeneratedRouteMap extends never
|
|
53
|
+
? Record<string, string>
|
|
54
|
+
: Rango.GeneratedRouteMap
|
|
55
|
+
: Rango.RegisteredRoutes;
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
58
|
* Default route map for reverse() surfaces.
|
|
@@ -58,12 +60,11 @@ export type GetRegisteredRoutes = keyof RSCRouter.RegisteredRoutes extends never
|
|
|
58
60
|
* cycles, but falls back to RegisteredRoutes for manual augmentation and then to
|
|
59
61
|
* a permissive record when no route types are available.
|
|
60
62
|
*/
|
|
61
|
-
export type DefaultReverseRouteMap =
|
|
62
|
-
keyof
|
|
63
|
-
?
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
: RSCRouter.GeneratedRouteMap;
|
|
63
|
+
export type DefaultReverseRouteMap = keyof Rango.GeneratedRouteMap extends never
|
|
64
|
+
? keyof Rango.RegisteredRoutes extends never
|
|
65
|
+
? Record<string, string>
|
|
66
|
+
: Rango.RegisteredRoutes
|
|
67
|
+
: Rango.GeneratedRouteMap;
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
70
|
* Default route map for Handler type.
|
|
@@ -71,30 +72,42 @@ export type DefaultReverseRouteMap =
|
|
|
71
72
|
* circular dependencies: router.tsx -> urls.tsx -> handler.tsx -> RegisteredRoutes -> router.tsx.
|
|
72
73
|
* GeneratedRouteMap is declared in a standalone gen file with no imports.
|
|
73
74
|
*/
|
|
74
|
-
export type DefaultHandlerRouteMap =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
: RSCRouter.GeneratedRouteMap;
|
|
75
|
+
export type DefaultHandlerRouteMap = keyof Rango.GeneratedRouteMap extends never
|
|
76
|
+
? {}
|
|
77
|
+
: Rango.GeneratedRouteMap;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* Default environment type - uses global augmentation if available
|
|
80
|
+
* Default environment type - uses global augmentation if available.
|
|
81
|
+
*
|
|
82
|
+
* Falls back to `unknown` (not `any`) when `Rango.Env` is not augmented, so
|
|
83
|
+
* an app that forgets to register its bindings gets a compile error on
|
|
84
|
+
* `ctx.env.SOMETHING` instead of silently losing all env type-checking. Augment
|
|
85
|
+
* `Rango.Env` to type `ctx.env`.
|
|
81
86
|
*/
|
|
82
|
-
export type DefaultEnv = keyof
|
|
83
|
-
? any
|
|
84
|
-
: RSCRouter.Env;
|
|
87
|
+
export type DefaultEnv = keyof Rango.Env extends never ? unknown : Rango.Env;
|
|
85
88
|
|
|
86
89
|
/**
|
|
87
|
-
*
|
|
90
|
+
* Variables type backing the string-key `ctx.get` / `ctx.set` overloads.
|
|
91
|
+
*
|
|
92
|
+
* Uses `Rango.Vars` augmentation when present; otherwise falls back to
|
|
93
|
+
* `Record<string, any>` so an un-augmented app can use string-key vars with
|
|
94
|
+
* zero config -- at the cost of a typo'd key being silently `any`.
|
|
95
|
+
*
|
|
96
|
+
* This `any` fallback is deliberate (see #561) and is an intentional asymmetry
|
|
97
|
+
* with `DefaultEnv` above, which falls back to `unknown`: env bindings are
|
|
98
|
+
* platform-critical and should be registered, so a forgotten binding is made a
|
|
99
|
+
* compile error; vars are ad-hoc and middleware-set, so the zero-config path
|
|
100
|
+
* wins. Augment `Rango.Vars` for type-safe keys.
|
|
88
101
|
*/
|
|
89
|
-
export type DefaultVars = keyof
|
|
102
|
+
export type DefaultVars = keyof Rango.Vars extends never
|
|
90
103
|
? Record<string, any>
|
|
91
|
-
:
|
|
104
|
+
: Rango.Vars;
|
|
92
105
|
|
|
93
106
|
/**
|
|
94
107
|
* Default route name type for public `routeName` on contexts.
|
|
95
108
|
* When GeneratedRouteMap is augmented, narrows to the known route names.
|
|
96
109
|
* Otherwise falls back to `string` for untyped usage.
|
|
97
110
|
*/
|
|
98
|
-
export type DefaultRouteName = keyof
|
|
111
|
+
export type DefaultRouteName = keyof Rango.GeneratedRouteMap extends never
|
|
99
112
|
? string
|
|
100
|
-
: keyof
|
|
113
|
+
: keyof Rango.GeneratedRouteMap & string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import type { Handle } from "../handle.js";
|
|
3
|
+
import type { HandlePush } from "../defer.js";
|
|
3
4
|
import type { ContextVar } from "../context-var.js";
|
|
4
5
|
import type { MiddlewareFn } from "../router/middleware.js";
|
|
5
6
|
import type { Theme } from "../theme/types.js";
|
|
@@ -20,6 +21,7 @@ import type {
|
|
|
20
21
|
} from "./route-config.js";
|
|
21
22
|
import type { LoaderDefinition } from "./loader-types.js";
|
|
22
23
|
import type { UseItems, HandlerUseItem } from "../route-types.js";
|
|
24
|
+
import type { RequestScope } from "./request-scope.js";
|
|
23
25
|
|
|
24
26
|
// Re-export MiddlewareFn for internal/advanced use
|
|
25
27
|
export type { MiddlewareFn } from "../router/middleware.js";
|
|
@@ -42,7 +44,7 @@ export type { MiddlewareFn } from "../router/middleware.js";
|
|
|
42
44
|
*/
|
|
43
45
|
export type ScopedRouteMap<
|
|
44
46
|
TPrefix extends string,
|
|
45
|
-
TMap =
|
|
47
|
+
TMap = Rango.GeneratedRouteMap,
|
|
46
48
|
> = {
|
|
47
49
|
[K in keyof TMap as K extends `${TPrefix}.${infer Rest}`
|
|
48
50
|
? Rest
|
|
@@ -106,14 +108,6 @@ type StrictLocalParamsWithExtras<TEntry> =
|
|
|
106
108
|
? Record<string, string>
|
|
107
109
|
: ExtractParamsFromEntry<TEntry, {}> & Record<string, string>;
|
|
108
110
|
|
|
109
|
-
// HandlerContext.reverse is the only reverse surface with runtime param autofill
|
|
110
|
-
// from the current matched request. Middleware/loaders/request context do not
|
|
111
|
-
// have the same local-route guarantees, so they keep plain ScopedReverseFunction.
|
|
112
|
-
//
|
|
113
|
-
// When a handler has an explicit local route map, enforce that local route
|
|
114
|
-
// params declared by that map are present while still allowing extra mount
|
|
115
|
-
// params to be passed through. Global names remain autofill-friendly because
|
|
116
|
-
// parent include() params are often unknown at the module definition site.
|
|
117
111
|
type StrictLocalAutofillGlobalReverseFunction<TLocalRoutes, TGlobalRoutes> =
|
|
118
112
|
ScopedReverseFunction<TLocalRoutes, TGlobalRoutes> & {
|
|
119
113
|
<TName extends keyof TGlobalRoutes & string>(
|
|
@@ -195,7 +189,7 @@ export type HandlerContext<
|
|
|
195
189
|
TEnv = DefaultEnv,
|
|
196
190
|
TSearch extends SearchSchema = {},
|
|
197
191
|
TRouteMap = never,
|
|
198
|
-
> = {
|
|
192
|
+
> = RequestScope<TEnv> & {
|
|
199
193
|
/**
|
|
200
194
|
* Route parameters extracted from the URL pattern.
|
|
201
195
|
* Type-safe when using Handler<"/path/:param"> or Handler<{ param: string }>.
|
|
@@ -215,44 +209,11 @@ export type HandlerContext<
|
|
|
215
209
|
* changing build semantics (e.g., skip expensive operations in dev).
|
|
216
210
|
*/
|
|
217
211
|
dev: boolean;
|
|
218
|
-
/**
|
|
219
|
-
* The original incoming Request object (transport URL intact).
|
|
220
|
-
* Use `ctx.url` / `ctx.searchParams` for application logic — those have
|
|
221
|
-
* internal `_rsc*` params stripped. `ctx.request` preserves the raw URL
|
|
222
|
-
* for cases where you need original headers, method, or body.
|
|
223
|
-
*/
|
|
224
|
-
request: Request;
|
|
225
|
-
/**
|
|
226
|
-
* Query parameters from the URL (system params like `_rsc*` are filtered).
|
|
227
|
-
* Always a standard URLSearchParams instance.
|
|
228
|
-
*/
|
|
229
|
-
searchParams: URLSearchParams;
|
|
230
212
|
/**
|
|
231
213
|
* Typed search parameters parsed from URL query string via the route's
|
|
232
214
|
* search schema. Empty object when no schema is defined.
|
|
233
215
|
*/
|
|
234
216
|
search: {} extends TSearch ? {} : ResolveSearchSchema<TSearch>;
|
|
235
|
-
/**
|
|
236
|
-
* The pathname portion of the request URL.
|
|
237
|
-
*/
|
|
238
|
-
pathname: string;
|
|
239
|
-
/**
|
|
240
|
-
* The full URL object (with internal `_rsc*` params stripped).
|
|
241
|
-
* Use this for application logic — routing, link generation, display.
|
|
242
|
-
*/
|
|
243
|
-
url: URL;
|
|
244
|
-
/**
|
|
245
|
-
* The original request URL with all parameters intact, including
|
|
246
|
-
* internal `_rsc*` transport params. Use `ctx.url` for application
|
|
247
|
-
* logic — this is only needed for advanced cases like debugging
|
|
248
|
-
* or custom cache keying.
|
|
249
|
-
*/
|
|
250
|
-
originalUrl: URL;
|
|
251
|
-
/**
|
|
252
|
-
* Platform bindings (DB, KV, secrets, etc.).
|
|
253
|
-
* Access resources like `ctx.env.DB`, `ctx.env.KV`.
|
|
254
|
-
*/
|
|
255
|
-
env: TEnv;
|
|
256
217
|
/**
|
|
257
218
|
* Type-safe getter for middleware variables.
|
|
258
219
|
* Preferred way to read middleware-injected variables.
|
|
@@ -314,6 +275,8 @@ export type HandlerContext<
|
|
|
314
275
|
* For handles: Returns a push function to add data for this segment.
|
|
315
276
|
* Handle data accumulates across all matched route segments.
|
|
316
277
|
* Push accepts: direct value, Promise, or async callback (executed immediately).
|
|
278
|
+
* Or call `.defer()` to reserve the slot now and resolve it later (e.g. from a
|
|
279
|
+
* deep async component), with a timeout safety net — see {@link HandlePush}.
|
|
317
280
|
*
|
|
318
281
|
* @example
|
|
319
282
|
* ```typescript
|
|
@@ -347,6 +310,13 @@ export type HandlerContext<
|
|
|
347
310
|
* });
|
|
348
311
|
* return <ProductPage />;
|
|
349
312
|
* });
|
|
313
|
+
*
|
|
314
|
+
* // Handle usage - deferred (reserve the slot now, resolve from a deep component)
|
|
315
|
+
* route("product", (ctx) => {
|
|
316
|
+
* const resolve = ctx.use(Breadcrumbs).defer({ timeoutMs: 5000, else: null });
|
|
317
|
+
* loadCrumb(ctx.params.id).then(resolve); // resolver is push-equal
|
|
318
|
+
* return <ProductPage />; // auto-resolves to `else` on timeout
|
|
319
|
+
* });
|
|
350
320
|
* ```
|
|
351
321
|
*/
|
|
352
322
|
use: {
|
|
@@ -355,7 +325,7 @@ export type HandlerContext<
|
|
|
355
325
|
): Promise<T>;
|
|
356
326
|
<TData, TAccumulated = TData[]>(
|
|
357
327
|
handle: Handle<TData, TAccumulated>,
|
|
358
|
-
):
|
|
328
|
+
): HandlePush<TData>;
|
|
359
329
|
};
|
|
360
330
|
/**
|
|
361
331
|
* Current theme (from cookie or default).
|
|
@@ -462,6 +432,18 @@ export type InternalHandlerContext<
|
|
|
462
432
|
_responseType?: string;
|
|
463
433
|
/** Route name for cache key scoping (prevents cross-route collisions). */
|
|
464
434
|
_routeName?: string;
|
|
435
|
+
/**
|
|
436
|
+
* @internal Loader-cache override table: loaderId -> memoized data promise.
|
|
437
|
+
* A single stable ctx.use interceptor consults this instead of chaining one
|
|
438
|
+
* wrapper per cached loader (avoids O(N) dispatch). See loader-cache.ts.
|
|
439
|
+
*/
|
|
440
|
+
_loaderCacheOverrides?: Map<string, Promise<any>>;
|
|
441
|
+
/**
|
|
442
|
+
* @internal ctx.use captured before the loader-cache interceptor was installed.
|
|
443
|
+
* The cache-miss execute runs the loader through this, bypassing the override
|
|
444
|
+
* table (so a loader cannot await its own in-flight memoized promise).
|
|
445
|
+
*/
|
|
446
|
+
_loaderCacheOriginalUse?: (item: any) => any;
|
|
465
447
|
};
|
|
466
448
|
|
|
467
449
|
/**
|
|
@@ -503,13 +485,16 @@ export type RevalidateParams<TParams = GenericParams, TEnv = any> = Parameters<
|
|
|
503
485
|
* **Return Types:**
|
|
504
486
|
* - `boolean` - Hard decision: immediately returns this value (short-circuits)
|
|
505
487
|
* - `{ defaultShouldRevalidate: boolean }` - Soft decision: updates suggestion for next revalidator
|
|
488
|
+
* - `void` / `null` / `undefined` - Defer to the current suggestion (no opinion); the
|
|
489
|
+
* loop continues to the next revalidator without changing the running default
|
|
506
490
|
*
|
|
507
491
|
* **Execution Flow:**
|
|
508
492
|
* 1. Start with built-in `defaultShouldRevalidate` (true if params changed)
|
|
509
493
|
* 2. Execute global revalidators first, then route-specific
|
|
510
494
|
* 3. Hard decision (boolean): stop immediately and use that value
|
|
511
495
|
* 4. Soft decision (object): update suggestion and continue to next revalidator
|
|
512
|
-
* 5.
|
|
496
|
+
* 5. Defer (`void` / `null` / `undefined`): leave suggestion unchanged and continue
|
|
497
|
+
* 6. If no hard decision was returned: use the final running suggestion
|
|
513
498
|
*
|
|
514
499
|
* @param args.currentParams - Previous route params (generic by default, can be narrowed)
|
|
515
500
|
* @param args.currentUrl - Previous URL
|
|
@@ -519,9 +504,10 @@ export type RevalidateParams<TParams = GenericParams, TEnv = any> = Parameters<
|
|
|
519
504
|
* @param args.context - App context (db, user, etc.)
|
|
520
505
|
* @param args.actionResult - Result from action (future support)
|
|
521
506
|
* @param args.formData - Form data from action (future support)
|
|
522
|
-
* @param args.
|
|
507
|
+
* @param args.method - HTTP method: "GET" for navigation, "POST" for server actions
|
|
523
508
|
*
|
|
524
|
-
* @returns Hard decision (boolean)
|
|
509
|
+
* @returns Hard decision (boolean), soft suggestion (object), or defer
|
|
510
|
+
* (`void` / `null` / `undefined`) to keep the running suggestion as-is.
|
|
525
511
|
*
|
|
526
512
|
* @example
|
|
527
513
|
* ```typescript
|
|
@@ -541,20 +527,46 @@ export type RevalidateParams<TParams = GenericParams, TEnv = any> = Parameters<
|
|
|
541
527
|
* })
|
|
542
528
|
* ```
|
|
543
529
|
*/
|
|
530
|
+
/**
|
|
531
|
+
* A reference to a server action, used by `isAction()` in a revalidate predicate.
|
|
532
|
+
*
|
|
533
|
+
* Either a directly imported action (`import { addToCart }`) or a namespace
|
|
534
|
+
* import of an action module (`import * as CartActions`). Matching resolves the
|
|
535
|
+
* action's build-injected id (`path#export`) — the same identity the router uses
|
|
536
|
+
* for `actionId` — so a renamed or moved action breaks at compile time instead
|
|
537
|
+
* of silently failing to match.
|
|
538
|
+
*/
|
|
539
|
+
export type ActionRef =
|
|
540
|
+
| ((...args: never[]) => unknown)
|
|
541
|
+
| Record<string, unknown>;
|
|
542
|
+
|
|
544
543
|
/**
|
|
545
544
|
* Revalidation function called during client-side navigation to decide whether
|
|
546
545
|
* a segment (layout, route, parallel slot, or loader) should be re-rendered.
|
|
547
546
|
*
|
|
548
547
|
* Return `true` to re-render, `false` to skip (keep client's current version),
|
|
549
|
-
*
|
|
550
|
-
* downstream
|
|
548
|
+
* `{ defaultShouldRevalidate: boolean }` to update the running suggestion for
|
|
549
|
+
* downstream revalidators, or nothing (`void` / `null` / `undefined`) to defer
|
|
550
|
+
* to the current suggestion without changing it.
|
|
551
|
+
*
|
|
552
|
+
* Two idioms cover almost every case; they differ only in what an _unrelated_
|
|
553
|
+
* action does. Match actions by reference with `ctx.isAction()` (rename-safe)
|
|
554
|
+
* rather than `actionId?.includes("...")` (a renamed or moved action silently
|
|
555
|
+
* stops matching). Because `isAction` returns a raw boolean, combine it with
|
|
556
|
+
* `|| undefined` to defer or leave it bare to suppress.
|
|
551
557
|
*
|
|
552
558
|
* @example
|
|
553
559
|
* ```ts
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
560
|
+
* import * as CartActions from "./actions/cart";
|
|
561
|
+
*
|
|
562
|
+
* // Idiom A — "mine, else defer": re-render on my actions, otherwise return
|
|
563
|
+
* // undefined so the segment's default decision still applies (and downstream
|
|
564
|
+
* // revalidators get a say).
|
|
565
|
+
* revalidate((ctx) => ctx.isAction(CartActions) || undefined)
|
|
566
|
+
*
|
|
567
|
+
* // Idiom B — "mine only": re-render on my actions and suppress everything
|
|
568
|
+
* // else (isAction returns a raw boolean, so an unrelated action yields false).
|
|
569
|
+
* revalidate((ctx) => ctx.isAction(CartActions))
|
|
558
570
|
*
|
|
559
571
|
* // Always re-render when params change (default behavior made explicit)
|
|
560
572
|
* revalidate(({ defaultShouldRevalidate }) => defaultShouldRevalidate)
|
|
@@ -580,8 +592,11 @@ export type ShouldRevalidateFn<TParams = GenericParams, TEnv = any> = (args: {
|
|
|
580
592
|
|
|
581
593
|
// ── Segment metadata (which segment is being evaluated) ──────────────
|
|
582
594
|
|
|
583
|
-
/**
|
|
584
|
-
|
|
595
|
+
/**
|
|
596
|
+
* The type of segment being revalidated. `"loader"` is passed to revalidate
|
|
597
|
+
* functions attached to a `loader(Fn, () => [revalidate(...)])` registration.
|
|
598
|
+
*/
|
|
599
|
+
segmentType: "layout" | "route" | "parallel" | "loader";
|
|
585
600
|
/** Layout name (e.g., `"root"`, `"shop"`, `"auth"`). Only set for layout segments. */
|
|
586
601
|
layoutName?: string;
|
|
587
602
|
/** Slot name (e.g., `"@sidebar"`, `"@modal"`). Only set for parallel segments. */
|
|
@@ -597,21 +612,54 @@ export type ShouldRevalidateFn<TParams = GenericParams, TEnv = any> = (args: {
|
|
|
597
612
|
* relative to the project root, followed by `#` and the exported function name.
|
|
598
613
|
*
|
|
599
614
|
* This is stable and can be used for path-based matching to revalidate
|
|
600
|
-
* when any action in a module or directory fires
|
|
615
|
+
* when any action in a module or directory fires. Prefer `|| undefined`
|
|
616
|
+
* (defer to the segment default / downstream revalidators) over `?? false`
|
|
617
|
+
* (hard short-circuit that suppresses the default and ends the chain):
|
|
601
618
|
*
|
|
602
619
|
* @example
|
|
603
620
|
* ```ts
|
|
604
621
|
* // Match a specific action
|
|
605
|
-
* revalidate(({ actionId }) => actionId === "src/actions/cart.ts#addToCart")
|
|
622
|
+
* revalidate(({ actionId }) => actionId === "src/actions/cart.ts#addToCart" || undefined)
|
|
606
623
|
*
|
|
607
624
|
* // Match any action in the cart module
|
|
608
|
-
* revalidate(({ actionId }) => actionId?.includes("cart")
|
|
625
|
+
* revalidate(({ actionId }) => actionId?.includes("cart") || undefined)
|
|
609
626
|
*
|
|
610
627
|
* // Match any action under src/apps/store/actions/
|
|
611
|
-
* revalidate(({ actionId }) => actionId?.startsWith("src/apps/store/actions/")
|
|
628
|
+
* revalidate(({ actionId }) => actionId?.startsWith("src/apps/store/actions/") || undefined)
|
|
612
629
|
* ```
|
|
613
630
|
*/
|
|
614
631
|
actionId?: string;
|
|
632
|
+
/**
|
|
633
|
+
* Typed, rename-safe action matching. Returns `true` when the action that
|
|
634
|
+
* triggered this revalidation is one of the given references — or, for a
|
|
635
|
+
* namespace import (`import * as CartActions`), any export of that module —
|
|
636
|
+
* and `false` otherwise (including plain navigation with no action).
|
|
637
|
+
*
|
|
638
|
+
* Called with NO arguments it answers "is this request an action at all?":
|
|
639
|
+
* `true` for any action, `false` on plain navigation. Use the bare form when
|
|
640
|
+
* you want to revalidate on every action regardless of which one fired.
|
|
641
|
+
*
|
|
642
|
+
* Prefer this over hand-written `actionId` substring matches: it resolves the
|
|
643
|
+
* action's stable `path#export` id from the imported reference, so a rename is
|
|
644
|
+
* a type error in one place instead of silent drift across consumers. It
|
|
645
|
+
* resolves the reference the same way the action boundary derives `actionId`
|
|
646
|
+
* (`$id ?? $$id`), so it matches in both dev and production.
|
|
647
|
+
*
|
|
648
|
+
* Returns a raw boolean, so for the common "revalidate on match, else defer"
|
|
649
|
+
* intent combine with `|| undefined`:
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```ts
|
|
653
|
+
* import { addToCart, removeFromCart } from "./actions/cart";
|
|
654
|
+
* import * as CartActions from "./actions/cart";
|
|
655
|
+
*
|
|
656
|
+
* revalidate((ctx) => ctx.isAction() || undefined); // any action
|
|
657
|
+
* revalidate((ctx) => ctx.isAction(addToCart) || undefined); // one action
|
|
658
|
+
* revalidate((ctx) => ctx.isAction(addToCart, removeFromCart) || undefined); // several
|
|
659
|
+
* revalidate((ctx) => ctx.isAction(CartActions) || undefined); // any in the module
|
|
660
|
+
* ```
|
|
661
|
+
*/
|
|
662
|
+
isAction: (...actions: ActionRef[]) => boolean;
|
|
615
663
|
/** URL where the action was executed (the page the user was on when they triggered the action). */
|
|
616
664
|
actionUrl?: URL;
|
|
617
665
|
/** Return value from the action execution. Can be used to conditionally revalidate based on the action's outcome. */
|
|
@@ -647,7 +695,7 @@ export type ShouldRevalidateFn<TParams = GenericParams, TEnv = any> = (args: {
|
|
|
647
695
|
* action that may have mutated backend state.
|
|
648
696
|
*/
|
|
649
697
|
stale?: boolean;
|
|
650
|
-
}) => boolean | { defaultShouldRevalidate: boolean };
|
|
698
|
+
}) => boolean | { defaultShouldRevalidate: boolean } | null | void;
|
|
651
699
|
|
|
652
700
|
// MiddlewareFn is imported from "../router/middleware.js" and re-exported
|
|
653
701
|
|
|
@@ -752,7 +800,7 @@ export type Revalidate<
|
|
|
752
800
|
* Middleware function with typed params and environment
|
|
753
801
|
*
|
|
754
802
|
* @template TParams - Params object (defaults to generic)
|
|
755
|
-
* @template TEnv - Environment type (defaults to global
|
|
803
|
+
* @template TEnv - Environment type (defaults to global Rango.Env)
|
|
756
804
|
*
|
|
757
805
|
* Note: Middleware cannot directly use route names for params typing because
|
|
758
806
|
* middleware is defined during router setup, before RegisteredRoutes is populated.
|
|
@@ -760,7 +808,7 @@ export type Revalidate<
|
|
|
760
808
|
*
|
|
761
809
|
* @example
|
|
762
810
|
* ```typescript
|
|
763
|
-
* // Basic middleware (uses global
|
|
811
|
+
* // Basic middleware (uses global Rango.Env via module augmentation)
|
|
764
812
|
* const middleware: Middleware = async (ctx, next) => {
|
|
765
813
|
* ctx.set("user", { id: "123" }); // Type-safe!
|
|
766
814
|
* await next();
|