vinext 0.0.46 → 0.0.48
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 +8 -6
- package/dist/build/layout-classification.js +3 -1
- package/dist/build/layout-classification.js.map +1 -1
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +80 -24
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/report.d.ts +9 -5
- package/dist/build/report.js +17 -7
- package/dist/build/report.js.map +1 -1
- package/dist/build/route-classification-injector.d.ts +35 -0
- package/dist/build/route-classification-injector.js +61 -0
- package/dist/build/route-classification-injector.js.map +1 -0
- package/dist/build/route-classification-manifest.d.ts +1 -1
- package/dist/build/run-prerender.d.ts +5 -0
- package/dist/build/run-prerender.js +4 -1
- package/dist/build/run-prerender.js.map +1 -1
- package/dist/build/server-manifest.js +2 -7
- package/dist/build/server-manifest.js.map +1 -1
- package/dist/build/standalone.js +3 -5
- package/dist/build/standalone.js.map +1 -1
- package/dist/build/static-export.d.ts +1 -1
- package/dist/check.js +45 -29
- package/dist/check.js.map +1 -1
- package/dist/cli-args.d.ts +33 -0
- package/dist/cli-args.js +121 -0
- package/dist/cli-args.js.map +1 -0
- package/dist/cli.js +11 -20
- package/dist/cli.js.map +1 -1
- package/dist/cloudflare/kv-cache-handler.js +29 -9
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/config/config-matchers.js +46 -37
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +4 -2
- package/dist/config/next-config.js +3 -0
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.d.ts +18 -2
- package/dist/deploy.js +47 -4
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +4 -3
- package/dist/entries/app-rsc-entry.js +379 -858
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.d.ts +1 -1
- package/dist/entries/app-rsc-manifest.js +6 -1
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/pages-client-entry.js +3 -2
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +19 -61
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/entries/runtime-entry-module.d.ts +12 -3
- package/dist/entries/runtime-entry-module.js +15 -4
- package/dist/entries/runtime-entry-module.js.map +1 -1
- package/dist/index.js +40 -58
- package/dist/index.js.map +1 -1
- package/dist/plugins/fonts.js +54 -32
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/og-assets.js +15 -16
- package/dist/plugins/og-assets.js.map +1 -1
- package/dist/plugins/rsc-client-shim-excludes.d.ts +2 -1
- package/dist/plugins/rsc-client-shim-excludes.js +11 -1
- package/dist/plugins/rsc-client-shim-excludes.js.map +1 -1
- package/dist/routing/app-route-graph.d.ts +195 -0
- package/dist/routing/app-route-graph.js +1022 -0
- package/dist/routing/app-route-graph.js.map +1 -0
- package/dist/routing/app-router.d.ts +14 -88
- package/dist/routing/app-router.js +21 -712
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/file-matcher.d.ts +3 -1
- package/dist/routing/file-matcher.js +6 -1
- package/dist/routing/file-matcher.js.map +1 -1
- package/dist/routing/pages-router.js +10 -19
- package/dist/routing/pages-router.js.map +1 -1
- package/dist/routing/route-matching.d.ts +28 -0
- package/dist/routing/route-matching.js +44 -0
- package/dist/routing/route-matching.js.map +1 -0
- package/dist/routing/route-pattern.js +4 -1
- package/dist/routing/route-pattern.js.map +1 -1
- package/dist/routing/route-trie.d.ts +8 -0
- package/dist/routing/route-trie.js +12 -1
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/route-validation.js +3 -4
- package/dist/routing/route-validation.js.map +1 -1
- package/dist/routing/utils.d.ts +8 -1
- package/dist/routing/utils.js +25 -2
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/app-browser-entry.js +145 -294
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-error.d.ts +3 -4
- package/dist/server/app-browser-error.js +8 -4
- package/dist/server/app-browser-error.js.map +1 -1
- package/dist/server/app-browser-navigation-controller.d.ts +75 -0
- package/dist/server/app-browser-navigation-controller.js +290 -0
- package/dist/server/app-browser-navigation-controller.js.map +1 -0
- package/dist/server/app-browser-state.d.ts +33 -15
- package/dist/server/app-browser-state.js +52 -59
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +68 -0
- package/dist/server/app-browser-visible-commit.js +182 -0
- package/dist/server/app-browser-visible-commit.js.map +1 -0
- package/dist/server/app-client-reference-preloader.d.ts +15 -0
- package/dist/server/app-client-reference-preloader.js +46 -0
- package/dist/server/app-client-reference-preloader.js.map +1 -0
- package/dist/server/app-elements-wire.d.ts +130 -0
- package/dist/server/app-elements-wire.js +205 -0
- package/dist/server/app-elements-wire.js.map +1 -0
- package/dist/server/app-elements.d.ts +2 -84
- package/dist/server/app-elements.js +4 -107
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-fallback-renderer.d.ts +57 -0
- package/dist/server/app-fallback-renderer.js +79 -0
- package/dist/server/app-fallback-renderer.js.map +1 -0
- package/dist/server/app-hook-warning-suppression.d.ts +7 -0
- package/dist/server/app-hook-warning-suppression.js +12 -0
- package/dist/server/app-hook-warning-suppression.js.map +1 -0
- package/dist/server/app-middleware.d.ts +2 -1
- package/dist/server/app-middleware.js +34 -11
- package/dist/server/app-middleware.js.map +1 -1
- package/dist/server/app-mounted-slots-header.d.ts +17 -0
- package/dist/server/app-mounted-slots-header.js +21 -0
- package/dist/server/app-mounted-slots-header.js.map +1 -0
- package/dist/server/app-page-boundary-render.d.ts +3 -3
- package/dist/server/app-page-boundary-render.js +8 -5
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.js +2 -1
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +19 -4
- package/dist/server/app-page-cache.js +60 -22
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +9 -5
- package/dist/server/app-page-dispatch.js +41 -17
- package/dist/server/app-page-dispatch.js.map +1 -1
- package/dist/server/app-page-element-builder.d.ts +61 -0
- package/dist/server/app-page-element-builder.js +142 -0
- package/dist/server/app-page-element-builder.js.map +1 -0
- package/dist/server/app-page-execution.d.ts +23 -5
- package/dist/server/app-page-execution.js +39 -24
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.js +2 -1
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-method.js +2 -5
- package/dist/server/app-page-method.js.map +1 -1
- package/dist/server/app-page-params.d.ts +2 -1
- package/dist/server/app-page-params.js +3 -3
- package/dist/server/app-page-params.js.map +1 -1
- package/dist/server/app-page-probe.d.ts +1 -1
- package/dist/server/app-page-probe.js +5 -1
- package/dist/server/app-page-probe.js.map +1 -1
- package/dist/server/app-page-render.d.ts +6 -2
- package/dist/server/app-page-render.js +118 -30
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +19 -5
- package/dist/server/app-page-request.js +49 -7
- package/dist/server/app-page-request.js.map +1 -1
- package/dist/server/app-page-response.d.ts +1 -0
- package/dist/server/app-page-response.js +6 -9
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +20 -4
- package/dist/server/app-page-route-wiring.js +15 -12
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +7 -0
- package/dist/server/app-page-stream.js +9 -2
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-post-middleware-context.d.ts +16 -0
- package/dist/server/app-post-middleware-context.js +28 -0
- package/dist/server/app-post-middleware-context.js.map +1 -0
- package/dist/server/app-prerender-endpoints.js +3 -2
- package/dist/server/app-prerender-endpoints.js.map +1 -1
- package/dist/server/app-request-context.d.ts +22 -0
- package/dist/server/app-request-context.js +30 -0
- package/dist/server/app-request-context.js.map +1 -0
- package/dist/server/app-route-handler-cache.d.ts +1 -0
- package/dist/server/app-route-handler-cache.js +7 -2
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +8 -5
- package/dist/server/app-route-handler-dispatch.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +2 -1
- package/dist/server/app-route-handler-execution.js +2 -2
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-policy.js +13 -13
- package/dist/server/app-route-handler-policy.js.map +1 -1
- package/dist/server/app-route-handler-response.d.ts +4 -2
- package/dist/server/app-route-handler-response.js +9 -7
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-route-handler-runtime.d.ts +9 -1
- package/dist/server/app-route-handler-runtime.js +11 -1
- package/dist/server/app-route-handler-runtime.js.map +1 -1
- package/dist/server/app-router-entry.js +9 -4
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-rsc-cache-busting.d.ts +34 -0
- package/dist/server/app-rsc-cache-busting.js +137 -0
- package/dist/server/app-rsc-cache-busting.js.map +1 -0
- package/dist/server/app-rsc-error-handler.d.ts +21 -0
- package/dist/server/app-rsc-error-handler.js +30 -0
- package/dist/server/app-rsc-error-handler.js.map +1 -0
- package/dist/server/app-rsc-handler.d.ts +117 -0
- package/dist/server/app-rsc-handler.js +271 -0
- package/dist/server/app-rsc-handler.js.map +1 -0
- package/dist/server/app-rsc-request-normalization.d.ts +42 -0
- package/dist/server/app-rsc-request-normalization.js +67 -0
- package/dist/server/app-rsc-request-normalization.js.map +1 -0
- package/dist/server/app-rsc-response-finalizer.d.ts +30 -0
- package/dist/server/app-rsc-response-finalizer.js +38 -0
- package/dist/server/app-rsc-response-finalizer.js.map +1 -0
- package/dist/server/app-rsc-route-matching.js +8 -4
- package/dist/server/app-rsc-route-matching.js.map +1 -1
- package/dist/server/app-segment-config.d.ts +33 -0
- package/dist/server/app-segment-config.js +90 -0
- package/dist/server/app-segment-config.js.map +1 -0
- package/dist/server/app-server-action-execution.d.ts +2 -0
- package/dist/server/app-server-action-execution.js +45 -51
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.js +21 -20
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/artifact-compatibility.d.ts +44 -0
- package/dist/server/artifact-compatibility.js +82 -0
- package/dist/server/artifact-compatibility.js.map +1 -0
- package/dist/server/cache-control.d.ts +24 -0
- package/dist/server/cache-control.js +33 -0
- package/dist/server/cache-control.js.map +1 -0
- package/dist/server/cache-proof.d.ts +200 -0
- package/dist/server/cache-proof.js +342 -0
- package/dist/server/cache-proof.js.map +1 -0
- package/dist/server/dev-error-overlay-store.d.ts +23 -0
- package/dist/server/dev-error-overlay-store.js +67 -0
- package/dist/server/dev-error-overlay-store.js.map +1 -0
- package/dist/server/dev-error-overlay.d.ts +15 -0
- package/dist/server/dev-error-overlay.js +548 -0
- package/dist/server/dev-error-overlay.js.map +1 -0
- package/dist/server/dev-origin-check.js +8 -4
- package/dist/server/dev-origin-check.js.map +1 -1
- package/dist/server/dev-server.js +1 -6
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/http-error-responses.d.ts +67 -0
- package/dist/server/http-error-responses.js +77 -0
- package/dist/server/http-error-responses.js.map +1 -0
- package/dist/server/image-optimization.js +2 -1
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/instrumentation-runtime.d.ts +44 -0
- package/dist/server/instrumentation-runtime.js +29 -0
- package/dist/server/instrumentation-runtime.js.map +1 -0
- package/dist/server/isr-cache.d.ts +2 -7
- package/dist/server/isr-cache.js +7 -10
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/metadata-route-response.js +6 -5
- package/dist/server/metadata-route-response.js.map +1 -1
- package/dist/server/metadata-routes.d.ts +1 -0
- package/dist/server/metadata-routes.js +6 -0
- package/dist/server/metadata-routes.js.map +1 -1
- package/dist/server/middleware-matcher.js +2 -2
- package/dist/server/middleware-matcher.js.map +1 -1
- package/dist/server/middleware-response-headers.js +21 -0
- package/dist/server/middleware-response-headers.js.map +1 -1
- package/dist/server/middleware-runtime.js +3 -3
- package/dist/server/middleware-runtime.js.map +1 -1
- package/dist/server/navigation-trace.d.ts +33 -0
- package/dist/server/navigation-trace.js +35 -0
- package/dist/server/navigation-trace.js.map +1 -0
- package/dist/server/next-error-digest.d.ts +44 -0
- package/dist/server/next-error-digest.js +40 -0
- package/dist/server/next-error-digest.js.map +1 -0
- package/dist/server/pages-api-route.js +2 -1
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-node-compat.js +4 -16
- package/dist/server/pages-node-compat.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +2 -1
- package/dist/server/pages-page-data.js +6 -5
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +3 -8
- package/dist/server/pages-page-response.js +46 -15
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prod-server.d.ts +6 -0
- package/dist/server/prod-server.js +28 -21
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +42 -1
- package/dist/server/request-pipeline.js +97 -17
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/rsc-stream-hints.d.ts +3 -1
- package/dist/server/rsc-stream-hints.js +4 -1
- package/dist/server/rsc-stream-hints.js.map +1 -1
- package/dist/server/seed-cache.js +19 -8
- package/dist/server/seed-cache.js.map +1 -1
- package/dist/shims/cache-runtime.d.ts +2 -2
- package/dist/shims/cache-runtime.js +31 -17
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +15 -3
- package/dist/shims/cache.js +45 -20
- package/dist/shims/cache.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +17 -1
- package/dist/shims/error-boundary.js +31 -1
- package/dist/shims/error-boundary.js.map +1 -1
- package/dist/shims/fetch-cache.d.ts +4 -1
- package/dist/shims/fetch-cache.js +57 -16
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/head-state.js +2 -3
- package/dist/shims/head-state.js.map +1 -1
- package/dist/shims/headers.js +4 -44
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/i18n-state.js +2 -3
- package/dist/shims/i18n-state.js.map +1 -1
- package/dist/shims/image.js +93 -5
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/als-registry.d.ts +15 -0
- package/dist/shims/internal/als-registry.js +55 -0
- package/dist/shims/internal/als-registry.js.map +1 -0
- package/dist/shims/internal/cookie-serialize.d.ts +46 -0
- package/dist/shims/internal/cookie-serialize.js +51 -0
- package/dist/shims/internal/cookie-serialize.js.map +1 -0
- package/dist/shims/link.js +31 -26
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +26 -1
- package/dist/shims/metadata.js +94 -4
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation-state.js +2 -3
- package/dist/shims/navigation-state.js.map +1 -1
- package/dist/shims/navigation.d.ts +2 -7
- package/dist/shims/navigation.js +44 -36
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/request-context.js +2 -4
- package/dist/shims/request-context.js.map +1 -1
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/router-state.js +2 -3
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.js +2 -2
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/server.js +5 -30
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/slot.d.ts +1 -1
- package/dist/shims/slot.js +5 -4
- package/dist/shims/slot.js.map +1 -1
- package/dist/shims/thenable-params.d.ts +5 -2
- package/dist/shims/thenable-params.js +26 -6
- package/dist/shims/thenable-params.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +3 -14
- package/dist/shims/unified-request-context.js.map +1 -1
- package/dist/shims/use-merged-ref.d.ts +7 -0
- package/dist/shims/use-merged-ref.js +40 -0
- package/dist/shims/use-merged-ref.js.map +1 -0
- package/dist/utils/base-path.d.ts +7 -1
- package/dist/utils/base-path.js +12 -1
- package/dist/utils/base-path.js.map +1 -1
- package/dist/utils/cache-control-metadata.d.ts +6 -0
- package/dist/utils/cache-control-metadata.js +16 -0
- package/dist/utils/cache-control-metadata.js.map +1 -0
- package/dist/utils/safe-json-file.d.ts +18 -0
- package/dist/utils/safe-json-file.js +25 -0
- package/dist/utils/safe-json-file.js.map +1 -0
- package/dist/utils/text-stream.d.ts +29 -0
- package/dist/utils/text-stream.js +66 -0
- package/dist/utils/text-stream.js.map +1 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-request.js","names":[],"sources":["../../src/server/app-page-request.ts"],"sourcesContent":["import type { AppPageSpecialError } from \"./app-page-execution.js\";\n\ntype AppPageParams = Record<string, string | string[]>;\n\ntype ValidateAppPageDynamicParamsOptions = {\n clearRequestContext: () => void;\n enforceStaticParamsOnly: boolean;\n generateStaticParams?: ((args: { params: AppPageParams }) => unknown) | null;\n isDynamicRoute: boolean;\n logGenerateStaticParamsError?: (error: unknown) => void;\n params: AppPageParams;\n};\n\ntype BuildAppPageElementOptions<TElement> = {\n buildPageElement: () => Promise<TElement>;\n renderErrorBoundaryPage: (error: unknown) => Promise<Response | null>;\n renderSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n resolveSpecialError: (error: unknown) => AppPageSpecialError | null;\n};\n\ntype BuildAppPageElementResult<TElement> = {\n element: TElement | null;\n response: Response | null;\n};\n\ntype AppPageInterceptMatch<TPage = unknown> = {\n matchedParams: AppPageParams;\n page: TPage;\n slotKey: string;\n sourceRouteIndex: number;\n};\n\ntype ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts> = {\n cleanPathname: string;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> = {\n interceptOpts: TInterceptOpts;\n matchedParams: AppPageParams;\n sourceParams: AppPageParams;\n sourceRoute: TRoute;\n};\n\ntype AppPageInterceptState<TRoute, TPage> =\n | { kind: \"none\" }\n | { kind: \"current-route\"; intercept: AppPageInterceptMatch<TPage> }\n | { kind: \"source-route\"; intercept: AppPageInterceptMatch<TPage>; sourceRoute: TRoute };\n\ntype ResolveAppPageActionRerenderTargetOptions<TRoute, TPage, TInterceptOpts> = {\n cleanPathname: string;\n currentParams: AppPageParams;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageActionRerenderTargetResult<TRoute, TInterceptOpts> = {\n interceptOpts: TInterceptOpts | undefined;\n navigationParams: AppPageParams;\n params: AppPageParams;\n route: TRoute;\n};\n\ntype ResolveAppPageInterceptOptions<TRoute, TPage, TInterceptOpts, TElement> = {\n buildPageElement: (\n route: TRoute,\n params: AppPageParams,\n interceptOpts: TInterceptOpts | undefined,\n searchParams: URLSearchParams,\n ) => Promise<TElement>;\n cleanPathname: string;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n renderInterceptResponse: (route: TRoute, element: TElement) => Promise<Response> | Response;\n searchParams: URLSearchParams;\n setNavigationContext: (context: {\n params: AppPageParams;\n pathname: string;\n searchParams: URLSearchParams;\n }) => void;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageInterceptResult<TInterceptOpts> = {\n interceptOpts: TInterceptOpts | undefined;\n response: Response | null;\n};\n\nfunction pickRouteParams(\n matchedParams: AppPageParams,\n routeParamNames: readonly string[],\n): AppPageParams {\n const params: AppPageParams = {};\n\n for (const paramName of routeParamNames) {\n const value = matchedParams[paramName];\n if (value !== undefined) {\n params[paramName] = value;\n }\n }\n\n return params;\n}\n\nfunction areStaticParamsAllowed(\n params: AppPageParams,\n staticParams: readonly Record<string, unknown>[],\n): boolean {\n const paramKeys = Object.keys(params);\n\n return staticParams.some((staticParamSet) =>\n paramKeys.every((key) => {\n const value = params[key];\n const staticValue = staticParamSet[key];\n\n // Parent params may not appear in the leaf route's returned set because\n // Next.js passes them top-down through nested generateStaticParams calls.\n if (staticValue === undefined) {\n return true;\n }\n\n if (Array.isArray(value)) {\n return JSON.stringify(value) === JSON.stringify(staticValue);\n }\n\n if (\n typeof staticValue === \"string\" ||\n typeof staticValue === \"number\" ||\n typeof staticValue === \"boolean\"\n ) {\n return String(value) === String(staticValue);\n }\n\n return JSON.stringify(value) === JSON.stringify(staticValue);\n }),\n );\n}\n\nexport async function validateAppPageDynamicParams(\n options: ValidateAppPageDynamicParamsOptions,\n): Promise<Response | null> {\n if (\n !options.enforceStaticParamsOnly ||\n !options.isDynamicRoute ||\n typeof options.generateStaticParams !== \"function\"\n ) {\n return null;\n }\n\n try {\n const staticParams = await options.generateStaticParams({ params: options.params });\n if (Array.isArray(staticParams) && !areStaticParamsAllowed(options.params, staticParams)) {\n options.clearRequestContext();\n return new Response(\"Not Found\", { status: 404 });\n }\n } catch (error) {\n options.logGenerateStaticParamsError?.(error);\n }\n\n return null;\n}\n\n/**\n * Pure: decides whether the incoming request should re-render an intercepted\n * source-route tree, and if so returns the source route, the source-route's\n * param slice, the full matched param set (the URL params the client sees),\n * and an opaque `interceptOpts` bag for the caller's render pipeline.\n *\n * Returns `null` in three decision-fallthrough cases:\n * - non-RSC requests (server rendering the direct page for a full HTML load)\n * - no intercepting route matches the path\n * - the match's source route IS the current route (the same branch today\n * returns `interceptOpts` for the direct render)\n *\n * Shared by both the GET path (resolveAppPageIntercept, which layers on\n * `setNavigationContext` + element build + Response wrap) and the server-action\n * POST path (entries/app-rsc-entry.ts), which runs its own response pipeline.\n */\nexport function resolveAppPageInterceptMatch<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,\n): ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> | null {\n const interceptState = resolveAppPageInterceptState(options);\n if (interceptState.kind !== \"source-route\") {\n return null;\n }\n\n return {\n interceptOpts: options.toInterceptOpts(interceptState.intercept),\n matchedParams: interceptState.intercept.matchedParams,\n sourceParams: pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n sourceRoute: interceptState.sourceRoute,\n };\n}\n\nfunction resolveAppPageInterceptState<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,\n): AppPageInterceptState<TRoute, TPage> {\n if (!options.isRscRequest) {\n return { kind: \"none\" };\n }\n\n const intercept = options.findIntercept(options.cleanPathname);\n if (!intercept) {\n return { kind: \"none\" };\n }\n\n const sourceRoute = options.getSourceRoute(intercept.sourceRouteIndex);\n if (!sourceRoute) {\n return { kind: \"none\" };\n }\n\n if (sourceRoute === options.currentRoute) {\n return { kind: \"current-route\", intercept };\n }\n\n return { kind: \"source-route\", intercept, sourceRoute };\n}\n\nexport function resolveAppPageActionRerenderTarget<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageActionRerenderTargetOptions<TRoute, TPage, TInterceptOpts>,\n): ResolveAppPageActionRerenderTargetResult<TRoute, TInterceptOpts> {\n const interceptState = resolveAppPageInterceptState({\n cleanPathname: options.cleanPathname,\n currentRoute: options.currentRoute,\n findIntercept: options.findIntercept,\n getRouteParamNames: options.getRouteParamNames,\n getSourceRoute: options.getSourceRoute,\n isRscRequest: options.isRscRequest,\n toInterceptOpts: options.toInterceptOpts,\n });\n\n if (interceptState.kind === \"source-route\") {\n return {\n interceptOpts: options.toInterceptOpts(interceptState.intercept),\n navigationParams: interceptState.intercept.matchedParams,\n params: pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n route: interceptState.sourceRoute,\n };\n }\n\n return {\n interceptOpts:\n interceptState.kind === \"current-route\"\n ? options.toInterceptOpts(interceptState.intercept)\n : undefined,\n navigationParams: options.currentParams,\n params: options.currentParams,\n route: options.currentRoute,\n };\n}\n\nexport async function resolveAppPageIntercept<TRoute, TPage, TInterceptOpts, TElement>(\n options: ResolveAppPageInterceptOptions<TRoute, TPage, TInterceptOpts, TElement>,\n): Promise<ResolveAppPageInterceptResult<TInterceptOpts>> {\n const interceptState = resolveAppPageInterceptState({\n cleanPathname: options.cleanPathname,\n currentRoute: options.currentRoute,\n findIntercept: options.findIntercept,\n getRouteParamNames: options.getRouteParamNames,\n getSourceRoute: options.getSourceRoute,\n isRscRequest: options.isRscRequest,\n toInterceptOpts: options.toInterceptOpts,\n });\n\n if (interceptState.kind === \"source-route\") {\n options.setNavigationContext({\n params: interceptState.intercept.matchedParams,\n pathname: options.cleanPathname,\n searchParams: options.searchParams,\n });\n const interceptElement = await options.buildPageElement(\n interceptState.sourceRoute,\n pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n options.toInterceptOpts(interceptState.intercept),\n options.searchParams,\n );\n\n return {\n interceptOpts: undefined,\n response: await options.renderInterceptResponse(interceptState.sourceRoute, interceptElement),\n };\n }\n\n // Reproduce the current-route-is-source branch where we still need the opts\n // bag even though we did not render a separate intercepted response.\n return {\n interceptOpts:\n interceptState.kind === \"current-route\"\n ? options.toInterceptOpts(interceptState.intercept)\n : undefined,\n response: null,\n };\n}\n\nexport async function buildAppPageElement<TElement>(\n options: BuildAppPageElementOptions<TElement>,\n): Promise<BuildAppPageElementResult<TElement>> {\n try {\n return {\n element: await options.buildPageElement(),\n response: null,\n };\n } catch (error) {\n const specialError = options.resolveSpecialError(error);\n if (specialError) {\n return {\n element: null,\n response: await options.renderSpecialError(specialError),\n };\n }\n\n const errorBoundaryResponse = await options.renderErrorBoundaryPage(error);\n if (errorBoundaryResponse) {\n return {\n element: null,\n response: errorBoundaryResponse,\n };\n }\n\n throw error;\n }\n}\n"],"mappings":";AAoGA,SAAS,gBACP,eACA,iBACe;CACf,MAAM,SAAwB,EAAE;AAEhC,MAAK,MAAM,aAAa,iBAAiB;EACvC,MAAM,QAAQ,cAAc;AAC5B,MAAI,UAAU,KAAA,EACZ,QAAO,aAAa;;AAIxB,QAAO;;AAGT,SAAS,uBACP,QACA,cACS;CACT,MAAM,YAAY,OAAO,KAAK,OAAO;AAErC,QAAO,aAAa,MAAM,mBACxB,UAAU,OAAO,QAAQ;EACvB,MAAM,QAAQ,OAAO;EACrB,MAAM,cAAc,eAAe;AAInC,MAAI,gBAAgB,KAAA,EAClB,QAAO;AAGT,MAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,KAAK,UAAU,MAAM,KAAK,KAAK,UAAU,YAAY;AAG9D,MACE,OAAO,gBAAgB,YACvB,OAAO,gBAAgB,YACvB,OAAO,gBAAgB,UAEvB,QAAO,OAAO,MAAM,KAAK,OAAO,YAAY;AAG9C,SAAO,KAAK,UAAU,MAAM,KAAK,KAAK,UAAU,YAAY;GAC5D,CACH;;AAGH,eAAsB,6BACpB,SAC0B;AAC1B,KACE,CAAC,QAAQ,2BACT,CAAC,QAAQ,kBACT,OAAO,QAAQ,yBAAyB,WAExC,QAAO;AAGT,KAAI;EACF,MAAM,eAAe,MAAM,QAAQ,qBAAqB,EAAE,QAAQ,QAAQ,QAAQ,CAAC;AACnF,MAAI,MAAM,QAAQ,aAAa,IAAI,CAAC,uBAAuB,QAAQ,QAAQ,aAAa,EAAE;AACxF,WAAQ,qBAAqB;AAC7B,UAAO,IAAI,SAAS,aAA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AU,GACjD,KAAA;EACN,kBAAkB,QAAQ;EAC1B,QAAQ,QAAQ;EAChB,OAAO,QAAQ;EAChB;;AAGH,eAAsB,wBACpB,SACwD;CACxD,MAAM,iBAAiB,6BAA6B;EAClD,eAAe,QAAQ;EACvB,cAAc,QAAQ;EACtB,eAAe,QAAQ;EACvB,oBAAoB,QAAQ;EAC5B,gBAAgB,QAAQ;EACxB,cAAc,QAAQ;EACtB,iBAAiB,QAAQ;EAC1B,CAAC;AAEF,KAAI,eAAe,SAAS,gBAAgB;AAC1C,UAAQ,qBAAqB;GAC3B,QAAQ,eAAe,UAAU;GACjC,UAAU,QAAQ;GAClB,cAAc,QAAQ;GACvB,CAAC;EACF,MAAM,mBAAmB,MAAM,QAAQ,iBACrC,eAAe,aACf,gBACE,eAAe,UAAU,eACzB,QAAQ,mBAAmB,eAAe,YAAY,CACvD,EACD,QAAQ,gBAAgB,eAAe,UAAU,EACjD,QAAQ,aACT;AAED,SAAO;GACL,eAAe,KAAA;GACf,UAAU,MAAM,QAAQ,wBAAwB,eAAe,aAAa,iBAAiB;GAC9F;;AAKH,QAAO;EACL,eACE,eAAe,SAAS,kBACpB,QAAQ,gBAAgB,eAAe,UAAU,GACjD,KAAA;EACN,UAAU;EACX;;AAGH,eAAsB,oBACpB,SAC8C;AAC9C,KAAI;AACF,SAAO;GACL,SAAS,MAAM,QAAQ,kBAAkB;GACzC,UAAU;GACX;UACM,OAAO;EACd,MAAM,eAAe,QAAQ,oBAAoB,MAAM;AACvD,MAAI,aACF,QAAO;GACL,SAAS;GACT,UAAU,MAAM,QAAQ,mBAAmB,aAAa;GACzD;EAGH,MAAM,wBAAwB,MAAM,QAAQ,wBAAwB,MAAM;AAC1E,MAAI,sBACF,QAAO;GACL,SAAS;GACT,UAAU;GACX;AAGH,QAAM"}
|
|
1
|
+
{"version":3,"file":"app-page-request.js","names":[],"sources":["../../src/server/app-page-request.ts"],"sourcesContent":["import type { AppPageSpecialError } from \"./app-page-execution.js\";\nimport { getAppPageSegmentParamName } from \"./app-page-params.js\";\nimport { notFoundResponse } from \"./http-error-responses.js\";\n\ntype AppPageParams = Record<string, string | string[]>;\ntype GenerateStaticParams = (args: { params: AppPageParams }) => unknown;\n\ntype GenerateStaticParamsModule = {\n generateStaticParams?: GenerateStaticParams | null;\n};\n\ntype GenerateStaticParamsSource = {\n generateStaticParams: GenerateStaticParams;\n parentParamNames: readonly string[];\n};\n\nexport type ValidateAppPageDynamicParamsOptions = {\n clearRequestContext: () => void;\n enforceStaticParamsOnly: boolean;\n generateStaticParams?:\n | GenerateStaticParams\n | GenerateStaticParamsSource\n | readonly (GenerateStaticParams | GenerateStaticParamsSource | null | undefined)[]\n | null;\n isDynamicRoute: boolean;\n params: AppPageParams;\n};\n\ntype ResolveAppPageGenerateStaticParamsSourcesOptions = {\n layouts?: readonly (GenerateStaticParamsModule | null | undefined)[];\n layoutTreePositions?: readonly number[];\n page?: GenerateStaticParamsModule | null;\n routeSegments: readonly string[];\n};\n\ntype BuildAppPageElementOptions<TElement> = {\n buildPageElement: () => Promise<TElement>;\n renderErrorBoundaryPage: (error: unknown) => Promise<Response | null>;\n renderSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n resolveSpecialError: (error: unknown) => AppPageSpecialError | null;\n};\n\ntype BuildAppPageElementResult<TElement> = {\n element: TElement | null;\n response: Response | null;\n};\n\ntype AppPageInterceptMatch<TPage = unknown> = {\n matchedParams: AppPageParams;\n page: TPage;\n slotKey: string;\n sourceRouteIndex: number;\n};\n\ntype ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts> = {\n cleanPathname: string;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> = {\n interceptOpts: TInterceptOpts;\n matchedParams: AppPageParams;\n sourceParams: AppPageParams;\n sourceRoute: TRoute;\n};\n\ntype AppPageInterceptState<TRoute, TPage> =\n | { kind: \"none\" }\n | { kind: \"current-route\"; intercept: AppPageInterceptMatch<TPage> }\n | { kind: \"source-route\"; intercept: AppPageInterceptMatch<TPage>; sourceRoute: TRoute };\n\ntype ResolveAppPageActionRerenderTargetOptions<TRoute, TPage, TInterceptOpts> = {\n cleanPathname: string;\n currentParams: AppPageParams;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageActionRerenderTargetResult<TRoute, TInterceptOpts> = {\n interceptOpts: TInterceptOpts | undefined;\n navigationParams: AppPageParams;\n params: AppPageParams;\n route: TRoute;\n};\n\ntype ResolveAppPageInterceptOptions<TRoute, TPage, TInterceptOpts, TElement> = {\n buildPageElement: (\n route: TRoute,\n params: AppPageParams,\n interceptOpts: TInterceptOpts | undefined,\n searchParams: URLSearchParams,\n ) => Promise<TElement>;\n cleanPathname: string;\n currentRoute: TRoute;\n findIntercept: (pathname: string) => AppPageInterceptMatch<TPage> | null;\n getRouteParamNames: (route: TRoute) => readonly string[];\n getSourceRoute: (sourceRouteIndex: number) => TRoute | undefined;\n isRscRequest: boolean;\n renderInterceptResponse: (route: TRoute, element: TElement) => Promise<Response> | Response;\n searchParams: URLSearchParams;\n setNavigationContext: (context: {\n params: AppPageParams;\n pathname: string;\n searchParams: URLSearchParams;\n }) => void;\n toInterceptOpts: (intercept: AppPageInterceptMatch<TPage>) => TInterceptOpts;\n};\n\ntype ResolveAppPageInterceptResult<TInterceptOpts> = {\n interceptOpts: TInterceptOpts | undefined;\n response: Response | null;\n};\n\nfunction pickRouteParams(\n matchedParams: AppPageParams,\n routeParamNames: readonly string[],\n): AppPageParams {\n const params: AppPageParams = {};\n\n for (const paramName of routeParamNames) {\n const value = matchedParams[paramName];\n if (value !== undefined) {\n params[paramName] = value;\n }\n }\n\n return params;\n}\n\nfunction collectParentParamNames(\n routeSegments: readonly string[],\n boundaryPosition: number,\n): string[] {\n const limit = Math.max(0, Math.min(boundaryPosition, routeSegments.length));\n const names: string[] = [];\n\n for (const segment of routeSegments.slice(0, limit)) {\n const name = getAppPageSegmentParamName(segment);\n if (name && !names.includes(name)) {\n names.push(name);\n }\n }\n\n return names;\n}\n\nfunction getLayoutGenerateStaticParamsBoundary(layoutTreePosition: number | undefined): number {\n // A layout at app/[id]/layout.tsx has tree position 1, but its\n // generateStaticParams belongs to the [id] segment and receives only parent\n // params from segments before [id].\n return (layoutTreePosition ?? 0) - 1;\n}\n\nexport function resolveAppPageGenerateStaticParamsSources(\n options: ResolveAppPageGenerateStaticParamsSourcesOptions,\n): GenerateStaticParamsSource[] {\n const sources: GenerateStaticParamsSource[] = [];\n\n options.layouts?.forEach((layout, index) => {\n if (typeof layout?.generateStaticParams !== \"function\") return;\n\n sources.push({\n generateStaticParams: layout.generateStaticParams,\n parentParamNames: collectParentParamNames(\n options.routeSegments,\n getLayoutGenerateStaticParamsBoundary(options.layoutTreePositions?.[index]),\n ),\n });\n });\n\n if (typeof options.page?.generateStaticParams === \"function\") {\n sources.push({\n generateStaticParams: options.page.generateStaticParams,\n parentParamNames: collectParentParamNames(\n options.routeSegments,\n Math.max(0, options.routeSegments.length - 1),\n ),\n });\n }\n\n return sources;\n}\n\nfunction areStaticParamsAllowed(\n params: AppPageParams,\n staticParams: readonly Record<string, unknown>[],\n): boolean {\n const paramKeys = Object.keys(params);\n\n return staticParams.some((staticParamSet) =>\n paramKeys.every((key) => {\n const value = params[key];\n const staticValue = staticParamSet[key];\n\n // Parent params may not appear in the leaf route's returned set because\n // Next.js passes them top-down through nested generateStaticParams calls.\n if (staticValue === undefined) {\n return true;\n }\n\n if (Array.isArray(value)) {\n return JSON.stringify(value) === JSON.stringify(staticValue);\n }\n\n if (\n typeof staticValue === \"string\" ||\n typeof staticValue === \"number\" ||\n typeof staticValue === \"boolean\"\n ) {\n return String(value) === String(staticValue);\n }\n\n return JSON.stringify(value) === JSON.stringify(staticValue);\n }),\n );\n}\n\nfunction normalizeGenerateStaticParams(\n generateStaticParams: ValidateAppPageDynamicParamsOptions[\"generateStaticParams\"],\n): GenerateStaticParamsSource[] {\n const sources = Array.isArray(generateStaticParams)\n ? generateStaticParams\n : [generateStaticParams];\n\n return sources.flatMap((source) => {\n if (typeof source === \"function\") {\n return [{ generateStaticParams: source, parentParamNames: [] }];\n }\n\n if (typeof source?.generateStaticParams === \"function\") {\n return [source];\n }\n\n return [];\n });\n}\n\nexport async function validateAppPageDynamicParams(\n options: ValidateAppPageDynamicParamsOptions,\n): Promise<Response | null> {\n if (!options.enforceStaticParamsOnly || !options.isDynamicRoute) {\n return null;\n }\n\n const generateStaticParamsSources = normalizeGenerateStaticParams(options.generateStaticParams);\n if (generateStaticParamsSources.length === 0) {\n options.clearRequestContext();\n return notFoundResponse();\n }\n\n for (const source of generateStaticParamsSources) {\n const staticParams = await source.generateStaticParams({\n params: pickRouteParams(options.params, source.parentParamNames),\n });\n if (Array.isArray(staticParams) && !areStaticParamsAllowed(options.params, staticParams)) {\n options.clearRequestContext();\n return notFoundResponse();\n }\n }\n\n return null;\n}\n\n/**\n * Pure: decides whether the incoming request should re-render an intercepted\n * source-route tree, and if so returns the source route, the source-route's\n * param slice, the full matched param set (the URL params the client sees),\n * and an opaque `interceptOpts` bag for the caller's render pipeline.\n *\n * Returns `null` in three decision-fallthrough cases:\n * - non-RSC requests (server rendering the direct page for a full HTML load)\n * - no intercepting route matches the path\n * - the match's source route IS the current route (the same branch today\n * returns `interceptOpts` for the direct render)\n *\n * Shared by both the GET path (resolveAppPageIntercept, which layers on\n * `setNavigationContext` + element build + Response wrap) and the server-action\n * POST path (entries/app-rsc-entry.ts), which runs its own response pipeline.\n */\nexport function resolveAppPageInterceptMatch<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,\n): ResolveAppPageInterceptMatchResult<TRoute, TInterceptOpts> | null {\n const interceptState = resolveAppPageInterceptState(options);\n if (interceptState.kind !== \"source-route\") {\n return null;\n }\n\n return {\n interceptOpts: options.toInterceptOpts(interceptState.intercept),\n matchedParams: interceptState.intercept.matchedParams,\n sourceParams: pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n sourceRoute: interceptState.sourceRoute,\n };\n}\n\nfunction resolveAppPageInterceptState<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageInterceptMatchOptions<TRoute, TPage, TInterceptOpts>,\n): AppPageInterceptState<TRoute, TPage> {\n if (!options.isRscRequest) {\n return { kind: \"none\" };\n }\n\n const intercept = options.findIntercept(options.cleanPathname);\n if (!intercept) {\n return { kind: \"none\" };\n }\n\n const sourceRoute = options.getSourceRoute(intercept.sourceRouteIndex);\n if (!sourceRoute) {\n return { kind: \"none\" };\n }\n\n if (sourceRoute === options.currentRoute) {\n return { kind: \"current-route\", intercept };\n }\n\n return { kind: \"source-route\", intercept, sourceRoute };\n}\n\nexport function resolveAppPageActionRerenderTarget<TRoute, TPage, TInterceptOpts>(\n options: ResolveAppPageActionRerenderTargetOptions<TRoute, TPage, TInterceptOpts>,\n): ResolveAppPageActionRerenderTargetResult<TRoute, TInterceptOpts> {\n const interceptState = resolveAppPageInterceptState({\n cleanPathname: options.cleanPathname,\n currentRoute: options.currentRoute,\n findIntercept: options.findIntercept,\n getRouteParamNames: options.getRouteParamNames,\n getSourceRoute: options.getSourceRoute,\n isRscRequest: options.isRscRequest,\n toInterceptOpts: options.toInterceptOpts,\n });\n\n if (interceptState.kind === \"source-route\") {\n return {\n interceptOpts: options.toInterceptOpts(interceptState.intercept),\n navigationParams: interceptState.intercept.matchedParams,\n params: pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n route: interceptState.sourceRoute,\n };\n }\n\n return {\n interceptOpts:\n interceptState.kind === \"current-route\"\n ? options.toInterceptOpts(interceptState.intercept)\n : undefined,\n navigationParams: options.currentParams,\n params: options.currentParams,\n route: options.currentRoute,\n };\n}\n\nexport async function resolveAppPageIntercept<TRoute, TPage, TInterceptOpts, TElement>(\n options: ResolveAppPageInterceptOptions<TRoute, TPage, TInterceptOpts, TElement>,\n): Promise<ResolveAppPageInterceptResult<TInterceptOpts>> {\n const interceptState = resolveAppPageInterceptState({\n cleanPathname: options.cleanPathname,\n currentRoute: options.currentRoute,\n findIntercept: options.findIntercept,\n getRouteParamNames: options.getRouteParamNames,\n getSourceRoute: options.getSourceRoute,\n isRscRequest: options.isRscRequest,\n toInterceptOpts: options.toInterceptOpts,\n });\n\n if (interceptState.kind === \"source-route\") {\n options.setNavigationContext({\n params: interceptState.intercept.matchedParams,\n pathname: options.cleanPathname,\n searchParams: options.searchParams,\n });\n const interceptElement = await options.buildPageElement(\n interceptState.sourceRoute,\n pickRouteParams(\n interceptState.intercept.matchedParams,\n options.getRouteParamNames(interceptState.sourceRoute),\n ),\n options.toInterceptOpts(interceptState.intercept),\n options.searchParams,\n );\n\n return {\n interceptOpts: undefined,\n response: await options.renderInterceptResponse(interceptState.sourceRoute, interceptElement),\n };\n }\n\n // Reproduce the current-route-is-source branch where we still need the opts\n // bag even though we did not render a separate intercepted response.\n return {\n interceptOpts:\n interceptState.kind === \"current-route\"\n ? options.toInterceptOpts(interceptState.intercept)\n : undefined,\n response: null,\n };\n}\n\nexport async function buildAppPageElement<TElement>(\n options: BuildAppPageElementOptions<TElement>,\n): Promise<BuildAppPageElementResult<TElement>> {\n try {\n return {\n element: await options.buildPageElement(),\n response: null,\n };\n } catch (error) {\n const specialError = options.resolveSpecialError(error);\n if (specialError) {\n return {\n element: null,\n response: await options.renderSpecialError(specialError),\n };\n }\n\n const errorBoundaryResponse = await options.renderErrorBoundaryPage(error);\n if (errorBoundaryResponse) {\n return {\n element: null,\n response: errorBoundaryResponse,\n };\n }\n\n throw error;\n }\n}\n"],"mappings":";;;AA0HA,SAAS,gBACP,eACA,iBACe;CACf,MAAM,SAAwB,EAAE;AAEhC,MAAK,MAAM,aAAa,iBAAiB;EACvC,MAAM,QAAQ,cAAc;AAC5B,MAAI,UAAU,KAAA,EACZ,QAAO,aAAa;;AAIxB,QAAO;;AAGT,SAAS,wBACP,eACA,kBACU;CACV,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,kBAAkB,cAAc,OAAO,CAAC;CAC3E,MAAM,QAAkB,EAAE;AAE1B,MAAK,MAAM,WAAW,cAAc,MAAM,GAAG,MAAM,EAAE;EACnD,MAAM,OAAO,2BAA2B,QAAQ;AAChD,MAAI,QAAQ,CAAC,MAAM,SAAS,KAAK,CAC/B,OAAM,KAAK,KAAK;;AAIpB,QAAO;;AAGT,SAAS,sCAAsC,oBAAgD;AAI7F,SAAQ,sBAAsB,KAAK;;AAGrC,SAAgB,0CACd,SAC8B;CAC9B,MAAM,UAAwC,EAAE;AAEhD,SAAQ,SAAS,SAAS,QAAQ,UAAU;AAC1C,MAAI,OAAO,QAAQ,yBAAyB,WAAY;AAExD,UAAQ,KAAK;GACX,sBAAsB,OAAO;GAC7B,kBAAkB,wBAChB,QAAQ,eACR,sCAAsC,QAAQ,sBAAsB,OAAO,CAC5E;GACF,CAAC;GACF;AAEF,KAAI,OAAO,QAAQ,MAAM,yBAAyB,WAChD,SAAQ,KAAK;EACX,sBAAsB,QAAQ,KAAK;EACnC,kBAAkB,wBAChB,QAAQ,eACR,KAAK,IAAI,GAAG,QAAQ,cAAc,SAAS,EAAE,CAC9C;EACF,CAAC;AAGJ,QAAO;;AAGT,SAAS,uBACP,QACA,cACS;CACT,MAAM,YAAY,OAAO,KAAK,OAAO;AAErC,QAAO,aAAa,MAAM,mBACxB,UAAU,OAA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eAAe,QAAQ;EACvB,oBAAoB,QAAQ;EAC5B,gBAAgB,QAAQ;EACxB,cAAc,QAAQ;EACtB,iBAAiB,QAAQ;EAC1B,CAAC;AAEF,KAAI,eAAe,SAAS,gBAAgB;AAC1C,UAAQ,qBAAqB;GAC3B,QAAQ,eAAe,UAAU;GACjC,UAAU,QAAQ;GAClB,cAAc,QAAQ;GACvB,CAAC;EACF,MAAM,mBAAmB,MAAM,QAAQ,iBACrC,eAAe,aACf,gBACE,eAAe,UAAU,eACzB,QAAQ,mBAAmB,eAAe,YAAY,CACvD,EACD,QAAQ,gBAAgB,eAAe,UAAU,EACjD,QAAQ,aACT;AAED,SAAO;GACL,eAAe,KAAA;GACf,UAAU,MAAM,QAAQ,wBAAwB,eAAe,aAAa,iBAAiB;GAC9F;;AAKH,QAAO;EACL,eACE,eAAe,SAAS,kBACpB,QAAQ,gBAAgB,eAAe,UAAU,GACjD,KAAA;EACN,UAAU;EACX;;AAGH,eAAsB,oBACpB,SAC8C;AAC9C,KAAI;AACF,SAAO;GACL,SAAS,MAAM,QAAQ,kBAAkB;GACzC,UAAU;GACX;UACM,OAAO;EACd,MAAM,eAAe,QAAQ,oBAAoB,MAAM;AACvD,MAAI,aACF,QAAO;GACL,SAAS;GACT,UAAU,MAAM,QAAQ,mBAAmB,aAAa;GACzD;EAGH,MAAM,wBAAwB,MAAM,QAAQ,wBAAwB,MAAM;AAC1E,MAAI,sBACF,QAAO;GACL,SAAS;GACT,UAAU;GACX;AAGH,QAAM"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
+
import { VINEXT_RSC_VARY_HEADER } from "./app-rsc-cache-busting.js";
|
|
1
2
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
3
|
+
import { NO_STORE_CACHE_CONTROL, STATIC_CACHE_CONTROL, buildRevalidateCacheControl } from "./cache-control.js";
|
|
2
4
|
//#region src/server/app-page-response.ts
|
|
3
|
-
const STATIC_CACHE_CONTROL = "s-maxage=31536000, stale-while-revalidate";
|
|
4
|
-
const NO_STORE_CACHE_CONTROL = "no-store, must-revalidate";
|
|
5
|
-
function buildRevalidateCacheControl(revalidateSeconds) {
|
|
6
|
-
return `s-maxage=${revalidateSeconds}, stale-while-revalidate`;
|
|
7
|
-
}
|
|
8
5
|
function applyTimingHeader(headers, timing) {
|
|
9
6
|
if (!timing) return;
|
|
10
7
|
const handlerStart = Math.round(timing.handlerStart);
|
|
@@ -20,7 +17,7 @@ function resolveAppPageRscResponsePolicy(options) {
|
|
|
20
17
|
cacheState: "STATIC"
|
|
21
18
|
};
|
|
22
19
|
if (options.revalidateSeconds) return {
|
|
23
|
-
cacheControl: buildRevalidateCacheControl(options.revalidateSeconds),
|
|
20
|
+
cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),
|
|
24
21
|
cacheState: options.isProduction ? "MISS" : void 0
|
|
25
22
|
};
|
|
26
23
|
return {};
|
|
@@ -48,7 +45,7 @@ function resolveAppPageHtmlResponsePolicy(options) {
|
|
|
48
45
|
shouldWriteToCache: false
|
|
49
46
|
};
|
|
50
47
|
if (options.revalidateSeconds !== null && options.revalidateSeconds > 0 && options.revalidateSeconds !== Infinity) return {
|
|
51
|
-
cacheControl: buildRevalidateCacheControl(options.revalidateSeconds),
|
|
48
|
+
cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),
|
|
52
49
|
cacheState: options.isProduction ? "MISS" : void 0,
|
|
53
50
|
shouldWriteToCache: options.isProduction
|
|
54
51
|
};
|
|
@@ -62,7 +59,7 @@ function resolveAppPageHtmlResponsePolicy(options) {
|
|
|
62
59
|
function buildAppPageRscResponse(body, options) {
|
|
63
60
|
const headers = new Headers({
|
|
64
61
|
"Content-Type": "text/x-component; charset=utf-8",
|
|
65
|
-
Vary:
|
|
62
|
+
Vary: VINEXT_RSC_VARY_HEADER
|
|
66
63
|
});
|
|
67
64
|
if (options.params && Object.keys(options.params).length > 0) headers.set("X-Vinext-Params", encodeURIComponent(JSON.stringify(options.params)));
|
|
68
65
|
if (options.mountedSlotsHeader) headers.set("X-Vinext-Mounted-Slots", options.mountedSlotsHeader);
|
|
@@ -78,7 +75,7 @@ function buildAppPageRscResponse(body, options) {
|
|
|
78
75
|
function buildAppPageHtmlResponse(body, options) {
|
|
79
76
|
const headers = new Headers({
|
|
80
77
|
"Content-Type": "text/html; charset=utf-8",
|
|
81
|
-
Vary:
|
|
78
|
+
Vary: VINEXT_RSC_VARY_HEADER
|
|
82
79
|
});
|
|
83
80
|
if (options.policy.cacheControl) headers.set("Cache-Control", options.policy.cacheControl);
|
|
84
81
|
if (options.policy.cacheState) headers.set("X-Vinext-Cache", options.policy.cacheState);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-response.js","names":[],"sources":["../../src/server/app-page-response.ts"],"sourcesContent":["import { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\n\nexport type AppPageMiddlewareContext = {\n headers: Headers | null;\n status: number | null;\n};\n\nexport type AppPageResponseTiming = {\n compileEnd?: number;\n handlerStart: number;\n renderEnd?: number;\n responseKind: \"html\" | \"rsc\";\n};\n\ntype AppPageResponsePolicy = {\n cacheControl?: string;\n cacheState?: \"MISS\" | \"STATIC\";\n};\n\ntype ResolveAppPageResponsePolicyBaseOptions = {\n isDynamicError: boolean;\n isForceDynamic: boolean;\n isForceStatic: boolean;\n isProduction: boolean;\n revalidateSeconds: number | null;\n};\n\ntype ResolveAppPageRscResponsePolicyOptions = {\n dynamicUsedDuringBuild: boolean;\n} & ResolveAppPageResponsePolicyBaseOptions;\n\ntype ResolveAppPageHtmlResponsePolicyOptions = {\n dynamicUsedDuringRender: boolean;\n hasScriptNonce: boolean;\n} & ResolveAppPageResponsePolicyBaseOptions;\n\ntype AppPageHtmlResponsePolicy = {\n shouldWriteToCache: boolean;\n} & AppPageResponsePolicy;\n\ntype BuildAppPageRscResponseOptions = {\n middlewareContext: AppPageMiddlewareContext;\n mountedSlotsHeader?: string | null;\n params?: Record<string, unknown>;\n policy: AppPageResponsePolicy;\n timing?: AppPageResponseTiming;\n};\n\ntype BuildAppPageHtmlResponseOptions = {\n draftCookie?: string | null;\n fontLinkHeader?: string;\n middlewareContext: AppPageMiddlewareContext;\n policy: AppPageResponsePolicy;\n timing?: AppPageResponseTiming;\n};\n\nconst STATIC_CACHE_CONTROL = \"s-maxage=31536000, stale-while-revalidate\";\nconst NO_STORE_CACHE_CONTROL = \"no-store, must-revalidate\";\n\nfunction buildRevalidateCacheControl(revalidateSeconds: number): string {\n return `s-maxage=${revalidateSeconds}, stale-while-revalidate`;\n}\n\nfunction applyTimingHeader(headers: Headers, timing?: AppPageResponseTiming): void {\n if (!timing) {\n return;\n }\n\n const handlerStart = Math.round(timing.handlerStart);\n const compileMs =\n timing.compileEnd !== undefined ? Math.round(timing.compileEnd - timing.handlerStart) : -1;\n const renderMs =\n timing.responseKind === \"html\" &&\n timing.renderEnd !== undefined &&\n timing.compileEnd !== undefined\n ? Math.round(timing.renderEnd - timing.compileEnd)\n : -1;\n\n headers.set(\"x-vinext-timing\", `${handlerStart},${compileMs},${renderMs}`);\n}\n\nexport function resolveAppPageRscResponsePolicy(\n options: ResolveAppPageRscResponsePolicyOptions,\n): AppPageResponsePolicy {\n if (options.isForceDynamic || options.dynamicUsedDuringBuild) {\n return { cacheControl: NO_STORE_CACHE_CONTROL };\n }\n\n // revalidate = 0 means \"always dynamic, never cache\" — equivalent to\n // force-dynamic for caching purposes. Must be checked before the\n // isForceStatic/isDynamicError branch below, which uses !revalidateSeconds\n // and would incorrectly catch 0 as a falsy value.\n if (options.revalidateSeconds === 0) {\n return { cacheControl: NO_STORE_CACHE_CONTROL };\n }\n\n if (\n ((options.isForceStatic || options.isDynamicError) && !options.revalidateSeconds) ||\n options.revalidateSeconds === Infinity\n ) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n };\n }\n\n if (options.revalidateSeconds) {\n return {\n cacheControl: buildRevalidateCacheControl(options.revalidateSeconds),\n // Emit MISS as part of the initial RSC response shape rather than bolting\n // it on later in the cache-write block so response construction stays\n // centralized in this helper. This matches the eventual write path: the\n // first ISR-eligible production response is a cache miss.\n cacheState: options.isProduction ? \"MISS\" : undefined,\n };\n }\n\n return {};\n}\n\nexport function resolveAppPageHtmlResponsePolicy(\n options: ResolveAppPageHtmlResponsePolicyOptions,\n): AppPageHtmlResponsePolicy {\n if (options.isForceDynamic) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if (options.hasScriptNonce) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n // revalidate = 0 means \"always dynamic, never cache\" — equivalent to\n // force-dynamic for caching purposes. Must be checked before the\n // isForceStatic/isDynamicError branch below, which matches revalidateSeconds\n // === 0 and would incorrectly return a static Cache-Control.\n if (options.revalidateSeconds === 0) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if ((options.isForceStatic || options.isDynamicError) && options.revalidateSeconds === null) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n shouldWriteToCache: false,\n };\n }\n\n if (options.dynamicUsedDuringRender) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if (\n options.revalidateSeconds !== null &&\n options.revalidateSeconds > 0 &&\n options.revalidateSeconds !== Infinity\n ) {\n return {\n cacheControl: buildRevalidateCacheControl(options.revalidateSeconds),\n cacheState: options.isProduction ? \"MISS\" : undefined,\n shouldWriteToCache: options.isProduction,\n };\n }\n\n if (options.revalidateSeconds === Infinity) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n shouldWriteToCache: false,\n };\n }\n\n return { shouldWriteToCache: false };\n}\n\nexport { mergeMiddlewareResponseHeaders };\n\nexport function buildAppPageRscResponse(\n body: ReadableStream,\n options: BuildAppPageRscResponseOptions,\n): Response {\n const headers = new Headers({\n \"Content-Type\": \"text/x-component; charset=utf-8\",\n Vary: \"RSC, Accept\",\n });\n\n if (options.params && Object.keys(options.params).length > 0) {\n // encodeURIComponent so non-ASCII params (e.g. Korean slugs) survive the\n // HTTP ByteString constraint — Headers.set() rejects chars above U+00FF.\n headers.set(\"X-Vinext-Params\", encodeURIComponent(JSON.stringify(options.params)));\n }\n if (options.mountedSlotsHeader) {\n headers.set(\"X-Vinext-Mounted-Slots\", options.mountedSlotsHeader);\n }\n if (options.policy.cacheControl) {\n headers.set(\"Cache-Control\", options.policy.cacheControl);\n }\n if (options.policy.cacheState) {\n headers.set(\"X-Vinext-Cache\", options.policy.cacheState);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareContext.headers);\n\n applyTimingHeader(headers, options.timing);\n\n return new Response(body, {\n status: options.middlewareContext.status ?? 200,\n headers,\n });\n}\n\nexport function buildAppPageHtmlResponse(\n body: ReadableStream,\n options: BuildAppPageHtmlResponseOptions,\n): Response {\n const headers = new Headers({\n \"Content-Type\": \"text/html; charset=utf-8\",\n Vary: \"RSC, Accept\",\n });\n\n if (options.policy.cacheControl) {\n headers.set(\"Cache-Control\", options.policy.cacheControl);\n }\n if (options.policy.cacheState) {\n headers.set(\"X-Vinext-Cache\", options.policy.cacheState);\n }\n if (options.draftCookie) {\n headers.append(\"Set-Cookie\", options.draftCookie);\n }\n if (options.fontLinkHeader) {\n headers.set(\"Link\", options.fontLinkHeader);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareContext.headers);\n\n applyTimingHeader(headers, options.timing);\n\n return new Response(body, {\n status: options.middlewareContext.status ?? 200,\n headers,\n });\n}\n"],"mappings":";;AAwDA,MAAM,uBAAuB;AAC7B,MAAM,yBAAyB;AAE/B,SAAS,4BAA4B,mBAAmC;AACtE,QAAO,YAAY,kBAAkB;;AAGvC,SAAS,kBAAkB,SAAkB,QAAsC;AACjF,KAAI,CAAC,OACH;CAGF,MAAM,eAAe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C,QAAO,IAAI,SAAS,MAAM;EACxB,QAAQ,QAAQ,kBAAkB,UAAU;EAC5C;EACD,CAAC"}
|
|
1
|
+
{"version":3,"file":"app-page-response.js","names":[],"sources":["../../src/server/app-page-response.ts"],"sourcesContent":["import {\n buildRevalidateCacheControl,\n NO_STORE_CACHE_CONTROL,\n STATIC_CACHE_CONTROL,\n} from \"./cache-control.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\nimport { VINEXT_RSC_VARY_HEADER } from \"./app-rsc-cache-busting.js\";\n\nexport type AppPageMiddlewareContext = {\n headers: Headers | null;\n status: number | null;\n};\n\nexport type AppPageResponseTiming = {\n compileEnd?: number;\n handlerStart: number;\n renderEnd?: number;\n responseKind: \"html\" | \"rsc\";\n};\n\ntype AppPageResponsePolicy = {\n cacheControl?: string;\n cacheState?: \"MISS\" | \"STATIC\";\n};\n\ntype ResolveAppPageResponsePolicyBaseOptions = {\n isDynamicError: boolean;\n isForceDynamic: boolean;\n isForceStatic: boolean;\n isProduction: boolean;\n expireSeconds?: number;\n revalidateSeconds: number | null;\n};\n\ntype ResolveAppPageRscResponsePolicyOptions = {\n dynamicUsedDuringBuild: boolean;\n} & ResolveAppPageResponsePolicyBaseOptions;\n\ntype ResolveAppPageHtmlResponsePolicyOptions = {\n dynamicUsedDuringRender: boolean;\n hasScriptNonce: boolean;\n} & ResolveAppPageResponsePolicyBaseOptions;\n\ntype AppPageHtmlResponsePolicy = {\n shouldWriteToCache: boolean;\n} & AppPageResponsePolicy;\n\ntype BuildAppPageRscResponseOptions = {\n middlewareContext: AppPageMiddlewareContext;\n mountedSlotsHeader?: string | null;\n params?: Record<string, unknown>;\n policy: AppPageResponsePolicy;\n timing?: AppPageResponseTiming;\n};\n\ntype BuildAppPageHtmlResponseOptions = {\n draftCookie?: string | null;\n fontLinkHeader?: string;\n middlewareContext: AppPageMiddlewareContext;\n policy: AppPageResponsePolicy;\n timing?: AppPageResponseTiming;\n};\n\nfunction applyTimingHeader(headers: Headers, timing?: AppPageResponseTiming): void {\n if (!timing) {\n return;\n }\n\n const handlerStart = Math.round(timing.handlerStart);\n const compileMs =\n timing.compileEnd !== undefined ? Math.round(timing.compileEnd - timing.handlerStart) : -1;\n const renderMs =\n timing.responseKind === \"html\" &&\n timing.renderEnd !== undefined &&\n timing.compileEnd !== undefined\n ? Math.round(timing.renderEnd - timing.compileEnd)\n : -1;\n\n headers.set(\"x-vinext-timing\", `${handlerStart},${compileMs},${renderMs}`);\n}\n\nexport function resolveAppPageRscResponsePolicy(\n options: ResolveAppPageRscResponsePolicyOptions,\n): AppPageResponsePolicy {\n if (options.isForceDynamic || options.dynamicUsedDuringBuild) {\n return { cacheControl: NO_STORE_CACHE_CONTROL };\n }\n\n // revalidate = 0 means \"always dynamic, never cache\" — equivalent to\n // force-dynamic for caching purposes. Must be checked before the\n // isForceStatic/isDynamicError branch below, which uses !revalidateSeconds\n // and would incorrectly catch 0 as a falsy value.\n if (options.revalidateSeconds === 0) {\n return { cacheControl: NO_STORE_CACHE_CONTROL };\n }\n\n if (\n ((options.isForceStatic || options.isDynamicError) && !options.revalidateSeconds) ||\n options.revalidateSeconds === Infinity\n ) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n };\n }\n\n if (options.revalidateSeconds) {\n return {\n cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),\n // Emit MISS as part of the initial RSC response shape rather than bolting\n // it on later in the cache-write block so response construction stays\n // centralized in this helper. This matches the eventual write path: the\n // first ISR-eligible production response is a cache miss.\n cacheState: options.isProduction ? \"MISS\" : undefined,\n };\n }\n\n return {};\n}\n\nexport function resolveAppPageHtmlResponsePolicy(\n options: ResolveAppPageHtmlResponsePolicyOptions,\n): AppPageHtmlResponsePolicy {\n if (options.isForceDynamic) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if (options.hasScriptNonce) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n // revalidate = 0 means \"always dynamic, never cache\" — equivalent to\n // force-dynamic for caching purposes. Must be checked before the\n // isForceStatic/isDynamicError branch below, which matches revalidateSeconds\n // === 0 and would incorrectly return a static Cache-Control.\n if (options.revalidateSeconds === 0) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if ((options.isForceStatic || options.isDynamicError) && options.revalidateSeconds === null) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n shouldWriteToCache: false,\n };\n }\n\n if (options.dynamicUsedDuringRender) {\n return {\n cacheControl: NO_STORE_CACHE_CONTROL,\n shouldWriteToCache: false,\n };\n }\n\n if (\n options.revalidateSeconds !== null &&\n options.revalidateSeconds > 0 &&\n options.revalidateSeconds !== Infinity\n ) {\n return {\n cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),\n cacheState: options.isProduction ? \"MISS\" : undefined,\n shouldWriteToCache: options.isProduction,\n };\n }\n\n if (options.revalidateSeconds === Infinity) {\n return {\n cacheControl: STATIC_CACHE_CONTROL,\n cacheState: \"STATIC\",\n shouldWriteToCache: false,\n };\n }\n\n return { shouldWriteToCache: false };\n}\n\nexport { mergeMiddlewareResponseHeaders };\n\nexport function buildAppPageRscResponse(\n body: ReadableStream,\n options: BuildAppPageRscResponseOptions,\n): Response {\n const headers = new Headers({\n \"Content-Type\": \"text/x-component; charset=utf-8\",\n Vary: VINEXT_RSC_VARY_HEADER,\n });\n\n if (options.params && Object.keys(options.params).length > 0) {\n // encodeURIComponent so non-ASCII params (e.g. Korean slugs) survive the\n // HTTP ByteString constraint — Headers.set() rejects chars above U+00FF.\n headers.set(\"X-Vinext-Params\", encodeURIComponent(JSON.stringify(options.params)));\n }\n if (options.mountedSlotsHeader) {\n headers.set(\"X-Vinext-Mounted-Slots\", options.mountedSlotsHeader);\n }\n if (options.policy.cacheControl) {\n headers.set(\"Cache-Control\", options.policy.cacheControl);\n }\n if (options.policy.cacheState) {\n headers.set(\"X-Vinext-Cache\", options.policy.cacheState);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareContext.headers);\n\n applyTimingHeader(headers, options.timing);\n\n return new Response(body, {\n status: options.middlewareContext.status ?? 200,\n headers,\n });\n}\n\nexport function buildAppPageHtmlResponse(\n body: ReadableStream,\n options: BuildAppPageHtmlResponseOptions,\n): Response {\n const headers = new Headers({\n \"Content-Type\": \"text/html; charset=utf-8\",\n Vary: VINEXT_RSC_VARY_HEADER,\n });\n\n if (options.policy.cacheControl) {\n headers.set(\"Cache-Control\", options.policy.cacheControl);\n }\n if (options.policy.cacheState) {\n headers.set(\"X-Vinext-Cache\", options.policy.cacheState);\n }\n if (options.draftCookie) {\n headers.append(\"Set-Cookie\", options.draftCookie);\n }\n if (options.fontLinkHeader) {\n headers.set(\"Link\", options.fontLinkHeader);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareContext.headers);\n\n applyTimingHeader(headers, options.timing);\n\n return new Response(body, {\n status: options.middlewareContext.status ?? 200,\n headers,\n });\n}\n"],"mappings":";;;;AA+DA,SAAS,kBAAkB,SAAkB,QAAsC;AACjF,KAAI,CAAC,OACH;CAGF,MAAM,eAAe,KAAK,MAAM,OAAO,aAAa;CACpD,MAAM,YACJ,OAAO,eAAe,KAAA,IAAY,KAAK,MAAM,OAAO,aAAa,OAAO,aAAa,GAAG;CAC1F,MAAM,WACJ,OAAO,iBAAiB,UACxB,OAAO,cAAc,KAAA,KACrB,OAAO,eAAe,KAAA,IAClB,KAAK,MAAM,OAAO,YAAY,OAAO,WAAW,GAChD;AAEN,SAAQ,IAAI,mBAAmB,GAAG,aAAa,GAAG,UAAU,GAAG,WAAW;;AAG5E,SAAgB,gCACd,SACuB;AACvB,KAAI,QAAQ,kBAAkB,QAAQ,uBACpC,QAAO,EAAE,cAAc,wBAAwB;AAOjD,KAAI,QAAQ,sBAAsB,EAChC,QAAO,EAAE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,KAAI,QAAQ,mBACV,SAAQ,IAAI,0BAA0B,QAAQ,mBAAmB;AAEnE,KAAI,QAAQ,OAAO,aACjB,SAAQ,IAAI,iBAAiB,QAAQ,OAAO,aAAa;AAE3D,KAAI,QAAQ,OAAO,WACjB,SAAQ,IAAI,kBAAkB,QAAQ,OAAO,WAAW;AAG1D,gCAA+B,SAAS,QAAQ,kBAAkB,QAAQ;AAE1E,mBAAkB,SAAS,QAAQ,OAAO;AAE1C,QAAO,IAAI,SAAS,MAAM;EACxB,QAAQ,QAAQ,kBAAkB,UAAU;EAC5C;EACD,CAAC;;AAGJ,SAAgB,yBACd,MACA,SACU;CACV,MAAM,UAAU,IAAI,QAAQ;EAC1B,gBAAgB;EAChB,MAAM;EACP,CAAC;AAEF,KAAI,QAAQ,OAAO,aACjB,SAAQ,IAAI,iBAAiB,QAAQ,OAAO,aAAa;AAE3D,KAAI,QAAQ,OAAO,WACjB,SAAQ,IAAI,kBAAkB,QAAQ,OAAO,WAAW;AAE1D,KAAI,QAAQ,YACV,SAAQ,OAAO,cAAc,QAAQ,YAAY;AAEnD,KAAI,QAAQ,eACV,SAAQ,IAAI,QAAQ,QAAQ,eAAe;AAG7C,gCAA+B,SAAS,QAAQ,kBAAkB,QAAQ;AAE1E,mBAAkB,SAAS,QAAQ,OAAO;AAE1C,QAAO,IAAI,SAAS,MAAM;EACxB,QAAQ,QAAQ,kBAAkB,UAAU;EAC5C;EACD,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AppRouteSemanticIds } from "../routing/app-route-graph.js";
|
|
2
|
+
import { AppElements } from "./app-elements-wire.js";
|
|
2
3
|
import { AppPageParams } from "./app-page-boundary.js";
|
|
3
4
|
import { Metadata, Viewport } from "../shims/metadata.js";
|
|
4
5
|
import { ComponentType, ReactNode } from "react";
|
|
@@ -22,7 +23,8 @@ type AppPageErrorModule = Record<string, unknown> & {
|
|
|
22
23
|
default?: AppPageErrorComponent | null | undefined;
|
|
23
24
|
};
|
|
24
25
|
type AppPageRouteWiringSlot<TModule extends AppPageModule = AppPageModule, TErrorModule extends AppPageErrorModule = AppPageErrorModule> = {
|
|
25
|
-
/** Slot prop name passed to the owning layout (e.g. "modal" from @modal). */
|
|
26
|
+
/** Graph-owned semantic slot identity. */id?: string | null; /** Slot prop name passed to the owning layout (e.g. "modal" from @modal). */
|
|
27
|
+
name: string;
|
|
26
28
|
default?: TModule | null;
|
|
27
29
|
error?: TErrorModule | null;
|
|
28
30
|
layout?: TModule | null;
|
|
@@ -30,8 +32,17 @@ type AppPageRouteWiringSlot<TModule extends AppPageModule = AppPageModule, TErro
|
|
|
30
32
|
loading?: TModule | null;
|
|
31
33
|
page?: TModule | null;
|
|
32
34
|
routeSegments?: readonly string[] | null;
|
|
35
|
+
/**
|
|
36
|
+
* Full URL pattern parts for the slot's mirrored sub-page. Set when the
|
|
37
|
+
* slot's params may differ from the route's (e.g. inherited slot whose
|
|
38
|
+
* dynamic markers have different names than the route's). The runtime
|
|
39
|
+
* matches the request URL against these parts to extract slot params.
|
|
40
|
+
*/
|
|
41
|
+
slotPatternParts?: readonly string[] | null; /** Param names captured by `slotPatternParts`, in order. */
|
|
42
|
+
slotParamNames?: readonly string[] | null;
|
|
33
43
|
};
|
|
34
44
|
type AppPageRouteWiringRoute<TModule extends AppPageModule = AppPageModule, TErrorModule extends AppPageErrorModule = AppPageErrorModule> = {
|
|
45
|
+
ids?: AppRouteSemanticIds | null;
|
|
35
46
|
error?: TErrorModule | null;
|
|
36
47
|
errors?: readonly (TErrorModule | null | undefined)[] | null;
|
|
37
48
|
layoutTreePositions?: readonly number[] | null;
|
|
@@ -53,7 +64,12 @@ type AppPageRouteWiringRoute<TModule extends AppPageModule = AppPageModule, TErr
|
|
|
53
64
|
};
|
|
54
65
|
type AppPageSlotOverride<TModule extends AppPageModule = AppPageModule> = {
|
|
55
66
|
layoutModules?: readonly (TModule | null | undefined)[] | null;
|
|
56
|
-
|
|
67
|
+
/**
|
|
68
|
+
* The page module to render for this slot. Optional — when omitted, the
|
|
69
|
+
* slot's existing `page` is used (e.g. when the override only changes the
|
|
70
|
+
* slot's `params` for an inherited mirror with distinct param names).
|
|
71
|
+
*/
|
|
72
|
+
pageModule?: TModule | null;
|
|
57
73
|
params?: AppPageParams;
|
|
58
74
|
props?: Readonly<Record<string, unknown>>;
|
|
59
75
|
};
|
|
@@ -94,5 +110,5 @@ declare function createAppPageLayoutEntries<TModule extends AppPageModule, TErro
|
|
|
94
110
|
declare function resolveAppPageChildSegments(routeSegments: readonly string[], treePosition: number, params: AppPageParams): string[];
|
|
95
111
|
declare function buildAppPageElements<TModule extends AppPageModule, TErrorModule extends AppPageErrorModule>(options: BuildAppPageElementsOptions<TModule, TErrorModule>): AppElements;
|
|
96
112
|
//#endregion
|
|
97
|
-
export { AppPageModule, AppPageSlotOverride, buildAppPageElements, createAppPageLayoutEntries, createAppPageTreePath, resolveAppPageChildSegments };
|
|
113
|
+
export { AppPageErrorModule, AppPageModule, AppPageRouteWiringRoute, AppPageSlotOverride, buildAppPageElements, createAppPageLayoutEntries, createAppPageTreePath, resolveAppPageChildSegments };
|
|
98
114
|
//# sourceMappingURL=app-page-route-wiring.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AppElementsWire } from "./app-elements-wire.js";
|
|
2
|
+
import "./app-elements.js";
|
|
2
3
|
import { ErrorBoundary, ForbiddenBoundary, NotFoundBoundary, UnauthorizedBoundary } from "../shims/error-boundary.js";
|
|
3
4
|
import { LayoutSegmentProvider } from "../shims/layout-segment-context.js";
|
|
4
5
|
import { MetadataHead, ViewportHead } from "../shims/metadata.js";
|
|
@@ -26,7 +27,7 @@ function createAppPageLayoutEntries(route) {
|
|
|
26
27
|
return {
|
|
27
28
|
errorModule: route.errors?.[index] ?? null,
|
|
28
29
|
forbiddenModule: route.forbiddens?.[index] ?? null,
|
|
29
|
-
id:
|
|
30
|
+
id: AppElementsWire.encodeLayoutId(treePath),
|
|
30
31
|
layoutModule,
|
|
31
32
|
notFoundModule: route.notFounds?.[index] ?? null,
|
|
32
33
|
unauthorizedModule: route.unauthorizeds?.[index] ?? null,
|
|
@@ -40,7 +41,7 @@ function createAppPageTemplateEntries(route) {
|
|
|
40
41
|
const treePosition = route.templateTreePositions?.[index] ?? 0;
|
|
41
42
|
const treePath = createAppPageTreePath(route.routeSegments, treePosition);
|
|
42
43
|
return {
|
|
43
|
-
id:
|
|
44
|
+
id: AppElementsWire.encodeTemplateId(treePath),
|
|
44
45
|
templateModule,
|
|
45
46
|
treePath,
|
|
46
47
|
treePosition
|
|
@@ -92,7 +93,7 @@ function createAppPageParallelSlotEntries(layoutIndex, layoutEntries, route, get
|
|
|
92
93
|
const slotParams = getEffectiveSlotParams(slotKey, slotName);
|
|
93
94
|
parallelSlots[slotName] = /* @__PURE__ */ jsx(LayoutSegmentProvider, {
|
|
94
95
|
segmentMap: { children: slot.routeSegments ? resolveAppPageChildSegments(slot.routeSegments, 0, slotParams) : [] },
|
|
95
|
-
children: /* @__PURE__ */ jsx(Slot, { id:
|
|
96
|
+
children: /* @__PURE__ */ jsx(Slot, { id: AppElementsWire.encodeSlotId(slotName, treePath) })
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
99
|
return Object.keys(parallelSlots).length > 0 ? parallelSlots : void 0;
|
|
@@ -105,10 +106,9 @@ function createAppPageRouteHead(metadata, viewport) {
|
|
|
105
106
|
] });
|
|
106
107
|
}
|
|
107
108
|
function buildAppPageElements(options) {
|
|
108
|
-
const elements = {};
|
|
109
109
|
const interceptionContext = options.interceptionContext ?? null;
|
|
110
|
-
const routeId =
|
|
111
|
-
const pageId =
|
|
110
|
+
const routeId = AppElementsWire.encodeRouteId(options.routePath, interceptionContext);
|
|
111
|
+
const pageId = AppElementsWire.encodePageId(options.routePath, interceptionContext);
|
|
112
112
|
const layoutEntries = createAppPageLayoutEntries(options.route);
|
|
113
113
|
const templateEntries = createAppPageTemplateEntries(options.route);
|
|
114
114
|
const layoutEntriesByTreePosition = /* @__PURE__ */ new Map();
|
|
@@ -124,6 +124,11 @@ function buildAppPageElements(options) {
|
|
|
124
124
|
const templateDependenciesBeforeById = /* @__PURE__ */ new Map();
|
|
125
125
|
const pageDependencies = [];
|
|
126
126
|
const rootLayoutTreePath = layoutEntries[0]?.treePath ?? null;
|
|
127
|
+
const elements = { ...AppElementsWire.createMetadataEntries({
|
|
128
|
+
interceptionContext,
|
|
129
|
+
rootLayoutTreePath,
|
|
130
|
+
routeId
|
|
131
|
+
}) };
|
|
127
132
|
const slotNameCounts = /* @__PURE__ */ new Map();
|
|
128
133
|
for (const slot of Object.values(options.route.slots ?? {})) {
|
|
129
134
|
const slotName = slot.name;
|
|
@@ -155,9 +160,6 @@ function buildAppPageElements(options) {
|
|
|
155
160
|
templateDependenciesBeforeById.set(templateEntry.id, [...pageDependencies]);
|
|
156
161
|
pageDependencies.push(templateDependency);
|
|
157
162
|
}
|
|
158
|
-
elements[APP_ROUTE_KEY] = routeId;
|
|
159
|
-
elements[APP_INTERCEPTION_CONTEXT_KEY] = interceptionContext;
|
|
160
|
-
elements[APP_ROOT_LAYOUT_KEY] = rootLayoutTreePath;
|
|
161
163
|
elements[pageId] = renderAfterAppDependencies(options.element, pageDependencies);
|
|
162
164
|
for (const templateEntry of templateEntries) {
|
|
163
165
|
const templateComponent = getDefaultExport(templateEntry.templateModule);
|
|
@@ -197,7 +199,8 @@ function buildAppPageElements(options) {
|
|
|
197
199
|
for (const [slotKey, slot] of Object.entries(options.route.slots ?? {})) {
|
|
198
200
|
const slotName = slot.name;
|
|
199
201
|
const targetIndex = slot.layoutIndex >= 0 ? slot.layoutIndex : layoutEntries.length - 1;
|
|
200
|
-
const
|
|
202
|
+
const treePath = layoutEntries[targetIndex]?.treePath ?? "/";
|
|
203
|
+
const slotId = AppElementsWire.encodeSlotId(slotName, treePath);
|
|
201
204
|
const slotOverride = resolveSlotOverride(slotKey, slotName);
|
|
202
205
|
const slotParams = getEffectiveSlotParams(slotKey, slotName);
|
|
203
206
|
const overrideOrPageComponent = getDefaultExport(slotOverride?.pageModule) ?? getDefaultExport(slot.page);
|
|
@@ -205,7 +208,7 @@ function buildAppPageElements(options) {
|
|
|
205
208
|
if (!overrideOrPageComponent && defaultComponent && options.isRscRequest && options.mountedSlotIds?.has(slotId)) continue;
|
|
206
209
|
const slotComponent = overrideOrPageComponent ?? defaultComponent;
|
|
207
210
|
if (!slotComponent) {
|
|
208
|
-
elements[slotId] =
|
|
211
|
+
elements[slotId] = AppElementsWire.unmatchedSlotValue;
|
|
209
212
|
continue;
|
|
210
213
|
}
|
|
211
214
|
const slotThenableParams = options.makeThenableParams(slotParams);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-route-wiring.js","names":["Children"],"sources":["../../src/server/app-page-route-wiring.tsx"],"sourcesContent":["import { Suspense, type ComponentType, type ReactNode } from \"react\";\nimport {\n APP_INTERCEPTION_CONTEXT_KEY,\n APP_ROOT_LAYOUT_KEY,\n APP_ROUTE_KEY,\n APP_UNMATCHED_SLOT_WIRE_VALUE,\n createAppPayloadPageId,\n createAppPayloadRouteId,\n type AppElements,\n} from \"./app-elements.js\";\nimport {\n ErrorBoundary,\n ForbiddenBoundary,\n NotFoundBoundary,\n UnauthorizedBoundary,\n} from \"vinext/shims/error-boundary\";\nimport { LayoutSegmentProvider } from \"vinext/shims/layout-segment-context\";\nimport { MetadataHead, ViewportHead, type Metadata, type Viewport } from \"vinext/shims/metadata\";\nimport { Children, ParallelSlot, Slot } from \"vinext/shims/slot\";\nimport type { AppPageParams } from \"./app-page-boundary.js\";\nimport {\n createAppRenderDependency,\n renderAfterAppDependencies,\n renderWithAppDependencyBarrier,\n type AppRenderDependency,\n} from \"./app-render-dependency.js\";\nimport { resolveAppPageSegmentParams } from \"./app-page-params.js\";\n\ntype AppPageComponentProps = {\n children?: ReactNode;\n error?: unknown;\n params?: unknown;\n reset?: () => void;\n} & Record<string, unknown>;\n\ntype AppPageComponent = ComponentType<AppPageComponentProps>;\ntype AppPageErrorComponent = ComponentType<{ error: unknown; reset: () => void }>;\n\nexport type AppPageModule = Record<string, unknown> & {\n default?: AppPageComponent | null | undefined;\n};\n\ntype AppPageErrorModule = Record<string, unknown> & {\n default?: AppPageErrorComponent | null | undefined;\n};\n\ntype AppPageRouteWiringSlot<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = {\n /** Slot prop name passed to the owning layout (e.g. \"modal\" from @modal). */\n name: string;\n default?: TModule | null;\n error?: TErrorModule | null;\n layout?: TModule | null;\n layoutIndex: number;\n loading?: TModule | null;\n page?: TModule | null;\n routeSegments?: readonly string[] | null;\n};\n\ntype AppPageRouteWiringRoute<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = {\n error?: TErrorModule | null;\n errors?: readonly (TErrorModule | null | undefined)[] | null;\n layoutTreePositions?: readonly number[] | null;\n layouts: readonly (TModule | null | undefined)[];\n loading?: TModule | null;\n notFound?: TModule | null;\n notFounds?: readonly (TModule | null | undefined)[] | null;\n forbidden?: TModule | null;\n forbiddens?: readonly (TModule | null | undefined)[] | null;\n unauthorized?: TModule | null;\n unauthorizeds?: readonly (TModule | null | undefined)[] | null;\n routeSegments?: readonly string[];\n /**\n * Keyed by stable slot id (name + owner path), not necessarily the slot prop name.\n */\n slots?: Readonly<Record<string, AppPageRouteWiringSlot<TModule, TErrorModule>>> | null;\n templateTreePositions?: readonly number[] | null;\n templates?: readonly (TModule | null | undefined)[] | null;\n};\n\nexport type AppPageSlotOverride<TModule extends AppPageModule = AppPageModule> = {\n layoutModules?: readonly (TModule | null | undefined)[] | null;\n pageModule: TModule;\n params?: AppPageParams;\n props?: Readonly<Record<string, unknown>>;\n};\n\ntype AppPageLayoutEntry<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = {\n errorModule?: TErrorModule | null | undefined;\n forbiddenModule?: TModule | null | undefined;\n id: string;\n layoutModule?: TModule | null | undefined;\n notFoundModule?: TModule | null | undefined;\n unauthorizedModule?: TModule | null | undefined;\n treePath: string;\n treePosition: number;\n};\n\ntype BuildAppPageRouteElementOptions<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = {\n element: ReactNode;\n globalErrorModule?: TErrorModule | null;\n makeThenableParams: (params: AppPageParams) => unknown;\n matchedParams: AppPageParams;\n resolvedMetadata: Metadata | null;\n resolvedViewport: Viewport;\n rootForbiddenModule?: TModule | null;\n rootNotFoundModule?: TModule | null;\n rootUnauthorizedModule?: TModule | null;\n route: AppPageRouteWiringRoute<TModule, TErrorModule>;\n slotOverrides?: Readonly<Record<string, AppPageSlotOverride<TModule>>> | null;\n};\n\ntype BuildAppPageElementsOptions<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = BuildAppPageRouteElementOptions<TModule, TErrorModule> & {\n interceptionContext?: string | null;\n isRscRequest?: boolean;\n mountedSlotIds?: ReadonlySet<string> | null;\n routePath: string;\n};\n\ntype AppPageTemplateEntry<TModule extends AppPageModule = AppPageModule> = {\n id: string;\n templateModule?: TModule | null | undefined;\n treePath: string;\n treePosition: number;\n};\n\nfunction getDefaultExport<TModule extends AppPageModule>(\n module: TModule | null | undefined,\n): AppPageComponent | null {\n return module?.default ?? null;\n}\n\nfunction getErrorBoundaryExport<TModule extends AppPageErrorModule>(\n module: TModule | null | undefined,\n): AppPageErrorComponent | null {\n return module?.default ?? null;\n}\n\nexport function createAppPageTreePath(\n routeSegments: readonly string[] | null | undefined,\n treePosition: number,\n): string {\n const treePathSegments = routeSegments?.slice(0, treePosition) ?? [];\n if (treePathSegments.length === 0) {\n return \"/\";\n }\n return `/${treePathSegments.join(\"/\")}`;\n}\n\nexport function createAppPageLayoutEntries<\n TModule extends AppPageModule,\n TErrorModule extends AppPageErrorModule,\n>(\n route: Pick<\n AppPageRouteWiringRoute<TModule, TErrorModule>,\n \"errors\" | \"layoutTreePositions\" | \"layouts\" | \"notFounds\" | \"routeSegments\"\n > & {\n forbiddens?: readonly (TModule | null | undefined)[] | null;\n unauthorizeds?: readonly (TModule | null | undefined)[] | null;\n },\n): AppPageLayoutEntry<TModule, TErrorModule>[] {\n return route.layouts.map((layoutModule, index) => {\n const treePosition = route.layoutTreePositions?.[index] ?? 0;\n const treePath = createAppPageTreePath(route.routeSegments, treePosition);\n return {\n errorModule: route.errors?.[index] ?? null,\n forbiddenModule: route.forbiddens?.[index] ?? null,\n id: `layout:${treePath}`,\n layoutModule,\n notFoundModule: route.notFounds?.[index] ?? null,\n unauthorizedModule: route.unauthorizeds?.[index] ?? null,\n treePath,\n treePosition,\n };\n });\n}\n\nfunction createAppPageTemplateEntries<TModule extends AppPageModule>(\n route: Pick<\n AppPageRouteWiringRoute<TModule>,\n \"routeSegments\" | \"templateTreePositions\" | \"templates\"\n >,\n): AppPageTemplateEntry<TModule>[] {\n return (route.templates ?? []).map((templateModule, index) => {\n const treePosition = route.templateTreePositions?.[index] ?? 0;\n const treePath = createAppPageTreePath(route.routeSegments, treePosition);\n return {\n id: `template:${treePath}`,\n templateModule,\n treePath,\n treePosition,\n };\n });\n}\n\nexport function resolveAppPageChildSegments(\n routeSegments: readonly string[],\n treePosition: number,\n params: AppPageParams,\n): string[] {\n const rawSegments = routeSegments.slice(treePosition);\n const resolvedSegments: string[] = [];\n\n for (const segment of rawSegments) {\n if (\n segment.startsWith(\"[[...\") &&\n segment.endsWith(\"]]\") &&\n segment.length > \"[[...x]]\".length - 1\n ) {\n const paramName = segment.slice(5, -2);\n const paramValue = params[paramName];\n if (Array.isArray(paramValue) && paramValue.length === 0) {\n continue;\n }\n if (paramValue === undefined) {\n continue;\n }\n resolvedSegments.push(Array.isArray(paramValue) ? paramValue.join(\"/\") : paramValue);\n continue;\n }\n\n if (segment.startsWith(\"[...\") && segment.endsWith(\"]\")) {\n const paramName = segment.slice(4, -1);\n const paramValue = params[paramName];\n if (Array.isArray(paramValue)) {\n resolvedSegments.push(paramValue.join(\"/\"));\n continue;\n }\n resolvedSegments.push(paramValue ?? segment);\n continue;\n }\n\n if (segment.startsWith(\"[\") && segment.endsWith(\"]\") && !segment.includes(\".\")) {\n const paramName = segment.slice(1, -1);\n const paramValue = params[paramName];\n resolvedSegments.push(\n Array.isArray(paramValue) ? paramValue.join(\"/\") : (paramValue ?? segment),\n );\n continue;\n }\n\n resolvedSegments.push(segment);\n }\n\n return resolvedSegments;\n}\n\nfunction resolveAppPageVisibleSegments(\n routeSegments: readonly string[],\n params: AppPageParams,\n): string[] {\n const resolvedSegments = resolveAppPageChildSegments(routeSegments, 0, params);\n return resolvedSegments.filter((segment) => !(segment.startsWith(\"(\") && segment.endsWith(\")\")));\n}\n\nfunction resolveAppPageTemplateKey(\n routeSegments: readonly string[],\n treePosition: number,\n params: AppPageParams,\n): string {\n const visibleSegments = resolveAppPageVisibleSegments(routeSegments.slice(treePosition), params);\n return visibleSegments[0] ?? \"\";\n}\n\nfunction createAppPageParallelSlotEntries<\n TModule extends AppPageModule,\n TErrorModule extends AppPageErrorModule,\n>(\n layoutIndex: number,\n layoutEntries: readonly AppPageLayoutEntry<TModule, TErrorModule>[],\n route: AppPageRouteWiringRoute<TModule, TErrorModule>,\n getEffectiveSlotParams: (slotKey: string, slotName: string) => AppPageParams,\n): Readonly<Record<string, ReactNode>> | undefined {\n const parallelSlots: Record<string, ReactNode> = {};\n\n for (const [slotKey, slot] of Object.entries(route.slots ?? {})) {\n const slotName = slot.name;\n const targetIndex = slot.layoutIndex >= 0 ? slot.layoutIndex : layoutEntries.length - 1;\n if (targetIndex !== layoutIndex) {\n continue;\n }\n\n const layoutEntry = layoutEntries[targetIndex];\n const treePath = layoutEntry?.treePath ?? \"/\";\n const slotParams = getEffectiveSlotParams(slotKey, slotName);\n const slotSegments = slot.routeSegments\n ? resolveAppPageChildSegments(slot.routeSegments, 0, slotParams)\n : [];\n parallelSlots[slotName] = (\n <LayoutSegmentProvider segmentMap={{ children: slotSegments }}>\n <Slot id={`slot:${slotName}:${treePath}`} />\n </LayoutSegmentProvider>\n );\n }\n\n return Object.keys(parallelSlots).length > 0 ? parallelSlots : undefined;\n}\n\nfunction createAppPageRouteHead(metadata: Metadata | null, viewport: Viewport): ReactNode {\n return (\n <>\n <meta charSet=\"utf-8\" />\n {metadata ? <MetadataHead metadata={metadata} /> : null}\n <ViewportHead viewport={viewport} />\n </>\n );\n}\n\nexport function buildAppPageElements<\n TModule extends AppPageModule,\n TErrorModule extends AppPageErrorModule,\n>(options: BuildAppPageElementsOptions<TModule, TErrorModule>): AppElements {\n const elements: Record<string, ReactNode | string | null> = {};\n const interceptionContext = options.interceptionContext ?? null;\n const routeId = createAppPayloadRouteId(options.routePath, interceptionContext);\n const pageId = createAppPayloadPageId(options.routePath, interceptionContext);\n const layoutEntries = createAppPageLayoutEntries(options.route);\n const templateEntries = createAppPageTemplateEntries(options.route);\n const layoutEntriesByTreePosition = new Map<number, AppPageLayoutEntry<TModule, TErrorModule>>();\n const templateEntriesByTreePosition = new Map<number, AppPageTemplateEntry<TModule>>();\n for (const layoutEntry of layoutEntries) {\n layoutEntriesByTreePosition.set(layoutEntry.treePosition, layoutEntry);\n }\n for (const templateEntry of templateEntries) {\n templateEntriesByTreePosition.set(templateEntry.treePosition, templateEntry);\n }\n const layoutIndicesByTreePosition = new Map<number, number>();\n for (let index = 0; index < layoutEntries.length; index++) {\n layoutIndicesByTreePosition.set(layoutEntries[index].treePosition, index);\n }\n const layoutDependenciesByIndex = new Map<number, AppRenderDependency>();\n const layoutDependenciesBefore: AppRenderDependency[][] = [];\n const slotDependenciesByLayoutIndex: AppRenderDependency[][] = [];\n const templateDependenciesById = new Map<string, AppRenderDependency>();\n const templateDependenciesBeforeById = new Map<string, AppRenderDependency[]>();\n const pageDependencies: AppRenderDependency[] = [];\n const rootLayoutTreePath = layoutEntries[0]?.treePath ?? null;\n const slotNameCounts = new Map<string, number>();\n for (const slot of Object.values(options.route.slots ?? {})) {\n const slotName = slot.name;\n slotNameCounts.set(slotName, (slotNameCounts.get(slotName) ?? 0) + 1);\n }\n const orderedTreePositions = Array.from(\n new Set<number>([\n ...layoutEntries.map((entry) => entry.treePosition),\n ...templateEntries.map((entry) => entry.treePosition),\n ]),\n ).sort((left, right) => left - right);\n const resolveSlotOverride = (slotKey: string, slotName: string) => {\n const overrideByKey = options.slotOverrides?.[slotKey];\n if (overrideByKey) {\n return overrideByKey;\n }\n\n // Legacy callers may still provide overrides by slot prop name.\n // Only allow that fallback when it is unambiguous.\n if (slotKey === slotName || (slotNameCounts.get(slotName) ?? 0) === 1) {\n return options.slotOverrides?.[slotName];\n }\n\n return undefined;\n };\n const getEffectiveSlotParams = (slotKey: string, slotName: string): AppPageParams =>\n resolveSlotOverride(slotKey, slotName)?.params ?? options.matchedParams;\n\n for (const treePosition of orderedTreePositions) {\n const layoutIndex = layoutIndicesByTreePosition.get(treePosition);\n if (layoutIndex !== undefined) {\n const layoutEntry = layoutEntries[layoutIndex];\n layoutDependenciesBefore[layoutIndex] = [...pageDependencies];\n if (getDefaultExport(layoutEntry.layoutModule)) {\n const layoutDependency = createAppRenderDependency();\n layoutDependenciesByIndex.set(layoutIndex, layoutDependency);\n pageDependencies.push(layoutDependency);\n }\n slotDependenciesByLayoutIndex[layoutIndex] = [...pageDependencies];\n }\n\n const templateEntry = templateEntriesByTreePosition.get(treePosition);\n if (!templateEntry || !getDefaultExport(templateEntry.templateModule)) {\n continue;\n }\n\n const templateDependency = createAppRenderDependency();\n templateDependenciesById.set(templateEntry.id, templateDependency);\n templateDependenciesBeforeById.set(templateEntry.id, [...pageDependencies]);\n pageDependencies.push(templateDependency);\n }\n\n elements[APP_ROUTE_KEY] = routeId;\n elements[APP_INTERCEPTION_CONTEXT_KEY] = interceptionContext;\n elements[APP_ROOT_LAYOUT_KEY] = rootLayoutTreePath;\n elements[pageId] = renderAfterAppDependencies(options.element, pageDependencies);\n\n for (const templateEntry of templateEntries) {\n const templateComponent = getDefaultExport(templateEntry.templateModule);\n if (!templateComponent) {\n continue;\n }\n const TemplateComponent = templateComponent;\n const templateDependency = templateDependenciesById.get(templateEntry.id);\n const templateElement = templateDependency ? (\n renderWithAppDependencyBarrier(\n <TemplateComponent params={options.matchedParams}>\n <Children />\n </TemplateComponent>,\n templateDependency,\n )\n ) : (\n <TemplateComponent params={options.matchedParams}>\n <Children />\n </TemplateComponent>\n );\n elements[templateEntry.id] = renderAfterAppDependencies(\n templateElement,\n templateDependenciesBeforeById.get(templateEntry.id) ?? [],\n );\n }\n\n for (let index = 0; index < layoutEntries.length; index++) {\n const layoutEntry = layoutEntries[index];\n const layoutComponent = getDefaultExport(layoutEntry.layoutModule);\n if (!layoutComponent) {\n continue;\n }\n\n const layoutProps: Record<string, unknown> = {\n params: options.makeThenableParams(\n resolveAppPageSegmentParams(\n options.route.routeSegments,\n layoutEntry.treePosition,\n options.matchedParams,\n ),\n ),\n };\n\n for (const slot of Object.values(options.route.slots ?? {})) {\n const slotName = slot.name;\n const targetIndex = slot.layoutIndex >= 0 ? slot.layoutIndex : layoutEntries.length - 1;\n if (targetIndex !== index) {\n continue;\n }\n layoutProps[slotName] = <ParallelSlot name={slotName} />;\n }\n\n const LayoutComponent = layoutComponent;\n const layoutDependency = layoutDependenciesByIndex.get(index);\n const layoutElement = layoutDependency ? (\n renderWithAppDependencyBarrier(\n <LayoutComponent {...layoutProps}>\n <Children />\n </LayoutComponent>,\n layoutDependency,\n )\n ) : (\n <LayoutComponent {...layoutProps}>\n <Children />\n </LayoutComponent>\n );\n elements[layoutEntry.id] = renderAfterAppDependencies(\n layoutElement,\n layoutDependenciesBefore[index] ?? [],\n );\n }\n\n for (const [slotKey, slot] of Object.entries(options.route.slots ?? {})) {\n const slotName = slot.name;\n const targetIndex = slot.layoutIndex >= 0 ? slot.layoutIndex : layoutEntries.length - 1;\n const treePath = layoutEntries[targetIndex]?.treePath ?? \"/\";\n const slotId = `slot:${slotName}:${treePath}`;\n const slotOverride = resolveSlotOverride(slotKey, slotName);\n const slotParams = getEffectiveSlotParams(slotKey, slotName);\n const overrideOrPageComponent =\n getDefaultExport(slotOverride?.pageModule) ?? getDefaultExport(slot.page);\n const defaultComponent = getDefaultExport(slot.default);\n\n // On soft nav (RSC): omit key when only default.tsx exists and the slot is\n // already mounted on the client. Absent key means the browser retains prior\n // slot content rather than replacing it. When the slot is not yet mounted\n // (first entry into this layout), include the key so default.tsx renders.\n if (\n !overrideOrPageComponent &&\n defaultComponent &&\n options.isRscRequest &&\n options.mountedSlotIds?.has(slotId)\n ) {\n continue;\n }\n\n const slotComponent = overrideOrPageComponent ?? defaultComponent;\n\n if (!slotComponent) {\n elements[slotId] = APP_UNMATCHED_SLOT_WIRE_VALUE;\n continue;\n }\n\n const slotThenableParams = options.makeThenableParams(slotParams);\n const slotProps: Record<string, unknown> = {\n params: slotThenableParams,\n };\n if (slotOverride?.props) {\n Object.assign(slotProps, slotOverride.props);\n }\n\n const SlotComponent = slotComponent;\n let slotElement: ReactNode = <SlotComponent {...slotProps} />;\n const interceptLayouts = slotOverride?.layoutModules ?? [];\n\n for (let layoutIndex = interceptLayouts.length - 1; layoutIndex >= 0; layoutIndex--) {\n const interceptLayoutComponent = getDefaultExport(interceptLayouts[layoutIndex]);\n if (!interceptLayoutComponent) {\n continue;\n }\n const InterceptLayoutComponent = interceptLayoutComponent;\n slotElement = (\n <InterceptLayoutComponent params={slotThenableParams}>\n {slotElement}\n </InterceptLayoutComponent>\n );\n }\n\n const slotLayoutComponent = getDefaultExport(slot.layout);\n if (slotLayoutComponent) {\n const SlotLayoutComponent = slotLayoutComponent;\n slotElement = (\n <SlotLayoutComponent params={slotThenableParams}>{slotElement}</SlotLayoutComponent>\n );\n }\n\n const slotLoadingComponent = getDefaultExport(slot.loading);\n if (slotLoadingComponent) {\n const SlotLoadingComponent = slotLoadingComponent;\n slotElement = <Suspense fallback={<SlotLoadingComponent />}>{slotElement}</Suspense>;\n }\n\n const slotErrorComponent = getErrorBoundaryExport(slot.error);\n if (slotErrorComponent) {\n slotElement = <ErrorBoundary fallback={slotErrorComponent}>{slotElement}</ErrorBoundary>;\n }\n\n elements[slotId] = renderAfterAppDependencies(\n slotElement,\n targetIndex >= 0 ? (slotDependenciesByLayoutIndex[targetIndex] ?? []) : [],\n );\n }\n\n let routeChildren: ReactNode = (\n <LayoutSegmentProvider segmentMap={{ children: [] }}>\n <Slot id={pageId} />\n </LayoutSegmentProvider>\n );\n\n const routeLoadingComponent = getDefaultExport(options.route.loading);\n if (routeLoadingComponent) {\n const RouteLoadingComponent = routeLoadingComponent;\n routeChildren = <Suspense fallback={<RouteLoadingComponent />}>{routeChildren}</Suspense>;\n }\n\n const lastLayoutErrorModule =\n options.route.errors && options.route.errors.length > 0\n ? options.route.errors[options.route.errors.length - 1]\n : null;\n // Next.js nesting (outer to inner): Error > Unauthorized > Forbidden > NotFound > children.\n // Building bottom-up means NotFoundBoundary must wrap first, then Forbidden, Unauthorized, Error.\n const notFoundComponent =\n getDefaultExport(options.route.notFound) ?? getDefaultExport(options.rootNotFoundModule);\n if (notFoundComponent) {\n const NotFoundComponent = notFoundComponent;\n routeChildren = (\n <NotFoundBoundary fallback={<NotFoundComponent />}>{routeChildren}</NotFoundBoundary>\n );\n }\n\n const forbiddenComponent =\n getDefaultExport(options.route.forbidden) ?? getDefaultExport(options.rootForbiddenModule);\n if (forbiddenComponent) {\n const ForbiddenComponent = forbiddenComponent;\n routeChildren = (\n <ForbiddenBoundary fallback={<ForbiddenComponent />}>{routeChildren}</ForbiddenBoundary>\n );\n }\n\n const unauthorizedComponent =\n getDefaultExport(options.route.unauthorized) ??\n getDefaultExport(options.rootUnauthorizedModule);\n if (unauthorizedComponent) {\n const UnauthorizedComponent = unauthorizedComponent;\n routeChildren = (\n <UnauthorizedBoundary fallback={<UnauthorizedComponent />}>\n {routeChildren}\n </UnauthorizedBoundary>\n );\n }\n\n const pageErrorComponent = getErrorBoundaryExport(options.route.error);\n if (pageErrorComponent && options.route.error !== lastLayoutErrorModule) {\n routeChildren = <ErrorBoundary fallback={pageErrorComponent}>{routeChildren}</ErrorBoundary>;\n }\n\n for (let index = orderedTreePositions.length - 1; index >= 0; index--) {\n const treePosition = orderedTreePositions[index];\n let segmentChildren: ReactNode = routeChildren;\n const layoutEntry = layoutEntriesByTreePosition.get(treePosition);\n const templateEntry = templateEntriesByTreePosition.get(treePosition);\n\n // Next.js nesting per segment (outer to inner): Layout > Template > Error > Unauthorized > Forbidden > NotFound > children.\n // Building bottom-up means NotFoundBoundary must wrap the leaf subtree first,\n // then ErrorBoundary, then Template, with the Layout slot outermost.\n if (layoutEntry) {\n const layoutNotFoundComponent = getDefaultExport(layoutEntry.notFoundModule);\n if (layoutNotFoundComponent) {\n const LayoutNotFoundComponent = layoutNotFoundComponent;\n segmentChildren = (\n <NotFoundBoundary fallback={<LayoutNotFoundComponent />}>\n {segmentChildren}\n </NotFoundBoundary>\n );\n }\n\n const layoutForbiddenComponent = getDefaultExport(layoutEntry.forbiddenModule);\n if (layoutForbiddenComponent) {\n const LayoutForbiddenComponent = layoutForbiddenComponent;\n segmentChildren = (\n <ForbiddenBoundary fallback={<LayoutForbiddenComponent />}>\n {segmentChildren}\n </ForbiddenBoundary>\n );\n }\n\n const layoutUnauthorizedComponent = getDefaultExport(layoutEntry.unauthorizedModule);\n if (layoutUnauthorizedComponent) {\n const LayoutUnauthorizedComponent = layoutUnauthorizedComponent;\n segmentChildren = (\n <UnauthorizedBoundary fallback={<LayoutUnauthorizedComponent />}>\n {segmentChildren}\n </UnauthorizedBoundary>\n );\n }\n\n const layoutErrorComponent = getErrorBoundaryExport(layoutEntry.errorModule);\n if (layoutErrorComponent) {\n segmentChildren = (\n <ErrorBoundary fallback={layoutErrorComponent}>{segmentChildren}</ErrorBoundary>\n );\n }\n }\n\n if (templateEntry && getDefaultExport(templateEntry.templateModule)) {\n segmentChildren = (\n <Slot\n id={templateEntry.id}\n key={resolveAppPageTemplateKey(\n options.route.routeSegments ?? [],\n templateEntry.treePosition,\n options.matchedParams,\n )}\n >\n {segmentChildren}\n </Slot>\n );\n }\n\n if (!layoutEntry) {\n routeChildren = segmentChildren;\n continue;\n }\n const layoutHasElement = getDefaultExport(layoutEntry.layoutModule) !== null;\n const layoutIndex = layoutIndicesByTreePosition.get(treePosition) ?? -1;\n const segmentMap: { children: string[] } & Record<string, string[]> = {\n children: resolveAppPageChildSegments(\n options.route.routeSegments ?? [],\n layoutEntry.treePosition,\n options.matchedParams,\n ),\n };\n for (const [slotKey, slot] of Object.entries(options.route.slots ?? {})) {\n const slotName = slot.name;\n const targetIndex = slot.layoutIndex >= 0 ? slot.layoutIndex : layoutEntries.length - 1;\n if (targetIndex !== layoutIndex) {\n continue;\n }\n const slotParams = getEffectiveSlotParams(slotKey, slotName);\n segmentMap[slotName] = slot.routeSegments\n ? resolveAppPageChildSegments(slot.routeSegments, 0, slotParams)\n : [];\n }\n\n routeChildren = (\n <LayoutSegmentProvider segmentMap={segmentMap}>\n {layoutHasElement ? (\n <Slot\n id={layoutEntry.id}\n parallelSlots={createAppPageParallelSlotEntries(\n layoutIndex,\n layoutEntries,\n options.route,\n getEffectiveSlotParams,\n )}\n >\n {segmentChildren}\n </Slot>\n ) : (\n segmentChildren\n )}\n </LayoutSegmentProvider>\n );\n }\n\n const globalErrorComponent = getErrorBoundaryExport(options.globalErrorModule);\n if (globalErrorComponent) {\n routeChildren = <ErrorBoundary fallback={globalErrorComponent}>{routeChildren}</ErrorBoundary>;\n }\n\n elements[routeId] = (\n <>\n {createAppPageRouteHead(options.resolvedMetadata, options.resolvedViewport)}\n {routeChildren}\n </>\n );\n\n return elements;\n}\n"],"mappings":";;;;;;;;;;AA4IA,SAAS,iBACP,QACyB;AACzB,QAAO,QAAQ,WAAW;;AAG5B,SAAS,uBACP,QAC8B;AAC9B,QAAO,QAAQ,WAAW;;AAG5B,SAAgB,sBACd,eACA,cACQ;CACR,MAAM,mBAAmB,eAAe,MAAM,GAAG,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AS,SAAS,OAAO,QAAQ,QAAQ,MAAM,SAAS,EAAE,CAAC,EAAE;GACvE,MAAM,WAAW,KAAK;AAEtB,QADoB,KAAK,eAAe,IAAI,KAAK,cAAc,cAAc,SAAS,OAClE,YAClB;GAEF,MAAM,aAAa,uBAAuB,SAAS,SAAS;AAC5D,cAAW,YAAY,KAAK,gBACxB,4BAA4B,KAAK,eAAe,GAAG,WAAW,GAC9D,EAAE;;AAGR,kBACE,oBAAC,uBAAD;GAAmC;aAChC,mBACC,oBAAC,MAAD;IACE,IAAI,YAAY;IAChB,eAAe,iCACb,aACA,eACA,QAAQ,OACR,uBACD;cAEA;IACI,CAAA,GAEP;GAEoB,CAAA;;CAI5B,MAAM,uBAAuB,uBAAuB,QAAQ,kBAAkB;AAC9E,KAAI,qBACF,iBAAgB,oBAAC,eAAD;EAAe,UAAU;YAAuB;EAA8B,CAAA;AAGhG,UAAS,WACP,qBAAA,YAAA,EAAA,UAAA,CACG,uBAAuB,QAAQ,kBAAkB,QAAQ,iBAAiB,EAC1E,cACA,EAAA,CAAA;AAGL,QAAO"}
|
|
1
|
+
{"version":3,"file":"app-page-route-wiring.js","names":["Children"],"sources":["../../src/server/app-page-route-wiring.tsx"],"sourcesContent":["import { Suspense, type ComponentType, type ReactNode } from \"react\";\nimport { AppElementsWire, type AppElements } from \"./app-elements.js\";\nimport {\n ErrorBoundary,\n ForbiddenBoundary,\n NotFoundBoundary,\n UnauthorizedBoundary,\n} from \"vinext/shims/error-boundary\";\nimport type { AppRouteSemanticIds } from \"../routing/app-route-graph.js\";\nimport { LayoutSegmentProvider } from \"vinext/shims/layout-segment-context\";\nimport { MetadataHead, ViewportHead, type Metadata, type Viewport } from \"vinext/shims/metadata\";\nimport { Children, ParallelSlot, Slot } from \"vinext/shims/slot\";\nimport type { AppPageParams } from \"./app-page-boundary.js\";\nimport {\n createAppRenderDependency,\n renderAfterAppDependencies,\n renderWithAppDependencyBarrier,\n type AppRenderDependency,\n} from \"./app-render-dependency.js\";\nimport { resolveAppPageSegmentParams } from \"./app-page-params.js\";\n\ntype AppPageComponentProps = {\n children?: ReactNode;\n error?: unknown;\n params?: unknown;\n reset?: () => void;\n} & Record<string, unknown>;\n\ntype AppPageComponent = ComponentType<AppPageComponentProps>;\ntype AppPageErrorComponent = ComponentType<{ error: unknown; reset: () => void }>;\n\nexport type AppPageModule = Record<string, unknown> & {\n default?: AppPageComponent | null | undefined;\n};\n\nexport type AppPageErrorModule = Record<string, unknown> & {\n default?: AppPageErrorComponent | null | undefined;\n};\n\ntype AppPageRouteWiringSlot<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = {\n /** Graph-owned semantic slot identity. */\n id?: string | null;\n /** Slot prop name passed to the owning layout (e.g. \"modal\" from @modal). */\n name: string;\n default?: TModule | null;\n error?: TErrorModule | null;\n layout?: TModule | null;\n layoutIndex: number;\n loading?: TModule | null;\n page?: TModule | null;\n routeSegments?: readonly string[] | null;\n /**\n * Full URL pattern parts for the slot's mirrored sub-page. Set when the\n * slot's params may differ from the route's (e.g. inherited slot whose\n * dynamic markers have different names than the route's). The runtime\n * matches the request URL against these parts to extract slot params.\n */\n slotPatternParts?: readonly string[] | null;\n /** Param names captured by `slotPatternParts`, in order. */\n slotParamNames?: readonly string[] | null;\n};\n\nexport type AppPageRouteWiringRoute<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = {\n ids?: AppRouteSemanticIds | null;\n error?: TErrorModule | null;\n errors?: readonly (TErrorModule | null | undefined)[] | null;\n layoutTreePositions?: readonly number[] | null;\n layouts: readonly (TModule | null | undefined)[];\n loading?: TModule | null;\n notFound?: TModule | null;\n notFounds?: readonly (TModule | null | undefined)[] | null;\n forbidden?: TModule | null;\n forbiddens?: readonly (TModule | null | undefined)[] | null;\n unauthorized?: TModule | null;\n unauthorizeds?: readonly (TModule | null | undefined)[] | null;\n routeSegments?: readonly string[];\n /**\n * Keyed by stable slot id (name + owner path), not necessarily the slot prop name.\n */\n slots?: Readonly<Record<string, AppPageRouteWiringSlot<TModule, TErrorModule>>> | null;\n templateTreePositions?: readonly number[] | null;\n templates?: readonly (TModule | null | undefined)[] | null;\n};\n\nexport type AppPageSlotOverride<TModule extends AppPageModule = AppPageModule> = {\n layoutModules?: readonly (TModule | null | undefined)[] | null;\n /**\n * The page module to render for this slot. Optional — when omitted, the\n * slot's existing `page` is used (e.g. when the override only changes the\n * slot's `params` for an inherited mirror with distinct param names).\n */\n pageModule?: TModule | null;\n params?: AppPageParams;\n props?: Readonly<Record<string, unknown>>;\n};\n\ntype AppPageLayoutEntry<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = {\n errorModule?: TErrorModule | null | undefined;\n forbiddenModule?: TModule | null | undefined;\n id: string;\n layoutModule?: TModule | null | undefined;\n notFoundModule?: TModule | null | undefined;\n unauthorizedModule?: TModule | null | undefined;\n treePath: string;\n treePosition: number;\n};\n\ntype BuildAppPageRouteElementOptions<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = {\n element: ReactNode;\n globalErrorModule?: TErrorModule | null;\n makeThenableParams: (params: AppPageParams) => unknown;\n matchedParams: AppPageParams;\n resolvedMetadata: Metadata | null;\n resolvedViewport: Viewport;\n rootForbiddenModule?: TModule | null;\n rootNotFoundModule?: TModule | null;\n rootUnauthorizedModule?: TModule | null;\n route: AppPageRouteWiringRoute<TModule, TErrorModule>;\n slotOverrides?: Readonly<Record<string, AppPageSlotOverride<TModule>>> | null;\n};\n\ntype BuildAppPageElementsOptions<\n TModule extends AppPageModule = AppPageModule,\n TErrorModule extends AppPageErrorModule = AppPageErrorModule,\n> = BuildAppPageRouteElementOptions<TModule, TErrorModule> & {\n interceptionContext?: string | null;\n isRscRequest?: boolean;\n mountedSlotIds?: ReadonlySet<string> | null;\n routePath: string;\n};\n\ntype AppPageTemplateEntry<TModule extends AppPageModule = AppPageModule> = {\n id: string;\n templateModule?: TModule | null | undefined;\n treePath: string;\n treePosition: number;\n};\n\nfunction getDefaultExport<TModule extends AppPageModule>(\n module: TModule | null | undefined,\n): AppPageComponent | null {\n return module?.default ?? null;\n}\n\nfunction getErrorBoundaryExport<TModule extends AppPageErrorModule>(\n module: TModule | null | undefined,\n): AppPageErrorComponent | null {\n return module?.default ?? null;\n}\n\nexport function createAppPageTreePath(\n routeSegments: readonly string[] | null | undefined,\n treePosition: number,\n): string {\n const treePathSegments = routeSegments?.slice(0, treePosition) ?? [];\n if (treePathSegments.length === 0) {\n return \"/\";\n }\n return `/${treePathSegments.join(\"/\")}`;\n}\n\nexport function createAppPageLayoutEntries<\n TModule extends AppPageModule,\n TErrorModule extends AppPageErrorModule,\n>(\n route: Pick<\n AppPageRouteWiringRoute<TModule, TErrorModule>,\n \"errors\" | \"layoutTreePositions\" | \"layouts\" | \"notFounds\" | \"routeSegments\"\n > & {\n forbiddens?: readonly (TModule | null | undefined)[] | null;\n unauthorizeds?: readonly (TModule | null | undefined)[] | null;\n },\n): AppPageLayoutEntry<TModule, TErrorModule>[] {\n return route.layouts.map((layoutModule, index) => {\n const treePosition = route.layoutTreePositions?.[index] ?? 0;\n const treePath = createAppPageTreePath(route.routeSegments, treePosition);\n return {\n errorModule: route.errors?.[index] ?? null,\n forbiddenModule: route.forbiddens?.[index] ?? null,\n id: AppElementsWire.encodeLayoutId(treePath),\n layoutModule,\n notFoundModule: route.notFounds?.[index] ?? null,\n unauthorizedModule: route.unauthorizeds?.[index] ?? null,\n treePath,\n treePosition,\n };\n });\n}\n\nfunction createAppPageTemplateEntries<TModule extends AppPageModule>(\n route: Pick<\n AppPageRouteWiringRoute<TModule>,\n \"routeSegments\" | \"templateTreePositions\" | \"templates\"\n >,\n): AppPageTemplateEntry<TModule>[] {\n return (route.templates ?? []).map((templateModule, index) => {\n const treePosition = route.templateTreePositions?.[index] ?? 0;\n const treePath = createAppPageTreePath(route.routeSegments, treePosition);\n return {\n id: AppElementsWire.encodeTemplateId(treePath),\n templateModule,\n treePath,\n treePosition,\n };\n });\n}\n\nexport function resolveAppPageChildSegments(\n routeSegments: readonly string[],\n treePosition: number,\n params: AppPageParams,\n): string[] {\n const rawSegments = routeSegments.slice(treePosition);\n const resolvedSegments: string[] = [];\n\n for (const segment of rawSegments) {\n if (\n segment.startsWith(\"[[...\") &&\n segment.endsWith(\"]]\") &&\n segment.length > \"[[...x]]\".length - 1\n ) {\n const paramName = segment.slice(5, -2);\n const paramValue = params[paramName];\n if (Array.isArray(paramValue) && paramValue.length === 0) {\n continue;\n }\n if (paramValue === undefined) {\n continue;\n }\n resolvedSegments.push(Array.isArray(paramValue) ? paramValue.join(\"/\") : paramValue);\n continue;\n }\n\n if (segment.startsWith(\"[...\") && segment.endsWith(\"]\")) {\n const paramName = segment.slice(4, -1);\n const paramValue = params[paramName];\n if (Array.isArray(paramValue)) {\n resolvedSegments.push(paramValue.join(\"/\"));\n continue;\n }\n resolvedSegments.push(paramValue ?? segment);\n continue;\n }\n\n if (segment.startsWith(\"[\") && segment.endsWith(\"]\") && !segment.includes(\".\")) {\n const paramName = segment.slice(1, -1);\n const paramValue = params[paramName];\n resolvedSegments.push(\n Array.isArray(paramValue) ? paramValue.join(\"/\") : (paramValue ?? segment),\n );\n continue;\n }\n\n resolvedSegments.push(segment);\n }\n\n return resolvedSegments;\n}\n\nfunction resolveAppPageVisibleSegments(\n routeSegments: readonly string[],\n params: AppPageParams,\n): string[] {\n const resolvedSegments = resolveAppPageChildSegments(routeSegments, 0, params);\n return resolvedSegments.filter((segment) => !(segment.startsWith(\"(\") && segment.endsWith(\")\")));\n}\n\nfunction resolveAppPageTemplateKey(\n routeSegments: readonly string[],\n treePosition: number,\n params: AppPageParams,\n): string {\n const visibleSegments = resolveAppPageVisibleSegments(routeSegments.slice(treePosition), params);\n return visibleSegments[0] ?? \"\";\n}\n\nfunction createAppPageParallelSlotEntries<\n TModule extends AppPageModule,\n TErrorModule extends AppPageErrorModule,\n>(\n layoutIndex: number,\n layoutEntries: readonly AppPageLayoutEntry<TModule, TErrorModule>[],\n route: AppPageRouteWiringRoute<TModule, TErrorModule>,\n getEffectiveSlotParams: (slotKey: string, slotName: string) => AppPageParams,\n): Readonly<Record<string, ReactNode>> | undefined {\n const parallelSlots: Record<string, ReactNode> = {};\n\n for (const [slotKey, slot] of Object.entries(route.slots ?? {})) {\n const slotName = slot.name;\n const targetIndex = slot.layoutIndex >= 0 ? slot.layoutIndex : layoutEntries.length - 1;\n if (targetIndex !== layoutIndex) {\n continue;\n }\n\n const layoutEntry = layoutEntries[targetIndex];\n const treePath = layoutEntry?.treePath ?? \"/\";\n const slotParams = getEffectiveSlotParams(slotKey, slotName);\n const slotSegments = slot.routeSegments\n ? resolveAppPageChildSegments(slot.routeSegments, 0, slotParams)\n : [];\n parallelSlots[slotName] = (\n <LayoutSegmentProvider segmentMap={{ children: slotSegments }}>\n <Slot id={AppElementsWire.encodeSlotId(slotName, treePath)} />\n </LayoutSegmentProvider>\n );\n }\n\n return Object.keys(parallelSlots).length > 0 ? parallelSlots : undefined;\n}\n\nfunction createAppPageRouteHead(metadata: Metadata | null, viewport: Viewport): ReactNode {\n return (\n <>\n <meta charSet=\"utf-8\" />\n {metadata ? <MetadataHead metadata={metadata} /> : null}\n <ViewportHead viewport={viewport} />\n </>\n );\n}\n\nexport function buildAppPageElements<\n TModule extends AppPageModule,\n TErrorModule extends AppPageErrorModule,\n>(options: BuildAppPageElementsOptions<TModule, TErrorModule>): AppElements {\n const interceptionContext = options.interceptionContext ?? null;\n const routeId = AppElementsWire.encodeRouteId(options.routePath, interceptionContext);\n const pageId = AppElementsWire.encodePageId(options.routePath, interceptionContext);\n const layoutEntries = createAppPageLayoutEntries(options.route);\n const templateEntries = createAppPageTemplateEntries(options.route);\n const layoutEntriesByTreePosition = new Map<number, AppPageLayoutEntry<TModule, TErrorModule>>();\n const templateEntriesByTreePosition = new Map<number, AppPageTemplateEntry<TModule>>();\n for (const layoutEntry of layoutEntries) {\n layoutEntriesByTreePosition.set(layoutEntry.treePosition, layoutEntry);\n }\n for (const templateEntry of templateEntries) {\n templateEntriesByTreePosition.set(templateEntry.treePosition, templateEntry);\n }\n const layoutIndicesByTreePosition = new Map<number, number>();\n for (let index = 0; index < layoutEntries.length; index++) {\n layoutIndicesByTreePosition.set(layoutEntries[index].treePosition, index);\n }\n const layoutDependenciesByIndex = new Map<number, AppRenderDependency>();\n const layoutDependenciesBefore: AppRenderDependency[][] = [];\n const slotDependenciesByLayoutIndex: AppRenderDependency[][] = [];\n const templateDependenciesById = new Map<string, AppRenderDependency>();\n const templateDependenciesBeforeById = new Map<string, AppRenderDependency[]>();\n const pageDependencies: AppRenderDependency[] = [];\n const rootLayoutTreePath = layoutEntries[0]?.treePath ?? null;\n const elements: Record<string, ReactNode | string | null> = {\n ...AppElementsWire.createMetadataEntries({\n interceptionContext,\n rootLayoutTreePath,\n routeId,\n }),\n };\n const slotNameCounts = new Map<string, number>();\n for (const slot of Object.values(options.route.slots ?? {})) {\n const slotName = slot.name;\n slotNameCounts.set(slotName, (slotNameCounts.get(slotName) ?? 0) + 1);\n }\n const orderedTreePositions = Array.from(\n new Set<number>([\n ...layoutEntries.map((entry) => entry.treePosition),\n ...templateEntries.map((entry) => entry.treePosition),\n ]),\n ).sort((left, right) => left - right);\n const resolveSlotOverride = (slotKey: string, slotName: string) => {\n const overrideByKey = options.slotOverrides?.[slotKey];\n if (overrideByKey) {\n return overrideByKey;\n }\n\n // Legacy callers may still provide overrides by slot prop name.\n // Only allow that fallback when it is unambiguous.\n if (slotKey === slotName || (slotNameCounts.get(slotName) ?? 0) === 1) {\n return options.slotOverrides?.[slotName];\n }\n\n return undefined;\n };\n const getEffectiveSlotParams = (slotKey: string, slotName: string): AppPageParams =>\n resolveSlotOverride(slotKey, slotName)?.params ?? options.matchedParams;\n\n for (const treePosition of orderedTreePositions) {\n const layoutIndex = layoutIndicesByTreePosition.get(treePosition);\n if (layoutIndex !== undefined) {\n const layoutEntry = layoutEntries[layoutIndex];\n layoutDependenciesBefore[layoutIndex] = [...pageDependencies];\n if (getDefaultExport(layoutEntry.layoutModule)) {\n const layoutDependency = createAppRenderDependency();\n layoutDependenciesByIndex.set(layoutIndex, layoutDependency);\n pageDependencies.push(layoutDependency);\n }\n slotDependenciesByLayoutIndex[layoutIndex] = [...pageDependencies];\n }\n\n const templateEntry = templateEntriesByTreePosition.get(treePosition);\n if (!templateEntry || !getDefaultExport(templateEntry.templateModule)) {\n continue;\n }\n\n const templateDependency = createAppRenderDependency();\n templateDependenciesById.set(templateEntry.id, templateDependency);\n templateDependenciesBeforeById.set(templateEntry.id, [...pageDependencies]);\n pageDependencies.push(templateDependency);\n }\n\n elements[pageId] = renderAfterAppDependencies(options.element, pageDependencies);\n\n for (const templateEntry of templateEntries) {\n const templateComponent = getDefaultExport(templateEntry.templateModule);\n if (!templateComponent) {\n continue;\n }\n const TemplateComponent = templateComponent;\n const templateDependency = templateDependenciesById.get(templateEntry.id);\n const templateElement = templateDependency ? (\n renderWithAppDependencyBarrier(\n <TemplateComponent params={options.matchedParams}>\n <Children />\n </TemplateComponent>,\n templateDependency,\n )\n ) : (\n <TemplateComponent params={options.matchedParams}>\n <Children />\n </TemplateComponent>\n );\n elements[templateEntry.id] = renderAfterAppDependencies(\n templateElement,\n templateDependenciesBeforeById.get(templateEntry.id) ?? [],\n );\n }\n\n for (let index = 0; index < layoutEntries.length; index++) {\n const layoutEntry = layoutEntries[index];\n const layoutComponent = getDefaultExport(layoutEntry.layoutModule);\n if (!layoutComponent) {\n continue;\n }\n\n const layoutProps: Record<string, unknown> = {\n params: options.makeThenableParams(\n resolveAppPageSegmentParams(\n options.route.routeSegments,\n layoutEntry.treePosition,\n options.matchedParams,\n ),\n ),\n };\n\n for (const slot of Object.values(options.route.slots ?? {})) {\n const slotName = slot.name;\n const targetIndex = slot.layoutIndex >= 0 ? slot.layoutIndex : layoutEntries.length - 1;\n if (targetIndex !== index) {\n continue;\n }\n layoutProps[slotName] = <ParallelSlot name={slotName} />;\n }\n\n const LayoutComponent = layoutComponent;\n const layoutDependency = layoutDependenciesByIndex.get(index);\n const layoutElement = layoutDependency ? (\n renderWithAppDependencyBarrier(\n <LayoutComponent {...layoutProps}>\n <Children />\n </LayoutComponent>,\n layoutDependency,\n )\n ) : (\n <LayoutComponent {...layoutProps}>\n <Children />\n </LayoutComponent>\n );\n elements[layoutEntry.id] = renderAfterAppDependencies(\n layoutElement,\n layoutDependenciesBefore[index] ?? [],\n );\n }\n\n for (const [slotKey, slot] of Object.entries(options.route.slots ?? {})) {\n const slotName = slot.name;\n const targetIndex = slot.layoutIndex >= 0 ? slot.layoutIndex : layoutEntries.length - 1;\n const treePath = layoutEntries[targetIndex]?.treePath ?? \"/\";\n const slotId = AppElementsWire.encodeSlotId(slotName, treePath);\n const slotOverride = resolveSlotOverride(slotKey, slotName);\n const slotParams = getEffectiveSlotParams(slotKey, slotName);\n const overrideOrPageComponent =\n getDefaultExport(slotOverride?.pageModule) ?? getDefaultExport(slot.page);\n const defaultComponent = getDefaultExport(slot.default);\n\n // On soft nav (RSC): omit key when only default.tsx exists and the slot is\n // already mounted on the client. Absent key means the browser retains prior\n // slot content rather than replacing it. When the slot is not yet mounted\n // (first entry into this layout), include the key so default.tsx renders.\n if (\n !overrideOrPageComponent &&\n defaultComponent &&\n options.isRscRequest &&\n options.mountedSlotIds?.has(slotId)\n ) {\n continue;\n }\n\n const slotComponent = overrideOrPageComponent ?? defaultComponent;\n\n if (!slotComponent) {\n elements[slotId] = AppElementsWire.unmatchedSlotValue;\n continue;\n }\n\n const slotThenableParams = options.makeThenableParams(slotParams);\n const slotProps: Record<string, unknown> = {\n params: slotThenableParams,\n };\n if (slotOverride?.props) {\n Object.assign(slotProps, slotOverride.props);\n }\n\n const SlotComponent = slotComponent;\n let slotElement: ReactNode = <SlotComponent {...slotProps} />;\n const interceptLayouts = slotOverride?.layoutModules ?? [];\n\n for (let layoutIndex = interceptLayouts.length - 1; layoutIndex >= 0; layoutIndex--) {\n const interceptLayoutComponent = getDefaultExport(interceptLayouts[layoutIndex]);\n if (!interceptLayoutComponent) {\n continue;\n }\n const InterceptLayoutComponent = interceptLayoutComponent;\n slotElement = (\n <InterceptLayoutComponent params={slotThenableParams}>\n {slotElement}\n </InterceptLayoutComponent>\n );\n }\n\n const slotLayoutComponent = getDefaultExport(slot.layout);\n if (slotLayoutComponent) {\n const SlotLayoutComponent = slotLayoutComponent;\n slotElement = (\n <SlotLayoutComponent params={slotThenableParams}>{slotElement}</SlotLayoutComponent>\n );\n }\n\n const slotLoadingComponent = getDefaultExport(slot.loading);\n if (slotLoadingComponent) {\n const SlotLoadingComponent = slotLoadingComponent;\n slotElement = <Suspense fallback={<SlotLoadingComponent />}>{slotElement}</Suspense>;\n }\n\n const slotErrorComponent = getErrorBoundaryExport(slot.error);\n if (slotErrorComponent) {\n slotElement = <ErrorBoundary fallback={slotErrorComponent}>{slotElement}</ErrorBoundary>;\n }\n\n elements[slotId] = renderAfterAppDependencies(\n slotElement,\n targetIndex >= 0 ? (slotDependenciesByLayoutIndex[targetIndex] ?? []) : [],\n );\n }\n\n let routeChildren: ReactNode = (\n <LayoutSegmentProvider segmentMap={{ children: [] }}>\n <Slot id={pageId} />\n </LayoutSegmentProvider>\n );\n\n const routeLoadingComponent = getDefaultExport(options.route.loading);\n if (routeLoadingComponent) {\n const RouteLoadingComponent = routeLoadingComponent;\n routeChildren = <Suspense fallback={<RouteLoadingComponent />}>{routeChildren}</Suspense>;\n }\n\n const lastLayoutErrorModule =\n options.route.errors && options.route.errors.length > 0\n ? options.route.errors[options.route.errors.length - 1]\n : null;\n // Next.js nesting (outer to inner): Error > Unauthorized > Forbidden > NotFound > children.\n // Building bottom-up means NotFoundBoundary must wrap first, then Forbidden, Unauthorized, Error.\n const notFoundComponent =\n getDefaultExport(options.route.notFound) ?? getDefaultExport(options.rootNotFoundModule);\n if (notFoundComponent) {\n const NotFoundComponent = notFoundComponent;\n routeChildren = (\n <NotFoundBoundary fallback={<NotFoundComponent />}>{routeChildren}</NotFoundBoundary>\n );\n }\n\n const forbiddenComponent =\n getDefaultExport(options.route.forbidden) ?? getDefaultExport(options.rootForbiddenModule);\n if (forbiddenComponent) {\n const ForbiddenComponent = forbiddenComponent;\n routeChildren = (\n <ForbiddenBoundary fallback={<ForbiddenComponent />}>{routeChildren}</ForbiddenBoundary>\n );\n }\n\n const unauthorizedComponent =\n getDefaultExport(options.route.unauthorized) ??\n getDefaultExport(options.rootUnauthorizedModule);\n if (unauthorizedComponent) {\n const UnauthorizedComponent = unauthorizedComponent;\n routeChildren = (\n <UnauthorizedBoundary fallback={<UnauthorizedComponent />}>\n {routeChildren}\n </UnauthorizedBoundary>\n );\n }\n\n const pageErrorComponent = getErrorBoundaryExport(options.route.error);\n if (pageErrorComponent && options.route.error !== lastLayoutErrorModule) {\n routeChildren = <ErrorBoundary fallback={pageErrorComponent}>{routeChildren}</ErrorBoundary>;\n }\n\n for (let index = orderedTreePositions.length - 1; index >= 0; index--) {\n const treePosition = orderedTreePositions[index];\n let segmentChildren: ReactNode = routeChildren;\n const layoutEntry = layoutEntriesByTreePosition.get(treePosition);\n const templateEntry = templateEntriesByTreePosition.get(treePosition);\n\n // Next.js nesting per segment (outer to inner): Layout > Template > Error > Unauthorized > Forbidden > NotFound > children.\n // Building bottom-up means NotFoundBoundary must wrap the leaf subtree first,\n // then ErrorBoundary, then Template, with the Layout slot outermost.\n if (layoutEntry) {\n const layoutNotFoundComponent = getDefaultExport(layoutEntry.notFoundModule);\n if (layoutNotFoundComponent) {\n const LayoutNotFoundComponent = layoutNotFoundComponent;\n segmentChildren = (\n <NotFoundBoundary fallback={<LayoutNotFoundComponent />}>\n {segmentChildren}\n </NotFoundBoundary>\n );\n }\n\n const layoutForbiddenComponent = getDefaultExport(layoutEntry.forbiddenModule);\n if (layoutForbiddenComponent) {\n const LayoutForbiddenComponent = layoutForbiddenComponent;\n segmentChildren = (\n <ForbiddenBoundary fallback={<LayoutForbiddenComponent />}>\n {segmentChildren}\n </ForbiddenBoundary>\n );\n }\n\n const layoutUnauthorizedComponent = getDefaultExport(layoutEntry.unauthorizedModule);\n if (layoutUnauthorizedComponent) {\n const LayoutUnauthorizedComponent = layoutUnauthorizedComponent;\n segmentChildren = (\n <UnauthorizedBoundary fallback={<LayoutUnauthorizedComponent />}>\n {segmentChildren}\n </UnauthorizedBoundary>\n );\n }\n\n const layoutErrorComponent = getErrorBoundaryExport(layoutEntry.errorModule);\n if (layoutErrorComponent) {\n segmentChildren = (\n <ErrorBoundary fallback={layoutErrorComponent}>{segmentChildren}</ErrorBoundary>\n );\n }\n }\n\n if (templateEntry && getDefaultExport(templateEntry.templateModule)) {\n segmentChildren = (\n <Slot\n id={templateEntry.id}\n key={resolveAppPageTemplateKey(\n options.route.routeSegments ?? [],\n templateEntry.treePosition,\n options.matchedParams,\n )}\n >\n {segmentChildren}\n </Slot>\n );\n }\n\n if (!layoutEntry) {\n routeChildren = segmentChildren;\n continue;\n }\n const layoutHasElement = getDefaultExport(layoutEntry.layoutModule) !== null;\n const layoutIndex = layoutIndicesByTreePosition.get(treePosition) ?? -1;\n const segmentMap: { children: string[] } & Record<string, string[]> = {\n children: resolveAppPageChildSegments(\n options.route.routeSegments ?? [],\n layoutEntry.treePosition,\n options.matchedParams,\n ),\n };\n for (const [slotKey, slot] of Object.entries(options.route.slots ?? {})) {\n const slotName = slot.name;\n const targetIndex = slot.layoutIndex >= 0 ? slot.layoutIndex : layoutEntries.length - 1;\n if (targetIndex !== layoutIndex) {\n continue;\n }\n const slotParams = getEffectiveSlotParams(slotKey, slotName);\n segmentMap[slotName] = slot.routeSegments\n ? resolveAppPageChildSegments(slot.routeSegments, 0, slotParams)\n : [];\n }\n\n routeChildren = (\n <LayoutSegmentProvider segmentMap={segmentMap}>\n {layoutHasElement ? (\n <Slot\n id={layoutEntry.id}\n parallelSlots={createAppPageParallelSlotEntries(\n layoutIndex,\n layoutEntries,\n options.route,\n getEffectiveSlotParams,\n )}\n >\n {segmentChildren}\n </Slot>\n ) : (\n segmentChildren\n )}\n </LayoutSegmentProvider>\n );\n }\n\n const globalErrorComponent = getErrorBoundaryExport(options.globalErrorModule);\n if (globalErrorComponent) {\n routeChildren = <ErrorBoundary fallback={globalErrorComponent}>{routeChildren}</ErrorBoundary>;\n }\n\n elements[routeId] = (\n <>\n {createAppPageRouteHead(options.resolvedMetadata, options.resolvedViewport)}\n {routeChildren}\n </>\n );\n\n return elements;\n}\n"],"mappings":";;;;;;;;;;;AAsJA,SAAS,iBACP,QACyB;AACzB,QAAO,QAAQ,WAAW;;AAG5B,SAAS,uBACP,QAC8B;AAC9B,QAAO,QAAQ,WAAW;;AAG5B,SAAgB,sBACd,eACA,cACQ;CACR,MAAM,mBAAmB,eAAe,MAAM,GAAG,aAAa,IAAI,EAAE;AACpE,KAAI,iBAAiB,WAAW,EAC9B,QAAO;AAET,QAAO,IAAI,iBAAiB,KAAK,IAAI;;AAGvC,SAAgB,2BAId,OAO6C;AAC7C,QAAO,MAAM,QAAQ,KAAK,cAAc,UAAU;EAChD,MAAM,eAAe,MAAM,sBAAsB,UAAU;EAC3D,MAAM,WAAW,sBAAsB,MAAM,eAAe,aAAa;AACzE,SAAO;GACL,aAAa,MAAM,SAAS,UAAU;GACtC,iBAAiB,MAAM,aAAa,UAAU;GAC9C,IAAI,gBAAgB,eAAe,SAAS;GAC5C;GACA,gBAAgB,MAAM,YAAY,UAAU;GAC5C,oBAAoB,MAAM,gBAAgB,UAAU;GACpD;GACA;GACD;GACD;;AAGJ,SAAS,6BACP,OAIiC;AACjC,SAAQ,MAAM,aAAa,EAAE,EAAE,KAAK,gBAAgB,UAAU;EAC5D,MAAM,eAAe,MAAM,wBAAwB,UAAU;EAC7D,MAAM,WAAW,sBAAsB,MAAM,eAAe,aAAa;AACzE,SAAO;GACL,IAAI,gBAAgB,iBAAiB,SAAS;GAC9C;GACA;GACA;GACD;GACD;;AAGJ,SAAgB,4BACd,eACA,cACA,QACU;CACV,MA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QAAO"}
|
|
@@ -52,6 +52,13 @@ type RenderAppPageHtmlStreamWithRecoveryOptions<TSpecialError> = {
|
|
|
52
52
|
};
|
|
53
53
|
type AppPageRscErrorTracker = {
|
|
54
54
|
getCapturedError: () => unknown;
|
|
55
|
+
/**
|
|
56
|
+
* Returns a NEXT_REDIRECT or NEXT_HTTP_ERROR_FALLBACK error captured during
|
|
57
|
+
* the RSC render. Read after the SSR shell promise resolves to swap a
|
|
58
|
+
* 307/404 in place of the streamed body when redirect()/notFound() throws
|
|
59
|
+
* synchronously inside a route-level Suspense boundary (loading.tsx).
|
|
60
|
+
*/
|
|
61
|
+
getCapturedSpecialError: () => unknown;
|
|
55
62
|
onRenderError: (error: unknown, requestInfo: unknown, errorContext: unknown) => unknown;
|
|
56
63
|
};
|
|
57
64
|
type ShouldRerenderAppPageWithGlobalErrorOptions = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { VINEXT_RSC_VARY_HEADER } from "./app-rsc-cache-busting.js";
|
|
1
2
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
2
3
|
//#region src/server/app-page-stream.ts
|
|
3
4
|
function createAppPageFontData(options) {
|
|
@@ -56,7 +57,7 @@ async function renderAppPageHtmlResponse(options) {
|
|
|
56
57
|
});
|
|
57
58
|
const headers = new Headers({
|
|
58
59
|
"Content-Type": "text/html; charset=utf-8",
|
|
59
|
-
Vary:
|
|
60
|
+
Vary: VINEXT_RSC_VARY_HEADER
|
|
60
61
|
});
|
|
61
62
|
if (options.fontLinkHeader) headers.set("Link", options.fontLinkHeader);
|
|
62
63
|
mergeMiddlewareResponseHeaders(headers, options.middlewareHeaders ?? null);
|
|
@@ -89,12 +90,18 @@ async function renderAppPageHtmlStreamWithRecovery(options) {
|
|
|
89
90
|
}
|
|
90
91
|
function createAppPageRscErrorTracker(baseOnError) {
|
|
91
92
|
let capturedError = null;
|
|
93
|
+
let capturedSpecialError = null;
|
|
92
94
|
return {
|
|
93
95
|
getCapturedError() {
|
|
94
96
|
return capturedError;
|
|
95
97
|
},
|
|
98
|
+
getCapturedSpecialError() {
|
|
99
|
+
return capturedSpecialError;
|
|
100
|
+
},
|
|
96
101
|
onRenderError(error, requestInfo, errorContext) {
|
|
97
|
-
if (
|
|
102
|
+
if (error && typeof error === "object" && "digest" in error) {
|
|
103
|
+
if (capturedSpecialError === null) capturedSpecialError = error;
|
|
104
|
+
} else capturedError = error;
|
|
98
105
|
return baseOnError(error, requestInfo, errorContext);
|
|
99
106
|
}
|
|
100
107
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-stream.js","names":[],"sources":["../../src/server/app-page-stream.ts"],"sourcesContent":["import type { AppPageFontPreload } from \"./app-page-execution.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\n\nexport type AppPageFontData = {\n links: string[];\n preloads: readonly AppPageFontPreload[];\n styles: string[];\n};\n\ntype CreateAppPageFontDataOptions = {\n getLinks: () => string[];\n getPreloads: () => AppPageFontPreload[];\n getStyles: () => string[];\n};\n\nexport type AppPageSsrHandler = {\n handleSsr: (\n rscStream: ReadableStream<Uint8Array>,\n navigationContext: unknown,\n fontData: AppPageFontData,\n options?: {\n scriptNonce?: string;\n sideStream?: ReadableStream<Uint8Array>;\n capturedRscDataRef?: { value: Promise<ArrayBuffer> | null };\n },\n ) => Promise<ReadableStream<Uint8Array>>;\n};\n\ntype RenderAppPageHtmlStreamOptions = {\n fontData: AppPageFontData;\n navigationContext: unknown;\n rscStream: ReadableStream<Uint8Array>;\n scriptNonce?: string;\n ssrHandler: AppPageSsrHandler;\n /** Pre-split side stream for fused embed+capture (#981). When set,\n * handleSsr skips its internal tee and accumulates raw RSC bytes. */\n sideStream?: ReadableStream<Uint8Array>;\n /** Out-parameter filled with accumulated raw RSC bytes after stream consumption. */\n capturedRscDataRef?: { value: Promise<ArrayBuffer> | null };\n};\n\ntype RenderAppPageHtmlResponseOptions = {\n clearRequestContext: () => void;\n fontLinkHeader?: string;\n middlewareHeaders?: Headers | null;\n status: number;\n} & RenderAppPageHtmlStreamOptions;\n\ntype AppPageHtmlStreamRecoveryResult = {\n htmlStream: ReadableStream<Uint8Array> | null;\n response: Response | null;\n};\n\ntype RenderAppPageHtmlStreamWithRecoveryOptions<TSpecialError> = {\n onShellRendered?: () => void;\n renderErrorBoundaryResponse: (error: unknown) => Promise<Response | null>;\n renderHtmlStream: () => Promise<ReadableStream<Uint8Array>>;\n renderSpecialErrorResponse: (specialError: TSpecialError) => Promise<Response>;\n resolveSpecialError: (error: unknown) => TSpecialError | null;\n};\n\ntype AppPageRscErrorTracker = {\n getCapturedError: () => unknown;\n onRenderError: (error: unknown, requestInfo: unknown, errorContext: unknown) => unknown;\n};\n\ntype ShouldRerenderAppPageWithGlobalErrorOptions = {\n capturedError: unknown;\n hasLocalBoundary: boolean;\n};\n\nexport function createAppPageFontData(options: CreateAppPageFontDataOptions): AppPageFontData {\n return {\n links: options.getLinks(),\n preloads: options.getPreloads(),\n styles: options.getStyles(),\n };\n}\n\nexport async function renderAppPageHtmlStream(\n options: RenderAppPageHtmlStreamOptions,\n): Promise<ReadableStream<Uint8Array>> {\n const ssrOptions = {\n scriptNonce: options.scriptNonce,\n sideStream: options.sideStream,\n capturedRscDataRef: options.capturedRscDataRef,\n };\n\n return options.ssrHandler.handleSsr(\n options.rscStream,\n options.navigationContext,\n options.fontData,\n ssrOptions,\n );\n}\n\n/**\n * Wraps a stream so that `onFlush` is called when the last byte has been read\n * by the downstream consumer (i.e. when the HTTP layer finishes draining the\n * response body). This is the correct place to clear per-request context,\n * because the RSC/SSR pipeline is lazy — components execute while the stream\n * is being consumed, not when the stream handle is first obtained.\n */\nexport function deferUntilStreamConsumed(\n stream: ReadableStream<Uint8Array>,\n onFlush: () => void,\n): ReadableStream<Uint8Array> {\n let called = false;\n const once = () => {\n if (!called) {\n called = true;\n onFlush();\n }\n };\n\n const cleanup = new TransformStream<Uint8Array, Uint8Array>({\n flush() {\n once();\n },\n });\n\n const piped = stream.pipeThrough(cleanup);\n\n // Wrap with a ReadableStream so we can intercept cancel() — the TransformStream\n // Transformer interface does not expose a cancel hook in the Web Streams spec.\n const reader = piped.getReader();\n return new ReadableStream<Uint8Array>({\n pull(controller) {\n return reader.read().then(\n ({ done, value }) => {\n if (done) {\n controller.close();\n } else {\n controller.enqueue(value);\n }\n },\n (error) => {\n once();\n controller.error(error);\n },\n );\n },\n cancel(reason) {\n // Stream cancelled before fully consumed (e.g. client disconnected).\n // Still clear per-request context to avoid leaks.\n once();\n return reader.cancel(reason);\n },\n });\n}\n\nexport async function renderAppPageHtmlResponse(\n options: RenderAppPageHtmlResponseOptions,\n): Promise<Response> {\n const htmlStream = await renderAppPageHtmlStream(options);\n\n // Defer clearRequestContext() until the stream is fully consumed by the HTTP\n // layer. Calling it synchronously here would race the lazy RSC/SSR pipeline:\n // components execute while the stream is being pulled, not when the handle\n // is first returned. See: https://github.com/cloudflare/vinext/issues/660\n const safeStream = deferUntilStreamConsumed(htmlStream, () => {\n options.clearRequestContext();\n });\n\n const headers = new Headers({\n \"Content-Type\": \"text/html; charset=utf-8\",\n Vary: \"RSC, Accept\",\n });\n\n if (options.fontLinkHeader) {\n headers.set(\"Link\", options.fontLinkHeader);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareHeaders ?? null);\n\n return new Response(safeStream, {\n status: options.status,\n headers,\n });\n}\n\nexport async function renderAppPageHtmlStreamWithRecovery<TSpecialError>(\n options: RenderAppPageHtmlStreamWithRecoveryOptions<TSpecialError>,\n): Promise<AppPageHtmlStreamRecoveryResult> {\n try {\n const htmlStream = await options.renderHtmlStream();\n options.onShellRendered?.();\n return {\n htmlStream,\n response: null,\n };\n } catch (error) {\n const specialError = options.resolveSpecialError(error);\n if (specialError) {\n return {\n htmlStream: null,\n response: await options.renderSpecialErrorResponse(specialError),\n };\n }\n\n const boundaryResponse = await options.renderErrorBoundaryResponse(error);\n if (boundaryResponse) {\n return {\n htmlStream: null,\n response: boundaryResponse,\n };\n }\n\n throw error;\n }\n}\n\nexport function createAppPageRscErrorTracker(\n baseOnError: (error: unknown, requestInfo: unknown, errorContext: unknown) => unknown,\n): AppPageRscErrorTracker {\n let capturedError: unknown = null;\n\n return {\n getCapturedError() {\n return capturedError;\n },\n onRenderError(error, requestInfo, errorContext) {\n if (!(error && typeof error === \"object\" && \"digest\" in error)) {\n capturedError = error;\n }\n return baseOnError(error, requestInfo, errorContext);\n },\n };\n}\n\nexport function shouldRerenderAppPageWithGlobalError(\n options: ShouldRerenderAppPageWithGlobalErrorOptions,\n): boolean {\n return Boolean(options.capturedError) && !options.hasLocalBoundary;\n}\n"],"mappings":";;AAuEA,SAAgB,sBAAsB,SAAwD;AAC5F,QAAO;EACL,OAAO,QAAQ,UAAU;EACzB,UAAU,QAAQ,aAAa;EAC/B,QAAQ,QAAQ,WAAW;EAC5B;;AAGH,eAAsB,wBACpB,SACqC;CACrC,MAAM,aAAa;EACjB,aAAa,QAAQ;EACrB,YAAY,QAAQ;EACpB,oBAAoB,QAAQ;EAC7B;AAED,QAAO,QAAQ,WAAW,UACxB,QAAQ,WACR,QAAQ,mBACR,QAAQ,UACR,WACD;;;;;;;;;AAUH,SAAgB,yBACd,QACA,SAC4B;CAC5B,IAAI,SAAS;CACb,MAAM,aAAa;AACjB,MAAI,CAAC,QAAQ;AACX,YAAS;AACT,YAAS;;;CAIb,MAAM,UAAU,IAAI,gBAAwC,EAC1D,QAAQ;AACN,QAAM;IAET,CAAC;CAMF,MAAM,SAJQ,OAAO,YAAY,QAAQ,CAIpB,WAAW;AAChC,QAAO,IAAI,eAA2B;EACpC,KAAK,YAAY;AACf,UAAO,OAAO,MAAM,CAAC,MAClB,EAAE,MAAM,YAAY;AACnB,QAAI,KACF,YAAW,OAAO;QAElB,YAAW,QAAQ,MAAM;OAG5B,UAAU;AACT,UAAM;AACN,eAAW,MAAM,MAAM;KAE1B;;EAEH,OAAO,QAAQ;AAGb,SAAM;AACN,UAAO,OAAO,OAAO,OAAO;;EAE/B,CAAC;;AAGJ,eAAsB,0BACpB,SACmB;CAOnB,MAAM,aAAa,yBANA,MAAM,wBAAwB,QAAQ,QAMK;AAC5D,UAAQ,qBAAqB;GAC7B;CAEF,MAAM,UAAU,IAAI,QAAQ;EAC1B,gBAAgB;EAChB,MAAM;EACP,CAAC;AAEF,KAAI,QAAQ,eACV,SAAQ,IAAI,QAAQ,QAAQ,eAAe;AAG7C,gCAA+B,SAAS,QAAQ,qBAAqB,KAAK;AAE1E,QAAO,IAAI,SAAS,YAAY;EAC9B,QAAQ,QAAQ;EAChB;EACD,CAAC;;AAGJ,eAAsB,oCACpB,SAC0C;AAC1C,KAAI;EACF,MAAM,aAAa,MAAM,QAAQ,kBAAkB;AACnD,UAAQ,mBAAmB;AAC3B,SAAO;GACL;GACA,UAAU;GACX;UACM,OAAO;EACd,MAAM,eAAe,QAAQ,oBAAoB,MAAM;AACvD,MAAI,aACF,QAAO;GACL,YAAY;GACZ,UAAU,MAAM,QAAQ,2BAA2B,aAAa;GACjE;EAGH,MAAM,mBAAmB,MAAM,QAAQ,4BAA4B,MAAM;AACzE,MAAI,iBACF,QAAO;GACL,YAAY;GACZ,UAAU;GACX;AAGH,QAAM;;;AAIV,SAAgB,6BACd,aACwB;CACxB,IAAI,gBAAyB;AAE7B,QAAO;EACL,mBAAmB;AACjB,UAAO;;EAET,cAAc,OAAO,aAAa,cAAc;AAC9C,OAAI,EAAE,SAAS,OAAO,UAAU,YAAY,YAAY,OACtD,iBAAgB;AAElB,UAAO,YAAY,OAAO,aAAa,aAAa;;EAEvD;;AAGH,SAAgB,qCACd,SACS;AACT,QAAO,QAAQ,QAAQ,cAAc,IAAI,CAAC,QAAQ"}
|
|
1
|
+
{"version":3,"file":"app-page-stream.js","names":[],"sources":["../../src/server/app-page-stream.ts"],"sourcesContent":["import type { AppPageFontPreload } from \"./app-page-execution.js\";\nimport { VINEXT_RSC_VARY_HEADER } from \"./app-rsc-cache-busting.js\";\nimport { mergeMiddlewareResponseHeaders } from \"./middleware-response-headers.js\";\n\nexport type AppPageFontData = {\n links: string[];\n preloads: readonly AppPageFontPreload[];\n styles: string[];\n};\n\ntype CreateAppPageFontDataOptions = {\n getLinks: () => string[];\n getPreloads: () => AppPageFontPreload[];\n getStyles: () => string[];\n};\n\nexport type AppPageSsrHandler = {\n handleSsr: (\n rscStream: ReadableStream<Uint8Array>,\n navigationContext: unknown,\n fontData: AppPageFontData,\n options?: {\n scriptNonce?: string;\n sideStream?: ReadableStream<Uint8Array>;\n capturedRscDataRef?: { value: Promise<ArrayBuffer> | null };\n },\n ) => Promise<ReadableStream<Uint8Array>>;\n};\n\ntype RenderAppPageHtmlStreamOptions = {\n fontData: AppPageFontData;\n navigationContext: unknown;\n rscStream: ReadableStream<Uint8Array>;\n scriptNonce?: string;\n ssrHandler: AppPageSsrHandler;\n /** Pre-split side stream for fused embed+capture (#981). When set,\n * handleSsr skips its internal tee and accumulates raw RSC bytes. */\n sideStream?: ReadableStream<Uint8Array>;\n /** Out-parameter filled with accumulated raw RSC bytes after stream consumption. */\n capturedRscDataRef?: { value: Promise<ArrayBuffer> | null };\n};\n\ntype RenderAppPageHtmlResponseOptions = {\n clearRequestContext: () => void;\n fontLinkHeader?: string;\n middlewareHeaders?: Headers | null;\n status: number;\n} & RenderAppPageHtmlStreamOptions;\n\ntype AppPageHtmlStreamRecoveryResult = {\n htmlStream: ReadableStream<Uint8Array> | null;\n response: Response | null;\n};\n\ntype RenderAppPageHtmlStreamWithRecoveryOptions<TSpecialError> = {\n onShellRendered?: () => void;\n renderErrorBoundaryResponse: (error: unknown) => Promise<Response | null>;\n renderHtmlStream: () => Promise<ReadableStream<Uint8Array>>;\n renderSpecialErrorResponse: (specialError: TSpecialError) => Promise<Response>;\n resolveSpecialError: (error: unknown) => TSpecialError | null;\n};\n\ntype AppPageRscErrorTracker = {\n getCapturedError: () => unknown;\n /**\n * Returns a NEXT_REDIRECT or NEXT_HTTP_ERROR_FALLBACK error captured during\n * the RSC render. Read after the SSR shell promise resolves to swap a\n * 307/404 in place of the streamed body when redirect()/notFound() throws\n * synchronously inside a route-level Suspense boundary (loading.tsx).\n */\n getCapturedSpecialError: () => unknown;\n onRenderError: (error: unknown, requestInfo: unknown, errorContext: unknown) => unknown;\n};\n\ntype ShouldRerenderAppPageWithGlobalErrorOptions = {\n capturedError: unknown;\n hasLocalBoundary: boolean;\n};\n\nexport function createAppPageFontData(options: CreateAppPageFontDataOptions): AppPageFontData {\n return {\n links: options.getLinks(),\n preloads: options.getPreloads(),\n styles: options.getStyles(),\n };\n}\n\nexport async function renderAppPageHtmlStream(\n options: RenderAppPageHtmlStreamOptions,\n): Promise<ReadableStream<Uint8Array>> {\n const ssrOptions = {\n scriptNonce: options.scriptNonce,\n sideStream: options.sideStream,\n capturedRscDataRef: options.capturedRscDataRef,\n };\n\n return options.ssrHandler.handleSsr(\n options.rscStream,\n options.navigationContext,\n options.fontData,\n ssrOptions,\n );\n}\n\n/**\n * Wraps a stream so that `onFlush` is called when the last byte has been read\n * by the downstream consumer (i.e. when the HTTP layer finishes draining the\n * response body). This is the correct place to clear per-request context,\n * because the RSC/SSR pipeline is lazy — components execute while the stream\n * is being consumed, not when the stream handle is first obtained.\n */\nexport function deferUntilStreamConsumed(\n stream: ReadableStream<Uint8Array>,\n onFlush: () => void,\n): ReadableStream<Uint8Array> {\n let called = false;\n const once = () => {\n if (!called) {\n called = true;\n onFlush();\n }\n };\n\n const cleanup = new TransformStream<Uint8Array, Uint8Array>({\n flush() {\n once();\n },\n });\n\n const piped = stream.pipeThrough(cleanup);\n\n // Wrap with a ReadableStream so we can intercept cancel() — the TransformStream\n // Transformer interface does not expose a cancel hook in the Web Streams spec.\n const reader = piped.getReader();\n return new ReadableStream<Uint8Array>({\n pull(controller) {\n return reader.read().then(\n ({ done, value }) => {\n if (done) {\n controller.close();\n } else {\n controller.enqueue(value);\n }\n },\n (error) => {\n once();\n controller.error(error);\n },\n );\n },\n cancel(reason) {\n // Stream cancelled before fully consumed (e.g. client disconnected).\n // Still clear per-request context to avoid leaks.\n once();\n return reader.cancel(reason);\n },\n });\n}\n\nexport async function renderAppPageHtmlResponse(\n options: RenderAppPageHtmlResponseOptions,\n): Promise<Response> {\n const htmlStream = await renderAppPageHtmlStream(options);\n\n // Defer clearRequestContext() until the stream is fully consumed by the HTTP\n // layer. Calling it synchronously here would race the lazy RSC/SSR pipeline:\n // components execute while the stream is being pulled, not when the handle\n // is first returned. See: https://github.com/cloudflare/vinext/issues/660\n const safeStream = deferUntilStreamConsumed(htmlStream, () => {\n options.clearRequestContext();\n });\n\n const headers = new Headers({\n \"Content-Type\": \"text/html; charset=utf-8\",\n Vary: VINEXT_RSC_VARY_HEADER,\n });\n\n if (options.fontLinkHeader) {\n headers.set(\"Link\", options.fontLinkHeader);\n }\n\n mergeMiddlewareResponseHeaders(headers, options.middlewareHeaders ?? null);\n\n return new Response(safeStream, {\n status: options.status,\n headers,\n });\n}\n\nexport async function renderAppPageHtmlStreamWithRecovery<TSpecialError>(\n options: RenderAppPageHtmlStreamWithRecoveryOptions<TSpecialError>,\n): Promise<AppPageHtmlStreamRecoveryResult> {\n try {\n const htmlStream = await options.renderHtmlStream();\n options.onShellRendered?.();\n return {\n htmlStream,\n response: null,\n };\n } catch (error) {\n const specialError = options.resolveSpecialError(error);\n if (specialError) {\n return {\n htmlStream: null,\n response: await options.renderSpecialErrorResponse(specialError),\n };\n }\n\n const boundaryResponse = await options.renderErrorBoundaryResponse(error);\n if (boundaryResponse) {\n return {\n htmlStream: null,\n response: boundaryResponse,\n };\n }\n\n throw error;\n }\n}\n\nexport function createAppPageRscErrorTracker(\n baseOnError: (error: unknown, requestInfo: unknown, errorContext: unknown) => unknown,\n): AppPageRscErrorTracker {\n let capturedError: unknown = null;\n let capturedSpecialError: unknown = null;\n\n return {\n getCapturedError() {\n return capturedError;\n },\n getCapturedSpecialError() {\n return capturedSpecialError;\n },\n onRenderError(error, requestInfo, errorContext) {\n if (error && typeof error === \"object\" && \"digest\" in error) {\n // Errors with a digest are signal throws (NEXT_REDIRECT,\n // NEXT_NOT_FOUND, NEXT_HTTP_ERROR_FALLBACK). They're not real\n // failures — keep the first one so the lifecycle can swap a\n // 307/404 in place of a streamed \"Switched to client rendering\"\n // body for routes with a route-level Suspense boundary.\n if (capturedSpecialError === null) {\n capturedSpecialError = error;\n }\n } else {\n capturedError = error;\n }\n return baseOnError(error, requestInfo, errorContext);\n },\n };\n}\n\nexport function shouldRerenderAppPageWithGlobalError(\n options: ShouldRerenderAppPageWithGlobalErrorOptions,\n): boolean {\n return Boolean(options.capturedError) && !options.hasLocalBoundary;\n}\n"],"mappings":";;;AA+EA,SAAgB,sBAAsB,SAAwD;AAC5F,QAAO;EACL,OAAO,QAAQ,UAAU;EACzB,UAAU,QAAQ,aAAa;EAC/B,QAAQ,QAAQ,WAAW;EAC5B;;AAGH,eAAsB,wBACpB,SACqC;CACrC,MAAM,aAAa;EACjB,aAAa,QAAQ;EACrB,YAAY,QAAQ;EACpB,oBAAoB,QAAQ;EAC7B;AAED,QAAO,QAAQ,WAAW,UACxB,QAAQ,WACR,QAAQ,mBACR,QAAQ,UACR,WACD;;;;;;;;;AAUH,SAAgB,yBACd,QACA,SAC4B;CAC5B,IAAI,SAAS;CACb,MAAM,aAAa;AACjB,MAAI,CAAC,QAAQ;AACX,YAAS;AACT,YAAS;;;CAIb,MAAM,UAAU,IAAI,gBAAwC,EAC1D,QAAQ;AACN,QAAM;IAET,CAAC;CAMF,MAAM,SAJQ,OAAO,YAAY,QAAQ,CAIpB,WAAW;AAChC,QAAO,IAAI,eAA2B;EACpC,KAAK,YAAY;AACf,UAAO,OAAO,MAAM,CAAC,MAClB,EAAE,MAAM,YAAY;AACnB,QAAI,KACF,YAAW,OAAO;QAElB,YAAW,QAAQ,MAAM;OAG5B,UAAU;AACT,UAAM;AACN,eAAW,MAAM,MAAM;KAE1B;;EAEH,OAAO,QAAQ;AAGb,SAAM;AACN,UAAO,OAAO,OAAO,OAAO;;EAE/B,CA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