vinext 0.0.30 → 0.0.32
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 +15 -7
- package/dist/build/prerender.d.ts +188 -0
- package/dist/build/prerender.js +675 -0
- package/dist/build/prerender.js.map +1 -0
- package/dist/build/report.d.ts +45 -46
- package/dist/build/report.js +581 -276
- package/dist/build/report.js.map +1 -1
- package/dist/build/run-prerender.d.ts +62 -0
- package/dist/build/run-prerender.js +183 -0
- package/dist/build/run-prerender.js.map +1 -0
- package/dist/build/server-manifest.d.ts +19 -0
- package/dist/build/server-manifest.js +29 -0
- package/dist/build/server-manifest.js.map +1 -0
- package/dist/build/static-export.d.ts +51 -66
- package/dist/build/static-export.js +51 -545
- package/dist/build/static-export.js.map +1 -1
- package/dist/check.d.ts +26 -24
- package/dist/check.js +681 -571
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +1 -15
- package/dist/cli.js +432 -491
- package/dist/cli.js.map +1 -1
- package/dist/client/entry.d.ts +1 -2
- package/dist/client/entry.js +49 -62
- package/dist/client/entry.js.map +1 -1
- package/dist/client/validate-module-path.d.ts +4 -1
- package/dist/client/validate-module-path.js +23 -28
- package/dist/client/validate-module-path.js.map +1 -1
- package/dist/client/vinext-next-data.d.ts +15 -20
- package/dist/client/vinext-next-data.js +0 -1
- package/dist/cloudflare/index.d.ts +3 -8
- package/dist/cloudflare/index.js +3 -8
- package/dist/cloudflare/kv-cache-handler.d.ts +95 -105
- package/dist/cloudflare/kv-cache-handler.js +354 -380
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.d.ts +36 -34
- package/dist/cloudflare/tpr.js +460 -603
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/config-matchers.d.ts +31 -40
- package/dist/config/config-matchers.js +727 -936
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/dotenv.d.ts +18 -11
- package/dist/config/dotenv.js +79 -84
- package/dist/config/dotenv.js.map +1 -1
- package/dist/config/next-config.d.ts +156 -146
- package/dist/config/next-config.js +376 -464
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.d.ts +87 -96
- package/dist/deploy.js +490 -628
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.d.ts +4 -1
- package/dist/entries/app-browser-entry.js +12 -8
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +33 -20
- package/dist/entries/app-rsc-entry.js +444 -212
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-ssr-entry.d.ts +9 -1
- package/dist/entries/app-ssr-entry.js +61 -28
- package/dist/entries/app-ssr-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.d.ts +6 -2
- package/dist/entries/pages-client-entry.js +30 -33
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-entry-helpers.d.ts +5 -1
- package/dist/entries/pages-entry-helpers.js +17 -14
- package/dist/entries/pages-entry-helpers.js.map +1 -1
- package/dist/entries/pages-server-entry.d.ts +6 -2
- package/dist/entries/pages-server-entry.js +86 -114
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.d.ts +92 -60
- package/dist/index.js +2151 -3133
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +40 -37
- package/dist/init.js +201 -258
- package/dist/init.js.map +1 -1
- package/dist/plugins/async-hooks-stub.d.ts +7 -3
- package/dist/plugins/async-hooks-stub.js +39 -42
- package/dist/plugins/async-hooks-stub.js.map +1 -1
- package/dist/plugins/client-reference-dedup.d.ts +7 -3
- package/dist/plugins/client-reference-dedup.js +63 -88
- package/dist/plugins/client-reference-dedup.js.map +1 -1
- package/dist/routing/app-router.d.ts +100 -96
- package/dist/routing/app-router.js +560 -670
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +18 -15
- package/dist/routing/file-matcher.js +65 -65
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/pages-router.d.ts +23 -24
- package/dist/routing/pages-router.js +147 -172
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/route-trie.d.ts +23 -20
- package/dist/routing/route-trie.js +131 -151
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/route-validation.d.ts +5 -2
- package/dist/routing/route-validation.js +98 -130
- package/dist/routing/route-validation.js.map +1 -1
- package/dist/routing/utils.d.ts +10 -7
- package/dist/routing/utils.js +75 -111
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.d.ts +8 -13
- package/dist/server/api-handler.js +160 -193
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-router-entry.d.ts +6 -16
- package/dist/server/app-router-entry.js +26 -54
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/dev-module-runner.d.ts +11 -64
- package/dist/server/dev-module-runner.js +89 -101
- package/dist/server/dev-module-runner.js.map +1 -1
- package/dist/server/dev-origin-check.d.ts +12 -10
- package/dist/server/dev-origin-check.js +98 -108
- package/dist/server/dev-origin-check.js.map +1 -1
- package/dist/server/dev-server.d.ts +19 -15
- package/dist/server/dev-server.js +543 -871
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/html.d.ts +4 -1
- package/dist/server/html.js +25 -26
- package/dist/server/html.js.map +1 -1
- package/dist/server/image-optimization.d.ts +31 -28
- package/dist/server/image-optimization.js +181 -210
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/instrumentation.d.ts +34 -59
- package/dist/server/instrumentation.js +112 -125
- package/dist/server/instrumentation.js.map +1 -1
- package/dist/server/isr-cache.d.ts +16 -26
- package/dist/server/isr-cache.js +106 -128
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/metadata-routes.d.ts +85 -88
- package/dist/server/metadata-routes.js +270 -317
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-codegen.d.ts +7 -4
- package/dist/server/middleware-codegen.js +61 -61
- package/dist/server/middleware-codegen.js.map +1 -1
- package/dist/server/middleware-request-headers.d.ts +8 -6
- package/dist/server/middleware-request-headers.js +47 -65
- package/dist/server/middleware-request-headers.js.map +1 -1
- package/dist/server/middleware.d.ts +32 -47
- package/dist/server/middleware.js +261 -409
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/normalize-path.d.ts +4 -1
- package/dist/server/normalize-path.js +33 -47
- package/dist/server/normalize-path.js.map +1 -1
- package/dist/server/pages-i18n.d.ts +38 -30
- package/dist/server/pages-i18n.js +112 -139
- package/dist/server/pages-i18n.js.map +1 -1
- package/dist/server/prod-server.d.ts +19 -31
- package/dist/server/prod-server.js +715 -945
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-log.d.ts +18 -12
- package/dist/server/request-log.js +45 -52
- package/dist/server/request-log.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +9 -17
- package/dist/server/request-pipeline.js +133 -184
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/worker-utils.d.ts +4 -1
- package/dist/server/worker-utils.js +31 -37
- package/dist/server/worker-utils.js.map +1 -1
- package/dist/shims/amp.d.ts +5 -2
- package/dist/shims/amp.js +19 -15
- package/dist/shims/amp.js.map +1 -1
- package/dist/shims/app.d.ts +8 -10
- package/dist/shims/app.js +0 -1
- package/dist/shims/cache-runtime.d.ts +20 -45
- package/dist/shims/cache-runtime.js +271 -422
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +130 -121
- package/dist/shims/cache.js +339 -427
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/client-only.d.ts +1 -18
- package/dist/shims/client-only.js +0 -17
- package/dist/shims/compat-router.d.ts +6 -1
- package/dist/shims/compat-router.js +23 -19
- package/dist/shims/compat-router.js.map +1 -1
- package/dist/shims/config.d.ts +7 -5
- package/dist/shims/config.js +16 -23
- package/dist/shims/config.js.map +1 -1
- package/dist/shims/constants.d.ts +119 -118
- package/dist/shims/constants.js +159 -164
- package/dist/shims/constants.js.map +1 -1
- package/dist/shims/document.d.ts +20 -16
- package/dist/shims/document.js +41 -22
- package/dist/shims/document.js.map +1 -1
- package/dist/shims/dynamic.d.ts +13 -22
- package/dist/shims/dynamic.js +122 -136
- package/dist/shims/dynamic.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +22 -15
- package/dist/shims/error-boundary.js +81 -79
- package/dist/shims/error-boundary.js.map +1 -1
- package/dist/shims/error.d.ts +11 -12
- package/dist/shims/error.js +35 -39
- package/dist/shims/error.js.map +1 -1
- package/dist/shims/fetch-cache.d.ts +16 -14
- package/dist/shims/fetch-cache.js +439 -645
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/font-google-base.d.ts +28 -26
- package/dist/shims/font-google-base.js +238 -325
- package/dist/shims/font-google-base.js.map +1 -1
- package/dist/shims/font-google.d.ts +3 -3
- package/dist/shims/font-google.generated.d.ts +1928 -1924
- package/dist/shims/font-google.generated.js +1928 -2133
- package/dist/shims/font-google.generated.js.map +1 -1
- package/dist/shims/font-google.js +3 -3
- package/dist/shims/font-local.d.ts +28 -26
- package/dist/shims/font-local.js +204 -260
- package/dist/shims/font-local.js.map +1 -1
- package/dist/shims/form.d.ts +13 -27
- package/dist/shims/form.js +128 -180
- package/dist/shims/form.js.map +1 -1
- package/dist/shims/head-state.d.ts +8 -13
- package/dist/shims/head-state.js +25 -42
- package/dist/shims/head-state.js.map +1 -1
- package/dist/shims/head.d.ts +17 -20
- package/dist/shims/head.js +194 -250
- package/dist/shims/head.js.map +1 -1
- package/dist/shims/headers.d.ts +84 -78
- package/dist/shims/headers.js +447 -575
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/i18n-context.d.ts +16 -20
- package/dist/shims/i18n-context.js +35 -48
- package/dist/shims/i18n-context.js.map +1 -1
- package/dist/shims/i18n-state.d.ts +8 -14
- package/dist/shims/i18n-state.js +34 -42
- package/dist/shims/i18n-state.js.map +1 -1
- package/dist/shims/image-config.d.ts +11 -8
- package/dist/shims/image-config.js +50 -83
- package/dist/shims/image-config.js.map +1 -1
- package/dist/shims/image.d.ts +37 -46
- package/dist/shims/image.js +283 -308
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/api-utils.d.ts +7 -4
- package/dist/shims/internal/api-utils.js +0 -6
- package/dist/shims/internal/app-router-context.d.ts +22 -17
- package/dist/shims/internal/app-router-context.js +17 -13
- package/dist/shims/internal/app-router-context.js.map +1 -1
- package/dist/shims/internal/cookies.d.ts +2 -9
- package/dist/shims/internal/cookies.js +2 -9
- package/dist/shims/internal/parse-cookie-header.d.ts +4 -1
- package/dist/shims/internal/parse-cookie-header.js +29 -29
- package/dist/shims/internal/parse-cookie-header.js.map +1 -1
- package/dist/shims/internal/router-context.d.ts +7 -1
- package/dist/shims/internal/router-context.js +11 -7
- package/dist/shims/internal/router-context.js.map +1 -1
- package/dist/shims/internal/utils.d.ts +40 -37
- package/dist/shims/internal/utils.js +24 -30
- package/dist/shims/internal/utils.js.map +1 -1
- package/dist/shims/internal/work-unit-async-storage.d.ts +6 -10
- package/dist/shims/internal/work-unit-async-storage.js +14 -11
- package/dist/shims/internal/work-unit-async-storage.js.map +1 -1
- package/dist/shims/layout-segment-context.d.ts +11 -14
- package/dist/shims/layout-segment-context.js +24 -23
- package/dist/shims/layout-segment-context.js.map +1 -1
- package/dist/shims/legacy-image.d.ts +39 -46
- package/dist/shims/legacy-image.js +47 -42
- package/dist/shims/legacy-image.js.map +1 -1
- package/dist/shims/link.d.ts +32 -36
- package/dist/shims/link.js +255 -391
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +210 -202
- package/dist/shims/metadata.js +545 -546
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation-state.d.ts +10 -18
- package/dist/shims/navigation-state.js +66 -74
- package/dist/shims/navigation-state.js.map +1 -1
- package/dist/shims/navigation.d.ts +59 -63
- package/dist/shims/navigation.js +505 -704
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/og.d.ts +2 -20
- package/dist/shims/og.js +2 -19
- package/dist/shims/readonly-url-search-params.d.ts +8 -5
- package/dist/shims/readonly-url-search-params.js +26 -22
- package/dist/shims/readonly-url-search-params.js.map +1 -1
- package/dist/shims/request-context.d.ts +8 -5
- package/dist/shims/request-context.js +50 -60
- package/dist/shims/request-context.js.map +1 -1
- package/dist/shims/request-state-types.d.ts +11 -11
- package/dist/shims/request-state-types.js +0 -1
- package/dist/shims/router-state.d.ts +13 -10
- package/dist/shims/router-state.js +34 -43
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.d.ts +81 -85
- package/dist/shims/router.js +506 -628
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.d.ts +39 -48
- package/dist/shims/script.js +107 -160
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server-only.d.ts +1 -19
- package/dist/shims/server-only.js +0 -18
- package/dist/shims/server.d.ts +213 -164
- package/dist/shims/server.js +545 -478
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +20 -20
- package/dist/shims/unified-request-context.js +81 -99
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/shims/url-safety.d.ts +4 -1
- package/dist/shims/url-safety.js +15 -11
- package/dist/shims/url-safety.js.map +1 -1
- package/dist/shims/url-utils.d.ts +8 -5
- package/dist/shims/url-utils.js +62 -93
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/shims/web-vitals.d.ts +10 -8
- package/dist/shims/web-vitals.js +9 -15
- package/dist/shims/web-vitals.js.map +1 -1
- package/dist/utils/base-path.d.ts +5 -2
- package/dist/utils/base-path.js +21 -19
- package/dist/utils/base-path.js.map +1 -1
- package/dist/utils/domain-locale.d.ts +17 -9
- package/dist/utils/domain-locale.js +36 -56
- package/dist/utils/domain-locale.js.map +1 -1
- package/dist/utils/hash.d.ts +4 -1
- package/dist/utils/hash.js +19 -17
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/manifest-paths.d.ts +6 -3
- package/dist/utils/manifest-paths.js +15 -16
- package/dist/utils/manifest-paths.js.map +1 -1
- package/dist/utils/project.d.ts +13 -11
- package/dist/utils/project.js +169 -216
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/query.d.ts +8 -6
- package/dist/utils/query.js +57 -67
- package/dist/utils/query.js.map +1 -1
- package/package.json +10 -9
- package/dist/build/report.d.ts.map +0 -1
- package/dist/build/static-export.d.ts.map +0 -1
- package/dist/check.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/client/entry.d.ts.map +0 -1
- package/dist/client/validate-module-path.d.ts.map +0 -1
- package/dist/client/vinext-next-data.d.ts.map +0 -1
- package/dist/client/vinext-next-data.js.map +0 -1
- package/dist/cloudflare/index.d.ts.map +0 -1
- package/dist/cloudflare/index.js.map +0 -1
- package/dist/cloudflare/kv-cache-handler.d.ts.map +0 -1
- package/dist/cloudflare/tpr.d.ts.map +0 -1
- package/dist/config/config-matchers.d.ts.map +0 -1
- package/dist/config/dotenv.d.ts.map +0 -1
- package/dist/config/next-config.d.ts.map +0 -1
- package/dist/deploy.d.ts.map +0 -1
- package/dist/entries/app-browser-entry.d.ts.map +0 -1
- package/dist/entries/app-rsc-entry.d.ts.map +0 -1
- package/dist/entries/app-ssr-entry.d.ts.map +0 -1
- package/dist/entries/pages-client-entry.d.ts.map +0 -1
- package/dist/entries/pages-entry-helpers.d.ts.map +0 -1
- package/dist/entries/pages-server-entry.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/init.d.ts.map +0 -1
- package/dist/plugins/async-hooks-stub.d.ts.map +0 -1
- package/dist/plugins/client-reference-dedup.d.ts.map +0 -1
- package/dist/routing/app-router.d.ts.map +0 -1
- package/dist/routing/file-matcher.d.ts.map +0 -1
- package/dist/routing/pages-router.d.ts.map +0 -1
- package/dist/routing/route-trie.d.ts.map +0 -1
- package/dist/routing/route-validation.d.ts.map +0 -1
- package/dist/routing/utils.d.ts.map +0 -1
- package/dist/server/api-handler.d.ts.map +0 -1
- package/dist/server/app-router-entry.d.ts.map +0 -1
- package/dist/server/dev-module-runner.d.ts.map +0 -1
- package/dist/server/dev-origin-check.d.ts.map +0 -1
- package/dist/server/dev-server.d.ts.map +0 -1
- package/dist/server/html.d.ts.map +0 -1
- package/dist/server/image-optimization.d.ts.map +0 -1
- package/dist/server/instrumentation.d.ts.map +0 -1
- package/dist/server/isr-cache.d.ts.map +0 -1
- package/dist/server/metadata-routes.d.ts.map +0 -1
- package/dist/server/middleware-codegen.d.ts.map +0 -1
- package/dist/server/middleware-request-headers.d.ts.map +0 -1
- package/dist/server/middleware.d.ts.map +0 -1
- package/dist/server/normalize-path.d.ts.map +0 -1
- package/dist/server/pages-i18n.d.ts.map +0 -1
- package/dist/server/prod-server.d.ts.map +0 -1
- package/dist/server/request-log.d.ts.map +0 -1
- package/dist/server/request-pipeline.d.ts.map +0 -1
- package/dist/server/worker-utils.d.ts.map +0 -1
- package/dist/shims/amp.d.ts.map +0 -1
- package/dist/shims/app.d.ts.map +0 -1
- package/dist/shims/app.js.map +0 -1
- package/dist/shims/cache-runtime.d.ts.map +0 -1
- package/dist/shims/cache.d.ts.map +0 -1
- package/dist/shims/client-only.d.ts.map +0 -1
- package/dist/shims/client-only.js.map +0 -1
- package/dist/shims/compat-router.d.ts.map +0 -1
- package/dist/shims/config.d.ts.map +0 -1
- package/dist/shims/constants.d.ts.map +0 -1
- package/dist/shims/document.d.ts.map +0 -1
- package/dist/shims/dynamic.d.ts.map +0 -1
- package/dist/shims/error-boundary.d.ts.map +0 -1
- package/dist/shims/error.d.ts.map +0 -1
- package/dist/shims/fetch-cache.d.ts.map +0 -1
- package/dist/shims/font-google-base.d.ts.map +0 -1
- package/dist/shims/font-google.d.ts.map +0 -1
- package/dist/shims/font-google.generated.d.ts.map +0 -1
- package/dist/shims/font-google.js.map +0 -1
- package/dist/shims/font-local.d.ts.map +0 -1
- package/dist/shims/form.d.ts.map +0 -1
- package/dist/shims/head-state.d.ts.map +0 -1
- package/dist/shims/head.d.ts.map +0 -1
- package/dist/shims/headers.d.ts.map +0 -1
- package/dist/shims/i18n-context.d.ts.map +0 -1
- package/dist/shims/i18n-state.d.ts.map +0 -1
- package/dist/shims/image-config.d.ts.map +0 -1
- package/dist/shims/image.d.ts.map +0 -1
- package/dist/shims/internal/api-utils.d.ts.map +0 -1
- package/dist/shims/internal/api-utils.js.map +0 -1
- package/dist/shims/internal/app-router-context.d.ts.map +0 -1
- package/dist/shims/internal/cookies.d.ts.map +0 -1
- package/dist/shims/internal/cookies.js.map +0 -1
- package/dist/shims/internal/parse-cookie-header.d.ts.map +0 -1
- package/dist/shims/internal/router-context.d.ts.map +0 -1
- package/dist/shims/internal/utils.d.ts.map +0 -1
- package/dist/shims/internal/work-unit-async-storage.d.ts.map +0 -1
- package/dist/shims/layout-segment-context.d.ts.map +0 -1
- package/dist/shims/legacy-image.d.ts.map +0 -1
- package/dist/shims/link.d.ts.map +0 -1
- package/dist/shims/metadata.d.ts.map +0 -1
- package/dist/shims/navigation-state.d.ts.map +0 -1
- package/dist/shims/navigation.d.ts.map +0 -1
- package/dist/shims/og.d.ts.map +0 -1
- package/dist/shims/og.js.map +0 -1
- package/dist/shims/readonly-url-search-params.d.ts.map +0 -1
- package/dist/shims/request-context.d.ts.map +0 -1
- package/dist/shims/request-state-types.d.ts.map +0 -1
- package/dist/shims/request-state-types.js.map +0 -1
- package/dist/shims/router-state.d.ts.map +0 -1
- package/dist/shims/router.d.ts.map +0 -1
- package/dist/shims/script.d.ts.map +0 -1
- package/dist/shims/server-only.d.ts.map +0 -1
- package/dist/shims/server-only.js.map +0 -1
- package/dist/shims/server.d.ts.map +0 -1
- package/dist/shims/unified-request-context.d.ts.map +0 -1
- package/dist/shims/url-safety.d.ts.map +0 -1
- package/dist/shims/url-utils.d.ts.map +0 -1
- package/dist/shims/web-vitals.d.ts.map +0 -1
- package/dist/utils/base-path.d.ts.map +0 -1
- package/dist/utils/domain-locale.d.ts.map +0 -1
- package/dist/utils/hash.d.ts.map +0 -1
- package/dist/utils/manifest-paths.d.ts.map +0 -1
- package/dist/utils/project.d.ts.map +0 -1
- package/dist/utils/query.d.ts.map +0 -1
package/dist/shims/navigation.js
CHANGED
|
@@ -1,764 +1,565 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* next/navigation shim
|
|
3
|
-
*
|
|
4
|
-
* App Router navigation hooks. These work on both server (RSC) and client.
|
|
5
|
-
* Server-side: reads from a request context set by the RSC handler.
|
|
6
|
-
* Client-side: reads from browser Location API and provides navigation.
|
|
7
|
-
*/
|
|
8
|
-
// Use namespace import for RSC safety: the react-server condition doesn't export
|
|
9
|
-
// createContext/useContext/useSyncExternalStore as named exports, and strict ESM
|
|
10
|
-
// would throw at link time for missing bindings. With `import * as React`, the
|
|
11
|
-
// bindings are just `undefined` on the namespace object and we can guard at runtime.
|
|
12
|
-
import * as React from "react";
|
|
13
|
-
import { toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
|
|
14
1
|
import { stripBasePath } from "../utils/base-path.js";
|
|
2
|
+
import { toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
|
|
15
3
|
import { ReadonlyURLSearchParams } from "./readonly-url-search-params.js";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
4
|
+
import * as React$1 from "react";
|
|
5
|
+
//#region src/shims/navigation.ts
|
|
6
|
+
/**
|
|
7
|
+
* next/navigation shim
|
|
8
|
+
*
|
|
9
|
+
* App Router navigation hooks. These work on both server (RSC) and client.
|
|
10
|
+
* Server-side: reads from a request context set by the RSC handler.
|
|
11
|
+
* Client-side: reads from browser Location API and provides navigation.
|
|
12
|
+
*/
|
|
24
13
|
const _LAYOUT_SEGMENT_CTX_KEY = Symbol.for("vinext.layoutSegmentContext");
|
|
25
14
|
const _SERVER_INSERTED_HTML_CTX_KEY = Symbol.for("vinext.serverInsertedHTMLContext");
|
|
26
|
-
// ─── ServerInsertedHTML context ────────────────────────────────────────────────
|
|
27
|
-
// Used by CSS-in-JS libraries (Apollo Client, styled-components, emotion) to
|
|
28
|
-
// register HTML injection callbacks during SSR via useContext().
|
|
29
|
-
// The SSR entry wraps the rendered tree with a Provider whose value is a
|
|
30
|
-
// callback registration function (useServerInsertedHTML).
|
|
31
|
-
//
|
|
32
|
-
// In Next.js, ServerInsertedHTMLContext holds a function:
|
|
33
|
-
// (callback: () => React.ReactNode) => void
|
|
34
|
-
// Libraries call useContext(ServerInsertedHTMLContext) to get this function,
|
|
35
|
-
// then call it to register callbacks that inject HTML during SSR.
|
|
36
|
-
//
|
|
37
|
-
// Created eagerly at module load time. In the RSC environment (react-server
|
|
38
|
-
// condition), createContext isn't available so this will be null.
|
|
39
15
|
function getServerInsertedHTMLContext() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return globalState[_LAYOUT_SEGMENT_CTX_KEY] ?? null;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Read the child segments below the current layout from context.
|
|
64
|
-
* Returns [] if no context is available (RSC environment, outside React tree).
|
|
65
|
-
*/
|
|
16
|
+
if (typeof React$1.createContext !== "function") return null;
|
|
17
|
+
const globalState = globalThis;
|
|
18
|
+
if (!globalState[_SERVER_INSERTED_HTML_CTX_KEY]) globalState[_SERVER_INSERTED_HTML_CTX_KEY] = React$1.createContext(null);
|
|
19
|
+
return globalState[_SERVER_INSERTED_HTML_CTX_KEY] ?? null;
|
|
20
|
+
}
|
|
21
|
+
const ServerInsertedHTMLContext = getServerInsertedHTMLContext();
|
|
22
|
+
/**
|
|
23
|
+
* Get or create the layout segment context.
|
|
24
|
+
* Returns null in the RSC environment (createContext unavailable).
|
|
25
|
+
*/
|
|
26
|
+
function getLayoutSegmentContext() {
|
|
27
|
+
if (typeof React$1.createContext !== "function") return null;
|
|
28
|
+
const globalState = globalThis;
|
|
29
|
+
if (!globalState[_LAYOUT_SEGMENT_CTX_KEY]) globalState[_LAYOUT_SEGMENT_CTX_KEY] = React$1.createContext([]);
|
|
30
|
+
return globalState[_LAYOUT_SEGMENT_CTX_KEY] ?? null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Read the child segments below the current layout from context.
|
|
34
|
+
* Returns [] if no context is available (RSC environment, outside React tree).
|
|
35
|
+
*/
|
|
66
36
|
function useChildSegments() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return React.useContext(ctx);
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
37
|
+
const ctx = getLayoutSegmentContext();
|
|
38
|
+
if (!ctx) return [];
|
|
39
|
+
try {
|
|
40
|
+
return React$1.useContext(ctx);
|
|
41
|
+
} catch {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
79
44
|
}
|
|
80
45
|
const _READONLY_SEARCH_PARAMS = Symbol("vinext.navigation.readonlySearchParams");
|
|
81
46
|
const _READONLY_SEARCH_PARAMS_SOURCE = Symbol("vinext.navigation.readonlySearchParamsSource");
|
|
82
|
-
// ---------------------------------------------------------------------------
|
|
83
|
-
// Server-side navigation state lives in a separate server-only module
|
|
84
|
-
// (navigation-state.ts) that uses AsyncLocalStorage for request isolation.
|
|
85
|
-
// This module is bundled for the browser, so it can't import node:async_hooks.
|
|
86
|
-
//
|
|
87
|
-
// On the server: state functions are set by navigation-state.ts at import time.
|
|
88
|
-
// On the client: _serverContext falls back to null (hooks use window instead).
|
|
89
|
-
// ---------------------------------------------------------------------------
|
|
90
47
|
let _serverContext = null;
|
|
91
48
|
let _serverInsertedHTMLCallbacks = [];
|
|
92
|
-
// These are overridden by navigation-state.ts on the server to use ALS.
|
|
93
49
|
let _getServerContext = () => _serverContext;
|
|
94
50
|
let _setServerContext = (ctx) => {
|
|
95
|
-
|
|
51
|
+
_serverContext = ctx;
|
|
96
52
|
};
|
|
97
53
|
let _getInsertedHTMLCallbacks = () => _serverInsertedHTMLCallbacks;
|
|
98
54
|
let _clearInsertedHTMLCallbacks = () => {
|
|
99
|
-
|
|
55
|
+
_serverInsertedHTMLCallbacks = [];
|
|
100
56
|
};
|
|
101
57
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
// ---------------------------------------------------------------------------
|
|
127
|
-
// Client-side state
|
|
128
|
-
// ---------------------------------------------------------------------------
|
|
58
|
+
* Register ALS-backed state accessors. Called by navigation-state.ts on import.
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
function _registerStateAccessors(accessors) {
|
|
62
|
+
_getServerContext = accessors.getServerContext;
|
|
63
|
+
_setServerContext = accessors.setServerContext;
|
|
64
|
+
_getInsertedHTMLCallbacks = accessors.getInsertedHTMLCallbacks;
|
|
65
|
+
_clearInsertedHTMLCallbacks = accessors.clearInsertedHTMLCallbacks;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get the navigation context for the current SSR/RSC render.
|
|
69
|
+
* Reads from AsyncLocalStorage when available (concurrent-safe),
|
|
70
|
+
* otherwise falls back to module-level state.
|
|
71
|
+
*/
|
|
72
|
+
function getNavigationContext() {
|
|
73
|
+
return _getServerContext();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set the navigation context for the current SSR/RSC render.
|
|
77
|
+
* Called by the framework entry before rendering each request.
|
|
78
|
+
*/
|
|
79
|
+
function setNavigationContext(ctx) {
|
|
80
|
+
_setServerContext(ctx);
|
|
81
|
+
}
|
|
129
82
|
const isServer = typeof window === "undefined";
|
|
130
83
|
/** basePath from next.config.js, injected by the plugin at build time */
|
|
131
84
|
const __basePath = process.env.__NEXT_ROUTER_BASEPATH ?? "";
|
|
132
|
-
// ---------------------------------------------------------------------------
|
|
133
|
-
// RSC prefetch cache utilities (shared between link.tsx and browser entry)
|
|
134
|
-
// ---------------------------------------------------------------------------
|
|
135
85
|
/** Maximum number of entries in the RSC prefetch cache. */
|
|
136
|
-
|
|
86
|
+
const MAX_PREFETCH_CACHE_SIZE = 50;
|
|
137
87
|
/** TTL for prefetch cache entries in ms (matches Next.js static prefetch TTL). */
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const normalizedPath = pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
|
|
151
|
-
return normalizedPath + ".rsc" + query;
|
|
88
|
+
const PREFETCH_CACHE_TTL = 3e4;
|
|
89
|
+
/**
|
|
90
|
+
* Convert a pathname (with optional query/hash) to its .rsc URL.
|
|
91
|
+
* Strips trailing slashes before appending `.rsc` so that cache keys
|
|
92
|
+
* are consistent regardless of the `trailingSlash` config setting.
|
|
93
|
+
*/
|
|
94
|
+
function toRscUrl(href) {
|
|
95
|
+
const [beforeHash] = href.split("#");
|
|
96
|
+
const qIdx = beforeHash.indexOf("?");
|
|
97
|
+
const pathname = qIdx === -1 ? beforeHash : beforeHash.slice(0, qIdx);
|
|
98
|
+
const query = qIdx === -1 ? "" : beforeHash.slice(qIdx);
|
|
99
|
+
return (pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname) + ".rsc" + query;
|
|
152
100
|
}
|
|
153
101
|
/** Get or create the shared in-memory RSC prefetch cache on window. */
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
cache.delete(oldest);
|
|
197
|
-
getPrefetchedUrls().delete(oldest);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
cache.set(rscUrl, { response, timestamp: now });
|
|
201
|
-
}
|
|
202
|
-
const _listeners = new Set();
|
|
102
|
+
function getPrefetchCache() {
|
|
103
|
+
if (isServer) return /* @__PURE__ */ new Map();
|
|
104
|
+
if (!window.__VINEXT_RSC_PREFETCH_CACHE__) window.__VINEXT_RSC_PREFETCH_CACHE__ = /* @__PURE__ */ new Map();
|
|
105
|
+
return window.__VINEXT_RSC_PREFETCH_CACHE__;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get or create the shared set of already-prefetched RSC URLs on window.
|
|
109
|
+
* Keyed by rscUrl so that the browser entry can clear entries when consumed.
|
|
110
|
+
*/
|
|
111
|
+
function getPrefetchedUrls() {
|
|
112
|
+
if (isServer) return /* @__PURE__ */ new Set();
|
|
113
|
+
if (!window.__VINEXT_RSC_PREFETCHED_URLS__) window.__VINEXT_RSC_PREFETCHED_URLS__ = /* @__PURE__ */ new Set();
|
|
114
|
+
return window.__VINEXT_RSC_PREFETCHED_URLS__;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Store a prefetched RSC response in the cache.
|
|
118
|
+
* Enforces a maximum cache size to prevent unbounded memory growth on
|
|
119
|
+
* link-heavy pages.
|
|
120
|
+
*/
|
|
121
|
+
function storePrefetchResponse(rscUrl, response) {
|
|
122
|
+
const cache = getPrefetchCache();
|
|
123
|
+
const now = Date.now();
|
|
124
|
+
if (cache.size >= 50) {
|
|
125
|
+
const prefetched = getPrefetchedUrls();
|
|
126
|
+
for (const [key, entry] of cache) if (now - entry.timestamp >= 3e4) {
|
|
127
|
+
cache.delete(key);
|
|
128
|
+
prefetched.delete(key);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (cache.size >= 50) {
|
|
132
|
+
const oldest = cache.keys().next().value;
|
|
133
|
+
if (oldest !== void 0) {
|
|
134
|
+
cache.delete(oldest);
|
|
135
|
+
getPrefetchedUrls().delete(oldest);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
cache.set(rscUrl, {
|
|
139
|
+
response,
|
|
140
|
+
timestamp: now
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const _listeners = /* @__PURE__ */ new Set();
|
|
203
144
|
function notifyListeners() {
|
|
204
|
-
|
|
205
|
-
fn();
|
|
145
|
+
for (const fn of _listeners) fn();
|
|
206
146
|
}
|
|
207
|
-
// Cached URLSearchParams, pathname, etc. for referential stability
|
|
208
|
-
// useSyncExternalStore compares snapshots with Object.is — avoid creating
|
|
209
|
-
// new instances on every render (infinite re-renders).
|
|
210
147
|
let _cachedSearch = !isServer ? window.location.search : "";
|
|
211
148
|
let _cachedReadonlySearchParams = new ReadonlyURLSearchParams(_cachedSearch);
|
|
212
149
|
let _cachedEmptyServerSearchParams = null;
|
|
213
150
|
let _cachedPathname = !isServer ? stripBasePath(window.location.pathname, __basePath) : "/";
|
|
214
151
|
function getPathnameSnapshot() {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
return _cachedPathname;
|
|
152
|
+
const current = stripBasePath(window.location.pathname, __basePath);
|
|
153
|
+
if (current !== _cachedPathname) _cachedPathname = current;
|
|
154
|
+
return _cachedPathname;
|
|
220
155
|
}
|
|
221
156
|
function getSearchParamsSnapshot() {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
157
|
+
const current = window.location.search;
|
|
158
|
+
if (current !== _cachedSearch) {
|
|
159
|
+
_cachedSearch = current;
|
|
160
|
+
_cachedReadonlySearchParams = new ReadonlyURLSearchParams(current);
|
|
161
|
+
}
|
|
162
|
+
return _cachedReadonlySearchParams;
|
|
228
163
|
}
|
|
229
164
|
function getServerSearchParamsSnapshot() {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return _cachedEmptyServerSearchParams;
|
|
243
|
-
}
|
|
244
|
-
// Track client-side params (set during RSC hydration/navigation)
|
|
245
|
-
// We cache the params object for referential stability — only create a new
|
|
246
|
-
// object when the params actually change (shallow key/value comparison).
|
|
165
|
+
const ctx = _getServerContext();
|
|
166
|
+
if (ctx != null) {
|
|
167
|
+
const searchParams = ctx.searchParams;
|
|
168
|
+
if (ctx[_READONLY_SEARCH_PARAMS_SOURCE] !== searchParams) {
|
|
169
|
+
ctx[_READONLY_SEARCH_PARAMS_SOURCE] = searchParams;
|
|
170
|
+
ctx[_READONLY_SEARCH_PARAMS] = new ReadonlyURLSearchParams(searchParams);
|
|
171
|
+
}
|
|
172
|
+
return ctx[_READONLY_SEARCH_PARAMS];
|
|
173
|
+
}
|
|
174
|
+
if (_cachedEmptyServerSearchParams === null) _cachedEmptyServerSearchParams = new ReadonlyURLSearchParams();
|
|
175
|
+
return _cachedEmptyServerSearchParams;
|
|
176
|
+
}
|
|
247
177
|
const _EMPTY_PARAMS = {};
|
|
248
178
|
let _clientParams = _EMPTY_PARAMS;
|
|
249
179
|
let _clientParamsJson = "{}";
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
180
|
+
function setClientParams(params) {
|
|
181
|
+
const json = JSON.stringify(params);
|
|
182
|
+
if (json !== _clientParamsJson) {
|
|
183
|
+
_clientParams = params;
|
|
184
|
+
_clientParamsJson = json;
|
|
185
|
+
notifyListeners();
|
|
186
|
+
}
|
|
258
187
|
}
|
|
259
188
|
/** Get the current client params (for testing referential stability). */
|
|
260
|
-
|
|
261
|
-
|
|
189
|
+
function getClientParams() {
|
|
190
|
+
return _clientParams;
|
|
262
191
|
}
|
|
263
192
|
function getClientParamsSnapshot() {
|
|
264
|
-
|
|
193
|
+
return _clientParams;
|
|
265
194
|
}
|
|
266
195
|
function getServerParamsSnapshot() {
|
|
267
|
-
|
|
196
|
+
return _getServerContext()?.params ?? _EMPTY_PARAMS;
|
|
268
197
|
}
|
|
269
198
|
function subscribeToNavigation(cb) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return React.useSyncExternalStore(subscribeToNavigation, getSearchParamsSnapshot, getServerSearchParamsSnapshot);
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Returns the dynamic params for the current route.
|
|
304
|
-
*/
|
|
305
|
-
export function useParams() {
|
|
306
|
-
if (isServer) {
|
|
307
|
-
// During SSR of "use client" components, the navigation context may not be set.
|
|
308
|
-
return (_getServerContext()?.params ?? _EMPTY_PARAMS);
|
|
309
|
-
}
|
|
310
|
-
return React.useSyncExternalStore(subscribeToNavigation, getClientParamsSnapshot, getServerParamsSnapshot);
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Check if a href is an external URL (any URL scheme per RFC 3986, or protocol-relative).
|
|
314
|
-
*/
|
|
199
|
+
_listeners.add(cb);
|
|
200
|
+
return () => {
|
|
201
|
+
_listeners.delete(cb);
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns the current pathname.
|
|
206
|
+
* Server: from request context. Client: from window.location.
|
|
207
|
+
*/
|
|
208
|
+
function usePathname() {
|
|
209
|
+
if (isServer) return _getServerContext()?.pathname ?? "/";
|
|
210
|
+
return React$1.useSyncExternalStore(subscribeToNavigation, getPathnameSnapshot, () => _getServerContext()?.pathname ?? "/");
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Returns the current search params as a read-only URLSearchParams.
|
|
214
|
+
*/
|
|
215
|
+
function useSearchParams() {
|
|
216
|
+
if (isServer) return getServerSearchParamsSnapshot();
|
|
217
|
+
return React$1.useSyncExternalStore(subscribeToNavigation, getSearchParamsSnapshot, getServerSearchParamsSnapshot);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Returns the dynamic params for the current route.
|
|
221
|
+
*/
|
|
222
|
+
function useParams() {
|
|
223
|
+
if (isServer) return _getServerContext()?.params ?? _EMPTY_PARAMS;
|
|
224
|
+
return React$1.useSyncExternalStore(subscribeToNavigation, getClientParamsSnapshot, getServerParamsSnapshot);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Check if a href is an external URL (any URL scheme per RFC 3986, or protocol-relative).
|
|
228
|
+
*/
|
|
315
229
|
function isExternalUrl(href) {
|
|
316
|
-
|
|
230
|
+
return /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("//");
|
|
317
231
|
}
|
|
318
232
|
/**
|
|
319
|
-
|
|
320
|
-
|
|
233
|
+
* Check if a href is only a hash change relative to the current URL.
|
|
234
|
+
*/
|
|
321
235
|
function isHashOnlyChange(href) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Scroll to a hash target element, or to the top if no hash.
|
|
337
|
-
*/
|
|
236
|
+
if (typeof window === "undefined") return false;
|
|
237
|
+
if (href.startsWith("#")) return true;
|
|
238
|
+
try {
|
|
239
|
+
const current = new URL(window.location.href);
|
|
240
|
+
const next = new URL(href, window.location.href);
|
|
241
|
+
return current.pathname === next.pathname && current.search === next.search && next.hash !== "";
|
|
242
|
+
} catch {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Scroll to a hash target element, or to the top if no hash.
|
|
248
|
+
*/
|
|
338
249
|
function scrollToHash(hash) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
*
|
|
362
|
-
* Uses _nativeReplaceState to avoid triggering the history.replaceState
|
|
363
|
-
* interception (which would cause spurious re-renders from notifyListeners).
|
|
364
|
-
*/
|
|
250
|
+
if (!hash || hash === "#") {
|
|
251
|
+
window.scrollTo(0, 0);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const id = hash.slice(1);
|
|
255
|
+
const element = document.getElementById(id);
|
|
256
|
+
if (element) element.scrollIntoView({ behavior: "auto" });
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Reference to the native history.replaceState before patching.
|
|
260
|
+
* Used internally to avoid triggering the interception for internal operations
|
|
261
|
+
* (e.g. saving scroll position shouldn't cause re-renders).
|
|
262
|
+
* Captured before the history method patching at the bottom of this module.
|
|
263
|
+
*/
|
|
264
|
+
const _nativeReplaceState = !isServer ? window.history.replaceState.bind(window.history) : null;
|
|
265
|
+
/**
|
|
266
|
+
* Save the current scroll position into the current history state.
|
|
267
|
+
* Called before every navigation to enable scroll restoration on back/forward.
|
|
268
|
+
*
|
|
269
|
+
* Uses _nativeReplaceState to avoid triggering the history.replaceState
|
|
270
|
+
* interception (which would cause spurious re-renders from notifyListeners).
|
|
271
|
+
*/
|
|
365
272
|
function saveScrollPosition() {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
273
|
+
if (!_nativeReplaceState) return;
|
|
274
|
+
const state = window.history.state ?? {};
|
|
275
|
+
_nativeReplaceState.call(window.history, {
|
|
276
|
+
...state,
|
|
277
|
+
__vinext_scrollX: window.scrollX,
|
|
278
|
+
__vinext_scrollY: window.scrollY
|
|
279
|
+
}, "");
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Restore scroll position from a history state object (used on popstate).
|
|
283
|
+
*
|
|
284
|
+
* When an RSC navigation is in flight (back/forward triggers both this
|
|
285
|
+
* handler and the browser entry's popstate handler which calls
|
|
286
|
+
* __VINEXT_RSC_NAVIGATE__), we must wait for the new content to render
|
|
287
|
+
* before scrolling. Otherwise the user sees old content flash at the
|
|
288
|
+
* restored scroll position.
|
|
289
|
+
*
|
|
290
|
+
* This handler fires before the browser entry's popstate handler (because
|
|
291
|
+
* navigation.ts is loaded before hydration completes), so we defer via a
|
|
292
|
+
* microtask to give the browser entry handler a chance to set
|
|
293
|
+
* __VINEXT_RSC_PENDING__ first.
|
|
294
|
+
*/
|
|
385
295
|
function restoreScrollPosition(state) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
window.scrollTo(x, y);
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Navigate to a URL, handling external URLs, hash-only changes, and RSC navigation.
|
|
412
|
-
*/
|
|
296
|
+
if (state && typeof state === "object" && "__vinext_scrollY" in state) {
|
|
297
|
+
const { __vinext_scrollX: x, __vinext_scrollY: y } = state;
|
|
298
|
+
Promise.resolve().then(() => {
|
|
299
|
+
const pending = window.__VINEXT_RSC_PENDING__ ?? null;
|
|
300
|
+
if (pending) pending.then(() => {
|
|
301
|
+
requestAnimationFrame(() => {
|
|
302
|
+
window.scrollTo(x, y);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
else requestAnimationFrame(() => {
|
|
306
|
+
window.scrollTo(x, y);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Navigate to a URL, handling external URLs, hash-only changes, and RSC navigation.
|
|
313
|
+
*/
|
|
413
314
|
async function navigateImpl(href, mode, scroll) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
notifyListeners();
|
|
445
|
-
if (scroll) {
|
|
446
|
-
scrollToHash(hash);
|
|
447
|
-
}
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
// Extract hash for post-navigation scrolling
|
|
451
|
-
const hashIdx = fullHref.indexOf("#");
|
|
452
|
-
const hash = hashIdx !== -1 ? fullHref.slice(hashIdx) : "";
|
|
453
|
-
if (mode === "replace") {
|
|
454
|
-
window.history.replaceState(null, "", fullHref);
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
window.history.pushState(null, "", fullHref);
|
|
458
|
-
}
|
|
459
|
-
notifyListeners();
|
|
460
|
-
// Trigger RSC re-fetch if available, and wait for the new content to render
|
|
461
|
-
// before scrolling. This prevents the old page from visibly jumping to the
|
|
462
|
-
// top before the new content paints.
|
|
463
|
-
if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") {
|
|
464
|
-
await window.__VINEXT_RSC_NAVIGATE__(fullHref);
|
|
465
|
-
}
|
|
466
|
-
if (scroll) {
|
|
467
|
-
if (hash) {
|
|
468
|
-
scrollToHash(hash);
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
window.scrollTo(0, 0);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
// ---------------------------------------------------------------------------
|
|
476
|
-
// App Router router singleton
|
|
477
|
-
//
|
|
478
|
-
// All methods close over module-level state (navigateImpl, withBasePath, etc.)
|
|
479
|
-
// and carry no per-render data, so the object can be created once and reused.
|
|
480
|
-
// Next.js returns the same router reference on every call to useRouter(), which
|
|
481
|
-
// matters for components that rely on referential equality (e.g. useMemo /
|
|
482
|
-
// useEffect dependency arrays, React.memo bailouts).
|
|
483
|
-
// ---------------------------------------------------------------------------
|
|
315
|
+
let normalizedHref = href;
|
|
316
|
+
if (isExternalUrl(href)) {
|
|
317
|
+
const localPath = toSameOriginAppPath(href, __basePath);
|
|
318
|
+
if (localPath == null) {
|
|
319
|
+
if (mode === "replace") window.location.replace(href);
|
|
320
|
+
else window.location.assign(href);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
normalizedHref = localPath;
|
|
324
|
+
}
|
|
325
|
+
const fullHref = toBrowserNavigationHref(normalizedHref, window.location.href, __basePath);
|
|
326
|
+
if (mode === "push") saveScrollPosition();
|
|
327
|
+
if (isHashOnlyChange(fullHref)) {
|
|
328
|
+
const hash = fullHref.includes("#") ? fullHref.slice(fullHref.indexOf("#")) : "";
|
|
329
|
+
if (mode === "replace") window.history.replaceState(null, "", fullHref);
|
|
330
|
+
else window.history.pushState(null, "", fullHref);
|
|
331
|
+
notifyListeners();
|
|
332
|
+
if (scroll) scrollToHash(hash);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const hashIdx = fullHref.indexOf("#");
|
|
336
|
+
const hash = hashIdx !== -1 ? fullHref.slice(hashIdx) : "";
|
|
337
|
+
if (mode === "replace") window.history.replaceState(null, "", fullHref);
|
|
338
|
+
else window.history.pushState(null, "", fullHref);
|
|
339
|
+
notifyListeners();
|
|
340
|
+
if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") await window.__VINEXT_RSC_NAVIGATE__(fullHref);
|
|
341
|
+
if (scroll) if (hash) scrollToHash(hash);
|
|
342
|
+
else window.scrollTo(0, 0);
|
|
343
|
+
}
|
|
484
344
|
const _appRouter = {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
prefetched.add(rscUrl);
|
|
523
|
-
fetch(rscUrl, {
|
|
524
|
-
headers: { Accept: "text/x-component" },
|
|
525
|
-
credentials: "include",
|
|
526
|
-
priority: "low",
|
|
527
|
-
})
|
|
528
|
-
.then((response) => {
|
|
529
|
-
if (response.ok) {
|
|
530
|
-
storePrefetchResponse(rscUrl, response);
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
// Non-ok response: allow retry on next prefetch() call
|
|
534
|
-
prefetched.delete(rscUrl);
|
|
535
|
-
}
|
|
536
|
-
})
|
|
537
|
-
.catch(() => {
|
|
538
|
-
// Network error: allow retry on next prefetch() call
|
|
539
|
-
prefetched.delete(rscUrl);
|
|
540
|
-
});
|
|
541
|
-
},
|
|
345
|
+
push(href, options) {
|
|
346
|
+
if (isServer) return;
|
|
347
|
+
navigateImpl(href, "push", options?.scroll !== false);
|
|
348
|
+
},
|
|
349
|
+
replace(href, options) {
|
|
350
|
+
if (isServer) return;
|
|
351
|
+
navigateImpl(href, "replace", options?.scroll !== false);
|
|
352
|
+
},
|
|
353
|
+
back() {
|
|
354
|
+
if (isServer) return;
|
|
355
|
+
window.history.back();
|
|
356
|
+
},
|
|
357
|
+
forward() {
|
|
358
|
+
if (isServer) return;
|
|
359
|
+
window.history.forward();
|
|
360
|
+
},
|
|
361
|
+
refresh() {
|
|
362
|
+
if (isServer) return;
|
|
363
|
+
if (typeof window.__VINEXT_RSC_NAVIGATE__ === "function") window.__VINEXT_RSC_NAVIGATE__(window.location.href);
|
|
364
|
+
},
|
|
365
|
+
prefetch(href) {
|
|
366
|
+
if (isServer) return;
|
|
367
|
+
const rscUrl = toRscUrl(toBrowserNavigationHref(href, window.location.href, __basePath));
|
|
368
|
+
const prefetched = getPrefetchedUrls();
|
|
369
|
+
if (prefetched.has(rscUrl)) return;
|
|
370
|
+
prefetched.add(rscUrl);
|
|
371
|
+
fetch(rscUrl, {
|
|
372
|
+
headers: { Accept: "text/x-component" },
|
|
373
|
+
credentials: "include",
|
|
374
|
+
priority: "low"
|
|
375
|
+
}).then((response) => {
|
|
376
|
+
if (response.ok) storePrefetchResponse(rscUrl, response);
|
|
377
|
+
else prefetched.delete(rscUrl);
|
|
378
|
+
}).catch(() => {
|
|
379
|
+
prefetched.delete(rscUrl);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
542
382
|
};
|
|
543
383
|
/**
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
/**
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
}
|
|
660
|
-
/**
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* Internal error class used by redirect/notFound/forbidden/unauthorized.
|
|
685
|
-
* The `digest` field is the serialised control-flow signal read by the
|
|
686
|
-
* framework's error boundary and server-side request handlers.
|
|
687
|
-
*/
|
|
688
|
-
class VinextNavigationError extends Error {
|
|
689
|
-
digest;
|
|
690
|
-
constructor(message, digest) {
|
|
691
|
-
super(message);
|
|
692
|
-
this.digest = digest;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Throw a redirect. Caught by the framework to send a redirect response.
|
|
697
|
-
*/
|
|
698
|
-
export function redirect(url, type) {
|
|
699
|
-
throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type ?? "replace"};${encodeURIComponent(url)}`);
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Trigger a permanent redirect (308).
|
|
703
|
-
*/
|
|
704
|
-
export function permanentRedirect(url) {
|
|
705
|
-
throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;replace;${encodeURIComponent(url)};308`);
|
|
706
|
-
}
|
|
707
|
-
/**
|
|
708
|
-
* Trigger a not-found response (404). Caught by the framework.
|
|
709
|
-
*/
|
|
710
|
-
export function notFound() {
|
|
711
|
-
throw new VinextNavigationError("NEXT_NOT_FOUND", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* Trigger a forbidden response (403). Caught by the framework.
|
|
715
|
-
* In Next.js, this is gated behind experimental.authInterrupts — we
|
|
716
|
-
* support it unconditionally for maximum compatibility.
|
|
717
|
-
*/
|
|
718
|
-
export function forbidden() {
|
|
719
|
-
throw new VinextNavigationError("NEXT_FORBIDDEN", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Trigger an unauthorized response (401). Caught by the framework.
|
|
723
|
-
* In Next.js, this is gated behind experimental.authInterrupts — we
|
|
724
|
-
* support it unconditionally for maximum compatibility.
|
|
725
|
-
*/
|
|
726
|
-
export function unauthorized() {
|
|
727
|
-
throw new VinextNavigationError("NEXT_UNAUTHORIZED", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);
|
|
728
|
-
}
|
|
729
|
-
// ---------------------------------------------------------------------------
|
|
730
|
-
// Helpers
|
|
731
|
-
// ---------------------------------------------------------------------------
|
|
732
|
-
// React hooks are imported at the top level via ESM.
|
|
733
|
-
// Listen for popstate on the client
|
|
734
|
-
if (!isServer) {
|
|
735
|
-
window.addEventListener("popstate", (event) => {
|
|
736
|
-
notifyListeners();
|
|
737
|
-
// Restore scroll position for back/forward navigation
|
|
738
|
-
restoreScrollPosition(event.state);
|
|
739
|
-
});
|
|
740
|
-
// ---------------------------------------------------------------------------
|
|
741
|
-
// history.pushState / replaceState interception (shallow routing)
|
|
742
|
-
//
|
|
743
|
-
// Next.js intercepts these native methods so that when user code calls
|
|
744
|
-
// `window.history.pushState(null, '', '/new-path?filter=abc')` directly,
|
|
745
|
-
// React hooks like usePathname() and useSearchParams() re-render with
|
|
746
|
-
// the new URL. This is the foundation for shallow routing patterns
|
|
747
|
-
// (filter UIs, tabs, URL search param state, etc.).
|
|
748
|
-
//
|
|
749
|
-
// We wrap the original methods, call through to the native implementation,
|
|
750
|
-
// then notify our listener system so useSyncExternalStore picks up the
|
|
751
|
-
// URL change.
|
|
752
|
-
// ---------------------------------------------------------------------------
|
|
753
|
-
const originalPushState = window.history.pushState.bind(window.history);
|
|
754
|
-
const originalReplaceState = window.history.replaceState.bind(window.history);
|
|
755
|
-
window.history.pushState = function patchedPushState(data, unused, url) {
|
|
756
|
-
originalPushState(data, unused, url);
|
|
757
|
-
notifyListeners();
|
|
758
|
-
};
|
|
759
|
-
window.history.replaceState = function patchedReplaceState(data, unused, url) {
|
|
760
|
-
originalReplaceState(data, unused, url);
|
|
761
|
-
notifyListeners();
|
|
762
|
-
};
|
|
384
|
+
* App Router's useRouter — returns push/replace/back/forward/refresh.
|
|
385
|
+
* Different from Pages Router's useRouter (next/router).
|
|
386
|
+
*
|
|
387
|
+
* Returns a stable singleton: the same object reference on every call,
|
|
388
|
+
* matching Next.js behavior so components using referential equality
|
|
389
|
+
* (e.g. useMemo / useEffect deps, React.memo) don't re-render unnecessarily.
|
|
390
|
+
*/
|
|
391
|
+
function useRouter() {
|
|
392
|
+
return _appRouter;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Returns the active child segment one level below the layout where it's called.
|
|
396
|
+
*
|
|
397
|
+
* Returns the first segment from the route tree below this layout, including
|
|
398
|
+
* route groups (e.g., "(marketing)") and resolved dynamic params. Returns null
|
|
399
|
+
* if at the leaf (no child segments).
|
|
400
|
+
*
|
|
401
|
+
* @param parallelRoutesKey - Which parallel route to read (default: "children")
|
|
402
|
+
*/
|
|
403
|
+
function useSelectedLayoutSegment(_parallelRoutesKey) {
|
|
404
|
+
const segments = useSelectedLayoutSegments(_parallelRoutesKey);
|
|
405
|
+
return segments.length > 0 ? segments[0] : null;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Returns all active segments below the layout where it's called.
|
|
409
|
+
*
|
|
410
|
+
* Each layout in the App Router tree wraps its children with a
|
|
411
|
+
* LayoutSegmentProvider whose value is the remaining route tree segments
|
|
412
|
+
* (including route groups, with dynamic params resolved to actual values
|
|
413
|
+
* and catch-all segments joined with "/"). This hook reads those segments
|
|
414
|
+
* directly from context.
|
|
415
|
+
*
|
|
416
|
+
* @param parallelRoutesKey - Which parallel route to read (default: "children")
|
|
417
|
+
*/
|
|
418
|
+
function useSelectedLayoutSegments(_parallelRoutesKey) {
|
|
419
|
+
return useChildSegments();
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* useServerInsertedHTML — inject HTML during SSR from client components.
|
|
423
|
+
*
|
|
424
|
+
* Used by CSS-in-JS libraries (styled-components, emotion, StyleX) to inject
|
|
425
|
+
* <style> tags during SSR so styles appear in the initial HTML (no FOUC).
|
|
426
|
+
*
|
|
427
|
+
* The callback is called once after each SSR render pass. The returned JSX/HTML
|
|
428
|
+
* is serialized and injected into the HTML stream.
|
|
429
|
+
*
|
|
430
|
+
* Usage (in a "use client" component wrapping children):
|
|
431
|
+
* useServerInsertedHTML(() => {
|
|
432
|
+
* const styles = sheet.getStyleElement();
|
|
433
|
+
* sheet.instance.clearTag();
|
|
434
|
+
* return <>{styles}</>;
|
|
435
|
+
* });
|
|
436
|
+
*/
|
|
437
|
+
function useServerInsertedHTML(callback) {
|
|
438
|
+
if (typeof document !== "undefined") return;
|
|
439
|
+
_getInsertedHTMLCallbacks().push(callback);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Flush all collected useServerInsertedHTML callbacks.
|
|
443
|
+
* Returns an array of results (React elements or strings).
|
|
444
|
+
* Clears the callback list so the next render starts fresh.
|
|
445
|
+
*
|
|
446
|
+
* Called by the SSR entry after renderToReadableStream completes.
|
|
447
|
+
*/
|
|
448
|
+
function flushServerInsertedHTML() {
|
|
449
|
+
const callbacks = _getInsertedHTMLCallbacks();
|
|
450
|
+
const results = [];
|
|
451
|
+
for (const cb of callbacks) try {
|
|
452
|
+
const result = cb();
|
|
453
|
+
if (result != null) results.push(result);
|
|
454
|
+
} catch {}
|
|
455
|
+
callbacks.length = 0;
|
|
456
|
+
return results;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Clear all collected useServerInsertedHTML callbacks without flushing.
|
|
460
|
+
* Used for cleanup between requests.
|
|
461
|
+
*/
|
|
462
|
+
function clearServerInsertedHTML() {
|
|
463
|
+
_clearInsertedHTMLCallbacks();
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* HTTP Access Fallback error code — shared prefix for notFound/forbidden/unauthorized.
|
|
467
|
+
* Matches Next.js 16's unified error handling approach.
|
|
468
|
+
*/
|
|
469
|
+
const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
|
|
470
|
+
/**
|
|
471
|
+
* Check if an error is an HTTP Access Fallback error (notFound, forbidden, unauthorized).
|
|
472
|
+
*/
|
|
473
|
+
function isHTTPAccessFallbackError(error) {
|
|
474
|
+
if (error && typeof error === "object" && "digest" in error) {
|
|
475
|
+
const digest = String(error.digest);
|
|
476
|
+
return digest === "NEXT_NOT_FOUND" || digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`);
|
|
477
|
+
}
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Extract the HTTP status code from an HTTP Access Fallback error.
|
|
482
|
+
* Returns 404 for legacy NEXT_NOT_FOUND errors.
|
|
483
|
+
*/
|
|
484
|
+
function getAccessFallbackHTTPStatus(error) {
|
|
485
|
+
if (error && typeof error === "object" && "digest" in error) {
|
|
486
|
+
const digest = String(error.digest);
|
|
487
|
+
if (digest === "NEXT_NOT_FOUND") return 404;
|
|
488
|
+
if (digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`)) return parseInt(digest.split(";")[1], 10);
|
|
489
|
+
}
|
|
490
|
+
return 404;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Enum matching Next.js RedirectType for type-safe redirect calls.
|
|
494
|
+
*/
|
|
495
|
+
let RedirectType = /* @__PURE__ */ function(RedirectType) {
|
|
496
|
+
RedirectType["push"] = "push";
|
|
497
|
+
RedirectType["replace"] = "replace";
|
|
498
|
+
return RedirectType;
|
|
499
|
+
}({});
|
|
500
|
+
/**
|
|
501
|
+
* Internal error class used by redirect/notFound/forbidden/unauthorized.
|
|
502
|
+
* The `digest` field is the serialised control-flow signal read by the
|
|
503
|
+
* framework's error boundary and server-side request handlers.
|
|
504
|
+
*/
|
|
505
|
+
var VinextNavigationError = class extends Error {
|
|
506
|
+
digest;
|
|
507
|
+
constructor(message, digest) {
|
|
508
|
+
super(message);
|
|
509
|
+
this.digest = digest;
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Throw a redirect. Caught by the framework to send a redirect response.
|
|
514
|
+
*/
|
|
515
|
+
function redirect(url, type) {
|
|
516
|
+
throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type ?? "replace"};${encodeURIComponent(url)}`);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Trigger a permanent redirect (308).
|
|
520
|
+
*/
|
|
521
|
+
function permanentRedirect(url) {
|
|
522
|
+
throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;replace;${encodeURIComponent(url)};308`);
|
|
763
523
|
}
|
|
524
|
+
/**
|
|
525
|
+
* Trigger a not-found response (404). Caught by the framework.
|
|
526
|
+
*/
|
|
527
|
+
function notFound() {
|
|
528
|
+
throw new VinextNavigationError("NEXT_NOT_FOUND", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Trigger a forbidden response (403). Caught by the framework.
|
|
532
|
+
* In Next.js, this is gated behind experimental.authInterrupts — we
|
|
533
|
+
* support it unconditionally for maximum compatibility.
|
|
534
|
+
*/
|
|
535
|
+
function forbidden() {
|
|
536
|
+
throw new VinextNavigationError("NEXT_FORBIDDEN", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Trigger an unauthorized response (401). Caught by the framework.
|
|
540
|
+
* In Next.js, this is gated behind experimental.authInterrupts — we
|
|
541
|
+
* support it unconditionally for maximum compatibility.
|
|
542
|
+
*/
|
|
543
|
+
function unauthorized() {
|
|
544
|
+
throw new VinextNavigationError("NEXT_UNAUTHORIZED", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);
|
|
545
|
+
}
|
|
546
|
+
if (!isServer) {
|
|
547
|
+
window.addEventListener("popstate", (event) => {
|
|
548
|
+
notifyListeners();
|
|
549
|
+
restoreScrollPosition(event.state);
|
|
550
|
+
});
|
|
551
|
+
const originalPushState = window.history.pushState.bind(window.history);
|
|
552
|
+
const originalReplaceState = window.history.replaceState.bind(window.history);
|
|
553
|
+
window.history.pushState = function patchedPushState(data, unused, url) {
|
|
554
|
+
originalPushState(data, unused, url);
|
|
555
|
+
notifyListeners();
|
|
556
|
+
};
|
|
557
|
+
window.history.replaceState = function patchedReplaceState(data, unused, url) {
|
|
558
|
+
originalReplaceState(data, unused, url);
|
|
559
|
+
notifyListeners();
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
563
|
+
export { HTTP_ERROR_FALLBACK_ERROR_CODE, MAX_PREFETCH_CACHE_SIZE, PREFETCH_CACHE_TTL, ReadonlyURLSearchParams, RedirectType, ServerInsertedHTMLContext, _registerStateAccessors, clearServerInsertedHTML, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getClientParams, getLayoutSegmentContext, getNavigationContext, getPrefetchCache, getPrefetchedUrls, isHTTPAccessFallbackError, notFound, permanentRedirect, redirect, setClientParams, setNavigationContext, storePrefetchResponse, toRscUrl, unauthorized, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
|
|
564
|
+
|
|
764
565
|
//# sourceMappingURL=navigation.js.map
|