vinext 0.0.51 → 0.0.53
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 +1 -1
- package/dist/build/clean-output.d.ts +14 -0
- package/dist/build/clean-output.js +36 -0
- package/dist/build/clean-output.js.map +1 -0
- package/dist/build/precompress.d.ts +7 -7
- package/dist/build/precompress.js +18 -17
- package/dist/build/precompress.js.map +1 -1
- package/dist/build/prerender.d.ts +9 -16
- package/dist/build/prerender.js +88 -50
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/run-prerender.js +10 -1
- package/dist/build/run-prerender.js.map +1 -1
- package/dist/build/static-export.d.ts +5 -0
- package/dist/build/static-export.js +8 -3
- package/dist/build/static-export.js.map +1 -1
- package/dist/check.js +4 -0
- package/dist/check.js.map +1 -1
- package/dist/cli-args.d.ts +1 -0
- package/dist/cli-args.js +5 -0
- package/dist/cli-args.js.map +1 -1
- package/dist/cli.js +58 -4
- package/dist/cli.js.map +1 -1
- package/dist/client/instrumentation-client-inject.d.ts +34 -0
- package/dist/client/instrumentation-client-inject.js +57 -0
- package/dist/client/instrumentation-client-inject.js.map +1 -0
- package/dist/client/navigation-runtime.d.ts +60 -0
- package/dist/client/navigation-runtime.js +171 -0
- package/dist/client/navigation-runtime.js.map +1 -0
- package/dist/client/pages-router-link-navigation.d.ts +26 -0
- package/dist/client/pages-router-link-navigation.js +14 -0
- package/dist/client/pages-router-link-navigation.js.map +1 -0
- package/dist/client/vinext-next-data.d.ts +14 -3
- package/dist/client/vinext-next-data.js +50 -1
- package/dist/client/vinext-next-data.js.map +1 -0
- package/dist/client/window-next.d.ts +10 -2
- package/dist/client/window-next.js.map +1 -1
- package/dist/cloudflare/kv-cache-handler.js +2 -1
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/config-matchers.d.ts +63 -16
- package/dist/config/config-matchers.js +145 -9
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +32 -5
- package/dist/config/next-config.js +55 -15
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.js +130 -46
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.js +9 -3
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +4 -2
- package/dist/entries/app-rsc-entry.js +76 -16
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.d.ts +1 -0
- package/dist/entries/app-rsc-manifest.js +53 -6
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/app-ssr-entry.d.ts +3 -3
- package/dist/entries/app-ssr-entry.js +4 -4
- package/dist/entries/app-ssr-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.js +40 -3
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +261 -31
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/entries/runtime-entry-module.d.ts +2 -1
- package/dist/entries/runtime-entry-module.js +9 -3
- package/dist/entries/runtime-entry-module.js.map +1 -1
- package/dist/index.js +161 -46
- package/dist/index.js.map +1 -1
- package/dist/plugins/css-data-url.d.ts +7 -0
- package/dist/plugins/css-data-url.js +81 -0
- package/dist/plugins/css-data-url.js.map +1 -0
- package/dist/plugins/fonts.js +30 -5
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/middleware-server-only.d.ts +54 -0
- package/dist/plugins/middleware-server-only.js +91 -0
- package/dist/plugins/middleware-server-only.js.map +1 -0
- package/dist/plugins/optimize-imports.js +4 -4
- package/dist/plugins/optimize-imports.js.map +1 -1
- package/dist/plugins/strip-server-exports.js +5 -8
- package/dist/plugins/strip-server-exports.js.map +1 -1
- package/dist/routing/app-route-graph.d.ts +20 -1
- package/dist/routing/app-route-graph.js +58 -6
- package/dist/routing/app-route-graph.js.map +1 -1
- package/dist/routing/app-router.d.ts +2 -2
- package/dist/routing/app-router.js +2 -2
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/route-trie.js +13 -18
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/utils.d.ts +12 -1
- package/dist/routing/utils.js +18 -1
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.js +153 -42
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-browser-action-result.d.ts +16 -1
- package/dist/server/app-browser-action-result.js +15 -1
- package/dist/server/app-browser-action-result.js.map +1 -1
- package/dist/server/app-browser-entry.js +309 -155
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-interception-context.d.ts +24 -0
- package/dist/server/app-browser-interception-context.js +32 -0
- package/dist/server/app-browser-interception-context.js.map +1 -0
- package/dist/server/app-browser-navigation-controller.d.ts +3 -1
- package/dist/server/app-browser-navigation-controller.js +5 -1
- package/dist/server/app-browser-navigation-controller.js.map +1 -1
- package/dist/server/app-browser-rsc-redirect.d.ts +2 -1
- package/dist/server/app-browser-rsc-redirect.js +2 -2
- package/dist/server/app-browser-rsc-redirect.js.map +1 -1
- package/dist/server/app-browser-state.d.ts +18 -1
- package/dist/server/app-browser-state.js +19 -1
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-stream.d.ts +5 -14
- package/dist/server/app-browser-stream.js +13 -7
- package/dist/server/app-browser-stream.js.map +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +2 -1
- package/dist/server/app-browser-visible-commit.js +1 -0
- package/dist/server/app-browser-visible-commit.js.map +1 -1
- package/dist/server/app-elements-wire.d.ts +10 -5
- package/dist/server/app-elements-wire.js +84 -2
- package/dist/server/app-elements-wire.js.map +1 -1
- package/dist/server/app-elements.d.ts +3 -2
- package/dist/server/app-elements.js +3 -2
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-fallback-renderer.d.ts +12 -3
- package/dist/server/app-fallback-renderer.js +15 -8
- package/dist/server/app-fallback-renderer.js.map +1 -1
- package/dist/server/app-history-state.js +6 -2
- package/dist/server/app-history-state.js.map +1 -1
- package/dist/server/app-interception-context-header.d.ts +33 -0
- package/dist/server/app-interception-context-header.js +44 -0
- package/dist/server/app-interception-context-header.js.map +1 -0
- package/dist/server/app-middleware.d.ts +13 -0
- package/dist/server/app-middleware.js +3 -1
- package/dist/server/app-middleware.js.map +1 -1
- package/dist/server/app-mounted-slots-header.d.ts +19 -0
- package/dist/server/app-mounted-slots-header.js +40 -1
- package/dist/server/app-mounted-slots-header.js.map +1 -1
- package/dist/server/app-optimistic-routing.d.ts +54 -0
- package/dist/server/app-optimistic-routing.js +208 -0
- package/dist/server/app-optimistic-routing.js.map +1 -0
- package/dist/server/app-page-boundary-render.d.ts +1 -0
- package/dist/server/app-page-boundary-render.js +2 -0
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.d.ts +1 -0
- package/dist/server/app-page-boundary.js +2 -0
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +15 -1
- package/dist/server/app-page-cache.js +68 -7
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +5 -0
- package/dist/server/app-page-dispatch.js +39 -5
- package/dist/server/app-page-dispatch.js.map +1 -1
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +7 -3
- package/dist/server/app-page-element-builder.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +29 -1
- package/dist/server/app-page-execution.js +91 -4
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.d.ts +1 -0
- package/dist/server/app-page-head.js +29 -2
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-probe.js +1 -1
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-render.d.ts +3 -0
- package/dist/server/app-page-render.js +7 -3
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-response.d.ts +11 -1
- package/dist/server/app-page-response.js +18 -5
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +1 -0
- package/dist/server/app-page-route-wiring.js +35 -15
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +4 -0
- package/dist/server/app-page-stream.js +3 -0
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-prerender-static-params.d.ts +2 -1
- package/dist/server/app-prerender-static-params.js +44 -8
- package/dist/server/app-prerender-static-params.js.map +1 -1
- package/dist/server/app-route-handler-cache.d.ts +2 -2
- package/dist/server/app-route-handler-cache.js +3 -2
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.d.ts +7 -1
- package/dist/server/app-route-handler-dispatch.js +4 -1
- package/dist/server/app-route-handler-dispatch.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +18 -2
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-response.js +6 -5
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-router-entry.js +6 -2
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-rsc-handler.d.ts +11 -1
- package/dist/server/app-rsc-handler.js +48 -21
- package/dist/server/app-rsc-handler.js.map +1 -1
- package/dist/server/app-rsc-render-mode.d.ts +4 -3
- package/dist/server/app-rsc-render-mode.js +7 -1
- package/dist/server/app-rsc-render-mode.js.map +1 -1
- package/dist/server/app-rsc-request-normalization.d.ts +4 -1
- package/dist/server/app-rsc-request-normalization.js +6 -2
- package/dist/server/app-rsc-request-normalization.js.map +1 -1
- package/dist/server/app-rsc-response-finalizer.d.ts +8 -1
- package/dist/server/app-rsc-response-finalizer.js +10 -3
- package/dist/server/app-rsc-response-finalizer.js.map +1 -1
- package/dist/server/app-rsc-route-matching.js +2 -2
- package/dist/server/app-rsc-route-matching.js.map +1 -1
- package/dist/server/app-segment-config.d.ts +4 -1
- package/dist/server/app-segment-config.js +6 -1
- package/dist/server/app-segment-config.js.map +1 -1
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +5 -1
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.d.ts +2 -0
- package/dist/server/app-ssr-entry.js +92 -55
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +30 -2
- package/dist/server/app-ssr-stream.js +95 -8
- package/dist/server/app-ssr-stream.js.map +1 -1
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +2 -1
- package/dist/server/app-static-generation.js.map +1 -1
- package/dist/server/artifact-compatibility.d.ts +1 -1
- package/dist/server/artifact-compatibility.js.map +1 -1
- package/dist/server/cache-headers.d.ts +7 -0
- package/dist/server/cache-headers.js +19 -0
- package/dist/server/cache-headers.js.map +1 -0
- package/dist/server/cache-proof.d.ts +49 -3
- package/dist/server/cache-proof.js +78 -22
- package/dist/server/cache-proof.js.map +1 -1
- package/dist/server/client-reuse-manifest.d.ts +99 -0
- package/dist/server/client-reuse-manifest.js +212 -0
- package/dist/server/client-reuse-manifest.js.map +1 -0
- package/dist/server/default-global-error-module.d.ts +20 -0
- package/dist/server/default-global-error-module.js +20 -0
- package/dist/server/default-global-error-module.js.map +1 -0
- package/dist/server/default-not-found-module.d.ts +20 -0
- package/dist/server/default-not-found-module.js +20 -0
- package/dist/server/default-not-found-module.js.map +1 -0
- package/dist/server/dev-server.d.ts +10 -2
- package/dist/server/dev-server.js +99 -36
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/edge-api-runtime.d.ts +5 -0
- package/dist/server/edge-api-runtime.js +8 -0
- package/dist/server/edge-api-runtime.js.map +1 -0
- package/dist/server/headers.d.ts +22 -1
- package/dist/server/headers.js +22 -1
- package/dist/server/headers.js.map +1 -1
- package/dist/server/http-error-responses.d.ts +16 -1
- package/dist/server/http-error-responses.js +21 -1
- package/dist/server/http-error-responses.js.map +1 -1
- package/dist/server/image-optimization.d.ts +13 -4
- package/dist/server/image-optimization.js +15 -4
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/isr-cache.d.ts +6 -2
- package/dist/server/isr-cache.js +20 -4
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/middleware-runtime.d.ts +15 -0
- package/dist/server/middleware-runtime.js +59 -7
- package/dist/server/middleware-runtime.js.map +1 -1
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +5 -3
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/navigation-planner.d.ts +9 -3
- package/dist/server/navigation-planner.js +98 -25
- package/dist/server/navigation-planner.js.map +1 -1
- package/dist/server/navigation-trace.d.ts +2 -1
- package/dist/server/navigation-trace.js +1 -0
- package/dist/server/navigation-trace.js.map +1 -1
- package/dist/server/pages-api-route.d.ts +45 -1
- package/dist/server/pages-api-route.js +27 -4
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-body-parser-config.d.ts +60 -0
- package/dist/server/pages-body-parser-config.js +79 -0
- package/dist/server/pages-body-parser-config.js.map +1 -0
- package/dist/server/pages-data-route.d.ts +77 -0
- package/dist/server/pages-data-route.js +98 -0
- package/dist/server/pages-data-route.js.map +1 -0
- package/dist/server/pages-default-404.d.ts +31 -0
- package/dist/server/pages-default-404.js +40 -0
- package/dist/server/pages-default-404.js.map +1 -0
- package/dist/server/pages-i18n.d.ts +51 -1
- package/dist/server/pages-i18n.js +61 -1
- package/dist/server/pages-i18n.js.map +1 -1
- package/dist/server/pages-node-compat.d.ts +10 -0
- package/dist/server/pages-node-compat.js +12 -1
- package/dist/server/pages-node-compat.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +69 -2
- package/dist/server/pages-page-data.js +47 -31
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +13 -1
- package/dist/server/pages-page-response.js +16 -11
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prerender-route-params.d.ts +14 -0
- package/dist/server/prerender-route-params.js +94 -0
- package/dist/server/prerender-route-params.js.map +1 -0
- package/dist/server/prod-server.d.ts +15 -37
- package/dist/server/prod-server.js +143 -107
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/proxy-trust.d.ts +41 -0
- package/dist/server/proxy-trust.js +70 -0
- package/dist/server/proxy-trust.js.map +1 -0
- package/dist/server/request-pipeline.d.ts +13 -4
- package/dist/server/request-pipeline.js +32 -14
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/seed-cache.d.ts +12 -31
- package/dist/server/seed-cache.js +30 -37
- package/dist/server/seed-cache.js.map +1 -1
- package/dist/server/server-action-not-found.js +8 -3
- package/dist/server/server-action-not-found.js.map +1 -1
- package/dist/server/skip-cache-proof.d.ts +41 -0
- package/dist/server/skip-cache-proof.js +101 -0
- package/dist/server/skip-cache-proof.js.map +1 -0
- package/dist/server/static-file-cache.d.ts +1 -1
- package/dist/server/static-file-cache.js +8 -7
- package/dist/server/static-file-cache.js.map +1 -1
- package/dist/server/streaming-metadata.d.ts +5 -0
- package/dist/server/streaming-metadata.js +10 -0
- package/dist/server/streaming-metadata.js.map +1 -0
- package/dist/shims/app-router-scroll-state.d.ts +12 -0
- package/dist/shims/app-router-scroll-state.js +38 -0
- package/dist/shims/app-router-scroll-state.js.map +1 -0
- package/dist/shims/app-router-scroll.d.ts +14 -0
- package/dist/shims/app-router-scroll.js +100 -0
- package/dist/shims/app-router-scroll.js.map +1 -0
- package/dist/shims/before-interactive-context.d.ts +30 -0
- package/dist/shims/before-interactive-context.js +10 -0
- package/dist/shims/before-interactive-context.js.map +1 -0
- package/dist/shims/cache-runtime.d.ts +1 -1
- package/dist/shims/cache-runtime.js +14 -1
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/client-locale.d.ts +15 -0
- package/dist/shims/client-locale.js +13 -0
- package/dist/shims/client-locale.js.map +1 -0
- package/dist/shims/default-global-error.d.ts +32 -0
- package/dist/shims/default-global-error.js +181 -0
- package/dist/shims/default-global-error.js.map +1 -0
- package/dist/shims/default-not-found.d.ts +12 -0
- package/dist/shims/default-not-found.js +61 -0
- package/dist/shims/default-not-found.js.map +1 -0
- package/dist/shims/document.d.ts +59 -3
- package/dist/shims/document.js +36 -5
- package/dist/shims/document.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +2 -2
- package/dist/shims/font-local.d.ts +5 -0
- package/dist/shims/font-local.js +6 -2
- package/dist/shims/font-local.js.map +1 -1
- package/dist/shims/form.js +13 -6
- package/dist/shims/form.js.map +1 -1
- package/dist/shims/head.js +4 -4
- package/dist/shims/head.js.map +1 -1
- package/dist/shims/headers.d.ts +6 -2
- package/dist/shims/headers.js +64 -21
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/image.d.ts +1 -1
- package/dist/shims/image.js +4 -4
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/pages-data-target.d.ts +58 -0
- package/dist/shims/internal/pages-data-target.js +91 -0
- package/dist/shims/internal/pages-data-target.js.map +1 -0
- package/dist/shims/internal/pages-data-url.d.ts +42 -0
- package/dist/shims/internal/pages-data-url.js +73 -0
- package/dist/shims/internal/pages-data-url.js.map +1 -0
- package/dist/shims/link.d.ts +21 -3
- package/dist/shims/link.js +189 -30
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +2 -1
- package/dist/shims/metadata.js +65 -6
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.d.ts +8 -2
- package/dist/shims/navigation.js +67 -23
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/og.d.ts +18 -2
- package/dist/shims/og.js +49 -1
- package/dist/shims/og.js.map +1 -0
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/root-params.d.ts +3 -1
- package/dist/shims/root-params.js +11 -3
- package/dist/shims/root-params.js.map +1 -1
- package/dist/shims/router-state.d.ts +1 -0
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.d.ts +12 -5
- package/dist/shims/router.js +535 -86
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.js +86 -12
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server.d.ts +21 -4
- package/dist/shims/server.js +30 -9
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/slot.js +5 -1
- package/dist/shims/slot.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-safety.d.ts +23 -1
- package/dist/shims/url-safety.js +29 -2
- package/dist/shims/url-safety.js.map +1 -1
- package/dist/shims/url-utils.d.ts +2 -1
- package/dist/shims/url-utils.js +15 -4
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/typegen.d.ts +10 -0
- package/dist/typegen.js +242 -0
- package/dist/typegen.js.map +1 -0
- package/dist/utils/asset-prefix.d.ts +33 -5
- package/dist/utils/asset-prefix.js +39 -6
- package/dist/utils/asset-prefix.js.map +1 -1
- package/dist/utils/cache-control-metadata.d.ts +2 -1
- package/dist/utils/cache-control-metadata.js +1 -3
- package/dist/utils/cache-control-metadata.js.map +1 -1
- package/dist/utils/domain-locale.d.ts +2 -1
- package/dist/utils/domain-locale.js +9 -1
- package/dist/utils/domain-locale.js.map +1 -1
- package/dist/utils/html-limited-bots.d.ts +5 -0
- package/dist/utils/html-limited-bots.js +15 -0
- package/dist/utils/html-limited-bots.js.map +1 -0
- package/dist/utils/lazy-chunks.d.ts +1 -1
- package/dist/utils/lazy-chunks.js +1 -1
- package/dist/utils/lazy-chunks.js.map +1 -1
- package/dist/utils/prerender-output-paths.d.ts +15 -0
- package/dist/utils/prerender-output-paths.js +24 -0
- package/dist/utils/prerender-output-paths.js.map +1 -0
- package/dist/utils/query.d.ts +23 -1
- package/dist/utils/query.js +46 -2
- package/dist/utils/query.js.map +1 -1
- package/dist/utils/record.d.ts +5 -0
- package/dist/utils/record.js +8 -0
- package/dist/utils/record.js.map +1 -0
- package/package.json +11 -3
|
@@ -1,14 +1,50 @@
|
|
|
1
|
-
import { pickRootParams,
|
|
1
|
+
import { pickRootParams, runWithRootParamsScope } from "../shims/root-params.js";
|
|
2
2
|
//#region src/server/app-prerender-static-params.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
function isGenerateStaticParamsFunction(value) {
|
|
4
|
+
return typeof value === "function";
|
|
5
|
+
}
|
|
6
|
+
function isRootParams(value) {
|
|
7
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function createAppPrerenderStaticParamsResolver(sources, rootParamNames) {
|
|
10
|
+
const generateStaticParamsFns = sources.filter(isGenerateStaticParamsFunction);
|
|
11
|
+
if (generateStaticParamsFns.length === 0) return null;
|
|
12
|
+
const filterRootParams = (params) => pickRootParams(params, rootParamNames ?? []);
|
|
13
|
+
if (generateStaticParamsFns.length === 1) {
|
|
14
|
+
const single = generateStaticParamsFns[0];
|
|
15
|
+
return async (input) => {
|
|
16
|
+
return runWithRootParamsScope(filterRootParams(input.params), async () => {
|
|
17
|
+
const result = await single(input);
|
|
18
|
+
if (!Array.isArray(result)) return [];
|
|
19
|
+
for (const item of result) if (!isRootParams(item)) return [];
|
|
20
|
+
return result;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
9
23
|
}
|
|
24
|
+
return async ({ params }) => {
|
|
25
|
+
let paramSets = [params];
|
|
26
|
+
for (const generateStaticParams of generateStaticParamsFns) {
|
|
27
|
+
const nextParamSets = [];
|
|
28
|
+
for (const parentParams of paramSets) {
|
|
29
|
+
const result = await runWithRootParamsScope(filterRootParams(parentParams), async () => generateStaticParams({ params: parentParams }));
|
|
30
|
+
if (!Array.isArray(result)) return [];
|
|
31
|
+
for (const item of result) {
|
|
32
|
+
if (!isRootParams(item)) return [];
|
|
33
|
+
nextParamSets.push({
|
|
34
|
+
...parentParams,
|
|
35
|
+
...item
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
paramSets = nextParamSets;
|
|
40
|
+
}
|
|
41
|
+
return paramSets;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async function callAppPrerenderStaticParams(options) {
|
|
45
|
+
return runWithRootParamsScope(pickRootParams(options.params, options.rootParamNamesByPattern[options.pattern]), () => options.fn({ params: options.params }));
|
|
10
46
|
}
|
|
11
47
|
//#endregion
|
|
12
|
-
export { callAppPrerenderStaticParams };
|
|
48
|
+
export { callAppPrerenderStaticParams, createAppPrerenderStaticParamsResolver };
|
|
13
49
|
|
|
14
50
|
//# sourceMappingURL=app-prerender-static-params.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-prerender-static-params.js","names":[],"sources":["../../src/server/app-prerender-static-params.ts"],"sourcesContent":["import { pickRootParams,
|
|
1
|
+
{"version":3,"file":"app-prerender-static-params.js","names":[],"sources":["../../src/server/app-prerender-static-params.ts"],"sourcesContent":["import { pickRootParams, runWithRootParamsScope, type RootParams } from \"vinext/shims/root-params\";\n\ntype GenerateStaticParamsFunction = (input: { params: RootParams }) => unknown;\n\nfunction isGenerateStaticParamsFunction(value: unknown): value is GenerateStaticParamsFunction {\n return typeof value === \"function\";\n}\n\nfunction isRootParams(value: unknown): value is RootParams {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport function createAppPrerenderStaticParamsResolver(\n sources: readonly unknown[],\n rootParamNames?: readonly string[],\n): GenerateStaticParamsFunction | null {\n const generateStaticParamsFns = sources.filter(isGenerateStaticParamsFunction);\n if (generateStaticParamsFns.length === 0) return null;\n\n const filterRootParams = (params: RootParams): RootParams =>\n pickRootParams(params, rootParamNames ?? []);\n\n if (generateStaticParamsFns.length === 1) {\n const single = generateStaticParamsFns[0];\n // Wrap the single source in the same non-array/non-object guards as the\n // multi-source composition path so the contract is uniform regardless of\n // how many sources were composed.\n return async (input) => {\n const picked = filterRootParams(input.params);\n return runWithRootParamsScope(picked, async () => {\n const result = await single(input);\n if (!Array.isArray(result)) return [];\n for (const item of result) {\n if (!isRootParams(item)) return [];\n }\n return result;\n });\n };\n }\n\n return async ({ params }) => {\n let paramSets: RootParams[] = [params];\n\n for (const generateStaticParams of generateStaticParamsFns) {\n const nextParamSets: RootParams[] = [];\n\n for (const parentParams of paramSets) {\n const rootScope = filterRootParams(parentParams);\n\n const result = await runWithRootParamsScope(rootScope, async () =>\n generateStaticParams({ params: parentParams }),\n );\n\n if (!Array.isArray(result)) return [];\n\n for (const item of result) {\n if (!isRootParams(item)) return [];\n nextParamSets.push({ ...parentParams, ...item });\n }\n }\n\n paramSets = nextParamSets;\n }\n\n return paramSets;\n };\n}\n\ntype CallAppPrerenderStaticParamsOptions = {\n fn: GenerateStaticParamsFunction;\n params: RootParams;\n pattern: string;\n rootParamNamesByPattern: Record<string, readonly string[] | undefined>;\n};\n\nexport async function callAppPrerenderStaticParams(\n options: CallAppPrerenderStaticParamsOptions,\n): Promise<unknown> {\n const picked = pickRootParams(options.params, options.rootParamNamesByPattern[options.pattern]);\n return runWithRootParamsScope(picked, () => options.fn({ params: options.params }));\n}\n"],"mappings":";;AAIA,SAAS,+BAA+B,OAAuD;CAC7F,OAAO,OAAO,UAAU;;AAG1B,SAAS,aAAa,OAAqC;CACzD,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,MAAM;;AAG7E,SAAgB,uCACd,SACA,gBACqC;CACrC,MAAM,0BAA0B,QAAQ,OAAO,+BAA+B;CAC9E,IAAI,wBAAwB,WAAW,GAAG,OAAO;CAEjD,MAAM,oBAAoB,WACxB,eAAe,QAAQ,kBAAkB,EAAE,CAAC;CAE9C,IAAI,wBAAwB,WAAW,GAAG;EACxC,MAAM,SAAS,wBAAwB;EAIvC,OAAO,OAAO,UAAU;GAEtB,OAAO,uBADQ,iBAAiB,MAAM,OACF,EAAE,YAAY;IAChD,MAAM,SAAS,MAAM,OAAO,MAAM;IAClC,IAAI,CAAC,MAAM,QAAQ,OAAO,EAAE,OAAO,EAAE;IACrC,KAAK,MAAM,QAAQ,QACjB,IAAI,CAAC,aAAa,KAAK,EAAE,OAAO,EAAE;IAEpC,OAAO;KACP;;;CAIN,OAAO,OAAO,EAAE,aAAa;EAC3B,IAAI,YAA0B,CAAC,OAAO;EAEtC,KAAK,MAAM,wBAAwB,yBAAyB;GAC1D,MAAM,gBAA8B,EAAE;GAEtC,KAAK,MAAM,gBAAgB,WAAW;IAGpC,MAAM,SAAS,MAAM,uBAFH,iBAAiB,aAEkB,EAAE,YACrD,qBAAqB,EAAE,QAAQ,cAAc,CAAC,CAC/C;IAED,IAAI,CAAC,MAAM,QAAQ,OAAO,EAAE,OAAO,EAAE;IAErC,KAAK,MAAM,QAAQ,QAAQ;KACzB,IAAI,CAAC,aAAa,KAAK,EAAE,OAAO,EAAE;KAClC,cAAc,KAAK;MAAE,GAAG;MAAc,GAAG;MAAM,CAAC;;;GAIpD,YAAY;;EAGd,OAAO;;;AAWX,eAAsB,6BACpB,SACkB;CAElB,OAAO,uBADQ,eAAe,QAAQ,QAAQ,QAAQ,wBAAwB,QAAQ,SAClD,QAAQ,QAAQ,GAAG,EAAE,QAAQ,QAAQ,QAAQ,CAAC,CAAC"}
|
|
@@ -24,8 +24,8 @@ type ReadAppRouteHandlerCacheOptions = {
|
|
|
24
24
|
isrRouteKey: (pathname: string) => string;
|
|
25
25
|
isrSet: RouteHandlerCacheSetter;
|
|
26
26
|
markDynamicUsage: MarkAppRouteDynamicUsageFn;
|
|
27
|
-
middlewareContext: RouteHandlerMiddlewareContext;
|
|
28
|
-
params: AppRouteParams;
|
|
27
|
+
middlewareContext: RouteHandlerMiddlewareContext; /** `null` for non-dynamic routes. See `AppRouteHandlerFunction` for details. */
|
|
28
|
+
params: AppRouteParams | null;
|
|
29
29
|
requestUrl: string;
|
|
30
30
|
revalidateSearchParams: URLSearchParams;
|
|
31
31
|
expireSeconds?: number;
|
|
@@ -3,6 +3,7 @@ import { markKnownDynamicAppRoute } from "./app-route-handler-runtime.js";
|
|
|
3
3
|
import { applyRouteHandlerMiddlewareContext, assertSupportedAppRouteHandlerResponse, buildAppRouteCacheValue, buildRouteHandlerCachedResponse } from "./app-route-handler-response.js";
|
|
4
4
|
import { runAppRouteHandler } from "./app-route-handler-execution.js";
|
|
5
5
|
//#region src/server/app-route-handler-cache.ts
|
|
6
|
+
const EMPTY_PARAMS = Object.freeze({});
|
|
6
7
|
function getCachedAppRouteValue(entry) {
|
|
7
8
|
return entry?.value.value && entry.value.value.kind === "APP_ROUTE" ? entry.value.value : null;
|
|
8
9
|
}
|
|
@@ -30,7 +31,7 @@ async function readAppRouteHandlerCacheResponse(options) {
|
|
|
30
31
|
options.setNavigationContext({
|
|
31
32
|
pathname: options.cleanPathname,
|
|
32
33
|
searchParams: revalidateSearchParams,
|
|
33
|
-
params: options.params
|
|
34
|
+
params: options.params ?? EMPTY_PARAMS
|
|
34
35
|
});
|
|
35
36
|
const { dynamicUsedInHandler, response } = await runAppRouteHandler({
|
|
36
37
|
basePath: options.basePath,
|
|
@@ -39,7 +40,7 @@ async function readAppRouteHandlerCacheResponse(options) {
|
|
|
39
40
|
handlerFn: options.handlerFn,
|
|
40
41
|
i18n: options.i18n,
|
|
41
42
|
markDynamicUsage: options.markDynamicUsage,
|
|
42
|
-
params: makeThenableParams(options.params),
|
|
43
|
+
params: options.params === null ? null : makeThenableParams(options.params),
|
|
43
44
|
request: new Request(options.requestUrl, { method: "GET" }),
|
|
44
45
|
routePattern: options.routePattern,
|
|
45
46
|
setHeadersAccessPhase: options.setHeadersAccessPhase
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-route-handler-cache.js","names":[],"sources":["../../src/server/app-route-handler-cache.ts"],"sourcesContent":["import type { NextI18nConfig } from \"../config/next-config.js\";\nimport type { HeadersAccessPhase } from \"vinext/shims/headers\";\nimport type { ISRCacheEntry } from \"./isr-cache.js\";\nimport type { RouteHandlerMiddlewareContext } from \"./app-route-handler-response.js\";\nimport {\n applyRouteHandlerMiddlewareContext,\n assertSupportedAppRouteHandlerResponse,\n buildAppRouteCacheValue,\n buildRouteHandlerCachedResponse,\n} from \"./app-route-handler-response.js\";\nimport { markKnownDynamicAppRoute } from \"./app-route-handler-runtime.js\";\nimport { makeThenableParams } from \"vinext/shims/thenable-params\";\nimport {\n runAppRouteHandler,\n type AppRouteDebugLogger,\n type AppRouteDynamicUsageFn,\n type AppRouteHandlerFunction,\n type AppRouteParams,\n type MarkAppRouteDynamicUsageFn,\n type RouteHandlerCacheSetter,\n} from \"./app-route-handler-execution.js\";\n\ntype RouteHandlerCacheGetter = (key: string) => Promise<ISRCacheEntry | null>;\ntype RouteHandlerBackgroundRegenerator = (key: string, renderFn: () => Promise<void>) => void;\ntype RouteHandlerRevalidationContextRunner = (renderFn: () => Promise<void>) => Promise<void>;\n\ntype ReadAppRouteHandlerCacheOptions = {\n basePath?: string;\n buildPageCacheTags: (pathname: string, extraTags: string[]) => string[];\n cleanPathname: string;\n clearRequestContext: () => void;\n consumeDynamicUsage: AppRouteDynamicUsageFn;\n dynamicConfig?: string;\n getCollectedFetchTags: () => string[];\n handlerFn: AppRouteHandlerFunction;\n i18n?: NextI18nConfig | null;\n isAutoHead: boolean;\n isrDebug?: AppRouteDebugLogger;\n isrGet: RouteHandlerCacheGetter;\n isrRouteKey: (pathname: string) => string;\n isrSet: RouteHandlerCacheSetter;\n markDynamicUsage: MarkAppRouteDynamicUsageFn;\n middlewareContext: RouteHandlerMiddlewareContext;\n params: AppRouteParams;\n requestUrl: string;\n revalidateSearchParams: URLSearchParams;\n expireSeconds?: number;\n revalidateSeconds: number;\n routePattern: string;\n runInRevalidationContext: RouteHandlerRevalidationContextRunner;\n scheduleBackgroundRegeneration: RouteHandlerBackgroundRegenerator;\n setHeadersAccessPhase: (phase: HeadersAccessPhase) => HeadersAccessPhase;\n setNavigationContext: (\n context: {\n pathname: string;\n searchParams: URLSearchParams;\n params: AppRouteParams;\n } | null,\n ) => void;\n};\n\nfunction getCachedAppRouteValue(entry: ISRCacheEntry | null) {\n return entry?.value.value && entry.value.value.kind === \"APP_ROUTE\" ? entry.value.value : null;\n}\n\nexport async function readAppRouteHandlerCacheResponse(\n options: ReadAppRouteHandlerCacheOptions,\n): Promise<Response | null> {\n const routeKey = options.isrRouteKey(options.cleanPathname);\n\n try {\n const cached = await options.isrGet(routeKey);\n const cachedValue = getCachedAppRouteValue(cached);\n\n if (cachedValue && !cached?.isStale) {\n options.isrDebug?.(\"HIT (route)\", options.cleanPathname);\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n buildRouteHandlerCachedResponse(cachedValue, {\n cacheState: \"HIT\",\n cacheControl: cached?.value.cacheControl,\n expireSeconds: options.expireSeconds,\n isHead: options.isAutoHead,\n revalidateSeconds: options.revalidateSeconds,\n }),\n options.middlewareContext,\n );\n }\n\n if (cached?.isStale && cachedValue) {\n const staleValue = cachedValue;\n const revalidateSearchParams = new URLSearchParams(options.revalidateSearchParams);\n\n options.scheduleBackgroundRegeneration(routeKey, async () => {\n await options.runInRevalidationContext(async () => {\n options.setNavigationContext({\n pathname: options.cleanPathname,\n searchParams: revalidateSearchParams,\n params: options.params,\n });\n\n const { dynamicUsedInHandler, response } = await runAppRouteHandler({\n basePath: options.basePath,\n consumeDynamicUsage: options.consumeDynamicUsage,\n dynamicConfig: options.dynamicConfig,\n handlerFn: options.handlerFn,\n i18n: options.i18n,\n markDynamicUsage: options.markDynamicUsage,\n params: makeThenableParams(options.params),\n request: new Request(options.requestUrl, { method: \"GET\" }),\n routePattern: options.routePattern,\n setHeadersAccessPhase: options.setHeadersAccessPhase,\n });\n\n options.setNavigationContext(null);\n assertSupportedAppRouteHandlerResponse(response);\n\n if (dynamicUsedInHandler) {\n markKnownDynamicAppRoute(options.routePattern);\n options.isrDebug?.(\"route regen skipped (dynamic usage)\", options.cleanPathname);\n return;\n }\n\n const routeTags = options.buildPageCacheTags(\n options.cleanPathname,\n options.getCollectedFetchTags(),\n );\n const routeCacheValue = await buildAppRouteCacheValue(response);\n await options.isrSet(\n routeKey,\n routeCacheValue,\n options.revalidateSeconds,\n routeTags,\n options.expireSeconds,\n );\n options.isrDebug?.(\"route regen complete\", routeKey);\n });\n });\n\n options.isrDebug?.(\"STALE (route)\", options.cleanPathname);\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n buildRouteHandlerCachedResponse(staleValue, {\n cacheState: \"STALE\",\n cacheControl: cached.value.cacheControl,\n expireSeconds: options.expireSeconds,\n isHead: options.isAutoHead,\n revalidateSeconds: options.revalidateSeconds,\n }),\n options.middlewareContext,\n );\n }\n } catch (routeCacheError) {\n console.error(\"[vinext] ISR route cache read error:\", routeCacheError);\n }\n\n return null;\n}\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"app-route-handler-cache.js","names":[],"sources":["../../src/server/app-route-handler-cache.ts"],"sourcesContent":["import type { NextI18nConfig } from \"../config/next-config.js\";\nimport type { HeadersAccessPhase } from \"vinext/shims/headers\";\nimport type { ISRCacheEntry } from \"./isr-cache.js\";\nimport type { RouteHandlerMiddlewareContext } from \"./app-route-handler-response.js\";\nimport {\n applyRouteHandlerMiddlewareContext,\n assertSupportedAppRouteHandlerResponse,\n buildAppRouteCacheValue,\n buildRouteHandlerCachedResponse,\n} from \"./app-route-handler-response.js\";\nimport { markKnownDynamicAppRoute } from \"./app-route-handler-runtime.js\";\nimport { makeThenableParams } from \"vinext/shims/thenable-params\";\nimport {\n runAppRouteHandler,\n type AppRouteDebugLogger,\n type AppRouteDynamicUsageFn,\n type AppRouteHandlerFunction,\n type AppRouteParams,\n type MarkAppRouteDynamicUsageFn,\n type RouteHandlerCacheSetter,\n} from \"./app-route-handler-execution.js\";\n\ntype RouteHandlerCacheGetter = (key: string) => Promise<ISRCacheEntry | null>;\ntype RouteHandlerBackgroundRegenerator = (key: string, renderFn: () => Promise<void>) => void;\ntype RouteHandlerRevalidationContextRunner = (renderFn: () => Promise<void>) => Promise<void>;\n\ntype ReadAppRouteHandlerCacheOptions = {\n basePath?: string;\n buildPageCacheTags: (pathname: string, extraTags: string[]) => string[];\n cleanPathname: string;\n clearRequestContext: () => void;\n consumeDynamicUsage: AppRouteDynamicUsageFn;\n dynamicConfig?: string;\n getCollectedFetchTags: () => string[];\n handlerFn: AppRouteHandlerFunction;\n i18n?: NextI18nConfig | null;\n isAutoHead: boolean;\n isrDebug?: AppRouteDebugLogger;\n isrGet: RouteHandlerCacheGetter;\n isrRouteKey: (pathname: string) => string;\n isrSet: RouteHandlerCacheSetter;\n markDynamicUsage: MarkAppRouteDynamicUsageFn;\n middlewareContext: RouteHandlerMiddlewareContext;\n /** `null` for non-dynamic routes. See `AppRouteHandlerFunction` for details. */\n params: AppRouteParams | null;\n requestUrl: string;\n revalidateSearchParams: URLSearchParams;\n expireSeconds?: number;\n revalidateSeconds: number;\n routePattern: string;\n runInRevalidationContext: RouteHandlerRevalidationContextRunner;\n scheduleBackgroundRegeneration: RouteHandlerBackgroundRegenerator;\n setHeadersAccessPhase: (phase: HeadersAccessPhase) => HeadersAccessPhase;\n setNavigationContext: (\n context: {\n pathname: string;\n searchParams: URLSearchParams;\n params: AppRouteParams;\n } | null,\n ) => void;\n};\n\n// Navigation context expects a plain object (used for `useParams()` etc),\n// not `null`. For non-dynamic routes there are no params to expose, so we\n// pass an empty object — only the user-visible handler context surfaces\n// `null` for non-dynamic routes.\nconst EMPTY_PARAMS: AppRouteParams = Object.freeze({}) as AppRouteParams;\n\nfunction getCachedAppRouteValue(entry: ISRCacheEntry | null) {\n return entry?.value.value && entry.value.value.kind === \"APP_ROUTE\" ? entry.value.value : null;\n}\n\nexport async function readAppRouteHandlerCacheResponse(\n options: ReadAppRouteHandlerCacheOptions,\n): Promise<Response | null> {\n const routeKey = options.isrRouteKey(options.cleanPathname);\n\n try {\n const cached = await options.isrGet(routeKey);\n const cachedValue = getCachedAppRouteValue(cached);\n\n if (cachedValue && !cached?.isStale) {\n options.isrDebug?.(\"HIT (route)\", options.cleanPathname);\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n buildRouteHandlerCachedResponse(cachedValue, {\n cacheState: \"HIT\",\n cacheControl: cached?.value.cacheControl,\n expireSeconds: options.expireSeconds,\n isHead: options.isAutoHead,\n revalidateSeconds: options.revalidateSeconds,\n }),\n options.middlewareContext,\n );\n }\n\n if (cached?.isStale && cachedValue) {\n const staleValue = cachedValue;\n const revalidateSearchParams = new URLSearchParams(options.revalidateSearchParams);\n\n options.scheduleBackgroundRegeneration(routeKey, async () => {\n await options.runInRevalidationContext(async () => {\n options.setNavigationContext({\n pathname: options.cleanPathname,\n searchParams: revalidateSearchParams,\n params: options.params ?? EMPTY_PARAMS,\n });\n\n const { dynamicUsedInHandler, response } = await runAppRouteHandler({\n basePath: options.basePath,\n consumeDynamicUsage: options.consumeDynamicUsage,\n dynamicConfig: options.dynamicConfig,\n handlerFn: options.handlerFn,\n i18n: options.i18n,\n markDynamicUsage: options.markDynamicUsage,\n params: options.params === null ? null : makeThenableParams(options.params),\n request: new Request(options.requestUrl, { method: \"GET\" }),\n routePattern: options.routePattern,\n setHeadersAccessPhase: options.setHeadersAccessPhase,\n });\n\n options.setNavigationContext(null);\n assertSupportedAppRouteHandlerResponse(response);\n\n if (dynamicUsedInHandler) {\n markKnownDynamicAppRoute(options.routePattern);\n options.isrDebug?.(\"route regen skipped (dynamic usage)\", options.cleanPathname);\n return;\n }\n\n const routeTags = options.buildPageCacheTags(\n options.cleanPathname,\n options.getCollectedFetchTags(),\n );\n const routeCacheValue = await buildAppRouteCacheValue(response);\n await options.isrSet(\n routeKey,\n routeCacheValue,\n options.revalidateSeconds,\n routeTags,\n options.expireSeconds,\n );\n options.isrDebug?.(\"route regen complete\", routeKey);\n });\n });\n\n options.isrDebug?.(\"STALE (route)\", options.cleanPathname);\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n buildRouteHandlerCachedResponse(staleValue, {\n cacheState: \"STALE\",\n cacheControl: cached.value.cacheControl,\n expireSeconds: options.expireSeconds,\n isHead: options.isAutoHead,\n revalidateSeconds: options.revalidateSeconds,\n }),\n options.middlewareContext,\n );\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D,cAAc,QAAQ;MACtB,uBAAuB,QAAQ;MAChC,CAAC;KAEF,QAAQ,qBAAqB,KAAK;KAClC,uCAAuC,SAAS;KAEhD,IAAI,sBAAsB;MACxB,yBAAyB,QAAQ,aAAa;MAC9C,QAAQ,WAAW,uCAAuC,QAAQ,cAAc;MAChF;;KAGF,MAAM,YAAY,QAAQ,mBACxB,QAAQ,eACR,QAAQ,uBAAuB,CAChC;KACD,MAAM,kBAAkB,MAAM,wBAAwB,SAAS;KAC/D,MAAM,QAAQ,OACZ,UACA,iBACA,QAAQ,mBACR,WACA,QAAQ,cACT;KACD,QAAQ,WAAW,wBAAwB,SAAS;MACpD;KACF;GAEF,QAAQ,WAAW,iBAAiB,QAAQ,cAAc;GAC1D,QAAQ,qBAAqB;GAC7B,OAAO,mCACL,gCAAgC,YAAY;IAC1C,YAAY;IACZ,cAAc,OAAO,MAAM;IAC3B,eAAe,QAAQ;IACvB,QAAQ,QAAQ;IAChB,mBAAmB,QAAQ;IAC5B,CAAC,EACF,QAAQ,kBACT;;UAEI,iBAAiB;EACxB,QAAQ,MAAM,wCAAwC,gBAAgB;;CAGxE,OAAO"}
|
|
@@ -21,6 +21,7 @@ type DispatchAppRouteHandlerOptions = {
|
|
|
21
21
|
basePath?: string;
|
|
22
22
|
cleanPathname: string;
|
|
23
23
|
clearRequestContext: () => void;
|
|
24
|
+
draftModeSecret: string;
|
|
24
25
|
expireSeconds?: number;
|
|
25
26
|
i18n?: NextI18nConfig | null;
|
|
26
27
|
isDevelopment?: boolean;
|
|
@@ -31,7 +32,12 @@ type DispatchAppRouteHandlerOptions = {
|
|
|
31
32
|
isrSet: RouteHandlerCacheSetter;
|
|
32
33
|
middlewareContext: RouteHandlerMiddlewareContext;
|
|
33
34
|
middlewareRequestHeaders?: Headers | null;
|
|
34
|
-
|
|
35
|
+
/**
|
|
36
|
+
* `null` for non-dynamic routes, matching Next.js semantics. The dispatch
|
|
37
|
+
* layer threads this through to the handler context unchanged so user code
|
|
38
|
+
* (`params ? await params : null`) resolves to `null`.
|
|
39
|
+
*/
|
|
40
|
+
params: AppRouteParams | null;
|
|
35
41
|
request: Request;
|
|
36
42
|
route: AppRouteHandlerDispatchRoute;
|
|
37
43
|
scheduleBackgroundRegeneration: RouteHandlerBackgroundRegenerator;
|
|
@@ -22,6 +22,7 @@ function buildRouteHandlerPageCacheTags(pathname, extraTags, routeSegments) {
|
|
|
22
22
|
async function runInRouteHandlerRevalidationContext(options, renderFn) {
|
|
23
23
|
await runWithRequestContext(createRequestContext({
|
|
24
24
|
headersContext: createStaticGenerationHeadersContext({
|
|
25
|
+
draftModeSecret: options.draftModeSecret,
|
|
25
26
|
dynamicConfig: options.dynamicConfig,
|
|
26
27
|
routeKind: "route",
|
|
27
28
|
routePattern: options.routePattern
|
|
@@ -92,6 +93,7 @@ async function dispatchAppRouteHandler(options) {
|
|
|
92
93
|
runInRevalidationContext(renderFn) {
|
|
93
94
|
return runInRouteHandlerRevalidationContext({
|
|
94
95
|
cleanPathname: options.cleanPathname,
|
|
96
|
+
draftModeSecret: options.draftModeSecret,
|
|
95
97
|
dynamicConfig: handler.dynamic,
|
|
96
98
|
routePattern: route.pattern,
|
|
97
99
|
routeSegments: route.routeSegments
|
|
@@ -117,6 +119,7 @@ async function dispatchAppRouteHandler(options) {
|
|
|
117
119
|
cleanPathname: options.cleanPathname,
|
|
118
120
|
clearRequestContext: options.clearRequestContext,
|
|
119
121
|
consumeDynamicUsage,
|
|
122
|
+
draftModeSecret: options.draftModeSecret,
|
|
120
123
|
executionContext: getRequestExecutionContext(),
|
|
121
124
|
getAndClearPendingCookies,
|
|
122
125
|
getCollectedFetchTags,
|
|
@@ -133,7 +136,7 @@ async function dispatchAppRouteHandler(options) {
|
|
|
133
136
|
method,
|
|
134
137
|
middlewareContext: options.middlewareContext,
|
|
135
138
|
middlewareRequestHeaders: options.middlewareRequestHeaders,
|
|
136
|
-
params: makeThenableParams(options.params),
|
|
139
|
+
params: options.params === null ? null : makeThenableParams(options.params),
|
|
137
140
|
reportRequestError(error, request, context) {
|
|
138
141
|
reportRequestError(error, request, context);
|
|
139
142
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-route-handler-dispatch.js","names":[],"sources":["../../src/server/app-route-handler-dispatch.ts"],"sourcesContent":["import type { NextI18nConfig } from \"../config/next-config.js\";\nimport {\n getCollectedFetchTags,\n ensureFetchPatch,\n setCurrentFetchSoftTags,\n} from \"vinext/shims/fetch-cache\";\nimport {\n consumeDynamicUsage,\n getAndClearPendingCookies,\n getDraftModeCookieHeader,\n markDynamicUsage,\n setHeadersAccessPhase,\n} from \"vinext/shims/headers\";\nimport { setNavigationContext } from \"vinext/shims/navigation\";\nimport { getRequestExecutionContext } from \"vinext/shims/request-context\";\nimport { createRequestContext, runWithRequestContext } from \"vinext/shims/unified-request-context\";\nimport type { ISRCacheEntry } from \"./isr-cache.js\";\nimport {\n getAppRouteHandlerRevalidateSeconds,\n hasAppRouteHandlerDefaultExport,\n resolveAppRouteHandlerMethod,\n shouldReadAppRouteHandlerCache,\n type AppRouteHandlerModule,\n} from \"./app-route-handler-policy.js\";\nimport { readAppRouteHandlerCacheResponse } from \"./app-route-handler-cache.js\";\nimport {\n executeAppRouteHandler,\n type AppRouteDebugLogger,\n type AppRouteHandlerFunction,\n type AppRouteParams,\n type RouteHandlerCacheSetter,\n} from \"./app-route-handler-execution.js\";\nimport { isKnownDynamicAppRoute, isValidHTTPMethod } from \"./app-route-handler-runtime.js\";\nimport {\n applyRouteHandlerMiddlewareContext,\n type RouteHandlerMiddlewareContext,\n} from \"./app-route-handler-response.js\";\nimport { createStaticGenerationHeadersContext } from \"./app-static-generation.js\";\nimport { buildPageCacheTags } from \"./implicit-tags.js\";\nimport { makeThenableParams } from \"vinext/shims/thenable-params\";\nimport { reportRequestError } from \"./instrumentation.js\";\n\ntype AppRouteHandlerDispatchRoute = {\n pattern: string;\n routeHandler: AppRouteHandlerModule;\n routeSegments: string[];\n};\n\ntype RouteHandlerCacheGetter = (key: string) => Promise<ISRCacheEntry | null>;\ntype RouteHandlerBackgroundRegenerationErrorContext = {\n routerKind: \"App Router\";\n routePath: string;\n routeType: \"route\";\n};\ntype RouteHandlerBackgroundRegenerator = (\n key: string,\n renderFn: () => Promise<void>,\n errorContext?: RouteHandlerBackgroundRegenerationErrorContext,\n) => void;\n\ntype DispatchAppRouteHandlerOptions = {\n basePath?: string;\n cleanPathname: string;\n clearRequestContext: () => void;\n expireSeconds?: number;\n i18n?: NextI18nConfig | null;\n isDevelopment?: boolean;\n isProduction?: boolean;\n isrDebug?: AppRouteDebugLogger;\n isrGet: RouteHandlerCacheGetter;\n isrRouteKey: (pathname: string) => string;\n isrSet: RouteHandlerCacheSetter;\n middlewareContext: RouteHandlerMiddlewareContext;\n middlewareRequestHeaders?: Headers | null;\n params: AppRouteParams;\n request: Request;\n route: AppRouteHandlerDispatchRoute;\n scheduleBackgroundRegeneration: RouteHandlerBackgroundRegenerator;\n searchParams: URLSearchParams;\n};\n\nfunction isAppRouteHandlerFunction(value: unknown): value is AppRouteHandlerFunction {\n return typeof value === \"function\";\n}\n\nfunction buildRouteHandlerPageCacheTags(\n pathname: string,\n extraTags: string[],\n routeSegments: string[],\n): string[] {\n return buildPageCacheTags(pathname, extraTags, routeSegments, \"route\");\n}\n\nasync function runInRouteHandlerRevalidationContext(\n options: {\n cleanPathname: string;\n dynamicConfig?: string;\n routePattern: string;\n routeSegments: string[];\n },\n renderFn: () => Promise<void>,\n): Promise<void> {\n const headersContext = createStaticGenerationHeadersContext({\n dynamicConfig: options.dynamicConfig,\n routeKind: \"route\",\n routePattern: options.routePattern,\n });\n const requestContext = createRequestContext({\n headersContext,\n executionContext: getRequestExecutionContext(),\n unstableCacheRevalidation: \"foreground\",\n });\n\n await runWithRequestContext(requestContext, async () => {\n ensureFetchPatch();\n setCurrentFetchSoftTags(\n buildRouteHandlerPageCacheTags(options.cleanPathname, [], options.routeSegments),\n );\n await renderFn();\n });\n}\n\nexport async function dispatchAppRouteHandler(\n options: DispatchAppRouteHandlerOptions,\n): Promise<Response> {\n const { route } = options;\n const handler = route.routeHandler;\n const method = options.request.method.toUpperCase();\n const revalidateSeconds = getAppRouteHandlerRevalidateSeconds(handler);\n const isDevelopment = options.isDevelopment ?? process.env.NODE_ENV === \"development\";\n const isProduction = options.isProduction ?? process.env.NODE_ENV === \"production\";\n\n if (hasAppRouteHandlerDefaultExport(handler) && isDevelopment) {\n console.error(\n \"[vinext] Detected default export in route handler \" +\n route.pattern +\n \". Export a named export for each HTTP method instead.\",\n );\n }\n\n // Reject non-standard HTTP methods before any auto-OPTIONS/405 logic.\n // Next.js returns 400 for invalid methods; vinext mirrors that behavior.\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/route-modules/app-route/module.ts#L390-L392\n if (!isValidHTTPMethod(method)) {\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n new Response(null, { status: 400 }),\n options.middlewareContext,\n );\n }\n\n const { allowHeaderForOptions, handlerFn, isAutoHead, shouldAutoRespondToOptions } =\n resolveAppRouteHandlerMethod(handler, method);\n\n if (shouldAutoRespondToOptions) {\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n new Response(null, {\n status: 204,\n headers: { Allow: allowHeaderForOptions },\n }),\n options.middlewareContext,\n );\n }\n\n const resolvedHandlerFn = isAppRouteHandlerFunction(handlerFn) ? handlerFn : undefined;\n\n if (\n revalidateSeconds !== null &&\n shouldReadAppRouteHandlerCache({\n dynamicConfig: handler.dynamic,\n handlerFn: resolvedHandlerFn,\n isAutoHead,\n isKnownDynamic: isKnownDynamicAppRoute(route.pattern),\n isProduction,\n method,\n revalidateSeconds,\n }) &&\n resolvedHandlerFn\n ) {\n const cachedRouteResponse = await readAppRouteHandlerCacheResponse({\n basePath: options.basePath,\n buildPageCacheTags(pathname, extraTags) {\n return buildRouteHandlerPageCacheTags(pathname, extraTags, route.routeSegments);\n },\n cleanPathname: options.cleanPathname,\n clearRequestContext: options.clearRequestContext,\n consumeDynamicUsage,\n dynamicConfig: handler.dynamic,\n getCollectedFetchTags,\n handlerFn: resolvedHandlerFn,\n i18n: options.i18n,\n isAutoHead,\n isrDebug: options.isrDebug,\n isrGet: options.isrGet,\n isrRouteKey: options.isrRouteKey,\n isrSet: options.isrSet,\n markDynamicUsage,\n middlewareContext: options.middlewareContext,\n params: options.params,\n requestUrl: options.request.url,\n revalidateSearchParams: options.searchParams,\n expireSeconds: options.expireSeconds,\n revalidateSeconds,\n routePattern: route.pattern,\n runInRevalidationContext(renderFn) {\n return runInRouteHandlerRevalidationContext(\n {\n cleanPathname: options.cleanPathname,\n dynamicConfig: handler.dynamic,\n routePattern: route.pattern,\n routeSegments: route.routeSegments,\n },\n renderFn,\n );\n },\n scheduleBackgroundRegeneration(key, renderFn) {\n options.scheduleBackgroundRegeneration(key, renderFn, {\n routerKind: \"App Router\",\n routePath: route.pattern,\n routeType: \"route\",\n });\n },\n setHeadersAccessPhase,\n setNavigationContext,\n });\n if (cachedRouteResponse) {\n return cachedRouteResponse;\n }\n }\n\n if (resolvedHandlerFn) {\n return executeAppRouteHandler({\n basePath: options.basePath,\n buildPageCacheTags(pathname, extraTags) {\n return buildRouteHandlerPageCacheTags(pathname, extraTags, route.routeSegments);\n },\n cleanPathname: options.cleanPathname,\n clearRequestContext: options.clearRequestContext,\n consumeDynamicUsage,\n executionContext: getRequestExecutionContext(),\n getAndClearPendingCookies,\n getCollectedFetchTags,\n getDraftModeCookieHeader,\n handler,\n handlerFn: resolvedHandlerFn,\n i18n: options.i18n,\n isAutoHead,\n isProduction,\n isrDebug: options.isrDebug,\n isrRouteKey: options.isrRouteKey,\n isrSet: options.isrSet,\n markDynamicUsage,\n method,\n middlewareContext: options.middlewareContext,\n middlewareRequestHeaders: options.middlewareRequestHeaders,\n params: makeThenableParams(options.params),\n reportRequestError(error, request, context) {\n void reportRequestError(error, request, context);\n },\n request: options.request,\n expireSeconds: options.expireSeconds,\n revalidateSeconds,\n routePattern: route.pattern,\n setHeadersAccessPhase,\n });\n }\n\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n new Response(null, {\n status: 405,\n }),\n options.middlewareContext,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiFA,SAAS,0BAA0B,OAAkD;CACnF,OAAO,OAAO,UAAU;;AAG1B,SAAS,+BACP,UACA,WACA,eACU;CACV,OAAO,mBAAmB,UAAU,WAAW,eAAe,QAAQ;;AAGxE,eAAe,qCACb,SAMA,UACe;CAYf,MAAM,sBANiB,qBAAqB;EAC1C,gBANqB,qCAAqC;GAC1D,eAAe,QAAQ;GACvB,WAAW;GACX,cAAc,QAAQ;GACvB,CAEe;EACd,kBAAkB,4BAA4B;EAC9C,2BAA2B;EAC5B,CAEyC,EAAE,YAAY;EACtD,kBAAkB;EAClB,wBACE,+BAA+B,QAAQ,eAAe,EAAE,EAAE,QAAQ,cAAc,CACjF;EACD,MAAM,UAAU;GAChB;;AAGJ,eAAsB,wBACpB,SACmB;CACnB,MAAM,EAAE,UAAU;CAClB,MAAM,UAAU,MAAM;CACtB,MAAM,SAAS,QAAQ,QAAQ,OAAO,aAAa;CACnD,MAAM,oBAAoB,oCAAoC,QAAQ;CACtE,MAAM,gBAAgB,QAAQ,iBAAiB,QAAQ,IAAI,aAAa;CACxE,MAAM,eAAe,QAAQ,gBAAgB,QAAQ,IAAI,aAAa;CAEtE,IAAI,gCAAgC,QAAQ,IAAI,eAC9C,QAAQ,MACN,uDACE,MAAM,UACN,wDACH;CAMH,IAAI,CAAC,kBAAkB,OAAO,EAAE;EAC9B,QAAQ,qBAAqB;EAC7B,OAAO,mCACL,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,CAAC,EACnC,QAAQ,kBACT;;CAGH,MAAM,EAAE,uBAAuB,WAAW,YAAY,+BACpD,6BAA6B,SAAS,OAAO;CAE/C,IAAI,4BAA4B;EAC9B,QAAQ,qBAAqB;EAC7B,OAAO,mCACL,IAAI,SAAS,MAAM;GACjB,QAAQ;GACR,SAA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M,QAAQ;EACd;EACA;EACA,UAAU,QAAQ;EAClB,aAAa,QAAQ;EACrB,QAAQ,QAAQ;EAChB;EACA;EACA,mBAAmB,QAAQ;EAC3B,0BAA0B,QAAQ;EAClC,QAAQ,mBAAmB,QAAQ,OAAO;EAC1C,mBAAmB,OAAO,SAAS,SAAS;GAC1C,mBAAwB,OAAO,SAAS,QAAQ;;EAElD,SAAS,QAAQ;EACjB,eAAe,QAAQ;EACvB;EACA,cAAc,MAAM;EACpB;EACD,CAAC;CAGJ,QAAQ,qBAAqB;CAC7B,OAAO,mCACL,IAAI,SAAS,MAAM,EACjB,QAAQ,KACT,CAAC,EACF,QAAQ,kBACT"}
|
|
1
|
+
{"version":3,"file":"app-route-handler-dispatch.js","names":[],"sources":["../../src/server/app-route-handler-dispatch.ts"],"sourcesContent":["import type { NextI18nConfig } from \"../config/next-config.js\";\nimport {\n getCollectedFetchTags,\n ensureFetchPatch,\n setCurrentFetchSoftTags,\n} from \"vinext/shims/fetch-cache\";\nimport {\n consumeDynamicUsage,\n getAndClearPendingCookies,\n getDraftModeCookieHeader,\n markDynamicUsage,\n setHeadersAccessPhase,\n} from \"vinext/shims/headers\";\nimport { setNavigationContext } from \"vinext/shims/navigation\";\nimport { getRequestExecutionContext } from \"vinext/shims/request-context\";\nimport { createRequestContext, runWithRequestContext } from \"vinext/shims/unified-request-context\";\nimport type { ISRCacheEntry } from \"./isr-cache.js\";\nimport {\n getAppRouteHandlerRevalidateSeconds,\n hasAppRouteHandlerDefaultExport,\n resolveAppRouteHandlerMethod,\n shouldReadAppRouteHandlerCache,\n type AppRouteHandlerModule,\n} from \"./app-route-handler-policy.js\";\nimport { readAppRouteHandlerCacheResponse } from \"./app-route-handler-cache.js\";\nimport {\n executeAppRouteHandler,\n type AppRouteDebugLogger,\n type AppRouteHandlerFunction,\n type AppRouteParams,\n type RouteHandlerCacheSetter,\n} from \"./app-route-handler-execution.js\";\nimport { isKnownDynamicAppRoute, isValidHTTPMethod } from \"./app-route-handler-runtime.js\";\nimport {\n applyRouteHandlerMiddlewareContext,\n type RouteHandlerMiddlewareContext,\n} from \"./app-route-handler-response.js\";\nimport { createStaticGenerationHeadersContext } from \"./app-static-generation.js\";\nimport { buildPageCacheTags } from \"./implicit-tags.js\";\nimport { makeThenableParams } from \"vinext/shims/thenable-params\";\nimport { reportRequestError } from \"./instrumentation.js\";\n\ntype AppRouteHandlerDispatchRoute = {\n pattern: string;\n routeHandler: AppRouteHandlerModule;\n routeSegments: string[];\n};\n\ntype RouteHandlerCacheGetter = (key: string) => Promise<ISRCacheEntry | null>;\ntype RouteHandlerBackgroundRegenerationErrorContext = {\n routerKind: \"App Router\";\n routePath: string;\n routeType: \"route\";\n};\ntype RouteHandlerBackgroundRegenerator = (\n key: string,\n renderFn: () => Promise<void>,\n errorContext?: RouteHandlerBackgroundRegenerationErrorContext,\n) => void;\n\ntype DispatchAppRouteHandlerOptions = {\n basePath?: string;\n cleanPathname: string;\n clearRequestContext: () => void;\n draftModeSecret: string;\n expireSeconds?: number;\n i18n?: NextI18nConfig | null;\n isDevelopment?: boolean;\n isProduction?: boolean;\n isrDebug?: AppRouteDebugLogger;\n isrGet: RouteHandlerCacheGetter;\n isrRouteKey: (pathname: string) => string;\n isrSet: RouteHandlerCacheSetter;\n middlewareContext: RouteHandlerMiddlewareContext;\n middlewareRequestHeaders?: Headers | null;\n /**\n * `null` for non-dynamic routes, matching Next.js semantics. The dispatch\n * layer threads this through to the handler context unchanged so user code\n * (`params ? await params : null`) resolves to `null`.\n */\n params: AppRouteParams | null;\n request: Request;\n route: AppRouteHandlerDispatchRoute;\n scheduleBackgroundRegeneration: RouteHandlerBackgroundRegenerator;\n searchParams: URLSearchParams;\n};\n\nfunction isAppRouteHandlerFunction(value: unknown): value is AppRouteHandlerFunction {\n return typeof value === \"function\";\n}\n\nfunction buildRouteHandlerPageCacheTags(\n pathname: string,\n extraTags: string[],\n routeSegments: string[],\n): string[] {\n return buildPageCacheTags(pathname, extraTags, routeSegments, \"route\");\n}\n\nasync function runInRouteHandlerRevalidationContext(\n options: {\n cleanPathname: string;\n draftModeSecret: string;\n dynamicConfig?: string;\n routePattern: string;\n routeSegments: string[];\n },\n renderFn: () => Promise<void>,\n): Promise<void> {\n const headersContext = createStaticGenerationHeadersContext({\n draftModeSecret: options.draftModeSecret,\n dynamicConfig: options.dynamicConfig,\n routeKind: \"route\",\n routePattern: options.routePattern,\n });\n const requestContext = createRequestContext({\n headersContext,\n executionContext: getRequestExecutionContext(),\n unstableCacheRevalidation: \"foreground\",\n });\n\n await runWithRequestContext(requestContext, async () => {\n ensureFetchPatch();\n setCurrentFetchSoftTags(\n buildRouteHandlerPageCacheTags(options.cleanPathname, [], options.routeSegments),\n );\n await renderFn();\n });\n}\n\nexport async function dispatchAppRouteHandler(\n options: DispatchAppRouteHandlerOptions,\n): Promise<Response> {\n const { route } = options;\n const handler = route.routeHandler;\n const method = options.request.method.toUpperCase();\n const revalidateSeconds = getAppRouteHandlerRevalidateSeconds(handler);\n const isDevelopment = options.isDevelopment ?? process.env.NODE_ENV === \"development\";\n const isProduction = options.isProduction ?? process.env.NODE_ENV === \"production\";\n\n if (hasAppRouteHandlerDefaultExport(handler) && isDevelopment) {\n console.error(\n \"[vinext] Detected default export in route handler \" +\n route.pattern +\n \". Export a named export for each HTTP method instead.\",\n );\n }\n\n // Reject non-standard HTTP methods before any auto-OPTIONS/405 logic.\n // Next.js returns 400 for invalid methods; vinext mirrors that behavior.\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/route-modules/app-route/module.ts#L390-L392\n if (!isValidHTTPMethod(method)) {\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n new Response(null, { status: 400 }),\n options.middlewareContext,\n );\n }\n\n const { allowHeaderForOptions, handlerFn, isAutoHead, shouldAutoRespondToOptions } =\n resolveAppRouteHandlerMethod(handler, method);\n\n if (shouldAutoRespondToOptions) {\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n new Response(null, {\n status: 204,\n headers: { Allow: allowHeaderForOptions },\n }),\n options.middlewareContext,\n );\n }\n\n const resolvedHandlerFn = isAppRouteHandlerFunction(handlerFn) ? handlerFn : undefined;\n\n if (\n revalidateSeconds !== null &&\n shouldReadAppRouteHandlerCache({\n dynamicConfig: handler.dynamic,\n handlerFn: resolvedHandlerFn,\n isAutoHead,\n isKnownDynamic: isKnownDynamicAppRoute(route.pattern),\n isProduction,\n method,\n revalidateSeconds,\n }) &&\n resolvedHandlerFn\n ) {\n const cachedRouteResponse = await readAppRouteHandlerCacheResponse({\n basePath: options.basePath,\n buildPageCacheTags(pathname, extraTags) {\n return buildRouteHandlerPageCacheTags(pathname, extraTags, route.routeSegments);\n },\n cleanPathname: options.cleanPathname,\n clearRequestContext: options.clearRequestContext,\n consumeDynamicUsage,\n dynamicConfig: handler.dynamic,\n getCollectedFetchTags,\n handlerFn: resolvedHandlerFn,\n i18n: options.i18n,\n isAutoHead,\n isrDebug: options.isrDebug,\n isrGet: options.isrGet,\n isrRouteKey: options.isrRouteKey,\n isrSet: options.isrSet,\n markDynamicUsage,\n middlewareContext: options.middlewareContext,\n params: options.params,\n requestUrl: options.request.url,\n revalidateSearchParams: options.searchParams,\n expireSeconds: options.expireSeconds,\n revalidateSeconds,\n routePattern: route.pattern,\n runInRevalidationContext(renderFn) {\n return runInRouteHandlerRevalidationContext(\n {\n cleanPathname: options.cleanPathname,\n draftModeSecret: options.draftModeSecret,\n dynamicConfig: handler.dynamic,\n routePattern: route.pattern,\n routeSegments: route.routeSegments,\n },\n renderFn,\n );\n },\n scheduleBackgroundRegeneration(key, renderFn) {\n options.scheduleBackgroundRegeneration(key, renderFn, {\n routerKind: \"App Router\",\n routePath: route.pattern,\n routeType: \"route\",\n });\n },\n setHeadersAccessPhase,\n setNavigationContext,\n });\n if (cachedRouteResponse) {\n return cachedRouteResponse;\n }\n }\n\n if (resolvedHandlerFn) {\n return executeAppRouteHandler({\n basePath: options.basePath,\n buildPageCacheTags(pathname, extraTags) {\n return buildRouteHandlerPageCacheTags(pathname, extraTags, route.routeSegments);\n },\n cleanPathname: options.cleanPathname,\n clearRequestContext: options.clearRequestContext,\n consumeDynamicUsage,\n draftModeSecret: options.draftModeSecret,\n executionContext: getRequestExecutionContext(),\n getAndClearPendingCookies,\n getCollectedFetchTags,\n getDraftModeCookieHeader,\n handler,\n handlerFn: resolvedHandlerFn,\n i18n: options.i18n,\n isAutoHead,\n isProduction,\n isrDebug: options.isrDebug,\n isrRouteKey: options.isrRouteKey,\n isrSet: options.isrSet,\n markDynamicUsage,\n method,\n middlewareContext: options.middlewareContext,\n middlewareRequestHeaders: options.middlewareRequestHeaders,\n params: options.params === null ? null : makeThenableParams(options.params),\n reportRequestError(error, request, context) {\n void reportRequestError(error, request, context);\n },\n request: options.request,\n expireSeconds: options.expireSeconds,\n revalidateSeconds,\n routePattern: route.pattern,\n setHeadersAccessPhase,\n });\n }\n\n options.clearRequestContext();\n return applyRouteHandlerMiddlewareContext(\n new Response(null, {\n status: 405,\n }),\n options.middlewareContext,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuFA,SAAS,0BAA0B,OAAkD;CACnF,OAAO,OAAO,UAAU;;AAG1B,SAAS,+BACP,UACA,WACA,eACU;CACV,OAAO,mBAAmB,UAAU,WAAW,eAAe,QAAQ;;AAGxE,eAAe,qCACb,SAOA,UACe;CAaf,MAAM,sBANiB,qBAAqB;EAC1C,gBAPqB,qCAAqC;GAC1D,iBAAiB,QAAQ;GACzB,eAAe,QAAQ;GACvB,WAAW;GACX,cAAc,QAAQ;GACvB,CAEe;EACd,kBAAkB,4BAA4B;EAC9C,2BAA2B;EAC5B,CAEyC,EAAE,YAAY;EACtD,kBAAkB;EAClB,wBACE,+BAA+B,QAAQ,eAAe,EAAE,EAAE,QAAQ,cAAc,CACjF;EACD,MAAM,UAAU;GAChB;;AAGJ,eAAsB,wBACpB,SACmB;CACnB,MAAM,EAAE,UAAU;CAClB,MAAM,UAAU,MAAM;CACtB,MAAM,SAAS,QAA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AAQ;GACvB;GACA,cAAc,MAAM;GACpB,yBAAyB,UAAU;IACjC,OAAO,qCACL;KACE,eAAe,QAAQ;KACvB,iBAAiB,QAAQ;KACzB,eAAe,QAAQ;KACvB,cAAc,MAAM;KACpB,eAAe,MAAM;KACtB,EACD,SACD;;GAEH,+BAA+B,KAAK,UAAU;IAC5C,QAAQ,+BAA+B,KAAK,UAAU;KACpD,YAAY;KACZ,WAAW,MAAM;KACjB,WAAW;KACZ,CAAC;;GAEJ;GACA;GACD,CAAC;EACF,IAAI,qBACF,OAAO;;CAIX,IAAI,mBACF,OAAO,uBAAuB;EAC5B,UAAU,QAAQ;EAClB,mBAAmB,UAAU,WAAW;GACtC,OAAO,+BAA+B,UAAU,WAAW,MAAM,cAAc;;EAEjF,eAAe,QAAQ;EACvB,qBAAqB,QAAQ;EAC7B;EACA,iBAAiB,QAAQ;EACzB,kBAAkB,4BAA4B;EAC9C;EACA;EACA;EACA;EACA,WAAW;EACX,MAAM,QAAQ;EACd;EACA;EACA,UAAU,QAAQ;EAClB,aAAa,QAAQ;EACrB,QAAQ,QAAQ;EAChB;EACA;EACA,mBAAmB,QAAQ;EAC3B,0BAA0B,QAAQ;EAClC,QAAQ,QAAQ,WAAW,OAAO,OAAO,mBAAmB,QAAQ,OAAO;EAC3E,mBAAmB,OAAO,SAAS,SAAS;GAC1C,mBAAwB,OAAO,SAAS,QAAQ;;EAElD,SAAS,QAAQ;EACjB,eAAe,QAAQ;EACvB;EACA,cAAc,MAAM;EACpB;EACD,CAAC;CAGJ,QAAQ,qBAAqB;CAC7B,OAAO,mCACL,IAAI,SAAS,MAAM,EACjB,QAAQ,KACT,CAAC,EACF,QAAQ,kBACT"}
|
|
@@ -10,8 +10,19 @@ import { AppRouteHandlerModule } from "./app-route-handler-policy.js";
|
|
|
10
10
|
type AppRouteParams = Record<string, string | string[]>;
|
|
11
11
|
type AppRouteDynamicUsageFn = () => boolean;
|
|
12
12
|
type MarkAppRouteDynamicUsageFn = () => void;
|
|
13
|
+
/**
|
|
14
|
+
* Route handler context.
|
|
15
|
+
*
|
|
16
|
+
* `params` is `null` for non-dynamic routes (no `[param]` segments) so that
|
|
17
|
+
* user code like `params ? await params : null` resolves to `null`, matching
|
|
18
|
+
* Next.js behavior. For dynamic routes it's a thenable that resolves to the
|
|
19
|
+
* matched params object.
|
|
20
|
+
*
|
|
21
|
+
* See: test/e2e/app-dir/app-routes/app-custom-routes.test.ts in Next.js for
|
|
22
|
+
* the authoritative assertion (`expect(meta.params).toEqual(null)`).
|
|
23
|
+
*/
|
|
13
24
|
type AppRouteHandlerFunction = (request: NextRequest, context: {
|
|
14
|
-
params: AppRouteParams;
|
|
25
|
+
params: AppRouteParams | null;
|
|
15
26
|
}) => Response | Promise<Response>;
|
|
16
27
|
type RouteHandlerCacheSetter = (key: string, data: CachedRouteValue, revalidateSeconds: number, tags: string[], expireSeconds?: number) => Promise<void>;
|
|
17
28
|
type AppRouteErrorReporter = (error: Error, request: {
|
|
@@ -27,12 +38,17 @@ type AppRouteDebugLogger = (event: string, detail: string) => void;
|
|
|
27
38
|
type RunAppRouteHandlerOptions = {
|
|
28
39
|
basePath?: string;
|
|
29
40
|
consumeDynamicUsage: AppRouteDynamicUsageFn;
|
|
41
|
+
draftModeSecret?: string;
|
|
30
42
|
dynamicConfig?: string;
|
|
31
43
|
handlerFn: AppRouteHandlerFunction;
|
|
32
44
|
i18n?: NextI18nConfig | null;
|
|
33
45
|
markDynamicUsage: MarkAppRouteDynamicUsageFn;
|
|
34
46
|
middlewareRequestHeaders?: Headers | null;
|
|
35
|
-
|
|
47
|
+
/**
|
|
48
|
+
* `null` for non-dynamic routes. Passed through to the handler context
|
|
49
|
+
* unchanged — callers are expected to compute this from `route.isDynamic`.
|
|
50
|
+
*/
|
|
51
|
+
params: AppRouteParams | null;
|
|
36
52
|
request: Request;
|
|
37
53
|
routePattern?: string;
|
|
38
54
|
setHeadersAccessPhase?: (phase: HeadersAccessPhase) => HeadersAccessPhase;
|
|
@@ -7,6 +7,7 @@ import { applyRouteHandlerMiddlewareContext, applyRouteHandlerRevalidateHeader,
|
|
|
7
7
|
function configureAppRouteStaticGenerationContext(options) {
|
|
8
8
|
if (options.dynamicConfig === "force-static" || options.dynamicConfig === "error") {
|
|
9
9
|
setHeadersContext(createStaticGenerationHeadersContext({
|
|
10
|
+
draftModeSecret: options.draftModeSecret,
|
|
10
11
|
dynamicConfig: options.dynamicConfig,
|
|
11
12
|
routeKind: "route",
|
|
12
13
|
routePattern: options.routePattern
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-route-handler-execution.js","names":[],"sources":["../../src/server/app-route-handler-execution.ts"],"sourcesContent":["import type { NextI18nConfig } from \"../config/next-config.js\";\nimport { setHeadersContext, type HeadersAccessPhase } from \"vinext/shims/headers\";\nimport type { ExecutionContextLike } from \"vinext/shims/request-context\";\nimport type { CachedRouteValue } from \"vinext/shims/cache\";\nimport type { NextRequest } from \"vinext/shims/server\";\nimport {\n createStaticGenerationHeadersContext,\n getAppRouteStaticGenerationErrorMessage,\n} from \"./app-static-generation.js\";\nimport {\n isPossibleAppRouteActionRequest,\n resolveAppRouteHandlerSpecialError,\n shouldApplyAppRouteHandlerRevalidateHeader,\n shouldWriteAppRouteHandlerCache,\n type AppRouteHandlerModule,\n} from \"./app-route-handler-policy.js\";\nimport {\n applyRouteHandlerMiddlewareContext,\n applyRouteHandlerRevalidateHeader,\n assertSupportedAppRouteHandlerResponse,\n buildAppRouteCacheValue,\n finalizeRouteHandlerResponse,\n markRouteHandlerCacheMiss,\n type RouteHandlerMiddlewareContext,\n} from \"./app-route-handler-response.js\";\nimport {\n createTrackedAppRouteRequest,\n markKnownDynamicAppRoute,\n} from \"./app-route-handler-runtime.js\";\n\nexport type AppRouteParams = Record<string, string | string[]>;\nexport type AppRouteDynamicUsageFn = () => boolean;\nexport type MarkAppRouteDynamicUsageFn = () => void;\nexport type AppRouteHandlerFunction = (\n request: NextRequest,\n context: { params: AppRouteParams },\n) => Response | Promise<Response>;\nexport type RouteHandlerCacheSetter = (\n key: string,\n data: CachedRouteValue,\n revalidateSeconds: number,\n tags: string[],\n expireSeconds?: number,\n) => Promise<void>;\ntype AppRouteErrorReporter = (\n error: Error,\n request: { path: string; method: string; headers: Record<string, string> },\n route: { routerKind: \"App Router\"; routePath: string; routeType: \"route\" },\n) => void;\nexport type AppRouteDebugLogger = (event: string, detail: string) => void;\n\ntype RunAppRouteHandlerOptions = {\n basePath?: string;\n consumeDynamicUsage: AppRouteDynamicUsageFn;\n dynamicConfig?: string;\n handlerFn: AppRouteHandlerFunction;\n i18n?: NextI18nConfig | null;\n markDynamicUsage: MarkAppRouteDynamicUsageFn;\n middlewareRequestHeaders?: Headers | null;\n params: AppRouteParams;\n request: Request;\n routePattern?: string;\n setHeadersAccessPhase?: (phase: HeadersAccessPhase) => HeadersAccessPhase;\n};\n\ntype RunAppRouteHandlerResult = {\n dynamicUsedInHandler: boolean;\n response: Response;\n};\n\ntype ExecuteAppRouteHandlerOptions = {\n buildPageCacheTags: (pathname: string, extraTags: string[]) => string[];\n clearRequestContext: () => void;\n cleanPathname: string;\n executionContext: ExecutionContextLike | null;\n getAndClearPendingCookies: () => string[];\n getCollectedFetchTags: () => string[];\n getDraftModeCookieHeader: () => string | null | undefined;\n handler: AppRouteHandlerModule;\n isAutoHead: boolean;\n isProduction: boolean;\n isrDebug?: AppRouteDebugLogger;\n isrRouteKey: (pathname: string) => string;\n isrSet: RouteHandlerCacheSetter;\n method: string;\n middlewareContext: RouteHandlerMiddlewareContext;\n reportRequestError: AppRouteErrorReporter;\n expireSeconds?: number;\n revalidateSeconds: number | null;\n routePattern: string;\n setHeadersAccessPhase: (phase: HeadersAccessPhase) => HeadersAccessPhase;\n} & RunAppRouteHandlerOptions;\n\nfunction configureAppRouteStaticGenerationContext(options: RunAppRouteHandlerOptions): void {\n if (options.dynamicConfig === \"force-static\" || options.dynamicConfig === \"error\") {\n setHeadersContext(\n createStaticGenerationHeadersContext({\n dynamicConfig: options.dynamicConfig,\n routeKind: \"route\",\n routePattern: options.routePattern,\n }),\n );\n options.setHeadersAccessPhase?.(\"route-handler\");\n }\n}\n\nexport async function runAppRouteHandler(\n options: RunAppRouteHandlerOptions,\n): Promise<RunAppRouteHandlerResult> {\n options.consumeDynamicUsage();\n configureAppRouteStaticGenerationContext(options);\n const trackedRequest = createTrackedAppRouteRequest(options.request, {\n basePath: options.basePath,\n i18n: options.i18n,\n middlewareHeaders: options.middlewareRequestHeaders,\n onDynamicAccess() {\n options.markDynamicUsage();\n },\n requestMode:\n options.dynamicConfig === \"force-static\" || options.dynamicConfig === \"error\"\n ? options.dynamicConfig\n : \"auto\",\n staticGenerationErrorMessage(expression) {\n return getAppRouteStaticGenerationErrorMessage(options.routePattern, expression);\n },\n });\n const response = await options.handlerFn(trackedRequest.request, {\n params: options.params,\n });\n\n return {\n dynamicUsedInHandler: options.consumeDynamicUsage(),\n response,\n };\n}\n\nexport async function executeAppRouteHandler(\n options: ExecuteAppRouteHandlerOptions,\n): Promise<Response> {\n const previousHeadersPhase = options.setHeadersAccessPhase(\"route-handler\");\n\n try {\n const { dynamicUsedInHandler, response } = await runAppRouteHandler({\n ...options,\n dynamicConfig: options.handler.dynamic,\n });\n assertSupportedAppRouteHandlerResponse(response);\n const handlerSetCacheControl = response.headers.has(\"cache-control\");\n\n if (dynamicUsedInHandler) {\n markKnownDynamicAppRoute(options.routePattern);\n }\n\n if (\n shouldApplyAppRouteHandlerRevalidateHeader({\n dynamicUsedInHandler,\n handlerSetCacheControl,\n isAutoHead: options.isAutoHead,\n method: options.method,\n revalidateSeconds: options.revalidateSeconds,\n })\n ) {\n const revalidateSeconds = options.revalidateSeconds;\n if (revalidateSeconds == null) {\n throw new Error(\"Expected route handler revalidate seconds\");\n }\n applyRouteHandlerRevalidateHeader(response, revalidateSeconds, options.expireSeconds);\n }\n\n if (\n shouldWriteAppRouteHandlerCache({\n dynamicConfig: options.handler.dynamic,\n dynamicUsedInHandler,\n handlerSetCacheControl,\n isAutoHead: options.isAutoHead,\n isProduction: options.isProduction,\n method: options.method,\n revalidateSeconds: options.revalidateSeconds,\n })\n ) {\n markRouteHandlerCacheMiss(response);\n const routeClone = response.clone();\n const routeKey = options.isrRouteKey(options.cleanPathname);\n const revalidateSeconds = options.revalidateSeconds;\n if (revalidateSeconds == null) {\n throw new Error(\"Expected route handler cache revalidate seconds\");\n }\n const routeTags = options.buildPageCacheTags(\n options.cleanPathname,\n options.getCollectedFetchTags(),\n );\n const routeWritePromise = (async () => {\n try {\n const routeCacheValue = await buildAppRouteCacheValue(routeClone);\n await options.isrSet(\n routeKey,\n routeCacheValue,\n revalidateSeconds,\n routeTags,\n options.expireSeconds,\n );\n options.isrDebug?.(\"route cache written\", routeKey);\n } catch (cacheErr) {\n console.error(\"[vinext] ISR route cache write error:\", cacheErr);\n }\n })();\n options.executionContext?.waitUntil(routeWritePromise);\n }\n\n const pendingCookies = options.getAndClearPendingCookies();\n const draftCookie = options.getDraftModeCookieHeader();\n options.clearRequestContext();\n\n return applyRouteHandlerMiddlewareContext(\n finalizeRouteHandlerResponse(response, {\n pendingCookies,\n draftCookie,\n isHead: options.isAutoHead,\n }),\n options.middlewareContext,\n );\n } catch (error) {\n const pendingCookies = options.getAndClearPendingCookies();\n const draftCookie = options.getDraftModeCookieHeader();\n const specialError = resolveAppRouteHandlerSpecialError(error, options.request.url, {\n isAction: isPossibleAppRouteActionRequest(options.request),\n });\n options.clearRequestContext();\n\n if (specialError) {\n if (specialError.kind === \"redirect\") {\n return applyRouteHandlerMiddlewareContext(\n finalizeRouteHandlerResponse(\n new Response(null, {\n status: specialError.statusCode,\n headers: { Location: specialError.location },\n }),\n {\n pendingCookies,\n draftCookie,\n isHead: options.isAutoHead,\n },\n ),\n options.middlewareContext,\n );\n }\n\n return applyRouteHandlerMiddlewareContext(\n new Response(null, { status: specialError.statusCode }),\n options.middlewareContext,\n );\n }\n\n console.error(\"[vinext] Route handler error:\", error);\n options.reportRequestError(\n error instanceof Error ? error : new Error(String(error)),\n {\n path: options.cleanPathname,\n method: options.request.method,\n headers: Object.fromEntries(options.request.headers.entries()),\n },\n {\n routerKind: \"App Router\",\n routePath: options.routePattern,\n routeType: \"route\",\n },\n );\n\n return applyRouteHandlerMiddlewareContext(\n new Response(null, { status: 500 }),\n options.middlewareContext,\n );\n } finally {\n options.setHeadersAccessPhase(previousHeadersPhase);\n }\n}\n"],"mappings":";;;;;;AA6FA,SAAS,yCAAyC,SAA0C;CAC1F,IAAI,QAAQ,kBAAkB,kBAAkB,QAAQ,kBAAkB,SAAS;EACjF,kBACE,qCAAqC;GACnC,eAAe,QAAQ;GACvB,WAAW;GACX,cAAc,QAAQ;GACvB,CAAC,CACH;EACD,QAAQ,wBAAwB,gBAAgB;;;AAIpD,eAAsB,mBACpB,SACmC;CACnC,QAAQ,qBAAqB;CAC7B,yCAAyC,QAAQ;CACjD,MAAM,iBAAiB,6BAA6B,QAAQ,SAAS;EACnE,UAAU,QAAQ;EAClB,MAAM,QAAQ;EACd,mBAAmB,QAAQ;EAC3B,kBAAkB;GAChB,QAAQ,kBAAkB;;EAE5B,aACE,QAAQ,kBAAkB,kBAAkB,QAAQ,kBAAkB,UAClE,QAAQ,gBACR;EACN,6BAA6B,YAAY;GACvC,OAAO,wCAAwC,QAAQ,cAAc,WAAW;;EAEnF,CAAC;CACF,MAAM,WAAW,MAAM,QAAQ,UAAU,eAAe,SAAS,EAC/D,QAAQ,QAAQ,QACjB,CAAC;CAEF,OAAO;EACL,sBAAsB,QAAQ,qBAAqB;EACnD;EACD;;AAGH,eAAsB,uBACpB,SACmB;CACnB,MAAM,uBAAuB,QAAQ,sBAAsB,gBAAgB;CAE3E,IAAI;EACF,MAAM,EAAE,sBAAsB,aAAa,MAAM,mBAAmB;GAClE,GAAG;GACH,eAAe,QAAQ,QAAQ;GAChC,CAAC;EACF,uCAAuC,SAAS;EAChD,MAAM,yBAAyB,SAAS,QAAQ,IAAI,gBAAgB;EAEpE,IAAI,sBACF,yBAAyB,Q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F,UAAU,gCAAgC,QAAQ,QAAQ,EAC3D,CAAC;EACF,QAAQ,qBAAqB;EAE7B,IAAI,cAAc;GAChB,IAAI,aAAa,SAAS,YACxB,OAAO,mCACL,6BACE,IAAI,SAAS,MAAM;IACjB,QAAQ,aAAa;IACrB,SAAS,EAAE,UAAU,aAAa,UAAU;IAC7C,CAAC,EACF;IACE;IACA;IACA,QAAQ,QAAQ;IACjB,CACF,EACD,QAAQ,kBACT;GAGH,OAAO,mCACL,IAAI,SAAS,MAAM,EAAE,QAAQ,aAAa,YAAY,CAAC,EACvD,QAAQ,kBACT;;EAGH,QAAQ,MAAM,iCAAiC,MAAM;EACrD,QAAQ,mBACN,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,EACzD;GACE,MAAM,QAAQ;GACd,QAAQ,QAAQ,QAAQ;GACxB,SAAS,OAAO,YAAY,QAAQ,QAAQ,QAAQ,SAAS,CAAC;GAC/D,EACD;GACE,YAAY;GACZ,WAAW,QAAQ;GACnB,WAAW;GACZ,CACF;EAED,OAAO,mCACL,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,CAAC,EACnC,QAAQ,kBACT;WACO;EACR,QAAQ,sBAAsB,qBAAqB"}
|
|
1
|
+
{"version":3,"file":"app-route-handler-execution.js","names":[],"sources":["../../src/server/app-route-handler-execution.ts"],"sourcesContent":["import type { NextI18nConfig } from \"../config/next-config.js\";\nimport { setHeadersContext, type HeadersAccessPhase } from \"vinext/shims/headers\";\nimport type { ExecutionContextLike } from \"vinext/shims/request-context\";\nimport type { CachedRouteValue } from \"vinext/shims/cache\";\nimport type { NextRequest } from \"vinext/shims/server\";\nimport {\n createStaticGenerationHeadersContext,\n getAppRouteStaticGenerationErrorMessage,\n} from \"./app-static-generation.js\";\nimport {\n isPossibleAppRouteActionRequest,\n resolveAppRouteHandlerSpecialError,\n shouldApplyAppRouteHandlerRevalidateHeader,\n shouldWriteAppRouteHandlerCache,\n type AppRouteHandlerModule,\n} from \"./app-route-handler-policy.js\";\nimport {\n applyRouteHandlerMiddlewareContext,\n applyRouteHandlerRevalidateHeader,\n assertSupportedAppRouteHandlerResponse,\n buildAppRouteCacheValue,\n finalizeRouteHandlerResponse,\n markRouteHandlerCacheMiss,\n type RouteHandlerMiddlewareContext,\n} from \"./app-route-handler-response.js\";\nimport {\n createTrackedAppRouteRequest,\n markKnownDynamicAppRoute,\n} from \"./app-route-handler-runtime.js\";\n\nexport type AppRouteParams = Record<string, string | string[]>;\nexport type AppRouteDynamicUsageFn = () => boolean;\nexport type MarkAppRouteDynamicUsageFn = () => void;\n/**\n * Route handler context.\n *\n * `params` is `null` for non-dynamic routes (no `[param]` segments) so that\n * user code like `params ? await params : null` resolves to `null`, matching\n * Next.js behavior. For dynamic routes it's a thenable that resolves to the\n * matched params object.\n *\n * See: test/e2e/app-dir/app-routes/app-custom-routes.test.ts in Next.js for\n * the authoritative assertion (`expect(meta.params).toEqual(null)`).\n */\nexport type AppRouteHandlerFunction = (\n request: NextRequest,\n context: { params: AppRouteParams | null },\n) => Response | Promise<Response>;\nexport type RouteHandlerCacheSetter = (\n key: string,\n data: CachedRouteValue,\n revalidateSeconds: number,\n tags: string[],\n expireSeconds?: number,\n) => Promise<void>;\ntype AppRouteErrorReporter = (\n error: Error,\n request: { path: string; method: string; headers: Record<string, string> },\n route: { routerKind: \"App Router\"; routePath: string; routeType: \"route\" },\n) => void;\nexport type AppRouteDebugLogger = (event: string, detail: string) => void;\n\ntype RunAppRouteHandlerOptions = {\n basePath?: string;\n consumeDynamicUsage: AppRouteDynamicUsageFn;\n draftModeSecret?: string;\n dynamicConfig?: string;\n handlerFn: AppRouteHandlerFunction;\n i18n?: NextI18nConfig | null;\n markDynamicUsage: MarkAppRouteDynamicUsageFn;\n middlewareRequestHeaders?: Headers | null;\n /**\n * `null` for non-dynamic routes. Passed through to the handler context\n * unchanged — callers are expected to compute this from `route.isDynamic`.\n */\n params: AppRouteParams | null;\n request: Request;\n routePattern?: string;\n setHeadersAccessPhase?: (phase: HeadersAccessPhase) => HeadersAccessPhase;\n};\n\ntype RunAppRouteHandlerResult = {\n dynamicUsedInHandler: boolean;\n response: Response;\n};\n\ntype ExecuteAppRouteHandlerOptions = {\n buildPageCacheTags: (pathname: string, extraTags: string[]) => string[];\n clearRequestContext: () => void;\n cleanPathname: string;\n executionContext: ExecutionContextLike | null;\n getAndClearPendingCookies: () => string[];\n getCollectedFetchTags: () => string[];\n getDraftModeCookieHeader: () => string | null | undefined;\n handler: AppRouteHandlerModule;\n isAutoHead: boolean;\n isProduction: boolean;\n isrDebug?: AppRouteDebugLogger;\n isrRouteKey: (pathname: string) => string;\n isrSet: RouteHandlerCacheSetter;\n method: string;\n middlewareContext: RouteHandlerMiddlewareContext;\n reportRequestError: AppRouteErrorReporter;\n expireSeconds?: number;\n revalidateSeconds: number | null;\n routePattern: string;\n setHeadersAccessPhase: (phase: HeadersAccessPhase) => HeadersAccessPhase;\n} & RunAppRouteHandlerOptions;\n\nfunction configureAppRouteStaticGenerationContext(options: RunAppRouteHandlerOptions): void {\n if (options.dynamicConfig === \"force-static\" || options.dynamicConfig === \"error\") {\n setHeadersContext(\n createStaticGenerationHeadersContext({\n draftModeSecret: options.draftModeSecret,\n dynamicConfig: options.dynamicConfig,\n routeKind: \"route\",\n routePattern: options.routePattern,\n }),\n );\n options.setHeadersAccessPhase?.(\"route-handler\");\n }\n}\n\nexport async function runAppRouteHandler(\n options: RunAppRouteHandlerOptions,\n): Promise<RunAppRouteHandlerResult> {\n options.consumeDynamicUsage();\n configureAppRouteStaticGenerationContext(options);\n const trackedRequest = createTrackedAppRouteRequest(options.request, {\n basePath: options.basePath,\n i18n: options.i18n,\n middlewareHeaders: options.middlewareRequestHeaders,\n onDynamicAccess() {\n options.markDynamicUsage();\n },\n requestMode:\n options.dynamicConfig === \"force-static\" || options.dynamicConfig === \"error\"\n ? options.dynamicConfig\n : \"auto\",\n staticGenerationErrorMessage(expression) {\n return getAppRouteStaticGenerationErrorMessage(options.routePattern, expression);\n },\n });\n const response = await options.handlerFn(trackedRequest.request, {\n params: options.params,\n });\n\n return {\n dynamicUsedInHandler: options.consumeDynamicUsage(),\n response,\n };\n}\n\nexport async function executeAppRouteHandler(\n options: ExecuteAppRouteHandlerOptions,\n): Promise<Response> {\n const previousHeadersPhase = options.setHeadersAccessPhase(\"route-handler\");\n\n try {\n const { dynamicUsedInHandler, response } = await runAppRouteHandler({\n ...options,\n dynamicConfig: options.handler.dynamic,\n });\n assertSupportedAppRouteHandlerResponse(response);\n const handlerSetCacheControl = response.headers.has(\"cache-control\");\n\n if (dynamicUsedInHandler) {\n markKnownDynamicAppRoute(options.routePattern);\n }\n\n if (\n shouldApplyAppRouteHandlerRevalidateHeader({\n dynamicUsedInHandler,\n handlerSetCacheControl,\n isAutoHead: options.isAutoHead,\n method: options.method,\n revalidateSeconds: options.revalidateSeconds,\n })\n ) {\n const revalidateSeconds = options.revalidateSeconds;\n if (revalidateSeconds == null) {\n throw new Error(\"Expected route handler revalidate seconds\");\n }\n applyRouteHandlerRevalidateHeader(response, revalidateSeconds, options.expireSeconds);\n }\n\n if (\n shouldWriteAppRouteHandlerCache({\n dynamicConfig: options.handler.dynamic,\n dynamicUsedInHandler,\n handlerSetCacheControl,\n isAutoHead: options.isAutoHead,\n isProduction: options.isProduction,\n method: options.method,\n revalidateSeconds: options.revalidateSeconds,\n })\n ) {\n markRouteHandlerCacheMiss(response);\n const routeClone = response.clone();\n const routeKey = options.isrRouteKey(options.cleanPathname);\n const revalidateSeconds = options.revalidateSeconds;\n if (revalidateSeconds == null) {\n throw new Error(\"Expected route handler cache revalidate seconds\");\n }\n const routeTags = options.buildPageCacheTags(\n options.cleanPathname,\n options.getCollectedFetchTags(),\n );\n const routeWritePromise = (async () => {\n try {\n const routeCacheValue = await buildAppRouteCacheValue(routeClone);\n await options.isrSet(\n routeKey,\n routeCacheValue,\n revalidateSeconds,\n routeTags,\n options.expireSeconds,\n );\n options.isrDebug?.(\"route cache written\", routeKey);\n } catch (cacheErr) {\n console.error(\"[vinext] ISR route cache write error:\", cacheErr);\n }\n })();\n options.executionContext?.waitUntil(routeWritePromise);\n }\n\n const pendingCookies = options.getAndClearPendingCookies();\n const draftCookie = options.getDraftModeCookieHeader();\n options.clearRequestContext();\n\n return applyRouteHandlerMiddlewareContext(\n finalizeRouteHandlerResponse(response, {\n pendingCookies,\n draftCookie,\n isHead: options.isAutoHead,\n }),\n options.middlewareContext,\n );\n } catch (error) {\n const pendingCookies = options.getAndClearPendingCookies();\n const draftCookie = options.getDraftModeCookieHeader();\n const specialError = resolveAppRouteHandlerSpecialError(error, options.request.url, {\n isAction: isPossibleAppRouteActionRequest(options.request),\n });\n options.clearRequestContext();\n\n if (specialError) {\n if (specialError.kind === \"redirect\") {\n return applyRouteHandlerMiddlewareContext(\n finalizeRouteHandlerResponse(\n new Response(null, {\n status: specialError.statusCode,\n headers: { Location: specialError.location },\n }),\n {\n pendingCookies,\n draftCookie,\n isHead: options.isAutoHead,\n },\n ),\n options.middlewareContext,\n );\n }\n\n return applyRouteHandlerMiddlewareContext(\n new Response(null, { status: specialError.statusCode }),\n options.middlewareContext,\n );\n }\n\n console.error(\"[vinext] Route handler error:\", error);\n options.reportRequestError(\n error instanceof Error ? error : new Error(String(error)),\n {\n path: options.cleanPathname,\n method: options.request.method,\n headers: Object.fromEntries(options.request.headers.entries()),\n },\n {\n routerKind: \"App Router\",\n routePath: options.routePattern,\n routeType: \"route\",\n },\n );\n\n return applyRouteHandlerMiddlewareContext(\n new Response(null, { status: 500 }),\n options.middlewareContext,\n );\n } finally {\n options.setHeadersAccessPhase(previousHeadersPhase);\n }\n}\n"],"mappings":";;;;;;AA6GA,SAAS,yCAAyC,SAA0C;CAC1F,IAAI,QAAQ,kBAAkB,kBAAkB,QAAQ,kBAAkB,SAAS;EACjF,kBACE,qCAAqC;GACnC,iBAAiB,QAAQ;GACzB,eAAe,QAAQ;GACvB,WAAW;GACX,cAAc,QAAQ;GACvB,CAAC,CACH;EACD,Q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AQ,IAAI,MAAM,OAAO,MAAM,CAAC,EACzD;GACE,MAAM,QAAQ;GACd,QAAQ,QAAQ,QAAQ;GACxB,SAAS,OAAO,YAAY,QAAQ,QAAQ,QAAQ,SAAS,CAAC;GAC/D,EACD;GACE,YAAY;GACZ,WAAW,QAAQ;GACnB,WAAW;GACZ,CACF;EAED,OAAO,mCACL,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,CAAC,EACnC,QAAQ,kBACT;WACO;EACR,QAAQ,sBAAsB,qBAAqB"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./headers.js";
|
|
2
2
|
import { processMiddlewareHeaders } from "./request-pipeline.js";
|
|
3
|
-
import {
|
|
3
|
+
import { setCacheStateHeaders } from "./cache-headers.js";
|
|
4
4
|
import { NEVER_CACHE_CONTROL, STATIC_CACHE_CONTROL, buildCachedRevalidateCacheControl } from "./cache-control.js";
|
|
5
|
+
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
5
6
|
//#region src/server/app-route-handler-response.ts
|
|
6
7
|
const APP_ROUTE_REWRITE_ERROR = "NextResponse.rewrite() was used in a app route handler, this is not currently supported. Please remove the invocation to continue.";
|
|
7
8
|
const APP_ROUTE_NEXT_ERROR = "NextResponse.next() was used in a app route handler, this is not supported. See here for more info: https://nextjs.org/docs/messages/next-response-next-in-app-route-handler";
|
|
@@ -32,7 +33,7 @@ function buildRouteHandlerCachedResponse(cachedValue, options) {
|
|
|
32
33
|
const headers = new Headers();
|
|
33
34
|
for (const [key, value] of Object.entries(cachedValue.headers)) if (Array.isArray(value)) for (const entry of value) headers.append(key, entry);
|
|
34
35
|
else headers.set(key, value);
|
|
35
|
-
headers
|
|
36
|
+
setCacheStateHeaders(headers, options.cacheState);
|
|
36
37
|
const revalidateSeconds = options.cacheControl?.revalidate ?? options.revalidateSeconds;
|
|
37
38
|
const expireSeconds = options.cacheControl === void 0 ? void 0 : options.cacheControl.expire ?? options.expireSeconds;
|
|
38
39
|
headers.set("Cache-Control", buildRouteHandlerCacheControl(options.cacheState, revalidateSeconds, expireSeconds));
|
|
@@ -45,7 +46,7 @@ function applyRouteHandlerRevalidateHeader(response, revalidateSeconds, expireSe
|
|
|
45
46
|
response.headers.set("cache-control", buildRouteHandlerCacheControl("HIT", revalidateSeconds, expireSeconds));
|
|
46
47
|
}
|
|
47
48
|
function markRouteHandlerCacheMiss(response) {
|
|
48
|
-
response.headers
|
|
49
|
+
setCacheStateHeaders(response.headers, "MISS");
|
|
49
50
|
}
|
|
50
51
|
function getSetCookieName(cookie) {
|
|
51
52
|
const equalsIndex = cookie.indexOf("=");
|
|
@@ -79,7 +80,7 @@ async function buildAppRouteCacheValue(response) {
|
|
|
79
80
|
const body = await response.arrayBuffer();
|
|
80
81
|
const headers = {};
|
|
81
82
|
response.headers.forEach((value, key) => {
|
|
82
|
-
if (key === "set-cookie" || key === "X-Vinext-Cache".toLowerCase() || key === "cache-control" || key.startsWith("x-middleware-")) return;
|
|
83
|
+
if (key === "set-cookie" || key === "X-Vinext-Cache".toLowerCase() || key === "x-nextjs-cache".toLowerCase() || key === "cache-control" || key.startsWith("x-middleware-")) return;
|
|
83
84
|
headers[key] = value;
|
|
84
85
|
});
|
|
85
86
|
const setCookies = response.headers.getSetCookie?.() ?? [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-route-handler-response.js","names":[],"sources":["../../src/server/app-route-handler-response.ts"],"sourcesContent":["import type { CachedRouteValue, CacheControlMetadata } from \"vinext/shims/cache\";\nimport {\n buildCachedRevalidateCacheControl,\n NEVER_CACHE_CONTROL,\n STATIC_CACHE_CONTROL,\n} from \"./cache-control.js\";\nimport {\n MIDDLEWARE_HEADER_PREFIX,\n MIDDLEWARE_NEXT_HEADER,\n MIDDLEWARE_REWRITE_HEADER,\n VINEXT_CACHE_HEADER,\n} from \"./headers.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\nimport { processMiddlewareHeaders } from \"./request-pipeline.js\";\n\nexport type RouteHandlerMiddlewareContext = {\n headers: Headers | null;\n status: number | null;\n};\n\ntype BuildRouteHandlerCachedResponseOptions = {\n cacheControl?: CacheControlMetadata;\n cacheState: \"HIT\" | \"STALE\";\n expireSeconds?: number;\n isHead: boolean;\n revalidateSeconds: number;\n};\n\ntype FinalizeRouteHandlerResponseOptions = {\n pendingCookies: string[];\n draftCookie?: string | null;\n isHead: boolean;\n};\n\nconst APP_ROUTE_REWRITE_ERROR =\n \"NextResponse.rewrite() was used in a app route handler, this is not currently supported. Please remove the invocation to continue.\";\nconst APP_ROUTE_NEXT_ERROR =\n \"NextResponse.next() was used in a app route handler, this is not supported. See here for more info: https://nextjs.org/docs/messages/next-response-next-in-app-route-handler\";\n\nfunction hasMiddlewareHeader(headers: Headers): boolean {\n for (const key of headers.keys()) {\n if (key.startsWith(MIDDLEWARE_HEADER_PREFIX)) return true;\n }\n return false;\n}\n\nfunction buildRouteHandlerCacheControl(\n cacheState: BuildRouteHandlerCachedResponseOptions[\"cacheState\"],\n revalidateSeconds: number,\n expireSeconds?: number,\n): string {\n if (revalidateSeconds === 0) {\n // A cached response is never produced for revalidate = 0 (the ISR write\n // path skips it), so only the HIT/STALE->fresh rewrite can arrive here\n // with a 0 value, via applyRouteHandlerRevalidateHeader. In all such\n // cases the author opted out of caching entirely.\n return NEVER_CACHE_CONTROL;\n }\n\n if (revalidateSeconds === Infinity) {\n // revalidate = false / Infinity means \"cache indefinitely\" — emit the\n // same static Cache-Control used by pages, not a dynamic SWR value.\n return STATIC_CACHE_CONTROL;\n }\n\n return buildCachedRevalidateCacheControl(cacheState, revalidateSeconds, expireSeconds);\n}\n\nexport function applyRouteHandlerMiddlewareContext(\n response: Response,\n middlewareContext: RouteHandlerMiddlewareContext,\n): Response {\n if (!middlewareContext.headers && middlewareContext.status == null) {\n return response;\n }\n\n const responseHeaders = new Headers(response.headers);\n mergeMiddlewareResponseHeaders(responseHeaders, middlewareContext.headers);\n\n return new Response(response.body, {\n status: middlewareContext.status ?? response.status,\n statusText: response.statusText,\n headers: responseHeaders,\n });\n}\n\nexport function assertSupportedAppRouteHandlerResponse(response: Response): void {\n // NextResponse.next() and rewrite() are middleware control-flow signals.\n // Once an App Route handler has returned, Next.js rejects those responses.\n if (response.headers.has(MIDDLEWARE_REWRITE_HEADER)) {\n throw new Error(APP_ROUTE_REWRITE_ERROR);\n }\n\n if (response.headers.get(MIDDLEWARE_NEXT_HEADER) === \"1\") {\n throw new Error(APP_ROUTE_NEXT_ERROR);\n }\n}\n\nexport function buildRouteHandlerCachedResponse(\n cachedValue: CachedRouteValue,\n options: BuildRouteHandlerCachedResponseOptions,\n): Response {\n const headers = new Headers();\n for (const [key, value] of Object.entries(cachedValue.headers)) {\n if (Array.isArray(value)) {\n for (const entry of value) {\n headers.append(key, entry);\n }\n } else {\n headers.set(key, value);\n }\n }\n headers.set(VINEXT_CACHE_HEADER, options.cacheState);\n const revalidateSeconds = options.cacheControl?.revalidate ?? options.revalidateSeconds;\n const expireSeconds =\n options.cacheControl === undefined\n ? undefined\n : (options.cacheControl.expire ?? options.expireSeconds);\n headers.set(\n \"Cache-Control\",\n buildRouteHandlerCacheControl(options.cacheState, revalidateSeconds, expireSeconds),\n );\n\n return new Response(options.isHead ? null : cachedValue.body, {\n status: cachedValue.status,\n headers,\n });\n}\n\nexport function applyRouteHandlerRevalidateHeader(\n response: Response,\n revalidateSeconds: number,\n expireSeconds?: number,\n): void {\n response.headers.set(\n \"cache-control\",\n buildRouteHandlerCacheControl(\"HIT\", revalidateSeconds, expireSeconds),\n );\n}\n\nexport function markRouteHandlerCacheMiss(response: Response): void {\n response.headers.set(VINEXT_CACHE_HEADER, \"MISS\");\n}\n\nfunction getSetCookieName(cookie: string): string | null {\n const equalsIndex = cookie.indexOf(\"=\");\n if (equalsIndex <= 0) {\n return null;\n }\n return cookie.slice(0, equalsIndex);\n}\n\nfunction applyMutableCookieFallbacks(headers: Headers, pendingCookies: string[]): void {\n if (pendingCookies.length === 0) {\n return;\n }\n\n const returnedCookies = headers.getSetCookie();\n const returnedCookieNames = new Set<string>();\n for (const cookie of returnedCookies) {\n const name = getSetCookieName(cookie);\n if (name) {\n returnedCookieNames.add(name);\n }\n }\n\n const fallbackCookies = new Map<string, string>();\n const unkeyedFallbackCookies: string[] = [];\n for (const cookie of pendingCookies) {\n const name = getSetCookieName(cookie);\n if (!name) {\n unkeyedFallbackCookies.push(cookie);\n continue;\n }\n\n if (!returnedCookieNames.has(name)) {\n fallbackCookies.set(name, cookie);\n }\n }\n\n headers.delete(\"Set-Cookie\");\n for (const cookie of unkeyedFallbackCookies) {\n headers.append(\"Set-Cookie\", cookie);\n }\n for (const cookie of fallbackCookies.values()) {\n headers.append(\"Set-Cookie\", cookie);\n }\n for (const cookie of returnedCookies) {\n headers.append(\"Set-Cookie\", cookie);\n }\n}\n\nexport async function buildAppRouteCacheValue(response: Response): Promise<CachedRouteValue> {\n const body = await response.arrayBuffer();\n const headers: CachedRouteValue[\"headers\"] = {};\n\n response.headers.forEach((value, key) => {\n if (\n key === \"set-cookie\" ||\n key === VINEXT_CACHE_HEADER.toLowerCase() ||\n key === \"cache-control\" ||\n key.startsWith(MIDDLEWARE_HEADER_PREFIX)\n ) {\n return;\n }\n headers[key] = value;\n });\n const setCookies = response.headers.getSetCookie?.() ?? [];\n if (setCookies.length > 0) {\n headers[\"set-cookie\"] = setCookies;\n }\n\n return {\n kind: \"APP_ROUTE\",\n body,\n status: response.status,\n headers,\n };\n}\n\nexport function finalizeRouteHandlerResponse(\n response: Response,\n options: FinalizeRouteHandlerResponseOptions,\n): Response {\n const { pendingCookies, draftCookie, isHead } = options;\n if (\n pendingCookies.length === 0 &&\n !draftCookie &&\n !isHead &&\n !hasMiddlewareHeader(response.headers)\n ) {\n return response;\n }\n\n const headers = new Headers(response.headers);\n processMiddlewareHeaders(headers);\n applyMutableCookieFallbacks(headers, pendingCookies);\n if (draftCookie) {\n headers.append(\"Set-Cookie\", draftCookie);\n }\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B,wBAAwB,UAA+C;CAC3F,MAAM,OAAO,MAAM,SAAS,aAAa;CACzC,MAAM,UAAuC,EAAE;CAE/C,SAAS,QAAQ,SAAS,OAAO,QAAQ;EACvC,IACE,QAAQ,gBACR,QAAA,iBAA4B,aAAa,IACzC,QAAQ,mBACR,IAAI,WAAA,gBAAoC,EAExC;EAEF,QAAQ,OAAO;GACf;CACF,MAAM,aAAa,SAAS,QAAQ,gBAAgB,IAAI,EAAE;CAC1D,IAAI,WAAW,SAAS,GACtB,QAAQ,gBAAgB;CAG1B,OAAO;EACL,MAAM;EACN;EACA,QAAQ,SAAS;EACjB;EACD;;AAGH,SAAgB,6BACd,UACA,SACU;CACV,MAAM,EAAE,gBAAgB,aAAa,WAAW;CAChD,IACE,eAAe,WAAW,KAC1B,CAAC,eACD,CAAC,UACD,CAAC,oBAAoB,SAAS,QAAQ,EAEtC,OAAO;CAGT,MAAM,UAAU,IAAI,QAAQ,SAAS,QAAQ;CAC7C,yBAAyB,QAAQ;CACjC,4BAA4B,SAAS,eAAe;CACpD,IAAI,aACF,QAAQ,OAAO,cAAc,YAAY;CAG3C,OAAO,IAAI,SAAS,SAAS,OAAO,SAAS,MAAM;EACjD,QAAQ,SAAS;EACjB,YAAY,SAAS;EACrB;EACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"app-route-handler-response.js","names":[],"sources":["../../src/server/app-route-handler-response.ts"],"sourcesContent":["import type { CachedRouteValue, CacheControlMetadata } from \"vinext/shims/cache\";\nimport {\n buildCachedRevalidateCacheControl,\n NEVER_CACHE_CONTROL,\n STATIC_CACHE_CONTROL,\n} from \"./cache-control.js\";\nimport {\n MIDDLEWARE_HEADER_PREFIX,\n MIDDLEWARE_NEXT_HEADER,\n MIDDLEWARE_REWRITE_HEADER,\n NEXTJS_CACHE_HEADER,\n VINEXT_CACHE_HEADER,\n} from \"./headers.js\";\nimport { setCacheStateHeaders } from \"./cache-headers.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\nimport { processMiddlewareHeaders } from \"./request-pipeline.js\";\n\nexport type RouteHandlerMiddlewareContext = {\n headers: Headers | null;\n status: number | null;\n};\n\ntype BuildRouteHandlerCachedResponseOptions = {\n cacheControl?: CacheControlMetadata;\n cacheState: \"HIT\" | \"STALE\";\n expireSeconds?: number;\n isHead: boolean;\n revalidateSeconds: number;\n};\n\ntype FinalizeRouteHandlerResponseOptions = {\n pendingCookies: string[];\n draftCookie?: string | null;\n isHead: boolean;\n};\n\nconst APP_ROUTE_REWRITE_ERROR =\n \"NextResponse.rewrite() was used in a app route handler, this is not currently supported. Please remove the invocation to continue.\";\nconst APP_ROUTE_NEXT_ERROR =\n \"NextResponse.next() was used in a app route handler, this is not supported. See here for more info: https://nextjs.org/docs/messages/next-response-next-in-app-route-handler\";\n\nfunction hasMiddlewareHeader(headers: Headers): boolean {\n for (const key of headers.keys()) {\n if (key.startsWith(MIDDLEWARE_HEADER_PREFIX)) return true;\n }\n return false;\n}\n\nfunction buildRouteHandlerCacheControl(\n cacheState: BuildRouteHandlerCachedResponseOptions[\"cacheState\"],\n revalidateSeconds: number,\n expireSeconds?: number,\n): string {\n if (revalidateSeconds === 0) {\n // A cached response is never produced for revalidate = 0 (the ISR write\n // path skips it), so only the HIT/STALE->fresh rewrite can arrive here\n // with a 0 value, via applyRouteHandlerRevalidateHeader. In all such\n // cases the author opted out of caching entirely.\n return NEVER_CACHE_CONTROL;\n }\n\n if (revalidateSeconds === Infinity) {\n // revalidate = false / Infinity means \"cache indefinitely\" — emit the\n // same static Cache-Control used by pages, not a dynamic SWR value.\n return STATIC_CACHE_CONTROL;\n }\n\n return buildCachedRevalidateCacheControl(cacheState, revalidateSeconds, expireSeconds);\n}\n\nexport function applyRouteHandlerMiddlewareContext(\n response: Response,\n middlewareContext: RouteHandlerMiddlewareContext,\n): Response {\n if (!middlewareContext.headers && middlewareContext.status == null) {\n return response;\n }\n\n const responseHeaders = new Headers(response.headers);\n mergeMiddlewareResponseHeaders(responseHeaders, middlewareContext.headers);\n\n return new Response(response.body, {\n status: middlewareContext.status ?? response.status,\n statusText: response.statusText,\n headers: responseHeaders,\n });\n}\n\nexport function assertSupportedAppRouteHandlerResponse(response: Response): void {\n // NextResponse.next() and rewrite() are middleware control-flow signals.\n // Once an App Route handler has returned, Next.js rejects those responses.\n if (response.headers.has(MIDDLEWARE_REWRITE_HEADER)) {\n throw new Error(APP_ROUTE_REWRITE_ERROR);\n }\n\n if (response.headers.get(MIDDLEWARE_NEXT_HEADER) === \"1\") {\n throw new Error(APP_ROUTE_NEXT_ERROR);\n }\n}\n\nexport function buildRouteHandlerCachedResponse(\n cachedValue: CachedRouteValue,\n options: BuildRouteHandlerCachedResponseOptions,\n): Response {\n const headers = new Headers();\n for (const [key, value] of Object.entries(cachedValue.headers)) {\n if (Array.isArray(value)) {\n for (const entry of value) {\n headers.append(key, entry);\n }\n } else {\n headers.set(key, value);\n }\n }\n setCacheStateHeaders(headers, options.cacheState);\n const revalidateSeconds = options.cacheControl?.revalidate ?? options.revalidateSeconds;\n const expireSeconds =\n options.cacheControl === undefined\n ? undefined\n : (options.cacheControl.expire ?? options.expireSeconds);\n headers.set(\n \"Cache-Control\",\n buildRouteHandlerCacheControl(options.cacheState, revalidateSeconds, expireSeconds),\n );\n\n return new Response(options.isHead ? null : cachedValue.body, {\n status: cachedValue.status,\n headers,\n });\n}\n\nexport function applyRouteHandlerRevalidateHeader(\n response: Response,\n revalidateSeconds: number,\n expireSeconds?: number,\n): void {\n response.headers.set(\n \"cache-control\",\n buildRouteHandlerCacheControl(\"HIT\", revalidateSeconds, expireSeconds),\n );\n}\n\nexport function markRouteHandlerCacheMiss(response: Response): void {\n setCacheStateHeaders(response.headers, \"MISS\");\n}\n\nfunction getSetCookieName(cookie: string): string | null {\n const equalsIndex = cookie.indexOf(\"=\");\n if (equalsIndex <= 0) {\n return null;\n }\n return cookie.slice(0, equalsIndex);\n}\n\nfunction applyMutableCookieFallbacks(headers: Headers, pendingCookies: string[]): void {\n if (pendingCookies.length === 0) {\n return;\n }\n\n const returnedCookies = headers.getSetCookie();\n const returnedCookieNames = new Set<string>();\n for (const cookie of returnedCookies) {\n const name = getSetCookieName(cookie);\n if (name) {\n returnedCookieNames.add(name);\n }\n }\n\n const fallbackCookies = new Map<string, string>();\n const unkeyedFallbackCookies: string[] = [];\n for (const cookie of pendingCookies) {\n const name = getSetCookieName(cookie);\n if (!name) {\n unkeyedFallbackCookies.push(cookie);\n continue;\n }\n\n if (!returnedCookieNames.has(name)) {\n fallbackCookies.set(name, cookie);\n }\n }\n\n headers.delete(\"Set-Cookie\");\n for (const cookie of unkeyedFallbackCookies) {\n headers.append(\"Set-Cookie\", cookie);\n }\n for (const cookie of fallbackCookies.values()) {\n headers.append(\"Set-Cookie\", cookie);\n }\n for (const cookie of returnedCookies) {\n headers.append(\"Set-Cookie\", cookie);\n }\n}\n\nexport async function buildAppRouteCacheValue(response: Response): Promise<CachedRouteValue> {\n const body = await response.arrayBuffer();\n const headers: CachedRouteValue[\"headers\"] = {};\n\n response.headers.forEach((value, key) => {\n if (\n key === \"set-cookie\" ||\n key === VINEXT_CACHE_HEADER.toLowerCase() ||\n key === NEXTJS_CACHE_HEADER.toLowerCase() ||\n key === \"cache-control\" ||\n key.startsWith(MIDDLEWARE_HEADER_PREFIX)\n ) {\n return;\n }\n headers[key] = value;\n });\n const setCookies = response.headers.getSetCookie?.() ?? [];\n if (setCookies.length > 0) {\n headers[\"set-cookie\"] = setCookies;\n }\n\n return {\n kind: \"APP_ROUTE\",\n body,\n status: response.status,\n headers,\n };\n}\n\nexport function finalizeRouteHandlerResponse(\n response: Response,\n options: FinalizeRouteHandlerResponseOptions,\n): Response {\n const { pendingCookies, draftCookie, isHead } = options;\n if (\n pendingCookies.length === 0 &&\n !draftCookie &&\n !isHead &&\n !hasMiddlewareHeader(response.headers)\n ) {\n return response;\n }\n\n const headers = new Headers(response.headers);\n processMiddlewareHeaders(headers);\n applyMutableCookieFallbacks(headers, pendingCookies);\n if (draftCookie) {\n headers.append(\"Set-Cookie\", draftCookie);\n }\n\n return new Response(isHead ? null : response.body, {\n status: response.status,\n statusText: response.statusText,\n headers,\n });\n}\n"],"mappings":";;;;;;AAoCA,MAAM,0BACJ;AACF,MAAM,uBACJ;AAEF,SAAS,oBAAoB,SAA2B;CACtD,KAAK,MAAM,OAAO,QAAQ,MAAM,EAC9B,IAAI,IAAI,WAAA,gBAAoC,EAAE,OAAO;CAEvD,OAAO;;AAGT,SAAS,8BACP,YACA,mBACA,eACQ;CACR,IAAI,sBAAsB,GAKxB,OAAO;CAGT,IAAI,sBAAsB,UAGxB,OAAO;CAGT,OAAO,kCAAkC,YAAY,mBAAmB,cAAc;;AAGxF,SAAgB,mCACd,UACA,mBACU;CACV,IAAI,CAAC,kBAAkB,WAAW,kBAAkB,UAAU,MAC5D,OAAO;CAGT,MAAM,kBAAkB,IAAI,QAAQ,SAAS,QAAQ;CACrD,+BAA+B,iBAAiB,kBAAkB,QAAQ;CAE1E,OAAO,IAAI,SAAS,SAAS,MAAM;EACjC,QAAQ,kBAAkB,UAAU,SAAS;EAC7C,YAAY,SAAS;EACrB,SAAS;EACV,CAAC;;AAGJ,SAAgB,uCAAuC,UAA0B;CAG/E,IAAI,SAAS,QAAQ,IAAA,uBAA8B,EACjD,MAAM,IAAI,MAAM,wBAAwB;CAG1C,IAAI,SAAS,QAAQ,IAAA,oBAA2B,KAAK,KACnD,MAAM,IAAI,MAAM,qBAAqB;;AAIzC,SAAgB,gCACd,aACA,SACU;CACV,MAAM,UAAU,IAAI,SAAS;CAC7B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,YAAY,QAAQ,EAC5D,IAAI,MAAM,QAAQ,MAAM,EACtB,KAAK,MAAM,SAAS,OAClB,QAAQ,OAAO,KAAK,MAAM;MAG5B,QAAQ,IAAI,KAAK,MAAM;CAG3B,qBAAqB,SAAS,QAAQ,WAAW;CACjD,MAAM,oBAAoB,QAAQ,cAAc,cAAc,QAAQ;CACtE,MA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cAAc,OAAO;;AAIxC,eAAsB,wBAAwB,UAA+C;CAC3F,MAAM,OAAO,MAAM,SAAS,aAAa;CACzC,MAAM,UAAuC,EAAE;CAE/C,SAAS,QAAQ,SAAS,OAAO,QAAQ;EACvC,IACE,QAAQ,gBACR,QAAA,iBAA4B,aAAa,IACzC,QAAA,iBAA4B,aAAa,IACzC,QAAQ,mBACR,IAAI,WAAA,gBAAoC,EAExC;EAEF,QAAQ,OAAO;GACf;CACF,MAAM,aAAa,SAAS,QAAQ,gBAAgB,IAAI,EAAE;CAC1D,IAAI,WAAW,SAAS,GACtB,QAAQ,gBAAgB;CAG1B,OAAO;EACL,MAAM;EACN;EACA,QAAQ,SAAS;EACjB;EACD;;AAGH,SAAgB,6BACd,UACA,SACU;CACV,MAAM,EAAE,gBAAgB,aAAa,WAAW;CAChD,IACE,eAAe,WAAW,KAC1B,CAAC,eACD,CAAC,UACD,CAAC,oBAAoB,SAAS,QAAQ,EAEtC,OAAO;CAGT,MAAM,UAAU,IAAI,QAAQ,SAAS,QAAQ;CAC7C,yBAAyB,QAAQ;CACjC,4BAA4B,SAAS,eAAe;CACpD,IAAI,aACF,QAAQ,OAAO,cAAc,YAAY;CAG3C,OAAO,IAAI,SAAS,SAAS,OAAO,SAAS,MAAM;EACjD,QAAQ,SAAS;EACjB,YAAY,SAAS;EACrB;EACD,CAAC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import "./server-globals.js";
|
|
2
2
|
import { runWithExecutionContext } from "../shims/request-context.js";
|
|
3
|
-
import { badRequestResponse, notFoundResponse } from "./http-error-responses.js";
|
|
3
|
+
import { badRequestResponse, notFoundResponse, notFoundStaticAssetResponse } from "./http-error-responses.js";
|
|
4
4
|
import { cloneRequestWithHeaders, filterInternalHeaders, isOpenRedirectShaped } from "./request-pipeline.js";
|
|
5
|
+
import { assetPrefixPathname, isNextStaticPath } from "../utils/asset-prefix.js";
|
|
5
6
|
import { resolveStaticAssetSignal } from "./worker-utils.js";
|
|
6
|
-
import rscHandler from "virtual:vinext-rsc-entry";
|
|
7
|
+
import rscHandler, { __assetPrefix, __basePath } from "virtual:vinext-rsc-entry";
|
|
7
8
|
//#region src/server/app-router-entry.ts
|
|
9
|
+
const __workerBasePath = typeof __basePath === "string" ? __basePath : "";
|
|
10
|
+
const __workerAssetPathPrefix = assetPrefixPathname(typeof __assetPrefix === "string" ? __assetPrefix : "");
|
|
8
11
|
var app_router_entry_default = { async fetch(request, env, ctx) {
|
|
9
12
|
return handleRequest(request, env, ctx);
|
|
10
13
|
} };
|
|
@@ -16,6 +19,7 @@ async function handleRequest(request, env, ctx) {
|
|
|
16
19
|
} catch {
|
|
17
20
|
return badRequestResponse();
|
|
18
21
|
}
|
|
22
|
+
if (isNextStaticPath(url.pathname, __workerBasePath, __workerAssetPathPrefix)) return notFoundStaticAssetResponse();
|
|
19
23
|
{
|
|
20
24
|
const filteredHeaders = filterInternalHeaders(request.headers);
|
|
21
25
|
request = cloneRequestWithHeaders(request, filteredHeaders);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-router-entry.js","names":[],"sources":["../../src/server/app-router-entry.ts"],"sourcesContent":["/**\n * Default Cloudflare Worker entry point for vinext App Router.\n *\n * Use this directly in wrangler.jsonc:\n * \"main\": \"vinext/server/app-router-entry\"\n *\n * Or import and delegate to it from a custom worker:\n * import handler from \"vinext/server/app-router-entry\";\n * return handler.fetch(request, env, ctx);\n *\n * This file runs in the RSC environment. Configure the Cloudflare plugin with:\n * cloudflare({ viteEnvironment: { name: \"rsc\", childEnvironments: [\"ssr\"] } })\n */\n\nimport \"./server-globals.js\";\n//
|
|
1
|
+
{"version":3,"file":"app-router-entry.js","names":["__rscBasePath","__rscAssetPrefix"],"sources":["../../src/server/app-router-entry.ts"],"sourcesContent":["/**\n * Default Cloudflare Worker entry point for vinext App Router.\n *\n * Use this directly in wrangler.jsonc:\n * \"main\": \"vinext/server/app-router-entry\"\n *\n * Or import and delegate to it from a custom worker:\n * import handler from \"vinext/server/app-router-entry\";\n * return handler.fetch(request, env, ctx);\n *\n * This file runs in the RSC environment. Configure the Cloudflare plugin with:\n * cloudflare({ viteEnvironment: { name: \"rsc\", childEnvironments: [\"ssr\"] } })\n */\n\nimport \"./server-globals.js\";\n// Virtual module generated by vinext at build time. The default export is\n// the request handler; `__assetPrefix` and `__basePath` are named exports\n// inlined from next.config (both as string literals) so this worker can\n// recognise asset-shaped requests without invoking the handler. Types\n// live in `virtual-vinext-rsc-entry.d.ts`; the generator is in\n// `entries/app-rsc-entry.ts`.\nimport rscHandler, {\n __assetPrefix as __rscAssetPrefix,\n __basePath as __rscBasePath,\n} from \"virtual:vinext-rsc-entry\";\nimport { runWithExecutionContext, type ExecutionContextLike } from \"vinext/shims/request-context\";\nimport { resolveStaticAssetSignal } from \"./worker-utils.js\";\nimport {\n cloneRequestWithHeaders,\n filterInternalHeaders,\n isOpenRedirectShaped,\n} from \"./request-pipeline.js\";\nimport {\n badRequestResponse,\n notFoundResponse,\n notFoundStaticAssetResponse,\n} from \"./http-error-responses.js\";\nimport { assetPrefixPathname, isNextStaticPath } from \"../utils/asset-prefix.js\";\n\n// Precompute the path components used for `_next/static/*` 404 short-circuit\n// detection. Both `__basePath` and `__assetPrefix` are inlined as\n// compile-time constants in the generated RSC entry — see entries/app-rsc-entry.ts.\nconst __workerBasePath: string = typeof __rscBasePath === \"string\" ? __rscBasePath : \"\";\nconst __workerAssetPathPrefix: string = assetPrefixPathname(\n typeof __rscAssetPrefix === \"string\" ? __rscAssetPrefix : \"\",\n);\n\ntype WorkerAssetEnv = {\n ASSETS?: {\n fetch(request: Request): Promise<Response> | Response;\n };\n};\n\nexport default {\n async fetch(\n request: Request,\n env?: WorkerAssetEnv,\n ctx?: ExecutionContextLike,\n ): Promise<Response> {\n return handleRequest(request, env, ctx);\n },\n};\n\nasync function handleRequest(\n request: Request,\n env: WorkerAssetEnv | undefined,\n ctx: ExecutionContextLike | undefined,\n): Promise<Response> {\n const url = new URL(request.url);\n\n // Block protocol-relative URL open redirects (//evil.com/, /\\evil.com/,\n // /%5Cevil.com/, /%2F/evil.com/). Check BEFORE decode so both literal and\n // percent-encoded variants are caught — encoded forms survive segment-wise\n // decoding and would otherwise reach trailing-slash redirect emitters.\n if (isOpenRedirectShaped(url.pathname)) {\n return notFoundResponse();\n }\n\n // Validate that percent-encoding is well-formed. The RSC handler performs\n // the actual decode + normalize; we only check here to return a clean 400\n // instead of letting a malformed sequence crash downstream.\n try {\n decodeURIComponent(url.pathname);\n } catch {\n // Malformed percent-encoding (e.g. /%E0%A4%A) — return 400 instead of throwing.\n return badRequestResponse();\n }\n\n // Invalid `_next/static/*` paths short-circuit with a plain-text 404\n // instead of falling through to the RSC handler (which would render the\n // full HTML 404 page). Valid assets are served by Cloudflare's ASSETS\n // binding BEFORE the worker is invoked; only misses reach this code.\n // Matches Next.js: packages/next/src/server/lib/router-server.ts.\n if (isNextStaticPath(url.pathname, __workerBasePath, __workerAssetPathPrefix)) {\n return notFoundStaticAssetResponse();\n }\n\n // Strip internal headers from inbound requests before any handler or\n // middleware sees them. Must happen before the RSC handler runs.\n // Builds a new Headers — Request.headers is immutable in Workers.\n {\n const filteredHeaders = filterInternalHeaders(request.headers);\n request = cloneRequestWithHeaders(request, filteredHeaders);\n }\n\n // Do NOT decode/normalize the pathname here. The RSC handler\n // (virtual:vinext-rsc-entry) is the single point of decoding — it calls\n // decodeURIComponent + normalizePath on the incoming URL. Decoding here\n // AND in the handler would double-decode, causing inconsistent path\n // matching between middleware and routing.\n\n // Delegate to RSC handler (which decodes + normalizes the pathname itself),\n // wrapping in the ExecutionContext ALS scope so downstream code can reach\n // ctx.waitUntil() without having ctx threaded through every call site.\n const handleFn = () => rscHandler(request, ctx);\n const result = await (ctx ? runWithExecutionContext(ctx, handleFn) : handleFn());\n\n if (result instanceof Response) {\n if (env?.ASSETS) {\n const assetFetcher = env.ASSETS;\n const assetResponse = await resolveStaticAssetSignal(result, {\n fetchAsset: (path) =>\n Promise.resolve(assetFetcher.fetch(new Request(new URL(path, request.url)))),\n });\n if (assetResponse) return assetResponse;\n }\n return result;\n }\n\n if (result === null || result === undefined) {\n return notFoundResponse();\n }\n\n return new Response(String(result), { status: 200 });\n}\n"],"mappings":";;;;;;;;AA0CA,MAAM,mBAA2B,OAAOA,eAAkB,WAAWA,aAAgB;AACrF,MAAM,0BAAkC,oBACtC,OAAOC,kBAAqB,WAAWA,gBAAmB,GAC3D;AAQD,IAAA,2BAAe,EACb,MAAM,MACJ,SACA,KACA,KACmB;CACnB,OAAO,cAAc,SAAS,KAAK,IAAI;GAE1C;AAED,eAAe,cACb,SACA,KACA,KACmB;CACnB,MAAM,MAAM,IAAI,IAAI,QAAQ,IAAI;CAMhC,IAAI,qBAAqB,IAAI,SAAS,EACpC,OAAO,kBAAkB;CAM3B,IAAI;EACF,mBAAmB,IAAI,SAAS;SAC1B;EAEN,OAAO,oBAAoB;;CAQ7B,IAAI,iBAAiB,IAAI,UAAU,kBAAkB,wBAAwB,EAC3E,OAAO,6BAA6B;CAMtC;EACE,MAAM,kBAAkB,sBAAsB,QAAQ,QAAQ;EAC9D,UAAU,wBAAwB,SAAS,gBAAgB;;CAY7D,MAAM,iBAAiB,WAAW,SAAS,IAAI;CAC/C,MAAM,SAAS,OAAO,MAAM,wBAAwB,KAAK,SAAS,GAAG,UAAU;CAE/E,IAAI,kBAAkB,UAAU;EAC9B,IAAI,KAAK,QAAQ;GACf,MAAM,eAAe,IAAI;GACzB,MAAM,gBAAgB,MAAM,yBAAyB,QAAQ,EAC3D,aAAa,SACX,QAAQ,QAAQ,aAAa,MAAM,IAAI,QAAQ,IAAI,IAAI,MAAM,QAAQ,IAAI,CAAC,CAAC,CAAC,EAC/E,CAAC;GACF,IAAI,eAAe,OAAO;;EAE5B,OAAO;;CAGT,IAAI,WAAW,QAAQ,WAAW,KAAA,GAChC,OAAO,kBAAkB;CAG3B,OAAO,IAAI,SAAS,OAAO,OAAO,EAAE,EAAE,QAAQ,KAAK,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextHeader, NextI18nConfig, NextRedirect, NextRewrite } from "../config/next-config.js";
|
|
2
|
+
import { RootParams } from "../shims/root-params.js";
|
|
2
3
|
import { MiddlewareModule } from "./middleware-runtime.js";
|
|
3
4
|
import { AppMiddlewareContext } from "./app-middleware.js";
|
|
4
5
|
import { AppRscRenderMode } from "./app-rsc-render-mode.js";
|
|
@@ -37,6 +38,8 @@ type DispatchMatchedPageOptions<TRoute> = {
|
|
|
37
38
|
middlewareContext: AppRscMiddlewareContext;
|
|
38
39
|
mountedSlotsHeader: string | null;
|
|
39
40
|
params: AppPageParams;
|
|
41
|
+
staticParamsValidationParams?: AppPageParams;
|
|
42
|
+
rootParams?: RootParams;
|
|
40
43
|
request: Request;
|
|
41
44
|
route: TRoute;
|
|
42
45
|
scriptNonce?: string;
|
|
@@ -46,7 +49,13 @@ type DispatchMatchedPageOptions<TRoute> = {
|
|
|
46
49
|
type DispatchMatchedRouteHandlerOptions<TRoute> = {
|
|
47
50
|
cleanPathname: string;
|
|
48
51
|
middlewareContext: AppRscMiddlewareContext;
|
|
49
|
-
|
|
52
|
+
/**
|
|
53
|
+
* `null` for non-dynamic routes. Mirrors Next.js' route handler context
|
|
54
|
+
* shape: user code that does `params ? await params : null` resolves to
|
|
55
|
+
* `null` for routes without dynamic segments. Dynamic routes receive the
|
|
56
|
+
* matched params object.
|
|
57
|
+
*/
|
|
58
|
+
params: AppPageParams | null;
|
|
50
59
|
request: Request;
|
|
51
60
|
route: TRoute;
|
|
52
61
|
searchParams: URLSearchParams;
|
|
@@ -107,6 +116,7 @@ type CreateAppRscHandlerOptions<TRoute extends AppRscHandlerRoute> = {
|
|
|
107
116
|
beforeFiles: NextRewrite[];
|
|
108
117
|
fallback: NextRewrite[];
|
|
109
118
|
};
|
|
119
|
+
draftModeSecret: string;
|
|
110
120
|
dispatchMatchedPage: (options: DispatchMatchedPageOptions<TRoute>) => Promise<Response>;
|
|
111
121
|
dispatchMatchedRouteHandler: (options: DispatchMatchedRouteHandlerOptions<TRoute>) => Promise<Response>;
|
|
112
122
|
ensureInstrumentation?: () => Promise<void>;
|