vinext 0.0.46 → 0.0.47
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 +7 -5
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +70 -14
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/report.d.ts +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/static-export.d.ts +1 -1
- package/dist/cli-args.d.ts +31 -0
- package/dist/cli-args.js +104 -0
- package/dist/cli-args.js.map +1 -0
- package/dist/cli.js +2 -19
- 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/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/entries/app-rsc-entry.d.ts +4 -3
- package/dist/entries/app-rsc-entry.js +373 -854
- 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 +2 -0
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/pages-server-entry.js +5 -2
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.js +28 -51
- 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/rsc-client-shim-excludes.js +1 -0
- package/dist/plugins/rsc-client-shim-excludes.js.map +1 -1
- package/dist/routing/app-route-graph.d.ts +109 -0
- package/dist/routing/app-route-graph.js +819 -0
- package/dist/routing/app-route-graph.js.map +1 -0
- package/dist/routing/app-router.d.ts +2 -88
- package/dist/routing/app-router.js +6 -694
- package/dist/routing/app-router.js.map +1 -1
- package/dist/server/app-browser-entry.js +86 -252
- 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 +73 -0
- package/dist/server/app-browser-navigation-controller.js +282 -0
- package/dist/server/app-browser-navigation-controller.js.map +1 -0
- package/dist/server/app-browser-state.d.ts +1 -1
- package/dist/server/app-elements.js +1 -5
- 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-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 +2 -2
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +18 -4
- package/dist/server/app-page-cache.js +53 -10
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +7 -4
- package/dist/server/app-page-dispatch.js +24 -8
- 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 +139 -0
- package/dist/server/app-page-element-builder.js.map +1 -0
- 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-render.d.ts +5 -1
- package/dist/server/app-page-render.js +80 -27
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-request.d.ts +19 -4
- package/dist/server/app-page-request.js +51 -6
- 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 +3 -7
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +15 -2
- package/dist/server/app-page-route-wiring.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-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 +5 -1
- 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 +2 -0
- 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-response.d.ts +4 -2
- package/dist/server/app-route-handler-response.js +8 -7
- package/dist/server/app-route-handler-response.js.map +1 -1
- 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 +260 -0
- package/dist/server/app-rsc-handler.js.map +1 -0
- package/dist/server/app-rsc-request-normalization.d.ts +40 -0
- package/dist/server/app-rsc-request-normalization.js +63 -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-segment-config.d.ts +33 -0
- package/dist/server/app-segment-config.js +86 -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 +2 -0
- package/dist/server/app-server-action-execution.js.map +1 -1
- 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/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/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/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 +2 -1
- package/dist/server/pages-page-response.js +3 -2
- package/dist/server/pages-page-response.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.js +28 -11
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/cache.d.ts +15 -3
- package/dist/shims/cache.js +42 -15
- 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 +55 -13
- package/dist/shims/fetch-cache.js.map +1 -1
- package/dist/shims/image.js +93 -5
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +1 -0
- 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/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/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-render.js","names":[],"sources":["../../src/server/app-page-render.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { CachedAppPageValue } from \"vinext/shims/cache\";\nimport { buildOutgoingAppPayload, type AppOutgoingElements } from \"./app-elements.js\";\nimport {\n finalizeAppPageHtmlCacheResponse,\n finalizeAppPageRscCacheResponse,\n} from \"./app-page-cache.js\";\nimport {\n buildAppPageFontLinkHeader,\n readAppPageBinaryStream,\n resolveAppPageSpecialError,\n teeAppPageRscStreamForCapture,\n type AppPageFontPreload,\n type AppPageSpecialError,\n type LayoutClassificationOptions,\n} from \"./app-page-execution.js\";\nimport { probeAppPageBeforeRender } from \"./app-page-probe.js\";\nimport {\n buildAppPageHtmlResponse,\n buildAppPageRscResponse,\n resolveAppPageHtmlResponsePolicy,\n resolveAppPageRscResponsePolicy,\n type AppPageMiddlewareContext,\n type AppPageResponseTiming,\n} from \"./app-page-response.js\";\nimport {\n createAppPageFontData,\n createAppPageRscErrorTracker,\n deferUntilStreamConsumed,\n renderAppPageHtmlStream,\n renderAppPageHtmlStreamWithRecovery,\n shouldRerenderAppPageWithGlobalError,\n type AppPageSsrHandler,\n} from \"./app-page-stream.js\";\n\ntype AppPageBoundaryOnError = (\n error: unknown,\n requestInfo: unknown,\n errorContext: unknown,\n) => unknown;\ntype AppPageDebugLogger = (event: string, detail: string) => void;\ntype AppPageCacheSetter = (\n key: string,\n data: CachedAppPageValue,\n revalidateSeconds: number,\n tags: string[],\n) => Promise<void>;\n\ntype AppPageRequestCacheLife = {\n revalidate?: number;\n};\n\ntype RenderAppPageLifecycleOptions = {\n cleanPathname: string;\n clearRequestContext: () => void;\n consumeDynamicUsage: () => boolean;\n /** Read and clear any invalid dynamic usage error recorded during render (dev-only). */\n consumeInvalidDynamicUsageError?: () => unknown;\n createRscOnErrorHandler: (pathname: string, routePath: string) => AppPageBoundaryOnError;\n getFontLinks: () => string[];\n getFontPreloads: () => AppPageFontPreload[];\n getFontStyles: () => string[];\n getNavigationContext: () => unknown;\n getPageTags: () => string[];\n getRequestCacheLife: () => AppPageRequestCacheLife | null;\n getDraftModeCookieHeader: () => string | null | undefined;\n handlerStart: number;\n hasLoadingBoundary: boolean;\n isDynamicError: boolean;\n isForceDynamic: boolean;\n isForceStatic: boolean;\n isProduction: boolean;\n isRscRequest: boolean;\n isrDebug?: AppPageDebugLogger;\n isrHtmlKey: (pathname: string) => string;\n isrRscKey: (pathname: string, mountedSlotsHeader?: string | null) => string;\n isrSet: AppPageCacheSetter;\n layoutCount: number;\n loadSsrHandler: () => Promise<AppPageSsrHandler>;\n middlewareContext: AppPageMiddlewareContext;\n params: Record<string, unknown>;\n probeLayoutAt: (layoutIndex: number) => unknown;\n probePage: () => unknown;\n revalidateSeconds: number | null;\n renderErrorBoundaryResponse: (error: unknown) => Promise<Response | null>;\n renderLayoutSpecialError: (\n specialError: AppPageSpecialError,\n layoutIndex: number,\n ) => Promise<Response>;\n renderPageSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n renderToReadableStream: (\n element: ReactNode | AppOutgoingElements,\n options: { onError: AppPageBoundaryOnError },\n ) => ReadableStream<Uint8Array>;\n routeHasLocalBoundary: boolean;\n routePattern: string;\n runWithSuppressedHookWarning<T>(probe: () => Promise<T>): Promise<T>;\n scriptNonce?: string;\n mountedSlotsHeader?: string | null;\n waitUntil?: (promise: Promise<void>) => void;\n element: ReactNode | Readonly<Record<string, ReactNode>>;\n classification?: LayoutClassificationOptions | null;\n};\n\nfunction buildResponseTiming(\n options: Pick<RenderAppPageLifecycleOptions, \"handlerStart\" | \"isProduction\"> & {\n compileEnd?: number;\n renderEnd?: number;\n responseKind: AppPageResponseTiming[\"responseKind\"];\n },\n): AppPageResponseTiming | undefined {\n if (options.isProduction) {\n return undefined;\n }\n\n return {\n compileEnd: options.compileEnd,\n handlerStart: options.handlerStart,\n renderEnd: options.renderEnd,\n responseKind: options.responseKind,\n };\n}\n\n/**\n * Wraps an RSC response body to report invalid dynamic usage errors after the\n * stream is fully consumed. In dev mode, errors from cookies()/headers() inside\n * \"use cache\" may be caught by user try/catch and silently swallowed — this\n * wrapper waits for the stream to drain and surfaces any recorded error to the\n * terminal (and, via HMR, the browser dev overlay).\n * Ported from Next.js: https://github.com/vercel/next.js/commit/f5e54c06726b571a042fce67417e40a29f6b8689\n */\nfunction wrapRscResponseForDevErrorReporting(\n response: Response,\n consumeInvalidDynamicUsageError: () => unknown,\n): Response {\n const originalBody = response.body;\n if (!originalBody) return response;\n\n let consumed = false;\n const onConsumed = () => {\n if (consumed) return;\n consumed = true;\n const error = consumeInvalidDynamicUsageError();\n if (error) {\n console.error(\"[vinext] Invalid dynamic usage:\", error);\n }\n };\n\n const cleanup = new TransformStream<Uint8Array, Uint8Array>({\n flush() {\n onConsumed();\n },\n });\n\n const piped = originalBody.pipeThrough(cleanup);\n const reader = piped.getReader();\n const wrappedStream = 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 (streamError) => {\n onConsumed();\n controller.error(streamError);\n },\n );\n },\n cancel(reason) {\n onConsumed();\n return reader.cancel(reason);\n },\n });\n\n return new Response(wrappedStream, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n });\n}\n\nexport async function renderAppPageLifecycle(\n options: RenderAppPageLifecycleOptions,\n): Promise<Response> {\n const preRenderResult = await probeAppPageBeforeRender({\n hasLoadingBoundary: options.hasLoadingBoundary,\n layoutCount: options.layoutCount,\n probeLayoutAt(layoutIndex) {\n return options.probeLayoutAt(layoutIndex);\n },\n probePage() {\n return options.probePage();\n },\n renderLayoutSpecialError(specialError, layoutIndex) {\n return options.renderLayoutSpecialError(specialError, layoutIndex);\n },\n renderPageSpecialError(specialError) {\n return options.renderPageSpecialError(specialError);\n },\n resolveSpecialError: resolveAppPageSpecialError,\n runWithSuppressedHookWarning(probe) {\n return options.runWithSuppressedHookWarning(probe);\n },\n classification: options.classification,\n });\n if (preRenderResult.response) {\n return preRenderResult.response;\n }\n\n const layoutFlags = preRenderResult.layoutFlags;\n\n // Render the CANONICAL element. The outgoing payload carries per-layout\n // static/dynamic flags under `__layoutFlags` so the client can later tell\n // which layouts are safe to skip on subsequent navigations.\n const outgoingElement = buildOutgoingAppPayload({\n element: options.element,\n layoutFlags,\n });\n\n const compileEnd = options.isProduction ? undefined : performance.now();\n const baseOnError = options.createRscOnErrorHandler(options.cleanPathname, options.routePattern);\n const rscErrorTracker = createAppPageRscErrorTracker(baseOnError);\n const rscStream = options.renderToReadableStream(outgoingElement, {\n onError: rscErrorTracker.onRenderError,\n });\n\n let revalidateSeconds = options.revalidateSeconds;\n const rscCapture = teeAppPageRscStreamForCapture(\n rscStream,\n options.isProduction &&\n revalidateSeconds !== null &&\n revalidateSeconds > 0 &&\n revalidateSeconds !== Infinity &&\n !options.isForceDynamic,\n );\n const rscForResponse = rscCapture.ssrStream;\n\n // When the fused tee (#981) is active, the sideStream carries both the embed\n // transform AND the raw RSC byte accumulation. For RSC requests, we consume\n // the sideStream directly. For HTML requests, handleSsr creates an embed\n // transform from it and fills capturedRscDataRef. The ref object is threaded\n // through so .value is read lazily after handleSsr completes.\n const capturedRscDataRef: { value: Promise<ArrayBuffer> | null } = { value: null };\n if (rscCapture.sideStream && options.isRscRequest) {\n capturedRscDataRef.value = readAppPageBinaryStream(rscCapture.sideStream);\n }\n\n if (options.isRscRequest) {\n const dynamicUsedDuringBuild = options.consumeDynamicUsage();\n const rscResponsePolicy = resolveAppPageRscResponsePolicy({\n dynamicUsedDuringBuild,\n isDynamicError: options.isDynamicError,\n isForceDynamic: options.isForceDynamic,\n isForceStatic: options.isForceStatic,\n isProduction: options.isProduction,\n revalidateSeconds,\n });\n const rscResponse = buildAppPageRscResponse(rscForResponse, {\n middlewareContext: options.middlewareContext,\n mountedSlotsHeader: options.mountedSlotsHeader,\n params: options.params,\n policy: rscResponsePolicy,\n timing: buildResponseTiming({\n compileEnd,\n handlerStart: options.handlerStart,\n isProduction: options.isProduction,\n responseKind: \"rsc\",\n }),\n });\n\n // In dev mode, wrap the RSC response body to forward invalid dynamic usage\n // errors after the stream is consumed. This mirrors Next.js behavior where\n // workStore.invalidDynamicUsageError is checked after the accumulated chunks\n // promise resolves (app-render.tsx generateDynamicFlightRenderResultWithStagesInDev).\n // Ported from Next.js: https://github.com/vercel/next.js/commit/f5e54c06726b571a042fce67417e40a29f6b8689\n //\n // Note: This only covers RSC responses (client-side navigations). The HTML path\n // (initial page loads) intentionally defers this coverage — the error is still\n // thrown through the RSC pipeline and captured by rscErrorTracker.onRenderError\n // if uncaught by user code. Full parity with Next.js would require checking\n // invalidDynamicUsageError after SSR rendering, which is deferred as out of scope\n // for this PR focused on client-side navigations.\n const devRscResponse =\n !options.isProduction && rscResponse.body && options.consumeInvalidDynamicUsageError\n ? wrapRscResponseForDevErrorReporting(rscResponse, options.consumeInvalidDynamicUsageError)\n : rscResponse;\n\n return finalizeAppPageRscCacheResponse(devRscResponse, {\n capturedRscDataPromise: options.isProduction ? capturedRscDataRef.value : null,\n cleanPathname: options.cleanPathname,\n consumeDynamicUsage: options.consumeDynamicUsage,\n dynamicUsedDuringBuild,\n getPageTags() {\n return options.getPageTags();\n },\n isrDebug: options.isrDebug,\n isrRscKey: options.isrRscKey,\n isrSet: options.isrSet,\n mountedSlotsHeader: options.mountedSlotsHeader,\n revalidateSeconds: revalidateSeconds ?? 0,\n waitUntil(promise) {\n options.waitUntil?.(promise);\n },\n });\n }\n\n const fontData = createAppPageFontData({\n getLinks: options.getFontLinks,\n getPreloads: options.getFontPreloads,\n getStyles: options.getFontStyles,\n });\n const fontLinkHeader = buildAppPageFontLinkHeader(fontData.preloads);\n let renderEnd: number | undefined;\n\n const htmlRender = await renderAppPageHtmlStreamWithRecovery({\n onShellRendered() {\n if (!options.isProduction) {\n renderEnd = performance.now();\n }\n },\n renderErrorBoundaryResponse(error) {\n return options.renderErrorBoundaryResponse(error);\n },\n async renderHtmlStream() {\n const ssrHandler = await options.loadSsrHandler();\n return renderAppPageHtmlStream({\n capturedRscDataRef,\n fontData,\n navigationContext: options.getNavigationContext(),\n rscStream: rscForResponse,\n scriptNonce: options.scriptNonce,\n sideStream: rscCapture.sideStream,\n ssrHandler,\n });\n },\n renderSpecialErrorResponse(specialError) {\n return options.renderPageSpecialError(specialError);\n },\n resolveSpecialError: resolveAppPageSpecialError,\n });\n if (htmlRender.response) {\n return htmlRender.response;\n }\n const htmlStream = htmlRender.htmlStream;\n if (!htmlStream) {\n throw new Error(\"[vinext] Expected an HTML stream when no fallback response was returned\");\n }\n\n if (\n shouldRerenderAppPageWithGlobalError({\n capturedError: rscErrorTracker.getCapturedError(),\n hasLocalBoundary: options.routeHasLocalBoundary,\n })\n ) {\n const cleanResponse = await options.renderErrorBoundaryResponse(\n rscErrorTracker.getCapturedError(),\n );\n if (cleanResponse) {\n return cleanResponse;\n }\n }\n\n // Eagerly read values that must be captured before the stream is consumed.\n const draftCookie = options.getDraftModeCookieHeader();\n const dynamicUsedDuringRender = options.consumeDynamicUsage();\n const requestCacheLife = options.getRequestCacheLife();\n if (requestCacheLife?.revalidate !== undefined && revalidateSeconds === null) {\n revalidateSeconds = requestCacheLife.revalidate;\n }\n\n // Defer clearRequestContext() until the HTML stream is fully consumed by the\n // HTTP layer. The RSC/SSR pipeline is lazy — Server Components execute while\n // the response body is being pulled, not when the stream handle is returned.\n // Clearing the context synchronously here would race those executions, causing\n // headers()/cookies() to see a null context on warm (module-cached) requests.\n // See: https://github.com/cloudflare/vinext/issues/660\n const safeHtmlStream = deferUntilStreamConsumed(htmlStream, () => {\n options.clearRequestContext();\n });\n\n const htmlResponsePolicy = resolveAppPageHtmlResponsePolicy({\n dynamicUsedDuringRender,\n hasScriptNonce: Boolean(options.scriptNonce),\n isDynamicError: options.isDynamicError,\n isForceDynamic: options.isForceDynamic,\n isForceStatic: options.isForceStatic,\n isProduction: options.isProduction,\n revalidateSeconds,\n });\n const htmlResponseTiming = buildResponseTiming({\n compileEnd,\n handlerStart: options.handlerStart,\n isProduction: options.isProduction,\n renderEnd,\n responseKind: \"html\",\n });\n\n if (htmlResponsePolicy.shouldWriteToCache) {\n const isrResponse = buildAppPageHtmlResponse(safeHtmlStream, {\n draftCookie,\n fontLinkHeader,\n middlewareContext: options.middlewareContext,\n policy: htmlResponsePolicy,\n timing: htmlResponseTiming,\n });\n return finalizeAppPageHtmlCacheResponse(isrResponse, {\n capturedRscDataPromise: capturedRscDataRef.value,\n cleanPathname: options.cleanPathname,\n consumeDynamicUsage: options.consumeDynamicUsage,\n getPageTags() {\n return options.getPageTags();\n },\n isrDebug: options.isrDebug,\n isrHtmlKey: options.isrHtmlKey,\n isrRscKey: options.isrRscKey,\n isrSet: options.isrSet,\n revalidateSeconds: revalidateSeconds ?? 0,\n waitUntil(cachePromise) {\n options.waitUntil?.(cachePromise);\n },\n });\n }\n\n return buildAppPageHtmlResponse(safeHtmlStream, {\n draftCookie,\n fontLinkHeader,\n middlewareContext: options.middlewareContext,\n policy: htmlResponsePolicy,\n timing: htmlResponseTiming,\n });\n}\n"],"mappings":";;;;;;;AAwGA,SAAS,oBACP,SAKmC;AACnC,KAAI,QAAQ,aACV;AAGF,QAAO;EACL,YAAY,QAAQ;EACpB,cAAc,QAAQ;EACtB,WAAW,QAAQ;EACnB,cAAc,QAAQ;EACvB;;;;;;;;;;AAWH,SAAS,oCACP,UACA,iCACU;CACV,MAAM,eAAe,SAAS;AAC9B,KAAI,CAAC,aAAc,QAAO;CAE1B,IAAI,WAAW;CACf,MAAM,mBAAmB;AACvB,MAAI,SAAU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vB,cAAc,QAAQ;EACtB;EACD,CAAC;CACF,MAAM,qBAAqB,oBAAoB;EAC7C;EACA,cAAc,QAAQ;EACtB,cAAc,QAAQ;EACtB;EACA,cAAc;EACf,CAAC;AAEF,KAAI,mBAAmB,mBAQrB,QAAO,iCAPa,yBAAyB,gBAAgB;EAC3D;EACA;EACA,mBAAmB,QAAQ;EAC3B,QAAQ;EACR,QAAQ;EACT,CAAC,EACmD;EACnD,wBAAwB,mBAAmB;EAC3C,eAAe,QAAQ;EACvB,qBAAqB,QAAQ;EAC7B,cAAc;AACZ,UAAO,QAAQ,aAAa;;EAE9B,UAAU,QAAQ;EAClB,YAAY,QAAQ;EACpB,WAAW,QAAQ;EACnB,QAAQ,QAAQ;EAChB,mBAAmB,qBAAqB;EACxC,UAAU,cAAc;AACtB,WAAQ,YAAY,aAAa;;EAEpC,CAAC;AAGJ,QAAO,yBAAyB,gBAAgB;EAC9C;EACA;EACA,mBAAmB,QAAQ;EAC3B,QAAQ;EACR,QAAQ;EACT,CAAC"}
|
|
1
|
+
{"version":3,"file":"app-page-render.js","names":[],"sources":["../../src/server/app-page-render.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { CachedAppPageValue } from \"vinext/shims/cache\";\nimport { buildOutgoingAppPayload, type AppOutgoingElements } from \"./app-elements.js\";\nimport {\n finalizeAppPageHtmlCacheResponse,\n finalizeAppPageRscCacheResponse,\n} from \"./app-page-cache.js\";\nimport {\n buildAppPageFontLinkHeader,\n readAppPageBinaryStream,\n resolveAppPageSpecialError,\n teeAppPageRscStreamForCapture,\n type AppPageFontPreload,\n type AppPageSpecialError,\n type LayoutClassificationOptions,\n} from \"./app-page-execution.js\";\nimport { probeAppPageBeforeRender } from \"./app-page-probe.js\";\nimport {\n buildAppPageHtmlResponse,\n buildAppPageRscResponse,\n resolveAppPageHtmlResponsePolicy,\n resolveAppPageRscResponsePolicy,\n type AppPageMiddlewareContext,\n type AppPageResponseTiming,\n} from \"./app-page-response.js\";\nimport {\n createAppPageFontData,\n createAppPageRscErrorTracker,\n deferUntilStreamConsumed,\n renderAppPageHtmlStream,\n renderAppPageHtmlStreamWithRecovery,\n shouldRerenderAppPageWithGlobalError,\n type AppPageSsrHandler,\n} from \"./app-page-stream.js\";\n\ntype AppPageBoundaryOnError = (\n error: unknown,\n requestInfo: unknown,\n errorContext: unknown,\n) => unknown;\ntype AppPageDebugLogger = (event: string, detail: string) => void;\ntype AppPageCacheSetter = (\n key: string,\n data: CachedAppPageValue,\n revalidateSeconds: number,\n tags: string[],\n expireSeconds?: number,\n) => Promise<void>;\n\ntype AppPageRequestCacheLife = {\n revalidate?: number;\n expire?: number;\n};\n\ntype RenderAppPageLifecycleOptions = {\n cleanPathname: string;\n clearRequestContext: () => void;\n consumeDynamicUsage: () => boolean;\n /** Read and clear any invalid dynamic usage error recorded during render (dev-only). */\n consumeInvalidDynamicUsageError?: () => unknown;\n createRscOnErrorHandler: (pathname: string, routePath: string) => AppPageBoundaryOnError;\n getFontLinks: () => string[];\n getFontPreloads: () => AppPageFontPreload[];\n getFontStyles: () => string[];\n getNavigationContext: () => unknown;\n getPageTags: () => string[];\n getRequestCacheLife: () => AppPageRequestCacheLife | null;\n peekRequestCacheLife?: () => AppPageRequestCacheLife | null;\n getDraftModeCookieHeader: () => string | null | undefined;\n handlerStart: number;\n hasLoadingBoundary: boolean;\n isDynamicError: boolean;\n isForceDynamic: boolean;\n isForceStatic: boolean;\n isPrerender?: boolean;\n isProduction: boolean;\n isRscRequest: boolean;\n isrDebug?: AppPageDebugLogger;\n isrHtmlKey: (pathname: string) => string;\n isrRscKey: (pathname: string, mountedSlotsHeader?: string | null) => string;\n isrSet: AppPageCacheSetter;\n layoutCount: number;\n loadSsrHandler: () => Promise<AppPageSsrHandler>;\n middlewareContext: AppPageMiddlewareContext;\n params: Record<string, unknown>;\n probeLayoutAt: (layoutIndex: number) => unknown;\n probePage: () => unknown;\n expireSeconds?: number;\n revalidateSeconds: number | null;\n renderErrorBoundaryResponse: (error: unknown) => Promise<Response | null>;\n renderLayoutSpecialError: (\n specialError: AppPageSpecialError,\n layoutIndex: number,\n ) => Promise<Response>;\n renderPageSpecialError: (specialError: AppPageSpecialError) => Promise<Response>;\n renderToReadableStream: (\n element: ReactNode | AppOutgoingElements,\n options: { onError: AppPageBoundaryOnError },\n ) => ReadableStream<Uint8Array>;\n routeHasLocalBoundary: boolean;\n routePattern: string;\n runWithSuppressedHookWarning<T>(probe: () => Promise<T>): Promise<T>;\n scriptNonce?: string;\n mountedSlotsHeader?: string | null;\n waitUntil?: (promise: Promise<void>) => void;\n element: ReactNode | Readonly<Record<string, ReactNode>>;\n classification?: LayoutClassificationOptions | null;\n};\n\nfunction buildResponseTiming(\n options: Pick<RenderAppPageLifecycleOptions, \"handlerStart\" | \"isProduction\"> & {\n compileEnd?: number;\n renderEnd?: number;\n responseKind: AppPageResponseTiming[\"responseKind\"];\n },\n): AppPageResponseTiming | undefined {\n if (options.isProduction) {\n return undefined;\n }\n\n return {\n compileEnd: options.compileEnd,\n handlerStart: options.handlerStart,\n renderEnd: options.renderEnd,\n responseKind: options.responseKind,\n };\n}\n\nfunction readRequestCacheLifeForPrerender(\n options: Pick<RenderAppPageLifecycleOptions, \"getRequestCacheLife\" | \"peekRequestCacheLife\">,\n): AppPageRequestCacheLife | null {\n // Prefer the non-destructive reader so prerender.ts can consume metadata\n // after the handler returns. The consume fallback supports older entry glue\n // and is only safe because this path reads at most once per prerender.\n return options.peekRequestCacheLife?.() ?? options.getRequestCacheLife();\n}\n\nfunction applyRequestCacheLife(options: {\n expireSeconds?: number;\n requestCacheLife: AppPageRequestCacheLife | null;\n revalidateSeconds: number | null;\n}): { expireSeconds?: number; revalidateSeconds: number | null } {\n let revalidateSeconds = options.revalidateSeconds;\n let expireSeconds = options.expireSeconds;\n const requestCacheLife = options.requestCacheLife;\n\n if (requestCacheLife?.revalidate !== undefined) {\n revalidateSeconds =\n revalidateSeconds === null\n ? requestCacheLife.revalidate\n : Math.min(revalidateSeconds, requestCacheLife.revalidate);\n }\n if (requestCacheLife?.expire !== undefined) {\n // cacheLife() supplies the effective hard-expire ceiling for this render,\n // so it replaces the config fallback instead of min-merging with it.\n expireSeconds = requestCacheLife.expire;\n }\n\n return { expireSeconds, revalidateSeconds };\n}\n\n/**\n * Wraps an RSC response body to report invalid dynamic usage errors after the\n * stream is fully consumed. In dev mode, errors from cookies()/headers() inside\n * \"use cache\" may be caught by user try/catch and silently swallowed — this\n * wrapper waits for the stream to drain and surfaces any recorded error to the\n * terminal (and, via HMR, the browser dev overlay).\n * Ported from Next.js: https://github.com/vercel/next.js/commit/f5e54c06726b571a042fce67417e40a29f6b8689\n */\nfunction wrapRscResponseForDevErrorReporting(\n response: Response,\n consumeInvalidDynamicUsageError: () => unknown,\n): Response {\n const originalBody = response.body;\n if (!originalBody) return response;\n\n let consumed = false;\n const onConsumed = () => {\n if (consumed) return;\n consumed = true;\n const error = consumeInvalidDynamicUsageError();\n if (error) {\n console.error(\"[vinext] Invalid dynamic usage:\", error);\n }\n };\n\n const cleanup = new TransformStream<Uint8Array, Uint8Array>({\n flush() {\n onConsumed();\n },\n });\n\n const piped = originalBody.pipeThrough(cleanup);\n const reader = piped.getReader();\n const wrappedStream = 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 (streamError) => {\n onConsumed();\n controller.error(streamError);\n },\n );\n },\n cancel(reason) {\n onConsumed();\n return reader.cancel(reason);\n },\n });\n\n return new Response(wrappedStream, {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n });\n}\n\nexport async function renderAppPageLifecycle(\n options: RenderAppPageLifecycleOptions,\n): Promise<Response> {\n const preRenderResult = await probeAppPageBeforeRender({\n hasLoadingBoundary: options.hasLoadingBoundary,\n layoutCount: options.layoutCount,\n probeLayoutAt(layoutIndex) {\n return options.probeLayoutAt(layoutIndex);\n },\n probePage() {\n return options.probePage();\n },\n renderLayoutSpecialError(specialError, layoutIndex) {\n return options.renderLayoutSpecialError(specialError, layoutIndex);\n },\n renderPageSpecialError(specialError) {\n return options.renderPageSpecialError(specialError);\n },\n resolveSpecialError: resolveAppPageSpecialError,\n runWithSuppressedHookWarning(probe) {\n return options.runWithSuppressedHookWarning(probe);\n },\n classification: options.classification,\n });\n if (preRenderResult.response) {\n return preRenderResult.response;\n }\n\n const layoutFlags = preRenderResult.layoutFlags;\n\n // Render the CANONICAL element. The outgoing payload carries per-layout\n // static/dynamic flags under `__layoutFlags` so the client can later tell\n // which layouts are safe to skip on subsequent navigations.\n const outgoingElement = buildOutgoingAppPayload({\n element: options.element,\n layoutFlags,\n });\n\n const compileEnd = options.isProduction ? undefined : performance.now();\n const baseOnError = options.createRscOnErrorHandler(options.cleanPathname, options.routePattern);\n const rscErrorTracker = createAppPageRscErrorTracker(baseOnError);\n const rscStream = options.renderToReadableStream(outgoingElement, {\n onError: rscErrorTracker.onRenderError,\n });\n\n let revalidateSeconds = options.revalidateSeconds;\n let expireSeconds = options.expireSeconds;\n const shouldCaptureRscForCacheMetadata =\n (options.isProduction || options.isPrerender === true) &&\n (revalidateSeconds === null || (revalidateSeconds > 0 && revalidateSeconds !== Infinity)) &&\n !options.isForceDynamic;\n const rscCapture = teeAppPageRscStreamForCapture(rscStream, shouldCaptureRscForCacheMetadata);\n const rscForResponse = rscCapture.ssrStream;\n\n // When the fused tee (#981) is active, the sideStream carries both the embed\n // transform AND the raw RSC byte accumulation. For RSC requests, we consume\n // the sideStream directly. For HTML requests, handleSsr creates an embed\n // transform from it and fills capturedRscDataRef. The ref object is threaded\n // through so .value is read lazily after handleSsr completes.\n const capturedRscDataRef: { value: Promise<ArrayBuffer> | null } = { value: null };\n if (rscCapture.sideStream && options.isRscRequest) {\n capturedRscDataRef.value = readAppPageBinaryStream(rscCapture.sideStream);\n }\n\n if (options.isRscRequest) {\n if (options.isPrerender === true) {\n await settleCapturedRscRenderForCacheMetadata(capturedRscDataRef.value);\n ({ expireSeconds, revalidateSeconds } = applyRequestCacheLife({\n expireSeconds,\n requestCacheLife: readRequestCacheLifeForPrerender(options),\n revalidateSeconds,\n }));\n }\n\n const dynamicUsedDuringBuild = options.consumeDynamicUsage();\n const rscResponsePolicy = resolveAppPageRscResponsePolicy({\n dynamicUsedDuringBuild,\n isDynamicError: options.isDynamicError,\n isForceDynamic: options.isForceDynamic,\n isForceStatic: options.isForceStatic,\n isProduction: options.isProduction,\n expireSeconds,\n revalidateSeconds,\n });\n const rscResponse = buildAppPageRscResponse(rscForResponse, {\n middlewareContext: options.middlewareContext,\n mountedSlotsHeader: options.mountedSlotsHeader,\n params: options.params,\n policy: rscResponsePolicy,\n timing: buildResponseTiming({\n compileEnd,\n handlerStart: options.handlerStart,\n isProduction: options.isProduction,\n responseKind: \"rsc\",\n }),\n });\n\n // In dev mode, wrap the RSC response body to forward invalid dynamic usage\n // errors after the stream is consumed. This mirrors Next.js behavior where\n // workStore.invalidDynamicUsageError is checked after the accumulated chunks\n // promise resolves (app-render.tsx generateDynamicFlightRenderResultWithStagesInDev).\n // Ported from Next.js: https://github.com/vercel/next.js/commit/f5e54c06726b571a042fce67417e40a29f6b8689\n //\n // Note: This only covers RSC responses (client-side navigations). The HTML path\n // (initial page loads) intentionally defers this coverage — the error is still\n // thrown through the RSC pipeline and captured by rscErrorTracker.onRenderError\n // if uncaught by user code. Full parity with Next.js would require checking\n // invalidDynamicUsageError after SSR rendering, which is deferred as out of scope\n // for this PR focused on client-side navigations.\n const devRscResponse =\n !options.isProduction && rscResponse.body && options.consumeInvalidDynamicUsageError\n ? wrapRscResponseForDevErrorReporting(rscResponse, options.consumeInvalidDynamicUsageError)\n : rscResponse;\n\n return finalizeAppPageRscCacheResponse(devRscResponse, {\n capturedRscDataPromise:\n options.isProduction && shouldCaptureRscForCacheMetadata ? capturedRscDataRef.value : null,\n cleanPathname: options.cleanPathname,\n consumeDynamicUsage: options.consumeDynamicUsage,\n dynamicUsedDuringBuild,\n getPageTags() {\n return options.getPageTags();\n },\n getRequestCacheLife() {\n return options.getRequestCacheLife();\n },\n isrDebug: options.isrDebug,\n isrRscKey: options.isrRscKey,\n isrSet: options.isrSet,\n mountedSlotsHeader: options.mountedSlotsHeader,\n preserveClientResponseHeaders: rscResponsePolicy.cacheState !== \"MISS\",\n expireSeconds,\n revalidateSeconds,\n waitUntil(promise) {\n options.waitUntil?.(promise);\n },\n });\n }\n\n const fontData = createAppPageFontData({\n getLinks: options.getFontLinks,\n getPreloads: options.getFontPreloads,\n getStyles: options.getFontStyles,\n });\n const fontLinkHeader = buildAppPageFontLinkHeader(fontData.preloads);\n let renderEnd: number | undefined;\n\n const htmlRender = await renderAppPageHtmlStreamWithRecovery({\n onShellRendered() {\n if (!options.isProduction) {\n renderEnd = performance.now();\n }\n },\n renderErrorBoundaryResponse(error) {\n return options.renderErrorBoundaryResponse(error);\n },\n async renderHtmlStream() {\n const ssrHandler = await options.loadSsrHandler();\n return renderAppPageHtmlStream({\n capturedRscDataRef,\n fontData,\n navigationContext: options.getNavigationContext(),\n rscStream: rscForResponse,\n scriptNonce: options.scriptNonce,\n sideStream: rscCapture.sideStream,\n ssrHandler,\n });\n },\n renderSpecialErrorResponse(specialError) {\n return options.renderPageSpecialError(specialError);\n },\n resolveSpecialError: resolveAppPageSpecialError,\n });\n if (htmlRender.response) {\n return htmlRender.response;\n }\n const htmlStream = htmlRender.htmlStream;\n if (!htmlStream) {\n throw new Error(\"[vinext] Expected an HTML stream when no fallback response was returned\");\n }\n\n if (\n shouldRerenderAppPageWithGlobalError({\n capturedError: rscErrorTracker.getCapturedError(),\n hasLocalBoundary: options.routeHasLocalBoundary,\n })\n ) {\n const cleanResponse = await options.renderErrorBoundaryResponse(\n rscErrorTracker.getCapturedError(),\n );\n if (cleanResponse) {\n return cleanResponse;\n }\n }\n\n // Eagerly read values that must be captured before the stream is consumed.\n if (options.isPrerender === true) {\n await settleCapturedRscRenderForCacheMetadata(capturedRscDataRef.value);\n ({ expireSeconds, revalidateSeconds } = applyRequestCacheLife({\n expireSeconds,\n requestCacheLife: readRequestCacheLifeForPrerender(options),\n revalidateSeconds,\n }));\n }\n const draftCookie = options.getDraftModeCookieHeader();\n const dynamicUsedDuringRender = options.consumeDynamicUsage();\n\n // Defer clearRequestContext() until the HTML stream is fully consumed by the\n // HTTP layer. The RSC/SSR pipeline is lazy — Server Components execute while\n // the response body is being pulled, not when the stream handle is returned.\n // Clearing the context synchronously here would race those executions, causing\n // headers()/cookies() to see a null context on warm (module-cached) requests.\n // See: https://github.com/cloudflare/vinext/issues/660\n const safeHtmlStream = deferUntilStreamConsumed(htmlStream, () => {\n options.clearRequestContext();\n });\n\n const htmlResponsePolicy = resolveAppPageHtmlResponsePolicy({\n dynamicUsedDuringRender,\n hasScriptNonce: Boolean(options.scriptNonce),\n isDynamicError: options.isDynamicError,\n isForceDynamic: options.isForceDynamic,\n isForceStatic: options.isForceStatic,\n isProduction: options.isProduction,\n expireSeconds,\n revalidateSeconds,\n });\n const htmlResponseTiming = buildResponseTiming({\n compileEnd,\n handlerStart: options.handlerStart,\n isProduction: options.isProduction,\n renderEnd,\n responseKind: \"html\",\n });\n\n const shouldSpeculativelyWriteCache =\n options.isProduction &&\n shouldCaptureRscForCacheMetadata &&\n revalidateSeconds === null &&\n !options.isDynamicError &&\n !options.isForceStatic &&\n !options.scriptNonce &&\n !dynamicUsedDuringRender;\n\n if (htmlResponsePolicy.shouldWriteToCache || shouldSpeculativelyWriteCache) {\n const isrResponse = buildAppPageHtmlResponse(safeHtmlStream, {\n draftCookie,\n fontLinkHeader,\n middlewareContext: options.middlewareContext,\n policy: htmlResponsePolicy,\n timing: htmlResponseTiming,\n });\n\n if (options.isPrerender === true) {\n return isrResponse;\n }\n\n return finalizeAppPageHtmlCacheResponse(isrResponse, {\n capturedRscDataPromise: capturedRscDataRef.value,\n cleanPathname: options.cleanPathname,\n consumeDynamicUsage: options.consumeDynamicUsage,\n getPageTags() {\n return options.getPageTags();\n },\n getRequestCacheLife() {\n return options.getRequestCacheLife();\n },\n isrDebug: options.isrDebug,\n isrHtmlKey: options.isrHtmlKey,\n isrRscKey: options.isrRscKey,\n isrSet: options.isrSet,\n preserveClientResponseHeaders: !htmlResponsePolicy.shouldWriteToCache,\n expireSeconds,\n revalidateSeconds,\n waitUntil(cachePromise) {\n options.waitUntil?.(cachePromise);\n },\n });\n }\n\n return buildAppPageHtmlResponse(safeHtmlStream, {\n draftCookie,\n fontLinkHeader,\n middlewareContext: options.middlewareContext,\n policy: htmlResponsePolicy,\n timing: htmlResponseTiming,\n });\n}\n\nasync function settleCapturedRscRenderForCacheMetadata(\n capturedRscDataPromise: Promise<ArrayBuffer> | null,\n): Promise<void> {\n if (!capturedRscDataPromise) {\n return;\n }\n\n try {\n await capturedRscDataPromise;\n } catch {\n // The response stream and cache-write path own render error propagation.\n // This pre-read only makes \"use cache\" metadata available before headers\n // and ISR seed metadata are finalized.\n }\n}\n"],"mappings":";;;;;;;AA6GA,SAAS,oBACP,SAKmC;AACnC,KAAI,QAAQ,aACV;AAGF,QAAO;EACL,YAAY,QAAQ;EACpB,cAAc,QAAQ;EACtB,WAAW,QAAQ;EACnB,cAAc,QAAQ;EACvB;;AAGH,SAAS,iCACP,SACgC;AAIhC,QAAO,QAAQ,wBAAwB,IAAI,QAAQ,qBAAqB;;AAG1E,SAAS,sBAAsB,SAIkC;CAC/D,IAAI,oBAAoB,QAAQ;CAChC,IAAI,gBAAgB,QAAQ;CAC5B,MAAM,mBAAmB,QAAQ;AAEjC,KAAI,kBAAkB,eAAe,KAAA,EACnC,qBACE,sBAAsB,OAClB,iBAAiB,aACjB,KAAK,IAAI,mBAAmB,iBAAiB,WAAW;AAEhE,KAAI,kBAAkB,WAAW,KAAA,EAG/B,iBAAgB,iBAAiB;AAGnC,QAAO;EAAE;EAAe;EAAmB;;;;;;;;;;AAW7C,SAAS,oCACP,UACA,iCACU;CACV,MAAM,eAAe,SAAS;AAC9B,KAAI,CAAC,aAAc,QAAO;CAE1B,IAAI,WAAW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gB;EAC9C;EACA;EACA,mBAAmB,QAAQ;EAC3B,QAAQ;EACR,QAAQ;EACT,CAAC;;AAGJ,eAAe,wCACb,wBACe;AACf,KAAI,CAAC,uBACH;AAGF,KAAI;AACF,QAAM;SACA"}
|
|
@@ -2,16 +2,30 @@ import { AppPageSpecialError } from "./app-page-execution.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/server/app-page-request.d.ts
|
|
4
4
|
type AppPageParams = Record<string, string | string[]>;
|
|
5
|
+
type GenerateStaticParams = (args: {
|
|
6
|
+
params: AppPageParams;
|
|
7
|
+
}) => unknown;
|
|
8
|
+
type GenerateStaticParamsModule = {
|
|
9
|
+
generateStaticParams?: GenerateStaticParams | null;
|
|
10
|
+
};
|
|
11
|
+
type GenerateStaticParamsSource = {
|
|
12
|
+
generateStaticParams: GenerateStaticParams;
|
|
13
|
+
parentParamNames: readonly string[];
|
|
14
|
+
};
|
|
5
15
|
type ValidateAppPageDynamicParamsOptions = {
|
|
6
16
|
clearRequestContext: () => void;
|
|
7
17
|
enforceStaticParamsOnly: boolean;
|
|
8
|
-
generateStaticParams?: (
|
|
9
|
-
params: AppPageParams;
|
|
10
|
-
}) => unknown) | null;
|
|
18
|
+
generateStaticParams?: GenerateStaticParams | GenerateStaticParamsSource | readonly (GenerateStaticParams | GenerateStaticParamsSource | null | undefined)[] | null;
|
|
11
19
|
isDynamicRoute: boolean;
|
|
12
20
|
logGenerateStaticParamsError?: (error: unknown) => void;
|
|
13
21
|
params: AppPageParams;
|
|
14
22
|
};
|
|
23
|
+
type ResolveAppPageGenerateStaticParamsSourcesOptions = {
|
|
24
|
+
layouts?: readonly (GenerateStaticParamsModule | null | undefined)[];
|
|
25
|
+
layoutTreePositions?: readonly number[];
|
|
26
|
+
page?: GenerateStaticParamsModule | null;
|
|
27
|
+
routeSegments: readonly string[];
|
|
28
|
+
};
|
|
15
29
|
type BuildAppPageElementOptions<TElement> = {
|
|
16
30
|
buildPageElement: () => Promise<TElement>;
|
|
17
31
|
renderErrorBoundaryPage: (error: unknown) => Promise<Response | null>;
|
|
@@ -80,6 +94,7 @@ type ResolveAppPageInterceptResult<TInterceptOpts> = {
|
|
|
80
94
|
interceptOpts: TInterceptOpts | undefined;
|
|
81
95
|
response: Response | null;
|
|
82
96
|
};
|
|
97
|
+
declare function resolveAppPageGenerateStaticParamsSources(options: ResolveAppPageGenerateStaticParamsSourcesOptions): GenerateStaticParamsSource[];
|
|
83
98
|
declare function validateAppPageDynamicParams(options: ValidateAppPageDynamicParamsOptions): Promise<Response | null>;
|
|
84
99
|
/**
|
|
85
100
|
* Pure: decides whether the incoming request should re-render an intercepted
|
|
@@ -102,5 +117,5 @@ declare function resolveAppPageActionRerenderTarget<TRoute, TPage, TInterceptOpt
|
|
|
102
117
|
declare function resolveAppPageIntercept<TRoute, TPage, TInterceptOpts, TElement>(options: ResolveAppPageInterceptOptions<TRoute, TPage, TInterceptOpts, TElement>): Promise<ResolveAppPageInterceptResult<TInterceptOpts>>;
|
|
103
118
|
declare function buildAppPageElement<TElement>(options: BuildAppPageElementOptions<TElement>): Promise<BuildAppPageElementResult<TElement>>;
|
|
104
119
|
//#endregion
|
|
105
|
-
export { buildAppPageElement, resolveAppPageActionRerenderTarget, resolveAppPageIntercept, resolveAppPageInterceptMatch, validateAppPageDynamicParams };
|
|
120
|
+
export { ValidateAppPageDynamicParamsOptions, buildAppPageElement, resolveAppPageActionRerenderTarget, resolveAppPageGenerateStaticParamsSources, resolveAppPageIntercept, resolveAppPageInterceptMatch, validateAppPageDynamicParams };
|
|
106
121
|
//# sourceMappingURL=app-page-request.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getAppPageSegmentParamName } from "./app-page-params.js";
|
|
1
2
|
//#region src/server/app-page-request.ts
|
|
2
3
|
function pickRouteParams(matchedParams, routeParamNames) {
|
|
3
4
|
const params = {};
|
|
@@ -7,6 +8,33 @@ function pickRouteParams(matchedParams, routeParamNames) {
|
|
|
7
8
|
}
|
|
8
9
|
return params;
|
|
9
10
|
}
|
|
11
|
+
function collectParentParamNames(routeSegments, boundaryPosition) {
|
|
12
|
+
const limit = Math.max(0, Math.min(boundaryPosition, routeSegments.length));
|
|
13
|
+
const names = [];
|
|
14
|
+
for (const segment of routeSegments.slice(0, limit)) {
|
|
15
|
+
const name = getAppPageSegmentParamName(segment);
|
|
16
|
+
if (name && !names.includes(name)) names.push(name);
|
|
17
|
+
}
|
|
18
|
+
return names;
|
|
19
|
+
}
|
|
20
|
+
function getLayoutGenerateStaticParamsBoundary(layoutTreePosition) {
|
|
21
|
+
return (layoutTreePosition ?? 0) - 1;
|
|
22
|
+
}
|
|
23
|
+
function resolveAppPageGenerateStaticParamsSources(options) {
|
|
24
|
+
const sources = [];
|
|
25
|
+
options.layouts?.forEach((layout, index) => {
|
|
26
|
+
if (typeof layout?.generateStaticParams !== "function") return;
|
|
27
|
+
sources.push({
|
|
28
|
+
generateStaticParams: layout.generateStaticParams,
|
|
29
|
+
parentParamNames: collectParentParamNames(options.routeSegments, getLayoutGenerateStaticParamsBoundary(options.layoutTreePositions?.[index]))
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
if (typeof options.page?.generateStaticParams === "function") sources.push({
|
|
33
|
+
generateStaticParams: options.page.generateStaticParams,
|
|
34
|
+
parentParamNames: collectParentParamNames(options.routeSegments, Math.max(0, options.routeSegments.length - 1))
|
|
35
|
+
});
|
|
36
|
+
return sources;
|
|
37
|
+
}
|
|
10
38
|
function areStaticParamsAllowed(params, staticParams) {
|
|
11
39
|
const paramKeys = Object.keys(params);
|
|
12
40
|
return staticParams.some((staticParamSet) => paramKeys.every((key) => {
|
|
@@ -18,13 +46,30 @@ function areStaticParamsAllowed(params, staticParams) {
|
|
|
18
46
|
return JSON.stringify(value) === JSON.stringify(staticValue);
|
|
19
47
|
}));
|
|
20
48
|
}
|
|
49
|
+
function normalizeGenerateStaticParams(generateStaticParams) {
|
|
50
|
+
return (Array.isArray(generateStaticParams) ? generateStaticParams : [generateStaticParams]).flatMap((source) => {
|
|
51
|
+
if (typeof source === "function") return [{
|
|
52
|
+
generateStaticParams: source,
|
|
53
|
+
parentParamNames: []
|
|
54
|
+
}];
|
|
55
|
+
if (typeof source?.generateStaticParams === "function") return [source];
|
|
56
|
+
return [];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
21
59
|
async function validateAppPageDynamicParams(options) {
|
|
22
|
-
if (!options.enforceStaticParamsOnly || !options.isDynamicRoute
|
|
60
|
+
if (!options.enforceStaticParamsOnly || !options.isDynamicRoute) return null;
|
|
61
|
+
const generateStaticParamsSources = normalizeGenerateStaticParams(options.generateStaticParams);
|
|
62
|
+
if (generateStaticParamsSources.length === 0) {
|
|
63
|
+
options.clearRequestContext();
|
|
64
|
+
return new Response("Not Found", { status: 404 });
|
|
65
|
+
}
|
|
23
66
|
try {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
67
|
+
for (const source of generateStaticParamsSources) {
|
|
68
|
+
const staticParams = await source.generateStaticParams({ params: pickRouteParams(options.params, source.parentParamNames) });
|
|
69
|
+
if (Array.isArray(staticParams) && !areStaticParamsAllowed(options.params, staticParams)) {
|
|
70
|
+
options.clearRequestContext();
|
|
71
|
+
return new Response("Not Found", { status: 404 });
|
|
72
|
+
}
|
|
28
73
|
}
|
|
29
74
|
} catch (error) {
|
|
30
75
|
options.logGenerateStaticParamsError?.(error);
|
|
@@ -144,6 +189,6 @@ async function buildAppPageElement(options) {
|
|
|
144
189
|
}
|
|
145
190
|
}
|
|
146
191
|
//#endregion
|
|
147
|
-
export { buildAppPageElement, resolveAppPageActionRerenderTarget, resolveAppPageIntercept, resolveAppPageInterceptMatch, validateAppPageDynamicParams };
|
|
192
|
+
export { buildAppPageElement, resolveAppPageActionRerenderTarget, resolveAppPageGenerateStaticParamsSources, resolveAppPageIntercept, resolveAppPageInterceptMatch, validateAppPageDynamicParams };
|
|
148
193
|
|
|
149
194
|
//# sourceMappingURL=app-page-request.js.map
|
|
@@ -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,iBAAi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3B,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\";\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 logGenerateStaticParamsError?: (error: unknown) => void;\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 new Response(\"Not Found\", { status: 404 });\n }\n\n try {\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 new Response(\"Not Found\", { status: 404 });\n }\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":";;AA0HA,SAAS,gBACP,eACA,iBACe;CACf,MAAM,SAAwB,EAAE;AAEhC,MAAK,MAAM,aAAa,iBAAiB;EACvC,MAAM,QAAQ,cAAc;AAC5B,MAAI,UAAU,KAAA,EACZ,QAA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B;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,6 @@
|
|
|
1
1
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
2
|
+
import { NO_STORE_CACHE_CONTROL, STATIC_CACHE_CONTROL, buildRevalidateCacheControl } from "./cache-control.js";
|
|
2
3
|
//#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
4
|
function applyTimingHeader(headers, timing) {
|
|
9
5
|
if (!timing) return;
|
|
10
6
|
const handlerStart = Math.round(timing.handlerStart);
|
|
@@ -20,7 +16,7 @@ function resolveAppPageRscResponsePolicy(options) {
|
|
|
20
16
|
cacheState: "STATIC"
|
|
21
17
|
};
|
|
22
18
|
if (options.revalidateSeconds) return {
|
|
23
|
-
cacheControl: buildRevalidateCacheControl(options.revalidateSeconds),
|
|
19
|
+
cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),
|
|
24
20
|
cacheState: options.isProduction ? "MISS" : void 0
|
|
25
21
|
};
|
|
26
22
|
return {};
|
|
@@ -48,7 +44,7 @@ function resolveAppPageHtmlResponsePolicy(options) {
|
|
|
48
44
|
shouldWriteToCache: false
|
|
49
45
|
};
|
|
50
46
|
if (options.revalidateSeconds !== null && options.revalidateSeconds > 0 && options.revalidateSeconds !== Infinity) return {
|
|
51
|
-
cacheControl: buildRevalidateCacheControl(options.revalidateSeconds),
|
|
47
|
+
cacheControl: buildRevalidateCacheControl(options.revalidateSeconds, options.expireSeconds),
|
|
52
48
|
cacheState: options.isProduction ? "MISS" : void 0,
|
|
53
49
|
shouldWriteToCache: options.isProduction
|
|
54
50
|
};
|
|
@@ -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,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,cAAc,wBAAwB;AAGjD,MACI,QAAQ,iBAAiB,QAAQ,mBAAmB,CAAC,QAAQ,qBAC/D,QAAQ,sBAAsB,SAE9B,QAAO;EACL,cAAc;EACd,YAAY;EACb;AAGH,KAAI,QAAQ,kBACV,QAAO;EACL,cAAc,4BAA4B,QAAQ,kBAAkB;EAKpE,YAAY,QAAQ,eAAe,SAAS,KAAA;EAC7C;AAGH,QAAO,EAAE;;AAGX,SAAgB,iCACd,SAC2B;AAC3B,KAAI,QAAQ,eACV,QAAO;EACL,cAAc;EACd,oBAAoB;EACrB;AAGH,KAAI,QAAQ,eACV,QAAO;EACL,cAAc;EACd,oBAAoB;EACrB;AAOH,KAAI,QAAQ,sBAAsB,EAChC,QAAO;EACL,cAAc;EACd,oBAAoB;EACrB;AAGH,MAAK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AQ,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
|
+
{"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\";\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: \"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":";;;AA8DA,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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| null;
|
|
32
32
|
routeSegments?: readonly string[] | null;
|
|
33
|
+
/**
|
|
34
|
+
* Full URL pattern parts for the slot's mirrored sub-page. Set when the
|
|
35
|
+
* slot's params may differ from the route's (e.g. inherited slot whose
|
|
36
|
+
* dynamic markers have different names than the route's). The runtime
|
|
37
|
+
* matches the request URL against these parts to extract slot params.
|
|
38
|
+
*/
|
|
39
|
+
slotPatternParts?: readonly string[] | null; /** Param names captured by `slotPatternParts`, in order. */
|
|
40
|
+
slotParamNames?: readonly string[] | null;
|
|
33
41
|
};
|
|
34
42
|
type AppPageRouteWiringRoute<TModule extends AppPageModule = AppPageModule, TErrorModule extends AppPageErrorModule = AppPageErrorModule> = {
|
|
35
43
|
error?: TErrorModule | null;
|
|
@@ -53,7 +61,12 @@ type AppPageRouteWiringRoute<TModule extends AppPageModule = AppPageModule, TErr
|
|
|
53
61
|
};
|
|
54
62
|
type AppPageSlotOverride<TModule extends AppPageModule = AppPageModule> = {
|
|
55
63
|
layoutModules?: readonly (TModule | null | undefined)[] | null;
|
|
56
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The page module to render for this slot. Optional — when omitted, the
|
|
66
|
+
* slot's existing `page` is used (e.g. when the override only changes the
|
|
67
|
+
* slot's `params` for an inherited mirror with distinct param names).
|
|
68
|
+
*/
|
|
69
|
+
pageModule?: TModule | null;
|
|
57
70
|
params?: AppPageParams;
|
|
58
71
|
props?: Readonly<Record<string, unknown>>;
|
|
59
72
|
};
|
|
@@ -94,5 +107,5 @@ declare function createAppPageLayoutEntries<TModule extends AppPageModule, TErro
|
|
|
94
107
|
declare function resolveAppPageChildSegments(routeSegments: readonly string[], treePosition: number, params: AppPageParams): string[];
|
|
95
108
|
declare function buildAppPageElements<TModule extends AppPageModule, TErrorModule extends AppPageErrorModule>(options: BuildAppPageElementsOptions<TModule, TErrorModule>): AppElements;
|
|
96
109
|
//#endregion
|
|
97
|
-
export { AppPageModule, AppPageSlotOverride, buildAppPageElements, createAppPageLayoutEntries, createAppPageTreePath, resolveAppPageChildSegments };
|
|
110
|
+
export { AppPageErrorModule, AppPageModule, AppPageRouteWiringRoute, AppPageSlotOverride, buildAppPageElements, createAppPageLayoutEntries, createAppPageTreePath, resolveAppPageChildSegments };
|
|
98
111
|
//# sourceMappingURL=app-page-route-wiring.d.ts.map
|