@rangojs/router 0.4.0 → 0.4.1
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/README.md +19 -1
- package/dist/types/browser/event-controller.d.ts +4 -0
- package/dist/types/browser/link-interceptor.d.ts +17 -7
- package/dist/types/browser/navigation-bridge.d.ts +13 -1
- package/dist/types/browser/notify-listeners.d.ts +2 -0
- package/dist/types/browser/prefetch/cache.d.ts +1 -1
- package/dist/types/browser/prefetch/default-strategy.d.ts +12 -3
- package/dist/types/browser/prefetch/invalidation.d.ts +6 -0
- package/dist/types/browser/prefetch/loader.d.ts +3 -1
- package/dist/types/browser/prefetch/observer.d.ts +3 -6
- package/dist/types/browser/rango-state.d.ts +4 -0
- package/dist/types/browser/react/Link.d.ts +4 -9
- package/dist/types/browser/react/context.d.ts +3 -0
- package/dist/types/browser/rsc-router.d.ts +7 -2
- package/dist/types/browser/types.d.ts +1 -0
- package/dist/types/cache/cache-key-utils.d.ts +11 -3
- package/dist/types/cache/cache-scope.d.ts +82 -3
- package/dist/types/cache/cf/cf-cache-store.d.ts +2 -2
- package/dist/types/cache/index.d.ts +3 -1
- package/dist/types/cache/search-params-filter.d.ts +64 -0
- package/dist/types/cache/shell-snapshot.d.ts +4 -4
- package/dist/types/cache/types.d.ts +30 -2
- package/dist/types/cache/vercel/vercel-cache-store.d.ts +2 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.rsc.d.ts +1 -0
- package/dist/types/router/match-middleware/cache-lookup.d.ts +13 -0
- package/dist/types/router/navigation-snapshot.d.ts +29 -0
- package/dist/types/router/router-options.d.ts +27 -3
- package/dist/types/rsc/shell-build-manifest.d.ts +7 -1
- package/dist/types/rsc/shell-serve.d.ts +7 -1
- package/dist/types/rsc/types.d.ts +17 -0
- package/dist/types/server/request-context.d.ts +57 -4
- package/dist/types/testing/render-route.d.ts +10 -1
- package/dist/types/testing/shell-status.d.ts +6 -3
- package/dist/types/vite/plugin-types.d.ts +1 -1
- package/dist/vite/index.js +5 -5
- package/package.json +23 -22
- package/skills/caching/SKILL.md +39 -0
- package/skills/comparison/references/framework-comparison.md +7 -1
- package/skills/links/SKILL.md +24 -0
- package/skills/ppr/SKILL.md +53 -4
- package/skills/router-setup/SKILL.md +7 -2
- package/skills/testing/client-components.md +15 -14
- package/skills/vercel/SKILL.md +1 -1
- package/src/browser/event-controller.ts +110 -11
- package/src/browser/link-interceptor.ts +469 -20
- package/src/browser/navigation-bridge.ts +71 -2
- package/src/browser/navigation-store.ts +24 -1
- package/src/browser/notify-listeners.ts +22 -0
- package/src/browser/prefetch/cache.ts +4 -2
- package/src/browser/prefetch/default-strategy.ts +43 -3
- package/src/browser/prefetch/invalidation.ts +30 -0
- package/src/browser/prefetch/loader.ts +19 -12
- package/src/browser/prefetch/observer.ts +50 -22
- package/src/browser/rango-state.ts +21 -0
- package/src/browser/react/Link.tsx +97 -88
- package/src/browser/react/NavigationProvider.tsx +1 -0
- package/src/browser/react/context.ts +4 -0
- package/src/browser/rsc-router.tsx +22 -9
- package/src/browser/types.ts +1 -0
- package/src/cache/cache-key-utils.ts +18 -4
- package/src/cache/cache-runtime.ts +7 -2
- package/src/cache/cache-scope.ts +152 -23
- package/src/cache/cf/cf-cache-store.ts +51 -16
- package/src/cache/document-cache.ts +7 -1
- package/src/cache/index.ts +7 -0
- package/src/cache/search-params-filter.ts +118 -0
- package/src/cache/shell-snapshot.ts +8 -4
- package/src/cache/types.ts +33 -2
- package/src/cache/vercel/vercel-cache-store.ts +17 -3
- package/src/index.rsc.ts +4 -0
- package/src/index.ts +6 -0
- package/src/router/match-middleware/cache-lookup.ts +146 -33
- package/src/router/match-middleware/cache-store.ts +70 -0
- package/src/router/navigation-snapshot.ts +46 -6
- package/src/router/router-options.ts +31 -4
- package/src/rsc/handler.ts +9 -0
- package/src/rsc/response-cache-serve.ts +1 -1
- package/src/rsc/rsc-rendering.ts +252 -27
- package/src/rsc/shell-build-manifest.ts +8 -1
- package/src/rsc/shell-capture.ts +5 -0
- package/src/rsc/shell-serve.ts +8 -2
- package/src/rsc/types.ts +17 -0
- package/src/server/request-context.ts +62 -3
- package/src/testing/dispatch.ts +21 -3
- package/src/testing/render-route.tsx +86 -17
- package/src/testing/shell-status.ts +20 -3
- package/src/vite/plugin-types.ts +1 -1
- package/src/vite/plugins/vercel-output.ts +2 -2
- package/dist/types.backup/__internal.d.ts +0 -127
- package/dist/types.backup/bin/rango.d.ts +0 -1
- package/dist/types.backup/browser/action-coordinator.d.ts +0 -57
- package/dist/types.backup/browser/action-fence.d.ts +0 -33
- package/dist/types.backup/browser/app-shell.d.ts +0 -34
- package/dist/types.backup/browser/app-version.d.ts +0 -6
- package/dist/types.backup/browser/connection-warmup.d.ts +0 -31
- package/dist/types.backup/browser/cookie-name.d.ts +0 -66
- package/dist/types.backup/browser/event-controller.d.ts +0 -221
- package/dist/types.backup/browser/history-state.d.ts +0 -26
- package/dist/types.backup/browser/index.d.ts +0 -1
- package/dist/types.backup/browser/intercept-utils.d.ts +0 -30
- package/dist/types.backup/browser/invalidate-client-cache.d.ts +0 -17
- package/dist/types.backup/browser/link-interceptor.d.ts +0 -43
- package/dist/types.backup/browser/logging.d.ts +0 -33
- package/dist/types.backup/browser/merge-segment-loaders.d.ts +0 -38
- package/dist/types.backup/browser/navigation-bridge.d.ts +0 -27
- package/dist/types.backup/browser/navigation-client.d.ts +0 -17
- package/dist/types.backup/browser/navigation-store-handle.d.ts +0 -25
- package/dist/types.backup/browser/navigation-store.d.ts +0 -95
- package/dist/types.backup/browser/navigation-transaction.d.ts +0 -75
- package/dist/types.backup/browser/network-error-handler.d.ts +0 -35
- package/dist/types.backup/browser/partial-update.d.ts +0 -61
- package/dist/types.backup/browser/prefetch/cache.d.ts +0 -183
- package/dist/types.backup/browser/prefetch/fetch.d.ts +0 -52
- package/dist/types.backup/browser/prefetch/observer.d.ts +0 -27
- package/dist/types.backup/browser/prefetch/policy.d.ts +0 -13
- package/dist/types.backup/browser/prefetch/queue.d.ts +0 -48
- package/dist/types.backup/browser/prefetch/resource-ready.d.ts +0 -28
- package/dist/types.backup/browser/rango-state.d.ts +0 -52
- package/dist/types.backup/browser/react/Link.d.ts +0 -140
- package/dist/types.backup/browser/react/NavigationProvider.d.ts +0 -88
- package/dist/types.backup/browser/react/ScrollRestoration.d.ts +0 -78
- package/dist/types.backup/browser/react/context.d.ts +0 -54
- package/dist/types.backup/browser/react/filter-segment-order.d.ts +0 -35
- package/dist/types.backup/browser/react/index.d.ts +0 -1
- package/dist/types.backup/browser/react/location-state-shared.d.ts +0 -162
- package/dist/types.backup/browser/react/location-state.d.ts +0 -29
- package/dist/types.backup/browser/react/mount-context.d.ts +0 -23
- package/dist/types.backup/browser/react/nonce-context.d.ts +0 -14
- package/dist/types.backup/browser/react/shallow-equal.d.ts +0 -5
- package/dist/types.backup/browser/react/use-action.d.ts +0 -61
- package/dist/types.backup/browser/react/use-handle.d.ts +0 -21
- package/dist/types.backup/browser/react/use-href.d.ts +0 -32
- package/dist/types.backup/browser/react/use-link-status.d.ts +0 -36
- package/dist/types.backup/browser/react/use-mount.d.ts +0 -24
- package/dist/types.backup/browser/react/use-navigation.d.ts +0 -15
- package/dist/types.backup/browser/react/use-params.d.ts +0 -21
- package/dist/types.backup/browser/react/use-pathname.d.ts +0 -13
- package/dist/types.backup/browser/react/use-reverse.d.ts +0 -40
- package/dist/types.backup/browser/react/use-router.d.ts +0 -23
- package/dist/types.backup/browser/react/use-search-params.d.ts +0 -19
- package/dist/types.backup/browser/react/use-segments.d.ts +0 -29
- package/dist/types.backup/browser/response-adapter.d.ts +0 -58
- package/dist/types.backup/browser/rsc-router.d.ts +0 -141
- package/dist/types.backup/browser/scroll-restoration.d.ts +0 -103
- package/dist/types.backup/browser/segment-reconciler.d.ts +0 -74
- package/dist/types.backup/browser/segment-structure-assert.d.ts +0 -16
- package/dist/types.backup/browser/server-action-bridge.d.ts +0 -29
- package/dist/types.backup/browser/types.d.ts +0 -530
- package/dist/types.backup/browser/validate-redirect-origin.d.ts +0 -28
- package/dist/types.backup/build/collect-fallback-refs.d.ts +0 -5
- package/dist/types.backup/build/generate-manifest.d.ts +0 -100
- package/dist/types.backup/build/generate-route-types.d.ts +0 -8
- package/dist/types.backup/build/index.d.ts +0 -21
- package/dist/types.backup/build/prefix-tree-utils.d.ts +0 -56
- package/dist/types.backup/build/route-trie.d.ts +0 -89
- package/dist/types.backup/build/route-types/ast-helpers.d.ts +0 -3
- package/dist/types.backup/build/route-types/ast-route-extraction.d.ts +0 -13
- package/dist/types.backup/build/route-types/codegen.d.ts +0 -16
- package/dist/types.backup/build/route-types/include-resolution.d.ts +0 -74
- package/dist/types.backup/build/route-types/param-extraction.d.ts +0 -13
- package/dist/types.backup/build/route-types/per-module-writer.d.ts +0 -18
- package/dist/types.backup/build/route-types/router-processing.d.ts +0 -82
- package/dist/types.backup/build/route-types/scan-filter.d.ts +0 -17
- package/dist/types.backup/build/route-types/source-scan.d.ts +0 -13
- package/dist/types.backup/build/runtime-discovery.d.ts +0 -24
- package/dist/types.backup/cache/background-task.d.ts +0 -21
- package/dist/types.backup/cache/cache-error.d.ts +0 -71
- package/dist/types.backup/cache/cache-key-utils.d.ts +0 -35
- package/dist/types.backup/cache/cache-policy.d.ts +0 -59
- package/dist/types.backup/cache/cache-runtime.d.ts +0 -51
- package/dist/types.backup/cache/cache-scope.d.ts +0 -134
- package/dist/types.backup/cache/cache-tag.d.ts +0 -79
- package/dist/types.backup/cache/cf/cf-base64.d.ts +0 -4
- package/dist/types.backup/cache/cf/cf-cache-constants.d.ts +0 -105
- package/dist/types.backup/cache/cf/cf-cache-store.d.ts +0 -481
- package/dist/types.backup/cache/cf/cf-cache-types.d.ts +0 -300
- package/dist/types.backup/cache/cf/cf-kv-utils.d.ts +0 -22
- package/dist/types.backup/cache/cf/cf-tag-marker-memo.d.ts +0 -15
- package/dist/types.backup/cache/cf/index.d.ts +0 -3
- package/dist/types.backup/cache/document-cache.d.ts +0 -69
- package/dist/types.backup/cache/handle-capture.d.ts +0 -23
- package/dist/types.backup/cache/handle-snapshot.d.ts +0 -39
- package/dist/types.backup/cache/index.d.ts +0 -7
- package/dist/types.backup/cache/memory-segment-store.d.ts +0 -163
- package/dist/types.backup/cache/profile-registry.d.ts +0 -40
- package/dist/types.backup/cache/read-through-swr.d.ts +0 -60
- package/dist/types.backup/cache/segment-codec.d.ts +0 -78
- package/dist/types.backup/cache/shell-snapshot.d.ts +0 -162
- package/dist/types.backup/cache/tag-invalidation.d.ts +0 -74
- package/dist/types.backup/cache/taint.d.ts +0 -71
- package/dist/types.backup/cache/types.d.ts +0 -407
- package/dist/types.backup/cache/vercel/index.d.ts +0 -1
- package/dist/types.backup/cache/vercel/vercel-cache-store.d.ts +0 -267
- package/dist/types.backup/client.d.ts +0 -184
- package/dist/types.backup/client.rsc.d.ts +0 -39
- package/dist/types.backup/cloudflare/index.d.ts +0 -7
- package/dist/types.backup/cloudflare/tracing.d.ts +0 -53
- package/dist/types.backup/component-utils.d.ts +0 -46
- package/dist/types.backup/components/DefaultDocument.d.ts +0 -13
- package/dist/types.backup/context-var.d.ts +0 -84
- package/dist/types.backup/debug.d.ts +0 -57
- package/dist/types.backup/decode-loader-results.d.ts +0 -5
- package/dist/types.backup/default-error-boundary.d.ts +0 -10
- package/dist/types.backup/defer.d.ts +0 -89
- package/dist/types.backup/deps/browser.d.ts +0 -1
- package/dist/types.backup/deps/html-stream-client.d.ts +0 -1
- package/dist/types.backup/deps/html-stream-server.d.ts +0 -1
- package/dist/types.backup/deps/rsc.d.ts +0 -1
- package/dist/types.backup/deps/ssr.d.ts +0 -1
- package/dist/types.backup/encode-kv.d.ts +0 -35
- package/dist/types.backup/errors.d.ts +0 -226
- package/dist/types.backup/escape-script.d.ts +0 -44
- package/dist/types.backup/handle.d.ts +0 -93
- package/dist/types.backup/handles/MetaTags.d.ts +0 -17
- package/dist/types.backup/handles/Scripts.d.ts +0 -38
- package/dist/types.backup/handles/breadcrumbs.d.ts +0 -43
- package/dist/types.backup/handles/deferred-resolution.d.ts +0 -53
- package/dist/types.backup/handles/is-thenable.d.ts +0 -12
- package/dist/types.backup/handles/meta.d.ts +0 -43
- package/dist/types.backup/handles/script.d.ts +0 -139
- package/dist/types.backup/host/cookie-handler.d.ts +0 -8
- package/dist/types.backup/host/errors.d.ts +0 -40
- package/dist/types.backup/host/index.d.ts +0 -33
- package/dist/types.backup/host/pattern-matcher.d.ts +0 -30
- package/dist/types.backup/host/router.d.ts +0 -12
- package/dist/types.backup/host/testing.d.ts +0 -41
- package/dist/types.backup/host/types.d.ts +0 -148
- package/dist/types.backup/host/utils.d.ts +0 -20
- package/dist/types.backup/href-client.d.ts +0 -214
- package/dist/types.backup/index.d.ts +0 -112
- package/dist/types.backup/index.rsc.d.ts +0 -51
- package/dist/types.backup/internal-debug.d.ts +0 -1
- package/dist/types.backup/loader-store.d.ts +0 -193
- package/dist/types.backup/loader.d.ts +0 -18
- package/dist/types.backup/loader.rsc.d.ts +0 -18
- package/dist/types.backup/missing-id-error.d.ts +0 -1
- package/dist/types.backup/outlet-context.d.ts +0 -12
- package/dist/types.backup/outlet-provider.d.ts +0 -12
- package/dist/types.backup/prerender/build-shell-capture.d.ts +0 -104
- package/dist/types.backup/prerender/param-hash.d.ts +0 -6
- package/dist/types.backup/prerender/shell-manifest-key.d.ts +0 -18
- package/dist/types.backup/prerender/store.d.ts +0 -62
- package/dist/types.backup/prerender.d.ts +0 -292
- package/dist/types.backup/redirect-origin.d.ts +0 -55
- package/dist/types.backup/regex-escape.d.ts +0 -6
- package/dist/types.backup/render-error-thrower.d.ts +0 -13
- package/dist/types.backup/response-utils.d.ts +0 -35
- package/dist/types.backup/reverse.d.ts +0 -206
- package/dist/types.backup/root-error-boundary.d.ts +0 -32
- package/dist/types.backup/route-content-wrapper.d.ts +0 -40
- package/dist/types.backup/route-definition/dsl-helpers.d.ts +0 -130
- package/dist/types.backup/route-definition/helper-factories.d.ts +0 -22
- package/dist/types.backup/route-definition/helpers-types.d.ts +0 -392
- package/dist/types.backup/route-definition/index.d.ts +0 -7
- package/dist/types.backup/route-definition/redirect.d.ts +0 -48
- package/dist/types.backup/route-definition/resolve-handler-use.d.ts +0 -19
- package/dist/types.backup/route-definition/use-item-types.d.ts +0 -1
- package/dist/types.backup/route-definition.d.ts +0 -1
- package/dist/types.backup/route-map-builder.d.ts +0 -127
- package/dist/types.backup/route-name.d.ts +0 -27
- package/dist/types.backup/route-types.d.ts +0 -172
- package/dist/types.backup/router/basename.d.ts +0 -10
- package/dist/types.backup/router/content-negotiation.d.ts +0 -91
- package/dist/types.backup/router/debug-manifest.d.ts +0 -7
- package/dist/types.backup/router/error-handling.d.ts +0 -76
- package/dist/types.backup/router/find-match.d.ts +0 -19
- package/dist/types.backup/router/handler-context.d.ts +0 -41
- package/dist/types.backup/router/instrument.d.ts +0 -161
- package/dist/types.backup/router/intercept-resolution.d.ts +0 -79
- package/dist/types.backup/router/lazy-includes.d.ts +0 -26
- package/dist/types.backup/router/loader-resolution.d.ts +0 -63
- package/dist/types.backup/router/logging.d.ts +0 -41
- package/dist/types.backup/router/manifest.d.ts +0 -8
- package/dist/types.backup/router/match-api.d.ts +0 -19
- package/dist/types.backup/router/match-context.d.ts +0 -184
- package/dist/types.backup/router/match-handlers.d.ts +0 -49
- package/dist/types.backup/router/match-middleware/background-revalidation.d.ts +0 -113
- package/dist/types.backup/router/match-middleware/cache-lookup.d.ts +0 -113
- package/dist/types.backup/router/match-middleware/cache-store.d.ts +0 -112
- package/dist/types.backup/router/match-middleware/index.d.ts +0 -80
- package/dist/types.backup/router/match-middleware/intercept-resolution.d.ts +0 -116
- package/dist/types.backup/router/match-middleware/segment-resolution.d.ts +0 -94
- package/dist/types.backup/router/match-pipelines.d.ts +0 -103
- package/dist/types.backup/router/match-result.d.ts +0 -114
- package/dist/types.backup/router/metrics.d.ts +0 -6
- package/dist/types.backup/router/middleware-types.d.ts +0 -74
- package/dist/types.backup/router/middleware.d.ts +0 -116
- package/dist/types.backup/router/navigation-snapshot.d.ts +0 -22
- package/dist/types.backup/router/params-util.d.ts +0 -8
- package/dist/types.backup/router/parse-pattern.d.ts +0 -38
- package/dist/types.backup/router/pattern-matching.d.ts +0 -169
- package/dist/types.backup/router/prefetch-cache-ttl.d.ts +0 -27
- package/dist/types.backup/router/prefetch-limits.d.ts +0 -20
- package/dist/types.backup/router/prerender-match.d.ts +0 -50
- package/dist/types.backup/router/preview-match.d.ts +0 -22
- package/dist/types.backup/router/request-classification.d.ts +0 -104
- package/dist/types.backup/router/revalidation.d.ts +0 -57
- package/dist/types.backup/router/route-snapshot.d.ts +0 -112
- package/dist/types.backup/router/router-context.d.ts +0 -137
- package/dist/types.backup/router/router-interfaces.d.ts +0 -432
- package/dist/types.backup/router/router-options.d.ts +0 -738
- package/dist/types.backup/router/router-registry.d.ts +0 -15
- package/dist/types.backup/router/segment-resolution/fresh.d.ts +0 -55
- package/dist/types.backup/router/segment-resolution/helpers.d.ts +0 -93
- package/dist/types.backup/router/segment-resolution/loader-cache.d.ts +0 -33
- package/dist/types.backup/router/segment-resolution/loader-mask.d.ts +0 -44
- package/dist/types.backup/router/segment-resolution/loader-snapshot.d.ts +0 -90
- package/dist/types.backup/router/segment-resolution/mask-nested.d.ts +0 -53
- package/dist/types.backup/router/segment-resolution/revalidation.d.ts +0 -85
- package/dist/types.backup/router/segment-resolution/static-store.d.ts +0 -17
- package/dist/types.backup/router/segment-resolution/streamed-handler-telemetry.d.ts +0 -16
- package/dist/types.backup/router/segment-resolution/view-transition-default.d.ts +0 -28
- package/dist/types.backup/router/segment-resolution.d.ts +0 -3
- package/dist/types.backup/router/segment-wrappers.d.ts +0 -53
- package/dist/types.backup/router/state-cookie-name.d.ts +0 -1
- package/dist/types.backup/router/substitute-pattern-params.d.ts +0 -23
- package/dist/types.backup/router/telemetry-otel.d.ts +0 -113
- package/dist/types.backup/router/telemetry.d.ts +0 -215
- package/dist/types.backup/router/timeout.d.ts +0 -68
- package/dist/types.backup/router/tracing.d.ts +0 -125
- package/dist/types.backup/router/trie-matching.d.ts +0 -32
- package/dist/types.backup/router/types.d.ts +0 -98
- package/dist/types.backup/router/url-params.d.ts +0 -26
- package/dist/types.backup/router.d.ts +0 -7
- package/dist/types.backup/rsc/capture-queue.d.ts +0 -6
- package/dist/types.backup/rsc/full-payload.d.ts +0 -22
- package/dist/types.backup/rsc/handler-context.d.ts +0 -31
- package/dist/types.backup/rsc/handler.d.ts +0 -9
- package/dist/types.backup/rsc/helpers.d.ts +0 -213
- package/dist/types.backup/rsc/index.d.ts +0 -17
- package/dist/types.backup/rsc/json-route-result.d.ts +0 -20
- package/dist/types.backup/rsc/loader-fetch.d.ts +0 -14
- package/dist/types.backup/rsc/manifest-init.d.ts +0 -18
- package/dist/types.backup/rsc/nonce.d.ts +0 -28
- package/dist/types.backup/rsc/origin-guard.d.ts +0 -50
- package/dist/types.backup/rsc/progressive-enhancement.d.ts +0 -19
- package/dist/types.backup/rsc/redirect-guard.d.ts +0 -35
- package/dist/types.backup/rsc/response-cache-serve.d.ts +0 -46
- package/dist/types.backup/rsc/response-error.d.ts +0 -19
- package/dist/types.backup/rsc/response-route-handler.d.ts +0 -29
- package/dist/types.backup/rsc/rsc-rendering.d.ts +0 -23
- package/dist/types.backup/rsc/runtime-warnings.d.ts +0 -22
- package/dist/types.backup/rsc/server-action.d.ts +0 -68
- package/dist/types.backup/rsc/shell-build-manifest.d.ts +0 -84
- package/dist/types.backup/rsc/shell-capture-constants.d.ts +0 -27
- package/dist/types.backup/rsc/shell-capture.d.ts +0 -374
- package/dist/types.backup/rsc/shell-serve.d.ts +0 -136
- package/dist/types.backup/rsc/ssr-setup.d.ts +0 -48
- package/dist/types.backup/rsc/transition-gate.d.ts +0 -27
- package/dist/types.backup/rsc/types.d.ts +0 -290
- package/dist/types.backup/runtime-env.d.ts +0 -1
- package/dist/types.backup/search-params.d.ts +0 -125
- package/dist/types.backup/segment-content-promise.d.ts +0 -13
- package/dist/types.backup/segment-fragments.d.ts +0 -56
- package/dist/types.backup/segment-loader-promise.d.ts +0 -22
- package/dist/types.backup/segment-system.d.ts +0 -84
- package/dist/types.backup/serialize.d.ts +0 -164
- package/dist/types.backup/server/context.d.ts +0 -494
- package/dist/types.backup/server/cookie-parse.d.ts +0 -10
- package/dist/types.backup/server/cookie-store.d.ts +0 -107
- package/dist/types.backup/server/fetchable-loader-store.d.ts +0 -20
- package/dist/types.backup/server/handle-store.d.ts +0 -100
- package/dist/types.backup/server/loader-registry.d.ts +0 -32
- package/dist/types.backup/server/request-context.d.ts +0 -596
- package/dist/types.backup/server/root-layout.d.ts +0 -3
- package/dist/types.backup/server.d.ts +0 -15
- package/dist/types.backup/ssr/index.d.ts +0 -233
- package/dist/types.backup/ssr/inject-rsc-eager.d.ts +0 -3
- package/dist/types.backup/ssr/preinit-client-references.d.ts +0 -71
- package/dist/types.backup/ssr/ssr-root.d.ts +0 -69
- package/dist/types.backup/static-handler.d.ts +0 -57
- package/dist/types.backup/testing/cache-status.d.ts +0 -63
- package/dist/types.backup/testing/collect-handle.d.ts +0 -20
- package/dist/types.backup/testing/dispatch.d.ts +0 -123
- package/dist/types.backup/testing/dom.entry.d.ts +0 -15
- package/dist/types.backup/testing/e2e/fixture.d.ts +0 -37
- package/dist/types.backup/testing/e2e/index.d.ts +0 -30
- package/dist/types.backup/testing/e2e/matchers.d.ts +0 -17
- package/dist/types.backup/testing/e2e/page-helpers.d.ts +0 -62
- package/dist/types.backup/testing/e2e/parity.d.ts +0 -111
- package/dist/types.backup/testing/e2e/server.d.ts +0 -35
- package/dist/types.backup/testing/flight-matchers.d.ts +0 -55
- package/dist/types.backup/testing/flight-normalize.d.ts +0 -1
- package/dist/types.backup/testing/flight-tree.d.ts +0 -192
- package/dist/types.backup/testing/flight.d.ts +0 -115
- package/dist/types.backup/testing/flight.entry.d.ts +0 -27
- package/dist/types.backup/testing/generated-routes.d.ts +0 -66
- package/dist/types.backup/testing/index.d.ts +0 -52
- package/dist/types.backup/testing/internal/context.d.ts +0 -225
- package/dist/types.backup/testing/internal/flight-client-globals.d.ts +0 -1
- package/dist/types.backup/testing/internal/seed-vars.d.ts +0 -30
- package/dist/types.backup/testing/render-handler.d.ts +0 -160
- package/dist/types.backup/testing/render-route.d.ts +0 -246
- package/dist/types.backup/testing/run-loader.d.ts +0 -186
- package/dist/types.backup/testing/run-middleware.d.ts +0 -132
- package/dist/types.backup/testing/run-transition-when.d.ts +0 -77
- package/dist/types.backup/testing/vitest-stubs/cloudflare-email.d.ts +0 -6
- package/dist/types.backup/testing/vitest-stubs/cloudflare-workers.d.ts +0 -13
- package/dist/types.backup/testing/vitest-stubs/plugin-rsc.d.ts +0 -7
- package/dist/types.backup/testing/vitest-stubs/version.d.ts +0 -1
- package/dist/types.backup/testing/vitest.d.ts +0 -205
- package/dist/types.backup/theme/ThemeProvider.d.ts +0 -13
- package/dist/types.backup/theme/ThemeScript.d.ts +0 -45
- package/dist/types.backup/theme/constants.d.ts +0 -39
- package/dist/types.backup/theme/index.d.ts +0 -29
- package/dist/types.backup/theme/theme-context.d.ts +0 -21
- package/dist/types.backup/theme/theme-script.d.ts +0 -26
- package/dist/types.backup/theme/types.d.ts +0 -162
- package/dist/types.backup/theme/use-theme.d.ts +0 -8
- package/dist/types.backup/types/boundaries.d.ts +0 -93
- package/dist/types.backup/types/cache-types.d.ts +0 -191
- package/dist/types.backup/types/error-types.d.ts +0 -114
- package/dist/types.backup/types/global-namespace.d.ts +0 -90
- package/dist/types.backup/types/handler-context.d.ts +0 -658
- package/dist/types.backup/types/index.d.ts +0 -11
- package/dist/types.backup/types/loader-types.d.ts +0 -182
- package/dist/types.backup/types/request-scope.d.ts +0 -93
- package/dist/types.backup/types/route-config.d.ts +0 -105
- package/dist/types.backup/types/route-entry.d.ts +0 -95
- package/dist/types.backup/types/segments.d.ts +0 -234
- package/dist/types.backup/types.d.ts +0 -1
- package/dist/types.backup/urls/include-helper.d.ts +0 -17
- package/dist/types.backup/urls/include-provider.d.ts +0 -27
- package/dist/types.backup/urls/index.d.ts +0 -6
- package/dist/types.backup/urls/path-helper-types.d.ts +0 -197
- package/dist/types.backup/urls/path-helper.d.ts +0 -12
- package/dist/types.backup/urls/pattern-types.d.ts +0 -166
- package/dist/types.backup/urls/response-types.d.ts +0 -67
- package/dist/types.backup/urls/type-extraction.d.ts +0 -157
- package/dist/types.backup/urls/urls-function.d.ts +0 -24
- package/dist/types.backup/urls.d.ts +0 -1
- package/dist/types.backup/use-loader.d.ts +0 -150
- package/dist/types.backup/vercel/index.d.ts +0 -10
- package/dist/types.backup/vercel/tracing.d.ts +0 -70
- package/dist/types.backup/vite/debug.d.ts +0 -80
- package/dist/types.backup/vite/discovery/bundle-postprocess.d.ts +0 -12
- package/dist/types.backup/vite/discovery/dev-prerender-cache.d.ts +0 -65
- package/dist/types.backup/vite/discovery/discover-routers.d.ts +0 -17
- package/dist/types.backup/vite/discovery/discovery-errors.d.ts +0 -113
- package/dist/types.backup/vite/discovery/gate-state.d.ts +0 -79
- package/dist/types.backup/vite/discovery/prerender-collection.d.ts +0 -24
- package/dist/types.backup/vite/discovery/route-types-writer.d.ts +0 -32
- package/dist/types.backup/vite/discovery/self-gen-tracking.d.ts +0 -22
- package/dist/types.backup/vite/discovery/shell-prerender-phase.d.ts +0 -40
- package/dist/types.backup/vite/discovery/state.d.ts +0 -162
- package/dist/types.backup/vite/discovery/virtual-module-codegen.d.ts +0 -15
- package/dist/types.backup/vite/index.d.ts +0 -11
- package/dist/types.backup/vite/inject-client-debug.d.ts +0 -56
- package/dist/types.backup/vite/plugin-types.d.ts +0 -298
- package/dist/types.backup/vite/plugins/cjs-to-esm.d.ts +0 -6
- package/dist/types.backup/vite/plugins/client-ref-dedup.d.ts +0 -40
- package/dist/types.backup/vite/plugins/client-ref-hashing.d.ts +0 -35
- package/dist/types.backup/vite/plugins/cloudflare-protocol-stub.d.ts +0 -64
- package/dist/types.backup/vite/plugins/expose-action-id.d.ts +0 -18
- package/dist/types.backup/vite/plugins/expose-id-utils.d.ts +0 -37
- package/dist/types.backup/vite/plugins/expose-ids/export-analysis.d.ts +0 -19
- package/dist/types.backup/vite/plugins/expose-ids/handler-transform.d.ts +0 -10
- package/dist/types.backup/vite/plugins/expose-ids/loader-transform.d.ts +0 -8
- package/dist/types.backup/vite/plugins/expose-ids/router-transform.d.ts +0 -13
- package/dist/types.backup/vite/plugins/expose-ids/types.d.ts +0 -29
- package/dist/types.backup/vite/plugins/expose-internal-ids.d.ts +0 -6
- package/dist/types.backup/vite/plugins/performance-tracks.d.ts +0 -25
- package/dist/types.backup/vite/plugins/refresh-cmd.d.ts +0 -20
- package/dist/types.backup/vite/plugins/use-cache-transform.d.ts +0 -20
- package/dist/types.backup/vite/plugins/vercel-output.d.ts +0 -85
- package/dist/types.backup/vite/plugins/version-injector.d.ts +0 -21
- package/dist/types.backup/vite/plugins/version-plugin.d.ts +0 -19
- package/dist/types.backup/vite/plugins/virtual-entries.d.ts +0 -36
- package/dist/types.backup/vite/plugins/virtual-stub-plugin.d.ts +0 -7
- package/dist/types.backup/vite/rango.d.ts +0 -29
- package/dist/types.backup/vite/router-discovery.d.ts +0 -23
- package/dist/types.backup/vite/utils/ast-handler-extract.d.ts +0 -64
- package/dist/types.backup/vite/utils/banner.d.ts +0 -2
- package/dist/types.backup/vite/utils/bundle-analysis.d.ts +0 -28
- package/dist/types.backup/vite/utils/client-chunks.d.ts +0 -55
- package/dist/types.backup/vite/utils/directive-prologue.d.ts +0 -16
- package/dist/types.backup/vite/utils/forward-user-plugins.d.ts +0 -37
- package/dist/types.backup/vite/utils/manifest-utils.d.ts +0 -7
- package/dist/types.backup/vite/utils/package-resolution.d.ts +0 -6
- package/dist/types.backup/vite/utils/prerender-utils.d.ts +0 -32
- package/dist/types.backup/vite/utils/shared-utils.d.ts +0 -55
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Notify every active listener and surface every callback failure. */
|
|
2
|
+
export function notifyListeners<T>(
|
|
3
|
+
entries: Iterable<T>,
|
|
4
|
+
notify: (entry: T) => void,
|
|
5
|
+
isActive?: (entry: T) => boolean,
|
|
6
|
+
shouldContinue?: () => boolean,
|
|
7
|
+
): void {
|
|
8
|
+
const errors: unknown[] = [];
|
|
9
|
+
for (const entry of entries) {
|
|
10
|
+
if (shouldContinue && !shouldContinue()) break;
|
|
11
|
+
if (isActive && !isActive(entry)) continue;
|
|
12
|
+
try {
|
|
13
|
+
notify(entry);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
errors.push(error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (errors.length === 1) throw errors[0];
|
|
19
|
+
if (errors.length > 1) {
|
|
20
|
+
throw new AggregateError(errors, "Multiple listener callbacks failed");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
42
|
import { abortAllPrefetches } from "./loader.js";
|
|
43
|
+
import { notifyPrefetchCacheInvalidated } from "./invalidation.js";
|
|
43
44
|
import { invalidateRangoState } from "../rango-state.js";
|
|
44
45
|
import type { RscPayload } from "../types.js";
|
|
45
46
|
|
|
@@ -368,7 +369,7 @@ export function clearPrefetchInflight(key: string): void {
|
|
|
368
369
|
});
|
|
369
370
|
}
|
|
370
371
|
|
|
371
|
-
export function clearPrefetchCache(): void {
|
|
372
|
+
export function clearPrefetchCache(rotateRangoState = true): void {
|
|
372
373
|
generation++;
|
|
373
374
|
inflight.clear();
|
|
374
375
|
inflightPromises.clear();
|
|
@@ -377,5 +378,6 @@ export function clearPrefetchCache(): void {
|
|
|
377
378
|
cache.clear();
|
|
378
379
|
earliestTimestamp = Infinity;
|
|
379
380
|
abortAllPrefetches();
|
|
380
|
-
invalidateRangoState();
|
|
381
|
+
if (rotateRangoState) invalidateRangoState();
|
|
382
|
+
notifyPrefetchCacheInvalidated();
|
|
381
383
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Router-wide default
|
|
2
|
+
* Router-wide default prefetch strategy (client seat).
|
|
3
3
|
*
|
|
4
4
|
* The server resolves `createRouter({ defaultPrefetch })` once at router init
|
|
5
5
|
* (router/prefetch-default.ts) and ships it in initial payload metadata; the
|
|
6
6
|
* browser entry applies it here before hydration — same lifecycle as
|
|
7
7
|
* `initPrefetchCache` / `setPrefetchConcurrency`. Every `<Link>` without an
|
|
8
|
-
* explicit `prefetch` prop
|
|
8
|
+
* explicit `prefetch` prop and every eligible intercepted plain anchor that has
|
|
9
|
+
* not opted out with `data-prefetch="false"` or `data-prefetch="none"` uses it.
|
|
10
|
+
* Containers use the same `false`/`none` vocabulary via
|
|
11
|
+
* `data-prefetch-scope`.
|
|
9
12
|
*
|
|
10
13
|
* The module initial value must equal the server resolver's environment default:
|
|
11
14
|
* `"none"` in development and `"viewport"` in production. During SSR this
|
|
@@ -15,11 +18,26 @@
|
|
|
15
18
|
|
|
16
19
|
import type { PrefetchStrategy } from "../../router/prefetch-default.js";
|
|
17
20
|
|
|
21
|
+
let hoverNoneQuery: MediaQueryList | null = null;
|
|
22
|
+
|
|
18
23
|
// Mirrors DEFAULT_PREFETCH_STRATEGY without pulling router-layer code into the
|
|
19
24
|
// client bundle. NODE_ENV is folded by the app build.
|
|
20
25
|
let defaultStrategy: PrefetchStrategy =
|
|
21
26
|
process.env.NODE_ENV === "production" ? "viewport" : "none";
|
|
22
27
|
|
|
28
|
+
function getHoverNoneQuery(): MediaQueryList | null {
|
|
29
|
+
if (typeof window === "undefined") return null;
|
|
30
|
+
if (!hoverNoneQuery) {
|
|
31
|
+
hoverNoneQuery = window.matchMedia("(hover: none)");
|
|
32
|
+
}
|
|
33
|
+
return hoverNoneQuery;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Reset module state between tests that replace browser media globals. */
|
|
37
|
+
export function resetAdaptiveStrategyForTesting(): void {
|
|
38
|
+
hoverNoneQuery = null;
|
|
39
|
+
}
|
|
40
|
+
|
|
23
41
|
/**
|
|
24
42
|
* Apply the server-resolved default strategy. Called once at browser app init
|
|
25
43
|
* from payload metadata; also used by tests to reset state.
|
|
@@ -28,7 +46,29 @@ export function setDefaultPrefetchStrategy(strategy: PrefetchStrategy): void {
|
|
|
28
46
|
defaultStrategy = strategy;
|
|
29
47
|
}
|
|
30
48
|
|
|
31
|
-
/** Current default strategy for Links
|
|
49
|
+
/** Current default strategy for Links and delegated plain anchors. */
|
|
32
50
|
export function getDefaultPrefetchStrategy(): PrefetchStrategy {
|
|
33
51
|
return defaultStrategy;
|
|
34
52
|
}
|
|
53
|
+
|
|
54
|
+
/** Resolve adaptive to the strategy for the current input capability. */
|
|
55
|
+
export function resolveAdaptiveStrategy(
|
|
56
|
+
strategy: PrefetchStrategy,
|
|
57
|
+
): PrefetchStrategy {
|
|
58
|
+
if (strategy !== "adaptive") return strategy;
|
|
59
|
+
return getHoverNoneQuery()?.matches ? "viewport" : "hover";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Subscribe to changes in the input capability used by adaptive prefetch. */
|
|
63
|
+
export function subscribeToAdaptiveStrategyChange(
|
|
64
|
+
listener: () => void,
|
|
65
|
+
): () => void {
|
|
66
|
+
const query = getHoverNoneQuery();
|
|
67
|
+
if (!query) return () => {};
|
|
68
|
+
if (typeof query.addEventListener === "function") {
|
|
69
|
+
query.addEventListener("change", listener);
|
|
70
|
+
return () => query.removeEventListener("change", listener);
|
|
71
|
+
}
|
|
72
|
+
query.addListener(listener);
|
|
73
|
+
return () => query.removeListener(listener);
|
|
74
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { notifyListeners } from "../notify-listeners.js";
|
|
2
|
+
|
|
3
|
+
type PrefetchCacheInvalidationListener = () => void;
|
|
4
|
+
|
|
5
|
+
const listeners = new Map<symbol, PrefetchCacheInvalidationListener>();
|
|
6
|
+
|
|
7
|
+
/** Subscribe to completed local prefetch-cache invalidations. */
|
|
8
|
+
export function subscribeToPrefetchCacheInvalidation(
|
|
9
|
+
listener: PrefetchCacheInvalidationListener,
|
|
10
|
+
): () => void {
|
|
11
|
+
const subscription = Symbol();
|
|
12
|
+
listeners.set(subscription, listener);
|
|
13
|
+
|
|
14
|
+
return () => listeners.delete(subscription);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Notify the registrations that existed when the cache was invalidated. */
|
|
18
|
+
export function notifyPrefetchCacheInvalidated(): void {
|
|
19
|
+
const registrations = [...listeners];
|
|
20
|
+
// Finish the current broadcast/action finalizer before re-arming work. A
|
|
21
|
+
// synchronous callback could throw before cross-tab invalidation is sent or
|
|
22
|
+
// prefetch while the action fence is still raised.
|
|
23
|
+
queueMicrotask(() => {
|
|
24
|
+
notifyListeners(
|
|
25
|
+
registrations,
|
|
26
|
+
([, listener]) => listener(),
|
|
27
|
+
([subscription, listener]) => listeners.get(subscription) === listener,
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { RscPayload } from "../types.js";
|
|
2
|
-
import {
|
|
3
|
-
observeForPrefetch as observeElementForPrefetch,
|
|
4
|
-
unobserveForPrefetch,
|
|
5
|
-
} from "./observer.js";
|
|
2
|
+
import type { EventController } from "../event-controller.js";
|
|
6
3
|
|
|
7
4
|
type PrefetchDecoder = (response: Promise<Response>) => Promise<RscPayload>;
|
|
8
5
|
|
|
@@ -82,15 +79,25 @@ export function prefetchQueued(
|
|
|
82
79
|
);
|
|
83
80
|
}
|
|
84
81
|
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
/** Run speculative work only when no navigation or stream is active. */
|
|
83
|
+
export function schedulePrefetchWhenRouterIdle(
|
|
84
|
+
eventController: Pick<EventController, "getState" | "subscribe">,
|
|
87
85
|
callback: () => void,
|
|
88
|
-
): () => void {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
86
|
+
): (() => void) | undefined {
|
|
87
|
+
const state = eventController.getState();
|
|
88
|
+
if (state.state === "idle" && !state.isStreaming) {
|
|
89
|
+
callback();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const unsubscribe = eventController.subscribe(() => {
|
|
94
|
+
const nextState = eventController.getState();
|
|
95
|
+
if (nextState.state === "idle" && !nextState.isStreaming) {
|
|
96
|
+
unsubscribe();
|
|
97
|
+
callback();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return unsubscribe;
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
export function cancelAllPrefetches(keepUrl?: string | null): void {
|
|
@@ -12,32 +12,53 @@
|
|
|
12
12
|
* scrolls in and out repeatedly.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import { notifyListeners } from "../notify-listeners.js";
|
|
16
|
+
|
|
15
17
|
type PrefetchCallback = () => void;
|
|
16
18
|
|
|
17
|
-
const callbacks = new Map<Element, PrefetchCallback
|
|
19
|
+
const callbacks = new Map<Element, Map<symbol, PrefetchCallback>>();
|
|
18
20
|
let observer: IntersectionObserver | null = null;
|
|
19
21
|
|
|
20
22
|
function getObserver(): IntersectionObserver {
|
|
21
23
|
if (!observer) {
|
|
22
24
|
observer = new IntersectionObserver(
|
|
23
|
-
(entries) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
callbacks.
|
|
30
|
-
|
|
25
|
+
(entries, currentObserver) => {
|
|
26
|
+
function* intersectingCallbacks(): Generator<
|
|
27
|
+
[Map<symbol, PrefetchCallback>, symbol, PrefetchCallback]
|
|
28
|
+
> {
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
if (entry.isIntersecting) {
|
|
31
|
+
const subscriptions = callbacks.get(entry.target);
|
|
32
|
+
if (subscriptions) {
|
|
33
|
+
currentObserver.unobserve(entry.target);
|
|
34
|
+
callbacks.delete(entry.target);
|
|
35
|
+
for (const [subscription, callback] of subscriptions) {
|
|
36
|
+
yield [subscriptions, subscription, callback];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
}
|
|
33
41
|
}
|
|
42
|
+
notifyListeners(
|
|
43
|
+
intersectingCallbacks(),
|
|
44
|
+
([, , callback]) => callback(),
|
|
45
|
+
([subscriptions, subscription]) => subscriptions.has(subscription),
|
|
46
|
+
);
|
|
34
47
|
},
|
|
35
48
|
{ rootMargin: "200px" },
|
|
36
49
|
);
|
|
50
|
+
for (const element of callbacks.keys()) observer.observe(element);
|
|
37
51
|
}
|
|
38
52
|
return observer;
|
|
39
53
|
}
|
|
40
54
|
|
|
55
|
+
/** Reset module state between tests that replace browser observer globals. */
|
|
56
|
+
export function resetPrefetchObserverForTesting(): void {
|
|
57
|
+
observer?.disconnect();
|
|
58
|
+
observer = null;
|
|
59
|
+
callbacks.clear();
|
|
60
|
+
}
|
|
61
|
+
|
|
41
62
|
/**
|
|
42
63
|
* Observe an element for viewport intersection.
|
|
43
64
|
* When the element becomes visible (within 200px margin), the callback fires
|
|
@@ -47,19 +68,26 @@ function getObserver(): IntersectionObserver {
|
|
|
47
68
|
export function observeForPrefetch(
|
|
48
69
|
element: Element,
|
|
49
70
|
onVisible: PrefetchCallback,
|
|
50
|
-
): void {
|
|
51
|
-
if (typeof IntersectionObserver === "undefined") return;
|
|
52
|
-
|
|
53
|
-
getObserver().observe(element);
|
|
54
|
-
}
|
|
71
|
+
): () => void {
|
|
72
|
+
if (typeof IntersectionObserver === "undefined") return () => {};
|
|
73
|
+
const currentObserver = getObserver();
|
|
55
74
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
export function unobserveForPrefetch(element: Element): void {
|
|
61
|
-
callbacks.delete(element);
|
|
62
|
-
if (observer) {
|
|
63
|
-
observer.unobserve(element);
|
|
75
|
+
let subscriptions = callbacks.get(element);
|
|
76
|
+
if (!subscriptions) {
|
|
77
|
+
subscriptions = new Map();
|
|
78
|
+
callbacks.set(element, subscriptions);
|
|
64
79
|
}
|
|
80
|
+
|
|
81
|
+
const subscription = Symbol();
|
|
82
|
+
subscriptions.set(subscription, onVisible);
|
|
83
|
+
if (subscriptions.size === 1) currentObserver.observe(element);
|
|
84
|
+
|
|
85
|
+
return () => {
|
|
86
|
+
const current = callbacks.get(element);
|
|
87
|
+
subscriptions.delete(subscription);
|
|
88
|
+
if (current !== subscriptions) return;
|
|
89
|
+
if (current.size > 0) return;
|
|
90
|
+
callbacks.delete(element);
|
|
91
|
+
observer?.unobserve(element);
|
|
92
|
+
};
|
|
65
93
|
}
|
|
@@ -52,6 +52,11 @@ export function setRangoStateObserver(
|
|
|
52
52
|
externalRotationObserver = observer;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/** Return the resolved cookie name used to namespace cross-tab messages. */
|
|
56
|
+
export function getRangoStateCookieName(): string {
|
|
57
|
+
return cookieName;
|
|
58
|
+
}
|
|
59
|
+
|
|
55
60
|
function notifyExternalRotation(value: string): void {
|
|
56
61
|
externalRotationObserver?.(value);
|
|
57
62
|
}
|
|
@@ -179,6 +184,22 @@ export function invalidateRangoState(): void {
|
|
|
179
184
|
writeCookie(cookieName, mirror);
|
|
180
185
|
}
|
|
181
186
|
|
|
187
|
+
/** Adopt the state carried by a same-origin cache-invalidation broadcast. */
|
|
188
|
+
export function adoptRangoState(value: string): boolean {
|
|
189
|
+
const incoming = decodeStateValue(value);
|
|
190
|
+
if (!incoming || incoming.version !== currentVersion) return false;
|
|
191
|
+
const current = mirror ? decodeStateValue(mirror) : null;
|
|
192
|
+
if (
|
|
193
|
+
current?.version === incoming.version &&
|
|
194
|
+
current.timestamp >= incoming.timestamp
|
|
195
|
+
) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
mirror = value;
|
|
199
|
+
cookieBacked = false;
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
|
|
182
203
|
function cleanupLegacyStorage(): void {
|
|
183
204
|
if (typeof localStorage === "undefined") return;
|
|
184
205
|
try {
|
|
@@ -7,13 +7,19 @@ import React, {
|
|
|
7
7
|
useEffect,
|
|
8
8
|
useMemo,
|
|
9
9
|
useRef,
|
|
10
|
+
useSyncExternalStore,
|
|
10
11
|
type ForwardRefExoticComponent,
|
|
11
12
|
type RefAttributes,
|
|
12
13
|
} from "react";
|
|
13
14
|
import { NavigationStoreContext } from "./context.js";
|
|
14
15
|
import { LinkContext } from "./use-link-status.js";
|
|
15
16
|
import type { NavigateOptions } from "../types.js";
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
isHashOnlyNavigation,
|
|
19
|
+
isPrefetchScopeDisabled,
|
|
20
|
+
subscribeToPrefetchScopeChange,
|
|
21
|
+
} from "../link-interceptor.js";
|
|
22
|
+
import { subscribeToLocationChange } from "../event-controller.js";
|
|
17
23
|
import {
|
|
18
24
|
isLocationStateEntry,
|
|
19
25
|
type LocationStateEntry,
|
|
@@ -33,55 +39,26 @@ export type LinkState =
|
|
|
33
39
|
| StateOrGetter<Record<string, unknown>>;
|
|
34
40
|
|
|
35
41
|
import {
|
|
36
|
-
observeForPrefetch,
|
|
37
42
|
prefetchDirect,
|
|
38
43
|
prefetchQueued,
|
|
44
|
+
schedulePrefetchWhenRouterIdle,
|
|
39
45
|
} from "../prefetch/loader.js";
|
|
40
|
-
import {
|
|
46
|
+
import { observeForPrefetch } from "../prefetch/observer.js";
|
|
47
|
+
import {
|
|
48
|
+
getDefaultPrefetchStrategy,
|
|
49
|
+
resolveAdaptiveStrategy,
|
|
50
|
+
subscribeToAdaptiveStrategyChange,
|
|
51
|
+
} from "../prefetch/default-strategy.js";
|
|
41
52
|
import { getAppVersion } from "../app-version.js";
|
|
42
53
|
import type { PrefetchStrategy } from "../../router/prefetch-default.js";
|
|
43
54
|
|
|
44
|
-
// The (hover: none) MediaQueryList, created lazily on first client read and
|
|
45
|
-
// reused across every Link render. matchMedia allocates and registers a live
|
|
46
|
-
// query object; a fresh one per render (Link renders can be very frequent) is
|
|
47
|
-
// wasteful when the same object's `.matches` is already live. Left null on the
|
|
48
|
-
// server (no window).
|
|
49
|
-
let hoverNoneQuery: MediaQueryList | null = null;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Read current touch/no-hover capability from the cached MediaQueryList. The
|
|
53
|
-
* `.matches` read is live, so `prefetch="adaptive"` still reacts to
|
|
54
|
-
* input-capability changes on hybrid devices (touch laptops, tablets gaining or
|
|
55
|
-
* losing a pointer) and after SSR -> hydrate. The SSR guard returns a stable
|
|
56
|
-
* `false` (pointer/hover default) so the resolved strategy doesn't drift on the
|
|
57
|
-
* server vs the first client render.
|
|
58
|
-
*/
|
|
59
|
-
function isTouchDevice(): boolean {
|
|
60
|
-
if (typeof window === "undefined") return false;
|
|
61
|
-
if (!hoverNoneQuery) {
|
|
62
|
-
hoverNoneQuery = window.matchMedia("(hover: none)");
|
|
63
|
-
}
|
|
64
|
-
return hoverNoneQuery.matches;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
55
|
// The PrefetchStrategy union is defined in router/prefetch-default.ts (both
|
|
68
56
|
// the server-side option resolver and this client seat consume it); re-export
|
|
69
57
|
// so the public `PrefetchStrategy` import path via client.tsx is unchanged.
|
|
70
58
|
export type { PrefetchStrategy } from "../../router/prefetch-default.js";
|
|
59
|
+
export { resolveAdaptiveStrategy } from "../prefetch/default-strategy.js";
|
|
71
60
|
|
|
72
|
-
|
|
73
|
-
* Resolve a prefetch strategy, expanding "adaptive" to the concrete strategy
|
|
74
|
-
* for the CURRENT input capability: "viewport" on touch (no-hover) devices,
|
|
75
|
-
* "hover" on pointer devices. Non-adaptive strategies pass through unchanged.
|
|
76
|
-
* Reads touch capability live (not a module-load snapshot) so the result
|
|
77
|
-
* tracks input-capability changes.
|
|
78
|
-
*/
|
|
79
|
-
export function resolveAdaptiveStrategy(
|
|
80
|
-
prefetch: PrefetchStrategy,
|
|
81
|
-
): PrefetchStrategy {
|
|
82
|
-
if (prefetch !== "adaptive") return prefetch;
|
|
83
|
-
return isTouchDevice() ? "viewport" : "hover";
|
|
84
|
-
}
|
|
61
|
+
const IGNORE_STRATEGY_CHANGES = (_listener: () => void) => () => {};
|
|
85
62
|
|
|
86
63
|
/**
|
|
87
64
|
* Link component props
|
|
@@ -120,7 +97,9 @@ export interface LinkProps extends Omit<
|
|
|
120
97
|
* Prefetch strategy for the link destination. When omitted, falls back to
|
|
121
98
|
* the router-wide default (`createRouter({ defaultPrefetch })`: `"none"` in
|
|
122
99
|
* development, `"viewport"` in production). An explicit value always wins
|
|
123
|
-
* over the router default, including `"none"` to opt a single Link out.
|
|
100
|
+
* over the router default, including `"none"` to opt a single Link out. An
|
|
101
|
+
* ancestor with `data-prefetch-scope="false"` or `"none"` remains a hard
|
|
102
|
+
* subtree opt-out.
|
|
124
103
|
*
|
|
125
104
|
* @default the router's environment-aware `defaultPrefetch`
|
|
126
105
|
*/
|
|
@@ -260,12 +239,16 @@ export const Link: ForwardRefExoticComponent<
|
|
|
260
239
|
|
|
261
240
|
// No explicit `prefetch` prop: fall back to the router-wide default
|
|
262
241
|
// (server-resolved, applied at browser init — before hydration, so this
|
|
263
|
-
// render-time read never races the metadata).
|
|
264
|
-
//
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const resolvedStrategy =
|
|
268
|
-
|
|
242
|
+
// render-time read never races the metadata). Adaptive reads the current
|
|
243
|
+
// input capability rather than a module-load snapshot.
|
|
244
|
+
const configuredStrategy =
|
|
245
|
+
prefetch ?? ctx?.defaultPrefetch ?? getDefaultPrefetchStrategy();
|
|
246
|
+
const resolvedStrategy = useSyncExternalStore(
|
|
247
|
+
configuredStrategy === "adaptive"
|
|
248
|
+
? subscribeToAdaptiveStrategyChange
|
|
249
|
+
: IGNORE_STRATEGY_CHANGES,
|
|
250
|
+
() => resolveAdaptiveStrategy(configuredStrategy),
|
|
251
|
+
() => (configuredStrategy === "adaptive" ? "hover" : configuredStrategy),
|
|
269
252
|
);
|
|
270
253
|
|
|
271
254
|
// Internal ref for viewport observation; merge with forwarded ref
|
|
@@ -365,10 +348,13 @@ export const Link: ForwardRefExoticComponent<
|
|
|
365
348
|
);
|
|
366
349
|
|
|
367
350
|
const handleMouseEnter = useCallback(() => {
|
|
351
|
+
const element = internalRef.current;
|
|
368
352
|
if (
|
|
369
353
|
(resolvedStrategy === "hover" || resolvedStrategy === "viewport") &&
|
|
370
354
|
!isExternal &&
|
|
371
|
-
ctx?.store
|
|
355
|
+
ctx?.store &&
|
|
356
|
+
(!element ||
|
|
357
|
+
(!isHashOnlyNavigation(element) && !isPrefetchScopeDisabled(element)))
|
|
372
358
|
) {
|
|
373
359
|
// For "hover", this is the primary prefetch trigger.
|
|
374
360
|
// For "viewport", this upgrades/prioritizes a potentially queued
|
|
@@ -393,54 +379,77 @@ export const Link: ForwardRefExoticComponent<
|
|
|
393
379
|
const isRender = resolvedStrategy === "render";
|
|
394
380
|
if (!isViewport && !isRender) return;
|
|
395
381
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
382
|
+
const armPrefetch = (): (() => void) => {
|
|
383
|
+
const element = internalRef.current;
|
|
384
|
+
if (
|
|
385
|
+
element &&
|
|
386
|
+
(isHashOnlyNavigation(element) || isPrefetchScopeDisabled(element))
|
|
387
|
+
) {
|
|
388
|
+
return () => {};
|
|
389
|
+
}
|
|
399
390
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
391
|
+
let cancelled = false;
|
|
392
|
+
let unsubIdle: (() => void) | undefined;
|
|
393
|
+
let stopObserving: (() => void) | undefined;
|
|
394
|
+
|
|
395
|
+
const triggerPrefetch = () => {
|
|
396
|
+
if (cancelled) return;
|
|
397
|
+
const currentElement = internalRef.current;
|
|
398
|
+
if (currentElement && isPrefetchScopeDisabled(currentElement)) return;
|
|
399
|
+
const segmentState = ctx.store.getSegmentState();
|
|
400
|
+
prefetchQueued(
|
|
401
|
+
resolvedTo,
|
|
402
|
+
segmentState.currentSegmentIds,
|
|
403
|
+
getAppVersion(),
|
|
404
|
+
ctx.store.getRouterId?.(),
|
|
405
|
+
prefetchKey,
|
|
406
|
+
);
|
|
407
|
+
};
|
|
411
408
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
409
|
+
if (isRender) {
|
|
410
|
+
unsubIdle = schedulePrefetchWhenRouterIdle(
|
|
411
|
+
ctx.eventController,
|
|
412
|
+
triggerPrefetch,
|
|
413
|
+
);
|
|
414
|
+
} else {
|
|
415
|
+
const viewportElement = internalRef.current;
|
|
416
|
+
if (viewportElement) {
|
|
417
|
+
stopObserving = observeForPrefetch(viewportElement, () => {
|
|
418
|
+
unsubIdle = schedulePrefetchWhenRouterIdle(
|
|
419
|
+
ctx.eventController,
|
|
420
|
+
triggerPrefetch,
|
|
421
|
+
);
|
|
422
|
+
});
|
|
425
423
|
}
|
|
426
|
-
}
|
|
427
|
-
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return () => {
|
|
427
|
+
cancelled = true;
|
|
428
|
+
unsubIdle?.();
|
|
429
|
+
stopObserving?.();
|
|
430
|
+
};
|
|
428
431
|
};
|
|
429
432
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
433
|
+
let disarmPrefetch = armPrefetch();
|
|
434
|
+
const element = internalRef.current;
|
|
435
|
+
const unsubscribeScope = element
|
|
436
|
+
? subscribeToPrefetchScopeChange(element, () => {
|
|
437
|
+
disarmPrefetch();
|
|
438
|
+
disarmPrefetch = armPrefetch();
|
|
439
|
+
})
|
|
440
|
+
: undefined;
|
|
441
|
+
const unsubscribeLocation = subscribeToLocationChange(
|
|
442
|
+
ctx.eventController,
|
|
443
|
+
() => {
|
|
444
|
+
disarmPrefetch();
|
|
445
|
+
disarmPrefetch = armPrefetch();
|
|
446
|
+
},
|
|
447
|
+
);
|
|
439
448
|
|
|
440
449
|
return () => {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
450
|
+
unsubscribeScope?.();
|
|
451
|
+
unsubscribeLocation();
|
|
452
|
+
disarmPrefetch();
|
|
444
453
|
};
|
|
445
454
|
}, [resolvedStrategy, resolvedTo, isExternal, ctx, prefetchKey]);
|
|
446
455
|
|
|
@@ -349,6 +349,7 @@ export function NavigationProvider({
|
|
|
349
349
|
eventController,
|
|
350
350
|
navigate,
|
|
351
351
|
refresh,
|
|
352
|
+
defaultPrefetch: initialPayload.metadata.defaultPrefetch,
|
|
352
353
|
} as NavigationStoreContextValue;
|
|
353
354
|
Object.defineProperty(value, "basename", {
|
|
354
355
|
configurable: true,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { createContext, type Context } from "react";
|
|
4
4
|
import type { NavigationStore, NavigateOptions } from "../types.js";
|
|
5
5
|
import type { EventController } from "../event-controller.js";
|
|
6
|
+
import type { PrefetchStrategy } from "../../router/prefetch-default.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Navigation context value provided by NavigationProvider
|
|
@@ -52,6 +53,9 @@ export interface NavigationStoreContextValue {
|
|
|
52
53
|
* Used by Link and useRouter() to auto-prefix app-local paths.
|
|
53
54
|
*/
|
|
54
55
|
basename: string | undefined;
|
|
56
|
+
|
|
57
|
+
/** Router default from this instance's initial payload. */
|
|
58
|
+
defaultPrefetch?: PrefetchStrategy;
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
/**
|