@rangojs/router 0.0.0-experimental.bd6e11bc → 0.0.0-experimental.bdaf10aa
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 -4
- package/README.md +296 -887
- package/dist/bin/rango.js +459 -91
- package/dist/testing/vitest.js +36 -2
- package/dist/vite/index.js +1708 -414
- package/package.json +35 -10
- package/skills/api-client/SKILL.md +211 -0
- package/skills/breadcrumbs/SKILL.md +82 -5
- package/skills/bundle-analysis/SKILL.md +2 -2
- package/skills/cache-guide/SKILL.md +14 -9
- package/skills/caching/SKILL.md +221 -12
- package/skills/catalog.json +271 -0
- package/skills/comparison/SKILL.md +50 -0
- package/skills/comparison/agents/openai.yaml +4 -0
- package/skills/comparison/references/framework-comparison.md +837 -0
- package/skills/composability/SKILL.md +83 -2
- package/skills/css/SKILL.md +76 -0
- package/skills/debug-manifest/SKILL.md +5 -3
- package/skills/defer-hydration/SKILL.md +235 -0
- package/skills/document-cache/SKILL.md +11 -3
- package/skills/fonts/SKILL.md +1 -1
- package/skills/handler-use/SKILL.md +9 -9
- package/skills/hooks/SKILL.md +73 -900
- package/skills/hooks/data.md +273 -0
- package/skills/hooks/handle-and-actions.md +103 -0
- package/skills/hooks/navigation.md +110 -0
- package/skills/hooks/outlets.md +41 -0
- package/skills/hooks/state.md +228 -0
- package/skills/hooks/urls.md +135 -0
- package/skills/host-router/SKILL.md +84 -7
- package/skills/i18n/SKILL.md +1 -1
- package/skills/intercept/SKILL.md +51 -17
- package/skills/layout/SKILL.md +38 -16
- package/skills/links/SKILL.md +1 -1
- package/skills/loader/SKILL.md +48 -20
- package/skills/middleware/SKILL.md +11 -5
- package/skills/migrate-nextjs/SKILL.md +203 -20
- package/skills/migrate-react-router/SKILL.md +59 -675
- package/skills/migrate-react-router/cloudflare-workers.md +129 -0
- package/skills/migrate-react-router/component-migration.md +196 -0
- package/skills/migrate-react-router/data-and-actions.md +225 -0
- package/skills/migrate-react-router/route-mapping.md +271 -0
- package/skills/mime-routes/SKILL.md +3 -3
- package/skills/observability/SKILL.md +70 -5
- package/skills/parallel/SKILL.md +32 -8
- package/skills/ppr/SKILL.md +622 -0
- package/skills/prerender/SKILL.md +59 -28
- package/skills/rango/SKILL.md +124 -50
- package/skills/response-routes/SKILL.md +78 -46
- package/skills/route/SKILL.md +85 -6
- package/skills/router-setup/SKILL.md +41 -6
- package/skills/scripts/SKILL.md +179 -0
- package/skills/server-actions/SKILL.md +28 -3
- package/skills/shell-manifest/SKILL.md +185 -0
- package/skills/streams-and-websockets/SKILL.md +1 -1
- package/skills/tailwind/SKILL.md +28 -4
- package/skills/testing/SKILL.md +68 -654
- 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 +131 -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 +85 -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/theme/SKILL.md +1 -1
- package/skills/typesafety/SKILL.md +45 -918
- package/skills/typesafety/env-and-bindings.md +254 -0
- package/skills/typesafety/generated-files-and-cli.md +335 -0
- package/skills/typesafety/params-and-search.md +153 -0
- package/skills/typesafety/route-types.md +209 -0
- package/skills/use-cache/SKILL.md +47 -17
- package/skills/vercel/SKILL.md +128 -0
- package/skills/view-transitions/SKILL.md +44 -1
- package/src/__augment-tests__/augmented.check.ts +2 -3
- package/src/__internal.ts +0 -65
- package/src/browser/action-coordinator.ts +1 -1
- package/src/browser/action-fence.ts +47 -0
- package/src/browser/app-shell.ts +14 -27
- package/src/browser/connection-warmup.ts +134 -0
- package/src/browser/cookie-name.ts +140 -0
- package/src/browser/event-controller.ts +178 -100
- package/src/browser/invalidate-client-cache.ts +52 -0
- package/src/browser/logging.ts +28 -0
- package/src/browser/merge-segment-loaders.ts +6 -4
- package/src/browser/navigation-bridge.ts +81 -68
- package/src/browser/navigation-client.ts +115 -70
- package/src/browser/navigation-store-handle.ts +38 -0
- package/src/browser/navigation-store.ts +153 -88
- package/src/browser/navigation-transaction.ts +0 -32
- package/src/browser/network-error-handler.ts +34 -7
- package/src/browser/partial-update.ts +157 -144
- package/src/browser/prefetch/cache.ts +148 -81
- package/src/browser/prefetch/fetch.ts +231 -51
- package/src/browser/prefetch/queue.ts +25 -7
- package/src/browser/rango-state.ts +157 -115
- package/src/browser/react/Link.tsx +40 -7
- package/src/browser/react/NavigationProvider.tsx +140 -99
- package/src/browser/react/ScrollRestoration.tsx +10 -6
- package/src/browser/react/filter-segment-order.ts +17 -2
- package/src/browser/react/index.ts +0 -51
- package/src/browser/react/location-state-shared.ts +14 -15
- package/src/browser/react/location-state.ts +0 -1
- package/src/browser/react/use-action.ts +6 -15
- package/src/browser/react/use-handle.ts +0 -5
- 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 +0 -2
- package/src/browser/react/use-router.ts +6 -4
- package/src/browser/react/use-search-params.ts +0 -5
- package/src/browser/react/use-segments.ts +0 -13
- package/src/browser/response-adapter.ts +74 -8
- package/src/browser/rsc-router.tsx +97 -22
- package/src/browser/scroll-restoration.ts +15 -8
- package/src/browser/segment-reconciler.ts +31 -21
- package/src/browser/server-action-bridge.ts +216 -38
- package/src/browser/types.ts +94 -22
- package/src/browser/validate-redirect-origin.ts +43 -16
- package/src/build/generate-manifest.ts +155 -131
- package/src/build/generate-route-types.ts +1 -1
- package/src/build/index.ts +11 -5
- package/src/build/prefix-tree-utils.ts +123 -0
- package/src/build/route-trie.ts +152 -22
- package/src/build/route-types/ast-route-extraction.ts +15 -8
- package/src/build/route-types/codegen.ts +12 -1
- package/src/build/route-types/include-resolution.ts +455 -61
- package/src/build/route-types/param-extraction.ts +6 -3
- package/src/build/route-types/per-module-writer.ts +15 -2
- package/src/build/route-types/router-processing.ts +77 -41
- package/src/build/route-types/source-scan.ts +105 -7
- package/src/build/runtime-discovery.ts +4 -1
- package/src/cache/cache-error.ts +104 -0
- package/src/cache/cache-key-utils.ts +58 -13
- package/src/cache/cache-policy.ts +108 -34
- package/src/cache/cache-runtime.ts +454 -101
- package/src/cache/cache-scope.ts +159 -54
- package/src/cache/cache-tag.ts +149 -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 +2170 -377
- 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 +126 -41
- package/src/cache/handle-snapshot.ts +70 -0
- package/src/cache/index.ts +23 -20
- package/src/cache/memory-segment-store.ts +243 -37
- package/src/cache/profile-registry.ts +46 -31
- package/src/cache/read-through-swr.ts +56 -12
- package/src/cache/segment-codec.ts +13 -21
- package/src/cache/shell-snapshot.ts +417 -0
- package/src/cache/tag-invalidation.ts +230 -0
- package/src/cache/types.ts +194 -99
- package/src/cache/vercel/index.ts +11 -0
- package/src/cache/vercel/vercel-cache-store.ts +1132 -0
- package/src/client.rsc.tsx +39 -22
- package/src/client.tsx +28 -58
- package/src/cloudflare/index.ts +11 -0
- package/src/cloudflare/tracing.ts +108 -0
- package/src/component-utils.ts +19 -0
- package/src/components/DefaultDocument.tsx +8 -2
- package/src/context-var.ts +13 -1
- package/src/decode-loader-results.ts +18 -2
- package/src/defer.ts +185 -0
- package/src/deps/ssr.ts +0 -1
- package/src/encode-kv.ts +49 -0
- package/src/errors.ts +0 -3
- package/src/escape-script.ts +52 -0
- package/src/handle.ts +57 -40
- package/src/handles/MetaTags.tsx +24 -53
- package/src/handles/Scripts.tsx +183 -0
- package/src/handles/breadcrumbs.ts +35 -8
- package/src/handles/deferred-resolution.ts +127 -0
- package/src/handles/is-thenable.ts +18 -0
- package/src/handles/meta.ts +14 -40
- package/src/handles/script.ts +244 -0
- package/src/host/cookie-handler.ts +9 -60
- package/src/host/errors.ts +13 -22
- package/src/host/index.ts +7 -0
- package/src/host/pattern-matcher.ts +23 -52
- package/src/host/router.ts +1 -65
- package/src/host/testing.ts +40 -27
- package/src/host/types.ts +6 -2
- package/src/href-client.ts +7 -12
- package/src/index.rsc.ts +88 -8
- package/src/index.ts +90 -16
- package/src/internal-debug.ts +11 -10
- package/src/loader.rsc.ts +19 -9
- package/src/loader.ts +12 -4
- 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 +75 -7
- package/src/redirect-origin.ts +114 -0
- package/src/regex-escape.ts +8 -0
- package/src/render-error-thrower.tsx +20 -0
- package/src/response-utils.ts +25 -0
- package/src/root-error-boundary.tsx +1 -19
- package/src/route-content-wrapper.tsx +13 -49
- package/src/route-definition/dsl-helpers.ts +60 -53
- package/src/route-definition/helper-factories.ts +0 -2
- package/src/route-definition/helpers-types.ts +46 -46
- package/src/route-definition/index.ts +1 -2
- package/src/route-definition/redirect.ts +44 -11
- package/src/route-definition/resolve-handler-use.ts +6 -1
- package/src/route-definition/use-item-types.ts +3 -6
- package/src/route-map-builder.ts +41 -20
- package/src/route-types.ts +0 -5
- package/src/router/content-negotiation.ts +58 -23
- package/src/router/error-handling.ts +44 -17
- package/src/router/find-match.ts +129 -30
- package/src/router/handler-context.ts +6 -1
- package/src/router/instrument.ts +355 -0
- package/src/router/intercept-resolution.ts +35 -2
- package/src/router/lazy-includes.ts +79 -56
- package/src/router/loader-resolution.ts +151 -73
- package/src/router/logging.ts +0 -6
- package/src/router/manifest.ts +74 -40
- package/src/router/match-api.ts +76 -52
- package/src/router/match-context.ts +0 -22
- package/src/router/match-handlers.ts +181 -178
- package/src/router/match-middleware/background-revalidation.ts +40 -24
- package/src/router/match-middleware/cache-lookup.ts +115 -194
- package/src/router/match-middleware/cache-store.ts +61 -50
- 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 +36 -67
- package/src/router/metrics.ts +0 -34
- package/src/router/middleware-types.ts +0 -116
- package/src/router/middleware.ts +231 -120
- package/src/router/navigation-snapshot.ts +7 -56
- package/src/router/params-util.ts +23 -0
- package/src/router/parse-pattern.ts +115 -0
- package/src/router/pattern-matching.ts +99 -152
- package/src/router/prefetch-cache-ttl.ts +51 -0
- package/src/router/prefetch-limits.ts +37 -0
- package/src/router/prerender-match.ts +111 -66
- package/src/router/preview-match.ts +3 -1
- package/src/router/request-classification.ts +47 -42
- package/src/router/revalidation.ts +75 -81
- package/src/router/route-snapshot.ts +14 -3
- package/src/router/router-context.ts +6 -29
- package/src/router/router-interfaces.ts +70 -8
- package/src/router/router-options.ts +126 -4
- package/src/router/segment-resolution/fresh.ts +104 -80
- package/src/router/segment-resolution/helpers.ts +86 -6
- package/src/router/segment-resolution/loader-cache.ts +155 -39
- package/src/router/segment-resolution/loader-mask.ts +60 -0
- package/src/router/segment-resolution/loader-snapshot.ts +259 -0
- package/src/router/segment-resolution/mask-nested.ts +83 -0
- package/src/router/segment-resolution/revalidation.ts +215 -304
- 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 +35 -15
- 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 +54 -35
- package/src/router/telemetry-otel.ts +160 -200
- package/src/router/telemetry.ts +9 -23
- package/src/router/timeout.ts +0 -20
- package/src/router/tracing.ts +215 -0
- package/src/router/trie-matching.ts +171 -64
- package/src/router/types.ts +1 -63
- package/src/router/url-params.ts +13 -5
- package/src/router.ts +119 -48
- package/src/rsc/full-payload.ts +70 -0
- package/src/rsc/handler-context.ts +1 -0
- package/src/rsc/handler.ts +267 -152
- package/src/rsc/helpers.ts +78 -4
- package/src/rsc/index.ts +1 -4
- package/src/rsc/json-route-result.ts +38 -0
- package/src/rsc/loader-fetch.ts +114 -38
- package/src/rsc/manifest-init.ts +29 -42
- package/src/rsc/nonce.ts +10 -1
- package/src/rsc/origin-guard.ts +11 -15
- package/src/rsc/progressive-enhancement.ts +120 -13
- package/src/rsc/redirect-guard.ts +100 -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 +58 -141
- package/src/rsc/rsc-rendering.ts +492 -49
- package/src/rsc/runtime-warnings.ts +14 -0
- package/src/rsc/server-action.ts +268 -82
- package/src/rsc/shell-capture.ts +1190 -0
- package/src/rsc/shell-serve.ts +181 -0
- package/src/rsc/transition-gate.ts +89 -0
- package/src/rsc/types.ts +45 -3
- package/src/runtime-env.ts +18 -0
- package/src/search-params.ts +31 -26
- package/src/segment-loader-promise.ts +49 -4
- package/src/segment-system.tsx +260 -95
- package/src/server/context.ts +99 -9
- package/src/server/cookie-parse.ts +32 -0
- package/src/server/cookie-store.ts +125 -2
- package/src/server/handle-store.ts +21 -38
- package/src/server/loader-registry.ts +33 -42
- package/src/server/request-context.ts +379 -138
- package/src/ssr/index.tsx +491 -182
- package/src/ssr/inject-rsc-eager.ts +167 -0
- package/src/ssr/ssr-root.tsx +228 -0
- package/src/static-handler.ts +10 -13
- package/src/testing/cache-status.ts +44 -48
- package/src/testing/collect-handle.ts +14 -31
- package/src/testing/dispatch.ts +533 -160
- package/src/testing/e2e/fixture.ts +45 -11
- package/src/testing/e2e/index.ts +1 -22
- package/src/testing/e2e/matchers.ts +0 -16
- package/src/testing/e2e/parity.ts +85 -4
- package/src/testing/e2e/server.ts +12 -0
- package/src/testing/flight-matchers.ts +7 -14
- package/src/testing/flight-normalize.ts +11 -0
- package/src/testing/flight-runtime.d.ts +36 -0
- package/src/testing/flight-tree.ts +682 -0
- package/src/testing/flight.entry.ts +30 -0
- package/src/testing/flight.ts +145 -70
- package/src/testing/generated-routes.ts +26 -50
- package/src/testing/index.ts +18 -19
- package/src/testing/internal/context.ts +184 -68
- 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 +134 -115
- package/src/testing/run-loader.ts +140 -51
- package/src/testing/run-middleware.ts +59 -33
- package/src/testing/run-transition-when.ts +164 -0
- package/src/testing/vitest-stubs/cloudflare-email.ts +1 -1
- package/src/testing/vitest-stubs/cloudflare-workers.ts +1 -1
- package/src/testing/vitest.ts +138 -16
- package/src/theme/ThemeProvider.tsx +56 -84
- 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 +15 -15
- package/src/types/handler-context.ts +45 -15
- package/src/types/index.ts +2 -10
- package/src/types/loader-types.ts +6 -3
- package/src/types/request-scope.ts +8 -22
- package/src/types/route-config.ts +20 -52
- package/src/types/route-entry.ts +0 -6
- package/src/types/segments.ts +100 -13
- package/src/urls/include-helper.ts +10 -12
- package/src/urls/include-provider.ts +71 -0
- package/src/urls/index.ts +2 -8
- package/src/urls/path-helper-types.ts +52 -14
- package/src/urls/path-helper.ts +5 -54
- package/src/urls/pattern-types.ts +36 -0
- package/src/urls/type-extraction.ts +76 -42
- package/src/urls/urls-function.ts +0 -14
- package/src/use-loader.tsx +0 -186
- package/src/vercel/index.ts +11 -0
- package/src/vercel/tracing.ts +88 -0
- package/src/vite/discovery/bundle-postprocess.ts +2 -1
- package/src/vite/discovery/dev-prerender-cache.ts +117 -0
- package/src/vite/discovery/discover-routers.ts +34 -43
- package/src/vite/discovery/discovery-errors.ts +61 -0
- package/src/vite/discovery/prerender-collection.ts +33 -46
- package/src/vite/discovery/state.ts +12 -1
- package/src/vite/discovery/virtual-module-codegen.ts +1 -11
- package/src/vite/index.ts +9 -0
- package/src/vite/inject-client-debug.ts +88 -0
- package/src/vite/plugin-types.ts +143 -10
- package/src/vite/plugins/cjs-to-esm.ts +8 -12
- package/src/vite/plugins/client-ref-dedup.ts +0 -11
- package/src/vite/plugins/client-ref-hashing.ts +0 -10
- package/src/vite/plugins/cloudflare-protocol-stub.ts +0 -20
- package/src/vite/plugins/expose-action-id.ts +2 -73
- package/src/vite/plugins/expose-id-utils.ts +85 -56
- package/src/vite/plugins/expose-ids/export-analysis.ts +30 -43
- package/src/vite/plugins/expose-ids/handler-transform.ts +5 -31
- package/src/vite/plugins/expose-ids/loader-transform.ts +12 -20
- package/src/vite/plugins/expose-ids/router-transform.ts +98 -26
- package/src/vite/plugins/expose-internal-ids.ts +10 -1
- package/src/vite/plugins/performance-tracks.ts +0 -3
- package/src/vite/plugins/refresh-cmd.ts +1 -1
- package/src/vite/plugins/use-cache-transform.ts +21 -46
- package/src/vite/plugins/vercel-output.ts +384 -0
- package/src/vite/plugins/version-injector.ts +22 -27
- package/src/vite/plugins/version-plugin.ts +6 -66
- package/src/vite/plugins/virtual-entries.ts +137 -26
- package/src/vite/rango.ts +146 -135
- package/src/vite/router-discovery.ts +189 -48
- package/src/vite/utils/ast-handler-extract.ts +11 -20
- package/src/vite/utils/bundle-analysis.ts +6 -13
- package/src/vite/utils/client-chunks.ts +0 -6
- package/src/vite/utils/directive-prologue.ts +40 -0
- package/src/vite/utils/forward-user-plugins.ts +0 -22
- package/src/vite/utils/manifest-utils.ts +4 -75
- package/src/vite/utils/package-resolution.ts +1 -73
- package/src/vite/utils/prerender-utils.ts +71 -44
- package/src/vite/utils/shared-utils.ts +55 -37
- 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
|
@@ -82,11 +82,9 @@ export function useLinkStatus(): LinkStatus {
|
|
|
82
82
|
const linkTo = useContext(LinkContext);
|
|
83
83
|
const ctx = useContext(NavigationStoreContext);
|
|
84
84
|
|
|
85
|
-
// Get origin for URL normalization (stable across renders)
|
|
86
85
|
const origin =
|
|
87
86
|
typeof window !== "undefined" ? window.location.origin : "http://localhost";
|
|
88
87
|
|
|
89
|
-
// Base state for useOptimistic
|
|
90
88
|
const [basePending, setBasePending] = useState<boolean>(() => {
|
|
91
89
|
if (!ctx || linkTo === null) {
|
|
92
90
|
return false;
|
|
@@ -97,7 +95,13 @@ export function useLinkStatus(): LinkStatus {
|
|
|
97
95
|
|
|
98
96
|
const prevPending = useRef(basePending);
|
|
99
97
|
|
|
100
|
-
//
|
|
98
|
+
// Tracks whether the most recent setOptimisticPending call pinned the value
|
|
99
|
+
// to a non-idle (loading) state. Used to decide whether to emit a release
|
|
100
|
+
// update when returning to idle, so the optimistic store doesn't stay pinned
|
|
101
|
+
// to `true` if a parent transition (e.g. the <Link> click / view transition
|
|
102
|
+
// commit) is still pending. Mirrors useNavigation's optimisticPinnedRef.
|
|
103
|
+
const optimisticPinnedRef = useRef(false);
|
|
104
|
+
|
|
101
105
|
const [pending, setOptimisticPending] = useOptimistic(basePending);
|
|
102
106
|
|
|
103
107
|
useEffect(() => {
|
|
@@ -105,25 +109,46 @@ export function useLinkStatus(): LinkStatus {
|
|
|
105
109
|
return;
|
|
106
110
|
}
|
|
107
111
|
|
|
108
|
-
|
|
109
|
-
return ctx.eventController.subscribe(() => {
|
|
112
|
+
const update = () => {
|
|
110
113
|
const state = ctx.eventController.getState();
|
|
111
114
|
const isPending = isPendingFor(linkTo, state.pendingUrl, origin);
|
|
112
115
|
|
|
113
116
|
if (isPending !== prevPending.current) {
|
|
114
117
|
prevPending.current = isPending;
|
|
115
118
|
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
const shouldPin = isPending && state.state !== "idle";
|
|
120
|
+
|
|
121
|
+
if (shouldPin) {
|
|
122
|
+
// Pin the optimistic value so the spinner shows immediately even if
|
|
123
|
+
// a parent transition (e.g. <Link> click) defers the urgent
|
|
124
|
+
// setBasePending commit.
|
|
118
125
|
startTransition(() => {
|
|
119
126
|
setOptimisticPending(isPending);
|
|
120
127
|
});
|
|
128
|
+
optimisticPinnedRef.current = true;
|
|
129
|
+
} else if (optimisticPinnedRef.current) {
|
|
130
|
+
// Release a previously-pinned optimistic value. Without this,
|
|
131
|
+
// useOptimistic keeps returning the stale `true` while any parent
|
|
132
|
+
// transition is still pending, even after basePending flipped to
|
|
133
|
+
// false at navigation completion — leaving the link spinner stuck.
|
|
134
|
+
startTransition(() => {
|
|
135
|
+
setOptimisticPending(isPending);
|
|
136
|
+
});
|
|
137
|
+
optimisticPinnedRef.current = false;
|
|
121
138
|
}
|
|
122
139
|
|
|
123
140
|
// Always update base state
|
|
124
141
|
setBasePending(isPending);
|
|
125
142
|
}
|
|
126
|
-
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Catch-up: re-read state synchronously on mount before subscribing, so a
|
|
146
|
+
// navigation that started between the seeding render and this effect commit
|
|
147
|
+
// isn't dropped until the next (debounced) notify. Mirrors usePathname /
|
|
148
|
+
// useSearchParams.
|
|
149
|
+
update();
|
|
150
|
+
|
|
151
|
+
return ctx.eventController.subscribe(update);
|
|
127
152
|
}, [linkTo, origin]);
|
|
128
153
|
|
|
129
154
|
// If not inside a Link, return not pending
|
|
@@ -46,7 +46,6 @@ export function useNavigation<T>(
|
|
|
46
46
|
throw new Error("useNavigation must be used within NavigationProvider");
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
// Base state for useOptimistic
|
|
50
49
|
const [baseValue, setBaseValue] = useState<T | PublicNavigationState>(() => {
|
|
51
50
|
const publicState = toPublicState(ctx.eventController.getState());
|
|
52
51
|
return selector ? selector(publicState) : publicState;
|
|
@@ -59,7 +58,6 @@ export function useNavigation<T>(
|
|
|
59
58
|
// parent transition (e.g. <Link> click) is still pending.
|
|
60
59
|
const optimisticPinnedRef = useRef(false);
|
|
61
60
|
|
|
62
|
-
// useOptimistic allows immediate updates during transitions/actions
|
|
63
61
|
const [value, setOptimisticValue] = useOptimistic(baseValue);
|
|
64
62
|
|
|
65
63
|
// Store selector in a ref so the subscription callback always uses the
|
|
@@ -72,8 +70,7 @@ export function useNavigation<T>(
|
|
|
72
70
|
|
|
73
71
|
// Subscribe to event controller state changes (only runs on client)
|
|
74
72
|
useEffect(() => {
|
|
75
|
-
|
|
76
|
-
return ctx.eventController.subscribe(() => {
|
|
73
|
+
const update = () => {
|
|
77
74
|
const currentState = ctx.eventController.getState();
|
|
78
75
|
const publicState = toPublicState(currentState);
|
|
79
76
|
const nextSelected = selectorRef.current
|
|
@@ -112,7 +109,15 @@ export function useNavigation<T>(
|
|
|
112
109
|
// Always update base state so UI reflects current state
|
|
113
110
|
setBaseValue(nextSelected);
|
|
114
111
|
}
|
|
115
|
-
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Catch-up: re-read state synchronously on mount before subscribing, so a
|
|
115
|
+
// state change between the seeding render and this effect commit isn't
|
|
116
|
+
// dropped until the next (debounced) notify. Mirrors usePathname /
|
|
117
|
+
// useSearchParams.
|
|
118
|
+
update();
|
|
119
|
+
|
|
120
|
+
return ctx.eventController.subscribe(update);
|
|
116
121
|
}, []);
|
|
117
122
|
|
|
118
123
|
return value as T | PublicNavigationState;
|
|
@@ -50,8 +50,6 @@ export function useParams<T>(
|
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
const prevValue = useRef(value);
|
|
53
|
-
// Ref keeps the latest selector without re-subscribing. Event-driven by
|
|
54
|
-
// design: value updates on store events, not on selector identity change.
|
|
55
53
|
const selectorRef = useRef(selector);
|
|
56
54
|
selectorRef.current = selector;
|
|
57
55
|
|
|
@@ -13,9 +13,10 @@ import type { RouterInstance, RouterNavigateOptions } from "../types.js";
|
|
|
13
13
|
* useRouter() do not re-render on navigation state changes.
|
|
14
14
|
* For reactive navigation state, use useNavigation() instead.
|
|
15
15
|
*
|
|
16
|
-
* Methods read `basename` from the
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Methods read `basename` from the context on each call. It is set once from
|
|
17
|
+
* the initial payload and is stable within a session — a cross-app navigation
|
|
18
|
+
* is a full document load (X-RSC-Reload), so the target app mounts fresh with
|
|
19
|
+
* its own basename.
|
|
19
20
|
*
|
|
20
21
|
* @example
|
|
21
22
|
* ```tsx
|
|
@@ -59,7 +60,7 @@ export function useRouter(): RouterInstance {
|
|
|
59
60
|
return ctx.refresh();
|
|
60
61
|
},
|
|
61
62
|
|
|
62
|
-
prefetch(url: string): void {
|
|
63
|
+
prefetch(url: string, options?: { key?: ":source" }): void {
|
|
63
64
|
const segmentState = ctx.store?.getSegmentState();
|
|
64
65
|
if (segmentState) {
|
|
65
66
|
prefetchDirect(
|
|
@@ -67,6 +68,7 @@ export function useRouter(): RouterInstance {
|
|
|
67
68
|
segmentState.currentSegmentIds,
|
|
68
69
|
getAppVersion(),
|
|
69
70
|
ctx.store?.getRouterId?.(),
|
|
71
|
+
options?.key,
|
|
70
72
|
);
|
|
71
73
|
}
|
|
72
74
|
},
|
|
@@ -24,9 +24,6 @@ import type { ReadonlyURLSearchParams } from "../types.js";
|
|
|
24
24
|
export function useSearchParams(): ReadonlyURLSearchParams {
|
|
25
25
|
const ctx = useContext(NavigationStoreContext);
|
|
26
26
|
|
|
27
|
-
// Always initialize with empty URLSearchParams to match SSR output
|
|
28
|
-
// and avoid hydration mismatch. The useEffect below syncs from
|
|
29
|
-
// the real URL after hydration.
|
|
30
27
|
const [searchParams, setSearchParams] = useState<ReadonlyURLSearchParams>(
|
|
31
28
|
() => new URLSearchParams(),
|
|
32
29
|
);
|
|
@@ -41,12 +38,10 @@ export function useSearchParams(): ReadonlyURLSearchParams {
|
|
|
41
38
|
const nextSearch = location.searchParams.toString();
|
|
42
39
|
if (nextSearch !== prevSearch.current) {
|
|
43
40
|
prevSearch.current = nextSearch;
|
|
44
|
-
// Create a snapshot so callers cannot mutate the source URLSearchParams
|
|
45
41
|
setSearchParams(new URLSearchParams(nextSearch));
|
|
46
42
|
}
|
|
47
43
|
};
|
|
48
44
|
|
|
49
|
-
// Sync on mount (picks up search params from browser URL)
|
|
50
45
|
update();
|
|
51
46
|
|
|
52
47
|
return ctx.eventController.subscribe(update);
|
|
@@ -86,31 +86,20 @@ export function useSegments<T>(
|
|
|
86
86
|
const selectorRef = useRef(selector);
|
|
87
87
|
selectorRef.current = selector;
|
|
88
88
|
|
|
89
|
-
// Track selector identity to detect when the selector function changes.
|
|
90
|
-
// Only then do we eagerly recompute during render to avoid staleness.
|
|
91
|
-
// Without this guard, no-selector mode causes infinite re-renders because
|
|
92
|
-
// buildSegmentsState creates fresh arrays that fail Object.is checks.
|
|
93
89
|
const prevSelectorIdentity = useRef(selector);
|
|
94
90
|
|
|
95
|
-
// Cache SegmentsState to stabilize nested references (path, segmentIds
|
|
96
|
-
// arrays) so selectors returning composite values don't cause spurious
|
|
97
|
-
// render-time setState calls.
|
|
98
91
|
const segmentsCache = useRef<{
|
|
99
92
|
location: URL;
|
|
100
93
|
routeSegmentIds: string[];
|
|
101
94
|
state: SegmentsState;
|
|
102
95
|
} | null>(null);
|
|
103
96
|
|
|
104
|
-
// Recompute selected value from current store state and apply selector.
|
|
105
|
-
// Shared by the render-time eager check and the subscription callback.
|
|
106
97
|
function recompute(
|
|
107
98
|
sel: ((state: SegmentsState) => T) | undefined,
|
|
108
99
|
): T | SegmentsState {
|
|
109
100
|
const location = ctx!.eventController.getLocation();
|
|
110
101
|
const handleState = ctx!.eventController.getHandleState();
|
|
111
102
|
|
|
112
|
-
// Reuse cached state when inputs haven't changed by reference,
|
|
113
|
-
// keeping array/object references stable for composite selectors.
|
|
114
103
|
const cache = segmentsCache.current;
|
|
115
104
|
let segmentsState: SegmentsState;
|
|
116
105
|
if (
|
|
@@ -165,8 +154,6 @@ export function useSegments<T>(
|
|
|
165
154
|
unsubscribeNav();
|
|
166
155
|
unsubscribeHandles();
|
|
167
156
|
};
|
|
168
|
-
// Stable subscription: selector changes are handled via selectorRef,
|
|
169
|
-
// state comparison uses prevState ref. No re-subscribe needed.
|
|
170
157
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
171
158
|
}, []);
|
|
172
159
|
|
|
@@ -2,6 +2,16 @@ import { validateRedirectOrigin } from "./validate-redirect-origin.js";
|
|
|
2
2
|
|
|
3
3
|
type HeaderResult = { url: string } | "blocked" | null;
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Null-body statuses: the Fetch spec forbids pairing these with a body, so
|
|
7
|
+
* `new Response(body, { status })` throws ("Response with null body status
|
|
8
|
+
* cannot have body"). fetch() can still surface one WITH a body straight from
|
|
9
|
+
* the network layer (never the JS constructor): a 304 stale-while-revalidate
|
|
10
|
+
* prefetch revalidated to Not Modified (body from cache), or a 204 soft
|
|
11
|
+
* redirect. teeWithCompletion must not re-run those through `new Response`.
|
|
12
|
+
*/
|
|
13
|
+
const NULL_BODY_STATUS = new Set([101, 204, 205, 304]);
|
|
14
|
+
|
|
5
15
|
/**
|
|
6
16
|
* Extract and validate an RSC response header URL (X-RSC-Reload, X-RSC-Redirect).
|
|
7
17
|
* Returns { url } if valid, "blocked" if present but invalid origin, null if absent.
|
|
@@ -24,6 +34,26 @@ export function emptyResponse(): Response {
|
|
|
24
34
|
return new Response(null, { status: 200 });
|
|
25
35
|
}
|
|
26
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Whether an RSC content response carries a server-stamped router identity
|
|
39
|
+
* (`X-RSC-Router-Id`) that DIFFERS from the id this client expects (its own
|
|
40
|
+
* routerId, also sent as `_rsc_rid`). Pre-decode integrity check: lets a caller
|
|
41
|
+
* refuse a foreign app's payload before `createFromFetch` imports its chunks.
|
|
42
|
+
*
|
|
43
|
+
* True ONLY when both the header and the expected id are present and differ. An
|
|
44
|
+
* absent header (control-only reload/redirect responses are not stamped) or an
|
|
45
|
+
* absent expected id (e.g. before the client is seeded) is a pass-through —
|
|
46
|
+
* never a false reject.
|
|
47
|
+
*/
|
|
48
|
+
export function isForeignRouterId(
|
|
49
|
+
response: Response,
|
|
50
|
+
expectedId: string | undefined,
|
|
51
|
+
): boolean {
|
|
52
|
+
const got = response.headers.get("X-RSC-Router-Id");
|
|
53
|
+
if (!got || !expectedId) return false;
|
|
54
|
+
return got !== expectedId;
|
|
55
|
+
}
|
|
56
|
+
|
|
27
57
|
/**
|
|
28
58
|
* Handle the X-RSC-Reload control header (server requests a full page reload on
|
|
29
59
|
* a version mismatch). Returns a short-circuit response when the header is
|
|
@@ -54,16 +84,42 @@ export function handleReloadHeader(
|
|
|
54
84
|
* Returns a new Response with one branch; the other is consumed to detect
|
|
55
85
|
* end-of-stream, calling onComplete when done.
|
|
56
86
|
*
|
|
57
|
-
*
|
|
87
|
+
* `onComplete` receives `endedCleanly`: true only on a normal EOF drain, false
|
|
88
|
+
* on a read error or an abort (the signal cancelled the reader). Callers that
|
|
89
|
+
* gate a "fully complete" fast path (e.g. prefetch's `entry.complete`) must
|
|
90
|
+
* treat a non-clean end as incomplete — a broken stream is not complete data.
|
|
91
|
+
*
|
|
92
|
+
* If the response has no body, onComplete fires synchronously with `true`
|
|
93
|
+
* (an empty body is a clean, complete stream).
|
|
58
94
|
* If signal is provided, an abort cancels the tracking reader.
|
|
95
|
+
*
|
|
96
|
+
* `silent` suppresses the stream-error log. Prefetch passes it: a speculative,
|
|
97
|
+
* low-priority prefetch that is aborted or never consumed can error its stream
|
|
98
|
+
* benignly, which is not worth surfacing. The fresh-navigation path keeps the
|
|
99
|
+
* log (default), where a stream error reflects a real failed navigation.
|
|
59
100
|
*/
|
|
60
101
|
export function teeWithCompletion(
|
|
61
102
|
response: Response,
|
|
62
|
-
onComplete: () => void,
|
|
103
|
+
onComplete: (endedCleanly: boolean) => void,
|
|
63
104
|
signal?: AbortSignal,
|
|
105
|
+
silent = false,
|
|
64
106
|
): Response {
|
|
65
|
-
|
|
66
|
-
|
|
107
|
+
// Once-guard: a mid-stream read error runs both the finally block and the
|
|
108
|
+
// rejection's .catch, so onComplete must be settled exactly once across all
|
|
109
|
+
// paths (no-body early return, finally, catch).
|
|
110
|
+
let settled = false;
|
|
111
|
+
const settle = (endedCleanly: boolean) => {
|
|
112
|
+
if (!settled) {
|
|
113
|
+
settled = true;
|
|
114
|
+
onComplete(endedCleanly);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Empty body, or a null-body status fetch() paired with a body: either way the
|
|
119
|
+
// body can't be re-attached via `new Response` below. Settle and pass the
|
|
120
|
+
// original response through; its body (when present) stays readable downstream.
|
|
121
|
+
if (!response.body || NULL_BODY_STATUS.has(response.status)) {
|
|
122
|
+
settle(true);
|
|
67
123
|
return response;
|
|
68
124
|
}
|
|
69
125
|
|
|
@@ -73,21 +129,31 @@ export function teeWithCompletion(
|
|
|
73
129
|
const reader = trackingStream.getReader();
|
|
74
130
|
const onAbort = signal ? reader.cancel.bind(reader) : undefined;
|
|
75
131
|
if (onAbort) signal!.addEventListener("abort", onAbort, { once: true });
|
|
132
|
+
// Only a loop that reaches `done` is a clean EOF. A read error rejects out
|
|
133
|
+
// of the try and still runs the finally, so the finally must NOT assume
|
|
134
|
+
// clean — it gates on this flag (false on error) AND on signal.aborted
|
|
135
|
+
// (an abort cancels the reader so read() resolves { done: true } and the
|
|
136
|
+
// loop breaks here normally, NOT in the .catch — re-check the signal to
|
|
137
|
+
// catch that case).
|
|
138
|
+
let cleanEof = false;
|
|
76
139
|
try {
|
|
77
140
|
while (true) {
|
|
78
141
|
const { done } = await reader.read();
|
|
79
|
-
if (done)
|
|
142
|
+
if (done) {
|
|
143
|
+
cleanEof = true;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
80
146
|
}
|
|
81
147
|
} finally {
|
|
82
148
|
if (onAbort) signal!.removeEventListener("abort", onAbort);
|
|
83
149
|
reader.releaseLock();
|
|
84
|
-
|
|
150
|
+
settle(cleanEof && !signal?.aborted);
|
|
85
151
|
}
|
|
86
152
|
})().catch((error) => {
|
|
87
|
-
if (!signal?.aborted) {
|
|
153
|
+
if (!silent && !signal?.aborted) {
|
|
88
154
|
console.error("[Browser] Error reading tracking stream:", error);
|
|
89
155
|
}
|
|
90
|
-
|
|
156
|
+
settle(false);
|
|
91
157
|
});
|
|
92
158
|
|
|
93
159
|
return new Response(rscStream, {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
generateHistoryKey,
|
|
9
9
|
} from "./navigation-store.js";
|
|
10
10
|
import { createEventController } from "./event-controller.js";
|
|
11
|
+
import { validateRedirectOrigin } from "./validate-redirect-origin.js";
|
|
11
12
|
import { createNavigationClient } from "./navigation-client.js";
|
|
12
13
|
import { createServerActionBridge } from "./server-action-bridge.js";
|
|
13
14
|
import { createNavigationBridge } from "./navigation-bridge.js";
|
|
@@ -22,13 +23,17 @@ import type {
|
|
|
22
23
|
import type { EventController } from "./event-controller.js";
|
|
23
24
|
import type { ResolvedThemeConfig, Theme } from "../theme/types.js";
|
|
24
25
|
import { initRangoState } from "./rango-state.js";
|
|
26
|
+
import { registerNavigationStore } from "./navigation-store-handle.js";
|
|
25
27
|
import { initPrefetchCache } from "./prefetch/cache.js";
|
|
28
|
+
import { setPrefetchConcurrency } from "./prefetch/queue.js";
|
|
29
|
+
import { setPrefetchDecoder } from "./prefetch/fetch.js";
|
|
26
30
|
import { setAppVersion } from "./app-version.js";
|
|
27
31
|
import {
|
|
28
32
|
isInterceptSegment,
|
|
29
33
|
splitInterceptSegments,
|
|
30
34
|
} from "./intercept-utils.js";
|
|
31
35
|
import { createAppShellRef } from "./app-shell.js";
|
|
36
|
+
import { bootLog, IS_BROWSER_DEBUG } from "./logging.js";
|
|
32
37
|
|
|
33
38
|
// Vite HMR types are provided by vite/client
|
|
34
39
|
|
|
@@ -113,13 +118,17 @@ export interface BrowserAppContext {
|
|
|
113
118
|
initialTheme?: Theme;
|
|
114
119
|
/** Whether connection warmup is enabled */
|
|
115
120
|
warmupEnabled?: boolean;
|
|
121
|
+
/** Whether the hydrated tree should be wrapped in React.StrictMode */
|
|
122
|
+
strictMode?: boolean;
|
|
116
123
|
/** App version for prefetch version mismatch detection */
|
|
117
124
|
version?: string;
|
|
118
125
|
/**
|
|
119
|
-
*
|
|
120
|
-
* NavigationProvider
|
|
121
|
-
*
|
|
122
|
-
*
|
|
126
|
+
* App-shell ref, read through on each render so renderSegments and the
|
|
127
|
+
* NavigationProvider see rootLayout/basename/version without closing over a
|
|
128
|
+
* stale snapshot. Set once from the initial payload and not swapped within a
|
|
129
|
+
* session: a cross-app navigation is a full document load (X-RSC-Reload), so
|
|
130
|
+
* the target app establishes its own shell on load. Theme, warmup, and
|
|
131
|
+
* prefetch TTL are document-lifetime too (see AppShell).
|
|
123
132
|
*/
|
|
124
133
|
appShellRef?: import("./app-shell.js").AppShellRef;
|
|
125
134
|
}
|
|
@@ -148,6 +157,8 @@ export async function initBrowserApp(
|
|
|
148
157
|
initialTheme,
|
|
149
158
|
} = options;
|
|
150
159
|
|
|
160
|
+
bootLog("initBrowserApp start");
|
|
161
|
+
bootLog("flight decode: awaiting initial payload from document stream");
|
|
151
162
|
const initialPayload =
|
|
152
163
|
await deps.createFromReadableStream<RscPayload>(rscStream);
|
|
153
164
|
|
|
@@ -161,6 +172,14 @@ export async function initBrowserApp(
|
|
|
161
172
|
// Get initial segments and compute history key from current URL
|
|
162
173
|
const initialSegments = (initialPayload.metadata?.segments ??
|
|
163
174
|
[]) as ResolvedSegment[];
|
|
175
|
+
if (IS_BROWSER_DEBUG) {
|
|
176
|
+
bootLog("initial payload decoded", {
|
|
177
|
+
version: initialPayload.metadata?.version,
|
|
178
|
+
routerId: initialPayload.metadata?.routerId,
|
|
179
|
+
segments: initialSegments.map((s) => s.id),
|
|
180
|
+
matched: initialPayload.metadata?.matched,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
164
183
|
const initialHistoryKey = generateHistoryKey(window.location.href);
|
|
165
184
|
|
|
166
185
|
// Create navigation store with history-based caching
|
|
@@ -172,6 +191,12 @@ export async function initBrowserApp(
|
|
|
172
191
|
...(storeOptions?.cacheSize && { cacheSize: storeOptions.cacheSize }),
|
|
173
192
|
});
|
|
174
193
|
|
|
194
|
+
// Register the active store on the module-level handle and wire the
|
|
195
|
+
// jar-divergence observer before any getRangoState() read can detect a
|
|
196
|
+
// cross-tab/server rotation. There is no global store singleton, so this
|
|
197
|
+
// handle is the live reference.
|
|
198
|
+
registerNavigationStore(store);
|
|
199
|
+
|
|
175
200
|
// Seed router identity from the initial SSR payload so the first
|
|
176
201
|
// cross-app SPA navigation can detect the app switch.
|
|
177
202
|
if (initialPayload.metadata?.routerId) {
|
|
@@ -193,11 +218,24 @@ export async function initBrowserApp(
|
|
|
193
218
|
// This ensures useHandle returns correct data during hydration to avoid mismatch
|
|
194
219
|
// The handles property is an async generator that yields on each push
|
|
195
220
|
if (initialPayload.metadata?.handles) {
|
|
221
|
+
// This for-await consumes the handle generator to completion BEFORE
|
|
222
|
+
// hydrateRoot is called — on a streaming/PPR document the generator only
|
|
223
|
+
// ends when its stream side does, so the per-push logs below are the
|
|
224
|
+
// primary probe for "the document render is holding hydration".
|
|
225
|
+
bootLog("handles: consuming payload handle stream (pre-hydration await)");
|
|
196
226
|
const handlesGenerator = initialPayload.metadata.handles;
|
|
197
227
|
let lastHandleData: Record<string, Record<string, unknown[]>> = {};
|
|
228
|
+
let handlePushes = 0;
|
|
198
229
|
for await (const handleData of handlesGenerator) {
|
|
199
230
|
lastHandleData = handleData;
|
|
231
|
+
if (IS_BROWSER_DEBUG) {
|
|
232
|
+
handlePushes += 1;
|
|
233
|
+
bootLog(`handles: push #${handlePushes}`, {
|
|
234
|
+
segments: Object.keys(handleData),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
200
237
|
}
|
|
238
|
+
bootLog("handles: stream complete", { pushes: handlePushes });
|
|
201
239
|
// Initialize event controller with initial handle state before hydration.
|
|
202
240
|
eventController.setHandleData(
|
|
203
241
|
lastHandleData,
|
|
@@ -207,16 +245,18 @@ export async function initBrowserApp(
|
|
|
207
245
|
// Update the initial cache entry with the processed handleData
|
|
208
246
|
// The cache entry was created by createNavigationStore but without handleData
|
|
209
247
|
store.updateCacheHandleData(initialHistoryKey, lastHandleData);
|
|
248
|
+
} else {
|
|
249
|
+
bootLog("handles: none in payload");
|
|
210
250
|
}
|
|
211
251
|
|
|
212
252
|
// Create composable utilities
|
|
213
253
|
const client = createNavigationClient(deps);
|
|
214
254
|
|
|
215
|
-
// Capture the per-router app-shell
|
|
216
|
-
//
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
//
|
|
255
|
+
// Capture the per-router app-shell. rootLayout, basename, and version live
|
|
256
|
+
// here and are read through the ref at call time rather than closed over.
|
|
257
|
+
// It is set once from the initial payload and not swapped within a session:
|
|
258
|
+
// a cross-app navigation is a full document load (X-RSC-Reload), so the
|
|
259
|
+
// target app establishes its own shell on load.
|
|
220
260
|
const version = initialPayload.metadata?.version;
|
|
221
261
|
const appShellRef = createAppShellRef({
|
|
222
262
|
routerId: initialPayload.metadata?.routerId,
|
|
@@ -225,22 +265,34 @@ export async function initBrowserApp(
|
|
|
225
265
|
version,
|
|
226
266
|
});
|
|
227
267
|
|
|
228
|
-
// Initialize the
|
|
229
|
-
//
|
|
230
|
-
// namespaces the
|
|
231
|
-
|
|
268
|
+
// Initialize the rango state cookie for cache invalidation. The build version
|
|
269
|
+
// busts cached prefetches on deploy; the server-resolved cookie name
|
|
270
|
+
// namespaces the cookie so sibling apps on the same origin don't collide
|
|
271
|
+
// (falls back to the bare default prefix if metadata lacks the name).
|
|
272
|
+
initRangoState(version ?? "0", initialPayload.metadata?.stateCookieName);
|
|
232
273
|
setAppVersion(version);
|
|
233
274
|
|
|
234
|
-
// Initialize the in-memory prefetch cache TTL
|
|
235
|
-
// A
|
|
275
|
+
// Initialize the in-memory prefetch cache (TTL + max size) and the prefetch
|
|
276
|
+
// queue concurrency from server config. A TTL of 0 disables the cache;
|
|
277
|
+
// undefined values fall back to the module defaults.
|
|
236
278
|
const prefetchCacheTTL = initialPayload.metadata?.prefetchCacheTTL;
|
|
237
|
-
|
|
238
|
-
|
|
279
|
+
const prefetchCacheSize = initialPayload.metadata?.prefetchCacheSize;
|
|
280
|
+
if (prefetchCacheTTL !== undefined || prefetchCacheSize !== undefined) {
|
|
281
|
+
initPrefetchCache(prefetchCacheTTL, prefetchCacheSize);
|
|
282
|
+
}
|
|
283
|
+
const prefetchConcurrency = initialPayload.metadata?.prefetchConcurrency;
|
|
284
|
+
if (prefetchConcurrency !== undefined) {
|
|
285
|
+
setPrefetchConcurrency(prefetchConcurrency);
|
|
239
286
|
}
|
|
240
287
|
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
|
|
288
|
+
// Wire the RSC decoder so prefetches decode eagerly and warm the route's
|
|
289
|
+
// client chunks (same createFromFetch the navigation client uses).
|
|
290
|
+
setPrefetchDecoder((response) => deps.createFromFetch<RscPayload>(response));
|
|
291
|
+
|
|
292
|
+
// Create a bound renderSegments that reads rootLayout through the shell ref.
|
|
293
|
+
// The shell is set once at init and not swapped within a session (a cross-app
|
|
294
|
+
// navigation is a full document load), so this always renders this app's
|
|
295
|
+
// Document; reading through the ref just avoids closing over a stale value.
|
|
244
296
|
const renderSegments = (
|
|
245
297
|
segments: ResolvedSegment[],
|
|
246
298
|
options?: RenderSegmentsOptions,
|
|
@@ -264,7 +316,13 @@ export async function initBrowserApp(
|
|
|
264
316
|
renderSegments,
|
|
265
317
|
onNavigate: (url, options) => {
|
|
266
318
|
if (!navigateFn) {
|
|
267
|
-
|
|
319
|
+
// Navigation bridge not wired yet: hard-navigate, but re-validate
|
|
320
|
+
// same-origin defensively so this init-window fallback cannot become an
|
|
321
|
+
// open redirect (the normal path validates inside the navigation bridge).
|
|
322
|
+
const safe = validateRedirectOrigin(url, window.location.origin);
|
|
323
|
+
if (safe) {
|
|
324
|
+
window.location.href = safe;
|
|
325
|
+
}
|
|
268
326
|
return Promise.resolve();
|
|
269
327
|
}
|
|
270
328
|
return navigateFn(url, options);
|
|
@@ -280,7 +338,6 @@ export async function initBrowserApp(
|
|
|
280
338
|
onUpdate: (update) => store.emitUpdate(update),
|
|
281
339
|
renderSegments,
|
|
282
340
|
version: version,
|
|
283
|
-
appShellRef,
|
|
284
341
|
});
|
|
285
342
|
|
|
286
343
|
// Connect action redirect → navigation bridge (now that both are initialized)
|
|
@@ -290,9 +347,17 @@ export async function initBrowserApp(
|
|
|
290
347
|
if (linkInterception) {
|
|
291
348
|
navigationBridge.registerLinkInterception();
|
|
292
349
|
}
|
|
350
|
+
bootLog("bridges registered (action + navigation)");
|
|
293
351
|
|
|
294
352
|
// Build initial tree with rootLayout
|
|
353
|
+
bootLog("building initial segment tree (renderSegments)");
|
|
295
354
|
const initialTree = renderSegments(initialPayload.metadata!.segments);
|
|
355
|
+
if (IS_BROWSER_DEBUG && initialTree instanceof Promise) {
|
|
356
|
+
initialTree.then(
|
|
357
|
+
() => bootLog("initial segment tree settled"),
|
|
358
|
+
(err: unknown) => bootLog("initial segment tree rejected", { err }),
|
|
359
|
+
);
|
|
360
|
+
}
|
|
296
361
|
|
|
297
362
|
// Setup HMR with debounce — burst saves (format-on-save, rapid edits)
|
|
298
363
|
// fire many rsc:update events in quick succession. Without debouncing,
|
|
@@ -454,14 +519,20 @@ export async function initBrowserApp(
|
|
|
454
519
|
themeConfig: effectiveThemeConfig,
|
|
455
520
|
initialTheme: effectiveInitialTheme,
|
|
456
521
|
warmupEnabled: initialPayload.metadata?.warmupEnabled ?? true,
|
|
522
|
+
strictMode: initialPayload.metadata?.strictMode ?? true,
|
|
457
523
|
version,
|
|
458
524
|
appShellRef,
|
|
459
525
|
};
|
|
460
526
|
browserAppContext = context;
|
|
461
527
|
|
|
528
|
+
bootLog("initBrowserApp complete -- handing off to hydrateRoot");
|
|
462
529
|
return context;
|
|
463
530
|
}
|
|
464
531
|
|
|
532
|
+
// Once-flag so the hydration-commit boot log fires a single time (StrictMode
|
|
533
|
+
// re-runs the root effect; the second flush is not a second hydration).
|
|
534
|
+
let hydrationCommitLogged = false;
|
|
535
|
+
|
|
465
536
|
/**
|
|
466
537
|
* Get the browser app context. Throws if initBrowserApp hasn't been called.
|
|
467
538
|
*/
|
|
@@ -529,6 +600,10 @@ export function Rango(_props: RangoProps): React.ReactElement {
|
|
|
529
600
|
// that does not depend on React internals like __reactFiber.
|
|
530
601
|
React.useEffect(() => {
|
|
531
602
|
document.documentElement.dataset.hydrated = "";
|
|
603
|
+
if (IS_BROWSER_DEBUG && !hydrationCommitLogged) {
|
|
604
|
+
hydrationCommitLogged = true;
|
|
605
|
+
bootLog("hydration commit (root effect flushed)");
|
|
606
|
+
}
|
|
532
607
|
}, []);
|
|
533
608
|
|
|
534
609
|
return (
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* - Supports hash link scrolling
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { debugLog } from "./logging.js";
|
|
11
|
+
import { debugLog, IS_BROWSER_DEBUG } from "./logging.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Defers a callback to the next animation frame.
|
|
@@ -150,10 +150,12 @@ export function initScrollRestoration(options?: {
|
|
|
150
150
|
|
|
151
151
|
window.addEventListener("pagehide", handlePageHide);
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
if (IS_BROWSER_DEBUG) {
|
|
154
|
+
debugLog(
|
|
155
|
+
"[Scroll] Initialized, loaded positions:",
|
|
156
|
+
Object.keys(savedScrollPositions).length,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
157
159
|
|
|
158
160
|
return () => {
|
|
159
161
|
cancelScrollRestorationPolling();
|
|
@@ -191,10 +193,15 @@ export function saveCurrentScrollPosition(): void {
|
|
|
191
193
|
|
|
192
194
|
/**
|
|
193
195
|
* Persist scroll positions to sessionStorage.
|
|
194
|
-
* If the write fails
|
|
195
|
-
* entries and retry
|
|
196
|
+
* If the write fails (typically QuotaExceededError), evict the oldest ~1/4 of
|
|
197
|
+
* entries ONCE and retry the write a single time; if that still fails, remove
|
|
198
|
+
* our storage key entirely so we don't block other sessionStorage consumers.
|
|
199
|
+
* This is a single evict-then-retry-then-clear ladder, not a loop.
|
|
200
|
+
*
|
|
201
|
+
* Exported so that single eviction/retry/clear ladder is unit-testable directly.
|
|
202
|
+
* The browser drives it from the `pagehide` handler.
|
|
196
203
|
*/
|
|
197
|
-
function persistToSessionStorage(): void {
|
|
204
|
+
export function persistToSessionStorage(): void {
|
|
198
205
|
try {
|
|
199
206
|
sessionStorage.setItem(
|
|
200
207
|
SCROLL_STORAGE_KEY,
|