vinext 0.0.52 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/build/clean-output.d.ts +14 -0
- package/dist/build/clean-output.js +36 -0
- package/dist/build/clean-output.js.map +1 -0
- package/dist/build/prerender.d.ts +6 -2
- package/dist/build/prerender.js +49 -11
- package/dist/build/prerender.js.map +1 -1
- package/dist/build/run-prerender.js +10 -1
- package/dist/build/run-prerender.js.map +1 -1
- package/dist/build/static-export.d.ts +5 -0
- package/dist/build/static-export.js +8 -3
- package/dist/build/static-export.js.map +1 -1
- package/dist/cli.js +19 -4
- package/dist/cli.js.map +1 -1
- package/dist/client/instrumentation-client-inject.d.ts +34 -0
- package/dist/client/instrumentation-client-inject.js +57 -0
- package/dist/client/instrumentation-client-inject.js.map +1 -0
- package/dist/client/navigation-runtime.d.ts +14 -1
- package/dist/client/navigation-runtime.js +16 -1
- package/dist/client/navigation-runtime.js.map +1 -1
- package/dist/client/vinext-next-data.d.ts +2 -1
- package/dist/client/vinext-next-data.js.map +1 -1
- package/dist/client/window-next.d.ts +10 -2
- package/dist/client/window-next.js.map +1 -1
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/cloudflare/tpr.js.map +1 -1
- package/dist/config/config-matchers.js +2 -1
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +12 -3
- package/dist/config/next-config.js +44 -14
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.js +29 -7
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-rsc-entry.d.ts +4 -2
- package/dist/entries/app-rsc-entry.js +23 -3
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.js +22 -1
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +211 -31
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/index.js +29 -6
- package/dist/index.js.map +1 -1
- package/dist/plugins/fonts.js +25 -2
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/routing/route-trie.js +13 -18
- package/dist/routing/route-trie.js.map +1 -1
- package/dist/routing/utils.d.ts +11 -1
- package/dist/routing/utils.js +15 -1
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.js +18 -9
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-browser-action-result.d.ts +16 -1
- package/dist/server/app-browser-action-result.js +15 -1
- package/dist/server/app-browser-action-result.js.map +1 -1
- package/dist/server/app-browser-entry.js +22 -12
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-elements.js +1 -1
- package/dist/server/app-fallback-renderer.d.ts +12 -3
- package/dist/server/app-fallback-renderer.js +10 -5
- package/dist/server/app-fallback-renderer.js.map +1 -1
- package/dist/server/app-history-state.js +6 -2
- package/dist/server/app-history-state.js.map +1 -1
- package/dist/server/app-interception-context-header.d.ts +33 -0
- package/dist/server/app-interception-context-header.js +44 -0
- package/dist/server/app-interception-context-header.js.map +1 -0
- package/dist/server/app-mounted-slots-header.d.ts +19 -0
- package/dist/server/app-mounted-slots-header.js +40 -1
- package/dist/server/app-mounted-slots-header.js.map +1 -1
- package/dist/server/app-optimistic-routing.js +26 -18
- package/dist/server/app-optimistic-routing.js.map +1 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -0
- package/dist/server/app-page-boundary-render.js +2 -0
- package/dist/server/app-page-boundary-render.js.map +1 -1
- package/dist/server/app-page-boundary.d.ts +1 -0
- package/dist/server/app-page-boundary.js +2 -0
- package/dist/server/app-page-boundary.js.map +1 -1
- package/dist/server/app-page-cache.d.ts +2 -0
- package/dist/server/app-page-cache.js +7 -1
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +3 -0
- package/dist/server/app-page-dispatch.js +11 -4
- package/dist/server/app-page-dispatch.js.map +1 -1
- package/dist/server/app-page-element-builder.d.ts +2 -1
- package/dist/server/app-page-element-builder.js +5 -2
- package/dist/server/app-page-element-builder.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +1 -0
- package/dist/server/app-page-execution.js +2 -0
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.d.ts +1 -0
- package/dist/server/app-page-head.js +8 -0
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-render.d.ts +1 -0
- package/dist/server/app-page-render.js +5 -2
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-response.d.ts +11 -1
- package/dist/server/app-page-response.js +14 -2
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.d.ts +1 -0
- package/dist/server/app-page-route-wiring.js +19 -6
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +1 -0
- package/dist/server/app-page-stream.js +2 -0
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +3 -0
- package/dist/server/app-route-handler-dispatch.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-response.js +1 -1
- package/dist/server/app-rsc-handler.d.ts +2 -0
- package/dist/server/app-rsc-handler.js +18 -9
- package/dist/server/app-rsc-handler.js.map +1 -1
- package/dist/server/app-rsc-request-normalization.js +3 -2
- package/dist/server/app-rsc-request-normalization.js.map +1 -1
- package/dist/server/app-segment-config.d.ts +4 -1
- package/dist/server/app-segment-config.js +6 -1
- package/dist/server/app-segment-config.js.map +1 -1
- package/dist/server/app-server-action-execution.d.ts +1 -0
- package/dist/server/app-server-action-execution.js +4 -0
- package/dist/server/app-server-action-execution.js.map +1 -1
- package/dist/server/app-ssr-entry.js +39 -3
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +24 -1
- package/dist/server/app-ssr-stream.js +78 -5
- package/dist/server/app-ssr-stream.js.map +1 -1
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +2 -1
- package/dist/server/app-static-generation.js.map +1 -1
- package/dist/server/default-not-found-module.d.ts +20 -0
- package/dist/server/default-not-found-module.js +20 -0
- package/dist/server/default-not-found-module.js.map +1 -0
- package/dist/server/dev-server.d.ts +1 -1
- package/dist/server/dev-server.js +23 -7
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/headers.d.ts +5 -1
- package/dist/server/headers.js +5 -1
- package/dist/server/headers.js.map +1 -1
- package/dist/server/image-optimization.d.ts +13 -4
- package/dist/server/image-optimization.js +15 -4
- package/dist/server/image-optimization.js.map +1 -1
- package/dist/server/middleware.js +1 -1
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/pages-api-route.d.ts +18 -0
- package/dist/server/pages-api-route.js +3 -1
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-body-parser-config.d.ts +60 -0
- package/dist/server/pages-body-parser-config.js +79 -0
- package/dist/server/pages-body-parser-config.js.map +1 -0
- package/dist/server/pages-data-route.js +1 -0
- package/dist/server/pages-data-route.js.map +1 -1
- package/dist/server/pages-default-404.d.ts +31 -0
- package/dist/server/pages-default-404.js +40 -0
- package/dist/server/pages-default-404.js.map +1 -0
- package/dist/server/pages-node-compat.d.ts +10 -0
- package/dist/server/pages-node-compat.js +12 -1
- package/dist/server/pages-node-compat.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +40 -0
- package/dist/server/pages-page-data.js +16 -14
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +2 -0
- package/dist/server/pages-page-response.js +11 -8
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prerender-route-params.d.ts +14 -0
- package/dist/server/prerender-route-params.js +94 -0
- package/dist/server/prerender-route-params.js.map +1 -0
- package/dist/server/prod-server.d.ts +3 -23
- package/dist/server/prod-server.js +40 -57
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/proxy-trust.d.ts +41 -0
- package/dist/server/proxy-trust.js +70 -0
- package/dist/server/proxy-trust.js.map +1 -0
- package/dist/server/request-pipeline.d.ts +3 -3
- package/dist/server/request-pipeline.js +5 -4
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/seed-cache.js +12 -6
- package/dist/server/seed-cache.js.map +1 -1
- package/dist/server/static-file-cache.js +1 -1
- package/dist/server/static-file-cache.js.map +1 -1
- package/dist/server/streaming-metadata.d.ts +5 -0
- package/dist/server/streaming-metadata.js +10 -0
- package/dist/server/streaming-metadata.js.map +1 -0
- package/dist/shims/app-router-scroll-state.d.ts +12 -0
- package/dist/shims/app-router-scroll-state.js +38 -0
- package/dist/shims/app-router-scroll-state.js.map +1 -0
- package/dist/shims/app-router-scroll.d.ts +14 -0
- package/dist/shims/app-router-scroll.js +100 -0
- package/dist/shims/app-router-scroll.js.map +1 -0
- package/dist/shims/before-interactive-context.d.ts +30 -0
- package/dist/shims/before-interactive-context.js +10 -0
- package/dist/shims/before-interactive-context.js.map +1 -0
- package/dist/shims/cache-runtime.d.ts +1 -1
- package/dist/shims/cache-runtime.js +14 -1
- package/dist/shims/cache-runtime.js.map +1 -1
- package/dist/shims/default-not-found.d.ts +12 -0
- package/dist/shims/default-not-found.js +61 -0
- package/dist/shims/default-not-found.js.map +1 -0
- package/dist/shims/font-local.d.ts +5 -0
- package/dist/shims/font-local.js +6 -2
- package/dist/shims/font-local.js.map +1 -1
- package/dist/shims/head.js +4 -4
- package/dist/shims/head.js.map +1 -1
- package/dist/shims/headers.d.ts +6 -2
- package/dist/shims/headers.js +64 -21
- package/dist/shims/headers.js.map +1 -1
- package/dist/shims/image.d.ts +1 -1
- package/dist/shims/image.js +4 -4
- package/dist/shims/image.js.map +1 -1
- package/dist/shims/internal/pages-data-target.d.ts +58 -0
- package/dist/shims/internal/pages-data-target.js +91 -0
- package/dist/shims/internal/pages-data-target.js.map +1 -0
- package/dist/shims/internal/pages-data-url.d.ts +42 -0
- package/dist/shims/internal/pages-data-url.js +73 -0
- package/dist/shims/internal/pages-data-url.js.map +1 -0
- package/dist/shims/link.js +59 -9
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.d.ts +2 -1
- package/dist/shims/metadata.js +61 -2
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.js +32 -9
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/router.js +376 -77
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/script.js +86 -12
- package/dist/shims/script.js.map +1 -1
- package/dist/shims/server.js +1 -0
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/url-utils.d.ts +2 -1
- package/dist/shims/url-utils.js +15 -4
- package/dist/shims/url-utils.js.map +1 -1
- package/dist/utils/html-limited-bots.d.ts +5 -0
- package/dist/utils/html-limited-bots.js +15 -0
- package/dist/utils/html-limited-bots.js.map +1 -0
- package/dist/utils/query.d.ts +6 -0
- package/dist/utils/query.js +10 -1
- package/dist/utils/query.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-fallback-renderer.js","names":[],"sources":["../../src/server/app-fallback-renderer.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { AppPageParams } from \"./app-page-boundary.js\";\nimport {\n renderAppPageErrorBoundary,\n renderAppPageHttpAccessFallback,\n type AppPageBoundaryRoute,\n} from \"./app-page-boundary-render.js\";\nimport { DEFAULT_GLOBAL_ERROR_MODULE } from \"./default-global-error-module.js\";\nimport type { AppPageFontPreload } from \"./app-page-execution.js\";\nimport type { AppPageMiddlewareContext } from \"./app-page-response.js\";\nimport type { AppPageSsrHandler } from \"./app-page-stream.js\";\nimport type { MetadataFileRoute } from \"./metadata-routes.js\";\nimport type { AppElements } from \"./app-elements.js\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype AppPageComponent = import(\"react\").ComponentType<any>;\ntype AppPageModule = Record<string, unknown> & {\n default?: AppPageComponent | null | undefined;\n};\ntype AppPageBoundaryOnError = (\n error: unknown,\n requestInfo: unknown,\n errorContext: unknown,\n) => unknown;\n\ntype AppFallbackRendererRootBoundaries<TModule extends AppPageModule = AppPageModule> = {\n rootForbiddenModule?: TModule | null;\n rootLayouts: readonly (TModule | null | undefined)[];\n rootNotFoundModule?: TModule | null;\n rootUnauthorizedModule?: TModule | null;\n};\n\ntype AppFallbackRendererFontProviders = {\n buildFontLinkHeader: (preloads: readonly AppPageFontPreload[] | null | undefined) => string;\n getFontLinks: () => string[];\n getFontPreloads: () => AppPageFontPreload[];\n getFontStyles: () => string[];\n};\n\ntype AppFallbackRendererOptions<TModule extends AppPageModule = AppPageModule> = {\n clearRequestContext: () => void;\n createRscOnErrorHandler: (\n request: Request,\n pathname: string,\n routePath: string,\n ) => AppPageBoundaryOnError;\n fontProviders: AppFallbackRendererFontProviders;\n getNavigationContext: () => unknown;\n globalErrorModule?: TModule | null;\n /**\n * Optional `app/global-not-found.tsx` module. When provided, route-miss 404s\n * render this module as a standalone document (skipping the root layout)\n * because it ships its own `<html>` and `<body>`. Page-triggered `notFound()`\n * calls continue to use the regular `not-found.tsx` boundary inside layouts.\n * @see https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/app-render.tsx\n */\n globalNotFoundModule?: TModule | null;\n makeThenableParams: (params: AppPageParams) => unknown;\n metadataRoutes: MetadataFileRoute[];\n /** Configured next.config `basePath`, threaded into file-based metadata href emission. */\n basePath?: string;\n resolveChildSegments: (\n routeSegments: readonly string[],\n treePosition: number,\n params: AppPageParams,\n ) => string[];\n rootBoundaries: AppFallbackRendererRootBoundaries<TModule>;\n rscRenderer: (\n element: ReactNode | AppElements,\n options: { onError: AppPageBoundaryOnError },\n ) => ReadableStream<Uint8Array>;\n sanitizer: (error: Error) => Error;\n ssrLoader: () => Promise<AppPageSsrHandler>;\n};\n\ntype AppFallbackRenderer<TModule extends AppPageModule = AppPageModule> = {\n renderErrorBoundary: (\n route: AppPageBoundaryRoute<TModule> | null,\n error: unknown,\n isRscRequest: boolean,\n request: Request,\n matchedParams: AppPageParams | undefined,\n scriptNonce: string | undefined,\n middlewareContext: AppPageMiddlewareContext,\n ) => Promise<Response | null>;\n renderHttpAccessFallback: (\n route: AppPageBoundaryRoute<TModule> | null,\n statusCode: number,\n isRscRequest: boolean,\n request: Request,\n opts: {\n boundaryComponent?: AppPageComponent | null;\n layouts?: readonly (TModule | null | undefined)[] | null;\n matchedParams?: AppPageParams;\n },\n scriptNonce: string | undefined,\n middlewareContext: AppPageMiddlewareContext,\n ) => Promise<Response | null>;\n renderNotFound: (\n route: AppPageBoundaryRoute<TModule> | null,\n isRscRequest: boolean,\n request: Request,\n matchedParams: AppPageParams | undefined,\n scriptNonce: string | undefined,\n middlewareContext: AppPageMiddlewareContext,\n ) => Promise<Response | null>;\n};\n\nconst EMPTY_MW_CTX: AppPageMiddlewareContext = { headers: null, status: null };\n\nexport function createAppFallbackRenderer<TModule extends AppPageModule>(\n options: AppFallbackRendererOptions<TModule>,\n): AppFallbackRenderer<TModule> {\n const {\n basePath = \"\",\n clearRequestContext,\n createRscOnErrorHandler: buildRscOnErrorHandler,\n fontProviders,\n getNavigationContext,\n globalErrorModule,\n globalNotFoundModule,\n makeThenableParams,\n metadataRoutes,\n resolveChildSegments,\n rootBoundaries,\n rscRenderer,\n sanitizer,\n ssrLoader,\n } = options;\n\n const { rootForbiddenModule, rootLayouts, rootNotFoundModule, rootUnauthorizedModule } =\n rootBoundaries;\n\n // When the app does not define `app/global-error.tsx`, fall back to vinext's\n // built-in default global error component so that uncaught render errors\n // produce the same UI Next.js ships out of the box (matching markup, inline\n // styles, theme CSS, and the \"ERROR <digest>\" footer for server errors).\n // See packages/vinext/src/shims/default-global-error.tsx and\n // packages/vinext/src/server/default-global-error-module.ts.\n const effectiveGlobalErrorModule: TModule | null =\n globalErrorModule ?? (DEFAULT_GLOBAL_ERROR_MODULE as unknown as TModule);\n\n return {\n renderHttpAccessFallback(\n route,\n statusCode,\n isRscRequest,\n request,\n opts,\n scriptNonce,\n middlewareContext,\n ) {\n // global-not-found.tsx replaces the root layout for route-miss 404s.\n // Only applies when:\n // - The user defined app/global-not-found.tsx\n // - The 404 originates from a route miss (no matched route)\n // - The caller did not already pick a specific boundary component\n // Page-triggered notFound() calls (route is non-null) keep using the\n // regular not-found.tsx boundary inside the route's layouts.\n // See https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/app-render.tsx#L495-L520\n const useGlobalNotFound =\n statusCode === 404 && !!globalNotFoundModule && !route && !opts?.boundaryComponent;\n\n if (useGlobalNotFound) {\n const globalNotFoundComponent = globalNotFoundModule?.default ?? null;\n if (globalNotFoundComponent) {\n return renderAppPageHttpAccessFallback({\n boundaryComponent: globalNotFoundComponent,\n buildFontLinkHeader: fontProviders.buildFontLinkHeader,\n clearRequestContext,\n createRscOnErrorHandler(pathname, routePath) {\n return buildRscOnErrorHandler(request, pathname, routePath);\n },\n getFontLinks: fontProviders.getFontLinks,\n getFontPreloads: fontProviders.getFontPreloads,\n getFontStyles: fontProviders.getFontStyles,\n getNavigationContext,\n globalErrorModule: effectiveGlobalErrorModule,\n isRscRequest,\n layoutModules: [],\n loadSsrHandler: ssrLoader,\n makeThenableParams,\n matchedParams: opts?.matchedParams ?? {},\n middlewareContext: middlewareContext ?? EMPTY_MW_CTX,\n metadataRoutes,\n requestUrl: request.url,\n resolveChildSegments,\n rootForbiddenModule: null,\n rootLayouts: [],\n rootNotFoundModule: null,\n rootUnauthorizedModule: null,\n route: null,\n renderToReadableStream: rscRenderer,\n scriptNonce,\n skipLayoutWrapping: true,\n statusCode,\n });\n }\n }\n\n return renderAppPageHttpAccessFallback({\n basePath,\n boundaryComponent: opts?.boundaryComponent ?? null,\n buildFontLinkHeader: fontProviders.buildFontLinkHeader,\n clearRequestContext,\n createRscOnErrorHandler(pathname, routePath) {\n return buildRscOnErrorHandler(request, pathname, routePath);\n },\n getFontLinks: fontProviders.getFontLinks,\n getFontPreloads: fontProviders.getFontPreloads,\n getFontStyles: fontProviders.getFontStyles,\n getNavigationContext,\n globalErrorModule: effectiveGlobalErrorModule,\n isRscRequest,\n layoutModules: opts?.layouts ?? null,\n loadSsrHandler: ssrLoader,\n makeThenableParams,\n matchedParams: opts?.matchedParams ?? route?.params ?? {},\n middlewareContext: middlewareContext ?? EMPTY_MW_CTX,\n metadataRoutes,\n requestUrl: request.url,\n resolveChildSegments,\n rootForbiddenModule,\n rootLayouts,\n rootNotFoundModule,\n rootUnauthorizedModule,\n route,\n renderToReadableStream: rscRenderer,\n scriptNonce,\n statusCode,\n });\n },\n\n renderNotFound(route, isRscRequest, request, matchedParams, scriptNonce, middlewareContext) {\n return this.renderHttpAccessFallback(\n route,\n 404,\n isRscRequest,\n request,\n { matchedParams },\n scriptNonce,\n middlewareContext,\n );\n },\n\n renderErrorBoundary(\n route,\n error,\n isRscRequest,\n request,\n matchedParams,\n scriptNonce,\n middlewareContext,\n ) {\n return renderAppPageErrorBoundary({\n basePath,\n buildFontLinkHeader: fontProviders.buildFontLinkHeader,\n clearRequestContext,\n createRscOnErrorHandler(pathname, routePath) {\n return buildRscOnErrorHandler(request, pathname, routePath);\n },\n error,\n getFontLinks: fontProviders.getFontLinks,\n getFontPreloads: fontProviders.getFontPreloads,\n getFontStyles: fontProviders.getFontStyles,\n getNavigationContext,\n globalErrorModule: effectiveGlobalErrorModule,\n isRscRequest,\n loadSsrHandler: ssrLoader,\n makeThenableParams,\n matchedParams: matchedParams ?? route?.params ?? {},\n middlewareContext: middlewareContext ?? EMPTY_MW_CTX,\n metadataRoutes,\n requestUrl: request.url,\n resolveChildSegments,\n rootLayouts,\n route,\n renderToReadableStream: rscRenderer,\n sanitizeErrorForClient: sanitizer,\n scriptNonce,\n });\n },\n };\n}\n"],"mappings":";;;AA4GA,MAAM,eAAyC;CAAE,SAAS;CAAM,QAAQ;CAAM;AAE9E,SAAgB,0BACd,SAC8B;CAC9B,MAAM,EACJ,WAAW,IACX,qBACA,y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,eAAe,OAAO,cAAc,SAAS,eAAe,aAAa,mBAAmB;GAC1F,OAAO,KAAK,yBACV,OACA,KACA,cACA,SACA,EAAE,eAAe,EACjB,aACA,kBACD;;EAGH,oBACE,OACA,OACA,cACA,SACA,eACA,aACA,mBACA;GACA,OAAO,2BAA2B;IAChC;IACA,qBAAqB,cAAc;IACnC;IACA,wBAAwB,UAAU,WAAW;KAC3C,OAAO,uBAAuB,SAAS,UAAU,UAAU;;IAE7D;IACA,cAAc,cAAc;IAC5B,iBAAiB,cAAc;IAC/B,eAAe,cAAc;IAC7B;IACA,mBAAmB;IACnB;IACA,gBAAgB;IAChB;IACA,eAAe,iBAAiB,OAAO,UAAU,EAAE;IACnD,mBAAmB,qBAAqB;IACxC;IACA,YAAY,QAAQ;IACpB;IACA;IACA;IACA,wBAAwB;IACxB,wBAAwB;IACxB;IACD,CAAC;;EAEL"}
|
|
1
|
+
{"version":3,"file":"app-fallback-renderer.js","names":[],"sources":["../../src/server/app-fallback-renderer.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { AppPageParams } from \"./app-page-boundary.js\";\nimport {\n renderAppPageErrorBoundary,\n renderAppPageHttpAccessFallback,\n type AppPageBoundaryRoute,\n} from \"./app-page-boundary-render.js\";\nimport { DEFAULT_GLOBAL_ERROR_MODULE } from \"./default-global-error-module.js\";\nimport { DEFAULT_NOT_FOUND_MODULE } from \"./default-not-found-module.js\";\nimport type { AppPageFontPreload } from \"./app-page-execution.js\";\nimport type { AppPageMiddlewareContext } from \"./app-page-response.js\";\nimport type { AppPageSsrHandler } from \"./app-page-stream.js\";\nimport type { MetadataFileRoute } from \"./metadata-routes.js\";\nimport type { AppElements } from \"./app-elements.js\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype AppPageComponent = import(\"react\").ComponentType<any>;\ntype AppPageModule = Record<string, unknown> & {\n default?: AppPageComponent | null | undefined;\n};\ntype AppPageBoundaryOnError = (\n error: unknown,\n requestInfo: unknown,\n errorContext: unknown,\n) => unknown;\n\ntype AppFallbackRendererRootBoundaries<TModule extends AppPageModule = AppPageModule> = {\n rootForbiddenModule?: TModule | null;\n rootLayouts: readonly (TModule | null | undefined)[];\n rootNotFoundModule?: TModule | null;\n rootUnauthorizedModule?: TModule | null;\n};\n\ntype AppFallbackRendererFontProviders = {\n buildFontLinkHeader: (preloads: readonly AppPageFontPreload[] | null | undefined) => string;\n getFontLinks: () => string[];\n getFontPreloads: () => AppPageFontPreload[];\n getFontStyles: () => string[];\n};\n\ntype AppFallbackRendererOptions<TModule extends AppPageModule = AppPageModule> = {\n clearRequestContext: () => void;\n createRscOnErrorHandler: (\n request: Request,\n pathname: string,\n routePath: string,\n ) => AppPageBoundaryOnError;\n fontProviders: AppFallbackRendererFontProviders;\n getNavigationContext: () => unknown;\n globalErrorModule?: TModule | null;\n /**\n * Optional `app/global-not-found.tsx` module. When provided, route-miss 404s\n * render this module as a standalone document (skipping the root layout)\n * because it ships its own `<html>` and `<body>`. Page-triggered `notFound()`\n * calls continue to use the regular `not-found.tsx` boundary inside layouts.\n * @see https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/app-render.tsx\n */\n globalNotFoundModule?: TModule | null;\n makeThenableParams: (params: AppPageParams) => unknown;\n metadataRoutes: MetadataFileRoute[];\n /** Configured next.config `basePath`, threaded into file-based metadata href emission. */\n basePath?: string;\n resolveChildSegments: (\n routeSegments: readonly string[],\n treePosition: number,\n params: AppPageParams,\n ) => string[];\n rootBoundaries: AppFallbackRendererRootBoundaries<TModule>;\n rscRenderer: (\n element: ReactNode | AppElements,\n options: { onError: AppPageBoundaryOnError },\n ) => ReadableStream<Uint8Array>;\n sanitizer: (error: Error) => Error;\n ssrLoader: () => Promise<AppPageSsrHandler>;\n};\n\ntype AppFallbackRendererCallContext = {\n /**\n * Whether the matched (or invoking) route opts into Next.js' edge runtime via\n * `export const runtime = \"edge\"`. Propagated so boundary/error/not-found\n * responses carry `x-edge-runtime: 1` for edge routes, matching the page\n * render path. Defaults to `false` when no route is matched.\n */\n isEdgeRuntime?: boolean;\n};\n\ntype AppFallbackRenderer<TModule extends AppPageModule = AppPageModule> = {\n renderErrorBoundary: (\n route: AppPageBoundaryRoute<TModule> | null,\n error: unknown,\n isRscRequest: boolean,\n request: Request,\n matchedParams: AppPageParams | undefined,\n scriptNonce: string | undefined,\n middlewareContext: AppPageMiddlewareContext,\n callContext?: AppFallbackRendererCallContext,\n ) => Promise<Response | null>;\n renderHttpAccessFallback: (\n route: AppPageBoundaryRoute<TModule> | null,\n statusCode: number,\n isRscRequest: boolean,\n request: Request,\n opts: {\n boundaryComponent?: AppPageComponent | null;\n layouts?: readonly (TModule | null | undefined)[] | null;\n matchedParams?: AppPageParams;\n },\n scriptNonce: string | undefined,\n middlewareContext: AppPageMiddlewareContext,\n callContext?: AppFallbackRendererCallContext,\n ) => Promise<Response | null>;\n renderNotFound: (\n route: AppPageBoundaryRoute<TModule> | null,\n isRscRequest: boolean,\n request: Request,\n matchedParams: AppPageParams | undefined,\n scriptNonce: string | undefined,\n middlewareContext: AppPageMiddlewareContext,\n callContext?: AppFallbackRendererCallContext,\n ) => Promise<Response | null>;\n};\n\nconst EMPTY_MW_CTX: AppPageMiddlewareContext = { headers: null, status: null };\n\nexport function createAppFallbackRenderer<TModule extends AppPageModule>(\n options: AppFallbackRendererOptions<TModule>,\n): AppFallbackRenderer<TModule> {\n const {\n basePath = \"\",\n clearRequestContext,\n createRscOnErrorHandler: buildRscOnErrorHandler,\n fontProviders,\n getNavigationContext,\n globalErrorModule,\n globalNotFoundModule,\n makeThenableParams,\n metadataRoutes,\n resolveChildSegments,\n rootBoundaries,\n rscRenderer,\n sanitizer,\n ssrLoader,\n } = options;\n\n const { rootForbiddenModule, rootLayouts, rootNotFoundModule, rootUnauthorizedModule } =\n rootBoundaries;\n\n // When the app does not define `app/global-error.tsx`, fall back to vinext's\n // built-in default global error component so that uncaught render errors\n // produce the same UI Next.js ships out of the box (matching markup, inline\n // styles, theme CSS, and the \"ERROR <digest>\" footer for server errors).\n // See packages/vinext/src/shims/default-global-error.tsx and\n // packages/vinext/src/server/default-global-error-module.ts.\n const effectiveGlobalErrorModule: TModule | null =\n globalErrorModule ?? (DEFAULT_GLOBAL_ERROR_MODULE as unknown as TModule);\n\n // When the app does not define `app/not-found.tsx` (and has not opted into\n // `app/global-not-found.tsx`), fall back to vinext's built-in default\n // not-found component so route-miss 404s render the canonical Next.js\n // markup (status + \"This page could not be found.\" message). Matches the\n // default not-found UI shipped with Next.js's app loader.\n // See packages/vinext/src/shims/default-not-found.tsx and\n // packages/vinext/src/server/default-not-found-module.ts.\n const effectiveRootNotFoundModule: TModule | null =\n rootNotFoundModule ?? (DEFAULT_NOT_FOUND_MODULE as unknown as TModule);\n\n return {\n renderHttpAccessFallback(\n route,\n statusCode,\n isRscRequest,\n request,\n opts,\n scriptNonce,\n middlewareContext,\n callContext,\n ) {\n // global-not-found.tsx replaces the root layout for route-miss 404s.\n // Only applies when:\n // - The user defined app/global-not-found.tsx\n // - The 404 originates from a route miss (no matched route)\n // - The caller did not already pick a specific boundary component\n // Page-triggered notFound() calls (route is non-null) keep using the\n // regular not-found.tsx boundary inside the route's layouts.\n // See https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/app-render.tsx#L495-L520\n const useGlobalNotFound =\n statusCode === 404 && !!globalNotFoundModule && !route && !opts?.boundaryComponent;\n\n if (useGlobalNotFound) {\n const globalNotFoundComponent = globalNotFoundModule?.default ?? null;\n if (globalNotFoundComponent) {\n return renderAppPageHttpAccessFallback({\n boundaryComponent: globalNotFoundComponent,\n buildFontLinkHeader: fontProviders.buildFontLinkHeader,\n clearRequestContext,\n createRscOnErrorHandler(pathname, routePath) {\n return buildRscOnErrorHandler(request, pathname, routePath);\n },\n getFontLinks: fontProviders.getFontLinks,\n getFontPreloads: fontProviders.getFontPreloads,\n getFontStyles: fontProviders.getFontStyles,\n getNavigationContext,\n globalErrorModule: effectiveGlobalErrorModule,\n isEdgeRuntime: callContext?.isEdgeRuntime,\n isRscRequest,\n layoutModules: [],\n loadSsrHandler: ssrLoader,\n makeThenableParams,\n matchedParams: opts?.matchedParams ?? {},\n middlewareContext: middlewareContext ?? EMPTY_MW_CTX,\n metadataRoutes,\n requestUrl: request.url,\n resolveChildSegments,\n rootForbiddenModule: null,\n rootLayouts: [],\n rootNotFoundModule: null,\n rootUnauthorizedModule: null,\n route: null,\n renderToReadableStream: rscRenderer,\n scriptNonce,\n skipLayoutWrapping: true,\n statusCode,\n });\n }\n }\n\n return renderAppPageHttpAccessFallback({\n basePath,\n boundaryComponent: opts?.boundaryComponent ?? null,\n buildFontLinkHeader: fontProviders.buildFontLinkHeader,\n clearRequestContext,\n createRscOnErrorHandler(pathname, routePath) {\n return buildRscOnErrorHandler(request, pathname, routePath);\n },\n getFontLinks: fontProviders.getFontLinks,\n getFontPreloads: fontProviders.getFontPreloads,\n getFontStyles: fontProviders.getFontStyles,\n getNavigationContext,\n globalErrorModule: effectiveGlobalErrorModule,\n isEdgeRuntime: callContext?.isEdgeRuntime,\n isRscRequest,\n layoutModules: opts?.layouts ?? null,\n loadSsrHandler: ssrLoader,\n makeThenableParams,\n matchedParams: opts?.matchedParams ?? route?.params ?? {},\n middlewareContext: middlewareContext ?? EMPTY_MW_CTX,\n metadataRoutes,\n requestUrl: request.url,\n resolveChildSegments,\n rootForbiddenModule,\n rootLayouts,\n rootNotFoundModule: effectiveRootNotFoundModule,\n rootUnauthorizedModule,\n route,\n renderToReadableStream: rscRenderer,\n scriptNonce,\n statusCode,\n });\n },\n\n renderNotFound(\n route,\n isRscRequest,\n request,\n matchedParams,\n scriptNonce,\n middlewareContext,\n callContext,\n ) {\n return this.renderHttpAccessFallback(\n route,\n 404,\n isRscRequest,\n request,\n { matchedParams },\n scriptNonce,\n middlewareContext,\n callContext,\n );\n },\n\n renderErrorBoundary(\n route,\n error,\n isRscRequest,\n request,\n matchedParams,\n scriptNonce,\n middlewareContext,\n callContext,\n ) {\n return renderAppPageErrorBoundary({\n basePath,\n buildFontLinkHeader: fontProviders.buildFontLinkHeader,\n clearRequestContext,\n createRscOnErrorHandler(pathname, routePath) {\n return buildRscOnErrorHandler(request, pathname, routePath);\n },\n error,\n getFontLinks: fontProviders.getFontLinks,\n getFontPreloads: fontProviders.getFontPreloads,\n getFontStyles: fontProviders.getFontStyles,\n getNavigationContext,\n globalErrorModule: effectiveGlobalErrorModule,\n isEdgeRuntime: callContext?.isEdgeRuntime,\n isRscRequest,\n loadSsrHandler: ssrLoader,\n makeThenableParams,\n matchedParams: matchedParams ?? route?.params ?? {},\n middlewareContext: middlewareContext ?? EMPTY_MW_CTX,\n metadataRoutes,\n requestUrl: request.url,\n resolveChildSegments,\n rootLayouts,\n route,\n renderToReadableStream: rscRenderer,\n sanitizeErrorForClient: sanitizer,\n scriptNonce,\n });\n },\n };\n}\n"],"mappings":";;;;AA0HA,MAAM,eAAyC;CAAE,SAAS;CAAM,QAAQ;CAAM;AAE9E,SAAgB,0BACd,SAC8B;CAC9B,MAAM,EACJ,WAAW,IACX,qBACA,yBAAyB,wBACzB,eACA,sBACA,mBACA,sBACA,oBACA,gBACA,sBACA,gBACA,aACA,WACA,cACE;CAEJ,MAAM,EAAE,qBAAqB,aAAa,oBAAoB,2BAC5D;CAQF,MAAM,6BACJ,qBAAsB;CASxB,MAAM,8BACJ,sBAAuB;CAEzB,OAAO;EACL,yBACE,OACA,YACA,cACA,SACA,MACA,aACA,mBACA,aACA;GAYA,IAFE,eAAe,OAAO,CAAC,CAAC,wBAAwB,CAAC,SAAS,CAAC,MAAM,mBAE5C;IACrB,MAAM,0BAA0B,sBAAsB,WAAW;IACjE,IAAI,yBACF,OAAO,gCAAgC;KACrC,mBAAmB;KACnB,qBAAqB,cAAc;KACnC;KACA,wBAAwB,UAAU,WAAW;MAC3C,OAAO,uBAAuB,SAAS,UAAU,UAAU;;KAE7D,cAAc,cAAc;KAC5B,iBAAiB,cAAc;KAC/B,eAAe,cAAc;KAC7B;KACA,mBAAmB;KACnB,eA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pB;IACA;IACA;IACA,wBAAwB;IACxB,wBAAwB;IACxB;IACD,CAAC;;EAEL"}
|
|
@@ -20,8 +20,12 @@ function createHistoryStateWithNavigationMetadata(state, metadata) {
|
|
|
20
20
|
}
|
|
21
21
|
function createExternalHistoryStatePreservingMetadata(callerState, currentHistoryState) {
|
|
22
22
|
const previousNextUrl = readHistoryStatePreviousNextUrl(currentHistoryState);
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const traversalIndex = readHistoryStateTraversalIndex(currentHistoryState);
|
|
24
|
+
if (previousNextUrl === null && traversalIndex === null) return callerState;
|
|
25
|
+
return createHistoryStateWithNavigationMetadata(callerState, {
|
|
26
|
+
previousNextUrl,
|
|
27
|
+
traversalIndex
|
|
28
|
+
});
|
|
25
29
|
}
|
|
26
30
|
function readHistoryStatePreviousNextUrl(state) {
|
|
27
31
|
const value = cloneHistoryState(state)[VINEXT_PREVIOUS_NEXT_URL_HISTORY_STATE_KEY];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-history-state.js","names":[],"sources":["../../src/server/app-history-state.ts"],"sourcesContent":["import type { TraverseDirection } from \"./navigation-planner.js\";\n\nconst VINEXT_PREVIOUS_NEXT_URL_HISTORY_STATE_KEY = \"__vinext_previousNextUrl\";\nconst VINEXT_HISTORY_INDEX_HISTORY_STATE_KEY = \"__vinext_historyIndex\";\n\ntype HistoryStateRecord = {\n [key: string]: unknown;\n};\n\nexport type HistoryTraversalIntent = {\n direction: TraverseDirection;\n historyState: unknown;\n targetHistoryIndex: number | null;\n};\n\nfunction cloneHistoryState(state: unknown): HistoryStateRecord {\n if (!state || typeof state !== \"object\") {\n return {};\n }\n\n const nextState: HistoryStateRecord = {};\n for (const [key, value] of Object.entries(state)) {\n nextState[key] = value;\n }\n return nextState;\n}\n\nexport function createHistoryStateWithPreviousNextUrl(\n state: unknown,\n previousNextUrl: string | null,\n): HistoryStateRecord | null {\n return createHistoryStateWithNavigationMetadata(state, { previousNextUrl });\n}\n\nexport function createHistoryStateWithNavigationMetadata(\n state: unknown,\n metadata: {\n previousNextUrl: string | null;\n traversalIndex?: number | null;\n },\n): HistoryStateRecord | null {\n const nextState = cloneHistoryState(state);\n\n if (metadata.previousNextUrl === null) {\n delete nextState[VINEXT_PREVIOUS_NEXT_URL_HISTORY_STATE_KEY];\n } else {\n nextState[VINEXT_PREVIOUS_NEXT_URL_HISTORY_STATE_KEY] = metadata.previousNextUrl;\n }\n\n if (metadata.traversalIndex !== undefined) {\n if (isValidHistoryTraversalIndex(metadata.traversalIndex)) {\n nextState[VINEXT_HISTORY_INDEX_HISTORY_STATE_KEY] = metadata.traversalIndex;\n } else {\n delete nextState[VINEXT_HISTORY_INDEX_HISTORY_STATE_KEY];\n }\n }\n\n return Object.keys(nextState).length > 0 ? nextState : null;\n}\n\nexport function createExternalHistoryStatePreservingMetadata(\n callerState: unknown,\n currentHistoryState: unknown,\n): unknown {\n const previousNextUrl = readHistoryStatePreviousNextUrl(currentHistoryState);\n if (previousNextUrl === null) {\n return callerState;\n }\n\n return
|
|
1
|
+
{"version":3,"file":"app-history-state.js","names":[],"sources":["../../src/server/app-history-state.ts"],"sourcesContent":["import type { TraverseDirection } from \"./navigation-planner.js\";\n\nconst VINEXT_PREVIOUS_NEXT_URL_HISTORY_STATE_KEY = \"__vinext_previousNextUrl\";\nconst VINEXT_HISTORY_INDEX_HISTORY_STATE_KEY = \"__vinext_historyIndex\";\n\ntype HistoryStateRecord = {\n [key: string]: unknown;\n};\n\nexport type HistoryTraversalIntent = {\n direction: TraverseDirection;\n historyState: unknown;\n targetHistoryIndex: number | null;\n};\n\nfunction cloneHistoryState(state: unknown): HistoryStateRecord {\n if (!state || typeof state !== \"object\") {\n return {};\n }\n\n const nextState: HistoryStateRecord = {};\n for (const [key, value] of Object.entries(state)) {\n nextState[key] = value;\n }\n return nextState;\n}\n\nexport function createHistoryStateWithPreviousNextUrl(\n state: unknown,\n previousNextUrl: string | null,\n): HistoryStateRecord | null {\n return createHistoryStateWithNavigationMetadata(state, { previousNextUrl });\n}\n\nexport function createHistoryStateWithNavigationMetadata(\n state: unknown,\n metadata: {\n previousNextUrl: string | null;\n traversalIndex?: number | null;\n },\n): HistoryStateRecord | null {\n const nextState = cloneHistoryState(state);\n\n if (metadata.previousNextUrl === null) {\n delete nextState[VINEXT_PREVIOUS_NEXT_URL_HISTORY_STATE_KEY];\n } else {\n nextState[VINEXT_PREVIOUS_NEXT_URL_HISTORY_STATE_KEY] = metadata.previousNextUrl;\n }\n\n if (metadata.traversalIndex !== undefined) {\n if (isValidHistoryTraversalIndex(metadata.traversalIndex)) {\n nextState[VINEXT_HISTORY_INDEX_HISTORY_STATE_KEY] = metadata.traversalIndex;\n } else {\n delete nextState[VINEXT_HISTORY_INDEX_HISTORY_STATE_KEY];\n }\n }\n\n return Object.keys(nextState).length > 0 ? nextState : null;\n}\n\nexport function createExternalHistoryStatePreservingMetadata(\n callerState: unknown,\n currentHistoryState: unknown,\n): unknown {\n const previousNextUrl = readHistoryStatePreviousNextUrl(currentHistoryState);\n const traversalIndex = readHistoryStateTraversalIndex(currentHistoryState);\n\n if (previousNextUrl === null && traversalIndex === null) {\n return callerState;\n }\n\n return createHistoryStateWithNavigationMetadata(callerState, {\n previousNextUrl,\n traversalIndex,\n });\n}\n\nexport function readHistoryStatePreviousNextUrl(state: unknown): string | null {\n const value = cloneHistoryState(state)[VINEXT_PREVIOUS_NEXT_URL_HISTORY_STATE_KEY];\n return typeof value === \"string\" ? value : null;\n}\n\nfunction isValidHistoryTraversalIndex(value: unknown): value is number {\n return typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nexport function readHistoryStateTraversalIndex(state: unknown): number | null {\n const value = cloneHistoryState(state)[VINEXT_HISTORY_INDEX_HISTORY_STATE_KEY];\n return isValidHistoryTraversalIndex(value) ? value : null;\n}\n\nexport function resolveHistoryTraversalIntent(options: {\n currentHistoryIndex: number | null;\n historyState: unknown;\n}): HistoryTraversalIntent {\n const targetHistoryIndex = readHistoryStateTraversalIndex(options.historyState);\n let direction: TraverseDirection = \"unknown\";\n\n if (options.currentHistoryIndex !== null && targetHistoryIndex !== null) {\n if (targetHistoryIndex < options.currentHistoryIndex) {\n direction = \"back\";\n } else if (targetHistoryIndex > options.currentHistoryIndex) {\n direction = \"forward\";\n }\n }\n\n return {\n direction,\n historyState: options.historyState,\n targetHistoryIndex,\n };\n}\n"],"mappings":";AAEA,MAAM,6CAA6C;AACnD,MAAM,yCAAyC;AAY/C,SAAS,kBAAkB,OAAoC;CAC7D,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,OAAO,EAAE;CAGX,MAAM,YAAgC,EAAE;CACxC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,MAAM,EAC9C,UAAU,OAAO;CAEnB,OAAO;;AAGT,SAAgB,sCACd,OACA,iBAC2B;CAC3B,OAAO,yCAAyC,OAAO,EAAE,iBAAiB,CAAC;;AAG7E,SAAgB,yCACd,OACA,UAI2B;CAC3B,MAAM,YAAY,kBAAkB,MAAM;CAE1C,IAAI,SAAS,oBAAoB,MAC/B,OAAO,UAAU;MAEjB,UAAU,8CAA8C,SAAS;CAGnE,IAAI,SAAS,mBAAmB,KAAA,GAC9B,IAAI,6BAA6B,SAAS,eAAe,EACvD,UAAU,0CAA0C,SAAS;MAE7D,OAAO,UAAU;CAIrB,OAAO,OAAO,KAAK,UAAU,CAAC,SAAS,IAAI,YAAY;;AAGzD,SAAgB,6CACd,aACA,qBACS;CACT,MAAM,kBAAkB,gCAAgC,oBAAoB;CAC5E,MAAM,iBAAiB,+BAA+B,oBAAoB;CAE1E,IAAI,oBAAoB,QAAQ,mBAAmB,MACjD,OAAO;CAGT,OAAO,yCAAyC,aAAa;EAC3D;EACA;EACD,CAAC;;AAGJ,SAAgB,gCAAgC,OAA+B;CAC7E,MAAM,QAAQ,kBAAkB,MAAM,CAAC;CACvC,OAAO,OAAO,UAAU,WAAW,QAAQ;;AAG7C,SAAS,6BAA6B,OAAiC;CACrE,OAAO,OAAO,UAAU,YAAY,OAAO,cAAc,MAAM,IAAI,SAAS;;AAG9E,SAAgB,+BAA+B,OAA+B;CAC5E,MAAM,QAAQ,kBAAkB,MAAM,CAAC;CACvC,OAAO,6BAA6B,MAAM,GAAG,QAAQ;;AAGvD,SAAgB,8BAA8B,SAGnB;CACzB,MAAM,qBAAqB,+BAA+B,QAAQ,aAAa;CAC/E,IAAI,YAA+B;CAEnC,IAAI,QAAQ,wBAAwB,QAAQ,uBAAuB;MAC7D,qBAAqB,QAAQ,qBAC/B,YAAY;OACP,IAAI,qBAAqB,QAAQ,qBACtC,YAAY;;CAIhB,OAAO;EACL;EACA,cAAc,QAAQ;EACtB;EACD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/server/app-interception-context-header.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Normalize the `x-vinext-interception-context` header from inbound requests.
|
|
4
|
+
*
|
|
5
|
+
* The browser sends the current pathname (e.g. `/feed`) as interception context
|
|
6
|
+
* so the server can decide whether to render an intercepted parallel route.
|
|
7
|
+
* The legitimate value is always a same-origin URL pathname produced by the
|
|
8
|
+
* vinext browser entry — never an arbitrary string.
|
|
9
|
+
*
|
|
10
|
+
* Security: this value flows into cache-key construction (via
|
|
11
|
+
* `getOptimisticRouteTemplateKey`, `getOptimisticPrefetchSourceKey`, and
|
|
12
|
+
* outbound RSC payload cache keys). Without bounds, an attacker who controls
|
|
13
|
+
* this header can fabricate unbounded distinct values to fragment the cache
|
|
14
|
+
* or drive per-write KV billing. See `SECURITY-AUDIT-2026-05.md` finding
|
|
15
|
+
* F-PROD-1.
|
|
16
|
+
*
|
|
17
|
+
* Bounds applied:
|
|
18
|
+
* - Null bytes are stripped (header-injection defense).
|
|
19
|
+
* - The value must start with `/` (a pathname).
|
|
20
|
+
* - Whitespace is rejected (real pathnames do not contain raw whitespace;
|
|
21
|
+
* legitimate spaces would be percent-encoded).
|
|
22
|
+
* - Length capped at MAX_INTERCEPTION_CONTEXT_LENGTH bytes. Values that
|
|
23
|
+
* exceed the cap are treated as absent so the request is still served,
|
|
24
|
+
* just without interception.
|
|
25
|
+
*
|
|
26
|
+
* Anything that fails validation returns null, matching the prior behavior of
|
|
27
|
+
* an absent header. This is intentionally more permissive than rejecting the
|
|
28
|
+
* whole request — interception is a progressive enhancement.
|
|
29
|
+
*/
|
|
30
|
+
declare function normalizeInterceptionContextHeader(raw: string | null | undefined): string | null;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { normalizeInterceptionContextHeader };
|
|
33
|
+
//# sourceMappingURL=app-interception-context-header.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/server/app-interception-context-header.ts
|
|
2
|
+
/**
|
|
3
|
+
* Normalize the `x-vinext-interception-context` header from inbound requests.
|
|
4
|
+
*
|
|
5
|
+
* The browser sends the current pathname (e.g. `/feed`) as interception context
|
|
6
|
+
* so the server can decide whether to render an intercepted parallel route.
|
|
7
|
+
* The legitimate value is always a same-origin URL pathname produced by the
|
|
8
|
+
* vinext browser entry — never an arbitrary string.
|
|
9
|
+
*
|
|
10
|
+
* Security: this value flows into cache-key construction (via
|
|
11
|
+
* `getOptimisticRouteTemplateKey`, `getOptimisticPrefetchSourceKey`, and
|
|
12
|
+
* outbound RSC payload cache keys). Without bounds, an attacker who controls
|
|
13
|
+
* this header can fabricate unbounded distinct values to fragment the cache
|
|
14
|
+
* or drive per-write KV billing. See `SECURITY-AUDIT-2026-05.md` finding
|
|
15
|
+
* F-PROD-1.
|
|
16
|
+
*
|
|
17
|
+
* Bounds applied:
|
|
18
|
+
* - Null bytes are stripped (header-injection defense).
|
|
19
|
+
* - The value must start with `/` (a pathname).
|
|
20
|
+
* - Whitespace is rejected (real pathnames do not contain raw whitespace;
|
|
21
|
+
* legitimate spaces would be percent-encoded).
|
|
22
|
+
* - Length capped at MAX_INTERCEPTION_CONTEXT_LENGTH bytes. Values that
|
|
23
|
+
* exceed the cap are treated as absent so the request is still served,
|
|
24
|
+
* just without interception.
|
|
25
|
+
*
|
|
26
|
+
* Anything that fails validation returns null, matching the prior behavior of
|
|
27
|
+
* an absent header. This is intentionally more permissive than rejecting the
|
|
28
|
+
* whole request — interception is a progressive enhancement.
|
|
29
|
+
*/
|
|
30
|
+
/** Hard cap on the byte length of the interception-context header value. */
|
|
31
|
+
const MAX_INTERCEPTION_CONTEXT_LENGTH = 1024;
|
|
32
|
+
function normalizeInterceptionContextHeader(raw) {
|
|
33
|
+
if (!raw) return null;
|
|
34
|
+
const stripped = raw.replaceAll("\0", "");
|
|
35
|
+
if (stripped.length === 0) return null;
|
|
36
|
+
if (stripped.length > MAX_INTERCEPTION_CONTEXT_LENGTH) return null;
|
|
37
|
+
if (!stripped.startsWith("/")) return null;
|
|
38
|
+
if (/\s/.test(stripped)) return null;
|
|
39
|
+
return stripped;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { normalizeInterceptionContextHeader };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=app-interception-context-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-interception-context-header.js","names":[],"sources":["../../src/server/app-interception-context-header.ts"],"sourcesContent":["/**\n * Normalize the `x-vinext-interception-context` header from inbound requests.\n *\n * The browser sends the current pathname (e.g. `/feed`) as interception context\n * so the server can decide whether to render an intercepted parallel route.\n * The legitimate value is always a same-origin URL pathname produced by the\n * vinext browser entry — never an arbitrary string.\n *\n * Security: this value flows into cache-key construction (via\n * `getOptimisticRouteTemplateKey`, `getOptimisticPrefetchSourceKey`, and\n * outbound RSC payload cache keys). Without bounds, an attacker who controls\n * this header can fabricate unbounded distinct values to fragment the cache\n * or drive per-write KV billing. See `SECURITY-AUDIT-2026-05.md` finding\n * F-PROD-1.\n *\n * Bounds applied:\n * - Null bytes are stripped (header-injection defense).\n * - The value must start with `/` (a pathname).\n * - Whitespace is rejected (real pathnames do not contain raw whitespace;\n * legitimate spaces would be percent-encoded).\n * - Length capped at MAX_INTERCEPTION_CONTEXT_LENGTH bytes. Values that\n * exceed the cap are treated as absent so the request is still served,\n * just without interception.\n *\n * Anything that fails validation returns null, matching the prior behavior of\n * an absent header. This is intentionally more permissive than rejecting the\n * whole request — interception is a progressive enhancement.\n */\n\n/** Hard cap on the byte length of the interception-context header value. */\nconst MAX_INTERCEPTION_CONTEXT_LENGTH = 1024;\n\nexport function normalizeInterceptionContextHeader(raw: string | null | undefined): string | null {\n if (!raw) return null;\n // Strip null bytes first so length bounds can't be evaded by padding with \\0.\n const stripped = raw.replaceAll(\"\\0\", \"\");\n if (stripped.length === 0) return null;\n if (stripped.length > MAX_INTERCEPTION_CONTEXT_LENGTH) return null;\n // Must look like a same-origin pathname. Anything else (a full URL, a token,\n // junk bytes) is not a legitimate value the browser would emit.\n if (!stripped.startsWith(\"/\")) return null;\n // Raw whitespace is not legitimate inside a pathname.\n if (/\\s/.test(stripped)) return null;\n return stripped;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,kCAAkC;AAExC,SAAgB,mCAAmC,KAA+C;CAChG,IAAI,CAAC,KAAK,OAAO;CAEjB,MAAM,WAAW,IAAI,WAAW,MAAM,GAAG;CACzC,IAAI,SAAS,WAAW,GAAG,OAAO;CAClC,IAAI,SAAS,SAAS,iCAAiC,OAAO;CAG9D,IAAI,CAAC,SAAS,WAAW,IAAI,EAAE,OAAO;CAEtC,IAAI,KAAK,KAAK,SAAS,EAAE,OAAO;CAChC,OAAO"}
|
|
@@ -6,6 +6,25 @@
|
|
|
6
6
|
* rendered, which changes across navigations. This normalizes to a canonical form
|
|
7
7
|
* (sorted, deduplicated) so equivalent slot sets map to the same RSC cache entry.
|
|
8
8
|
*
|
|
9
|
+
* Security: the value flows into the ISR RSC cache key (`appIsrRscKey`). Without
|
|
10
|
+
* bounds, an attacker who controls this header can fabricate unbounded distinct
|
|
11
|
+
* values to fan out KV writes (per-write billing) or fragment the cache. See
|
|
12
|
+
* `SECURITY-AUDIT-2026-05.md` finding F-PROD-1. The legitimate wire format is a
|
|
13
|
+
* whitespace-separated list of `slot:<name>:<treePath>` tokens (see
|
|
14
|
+
* `createAppPayloadSlotId` in `app-elements-wire.ts`); anything else is rejected.
|
|
15
|
+
*
|
|
16
|
+
* Bounds applied:
|
|
17
|
+
* - Total raw header value capped at MAX_RAW_HEADER_LENGTH bytes (returns null
|
|
18
|
+
* if exceeded so the request is treated as if the header were absent).
|
|
19
|
+
* - Each token capped at MAX_TOKEN_LENGTH bytes.
|
|
20
|
+
* - Token count capped at MAX_SLOT_TOKENS (extras are dropped after sort + dedup).
|
|
21
|
+
* - Each token must match the legitimate slot-id shape, as defined by the
|
|
22
|
+
* AppElements wire codec (`AppElementsWire.isSlotId`). Wire-format details
|
|
23
|
+
* are intentionally kept inside the codec so this module does not duplicate
|
|
24
|
+
* them. Malformed tokens are dropped silently rather than rejecting the
|
|
25
|
+
* whole request — this matches the prior forgiving behavior for browsers
|
|
26
|
+
* that send legitimate but stale formats during rolling deploys.
|
|
27
|
+
*
|
|
9
28
|
* Consumed by:
|
|
10
29
|
* - app-rsc-request-normalization (request lifecycle, reads incoming header)
|
|
11
30
|
* - app-elements (outgoing x-vinext-mounted-slots construction)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AppElementsWire } from "./app-elements-wire.js";
|
|
1
2
|
//#region src/server/app-mounted-slots-header.ts
|
|
2
3
|
/**
|
|
3
4
|
* Normalize the `x-vinext-mounted-slots` header for request handling and cache keying.
|
|
@@ -6,14 +7,52 @@
|
|
|
6
7
|
* rendered, which changes across navigations. This normalizes to a canonical form
|
|
7
8
|
* (sorted, deduplicated) so equivalent slot sets map to the same RSC cache entry.
|
|
8
9
|
*
|
|
10
|
+
* Security: the value flows into the ISR RSC cache key (`appIsrRscKey`). Without
|
|
11
|
+
* bounds, an attacker who controls this header can fabricate unbounded distinct
|
|
12
|
+
* values to fan out KV writes (per-write billing) or fragment the cache. See
|
|
13
|
+
* `SECURITY-AUDIT-2026-05.md` finding F-PROD-1. The legitimate wire format is a
|
|
14
|
+
* whitespace-separated list of `slot:<name>:<treePath>` tokens (see
|
|
15
|
+
* `createAppPayloadSlotId` in `app-elements-wire.ts`); anything else is rejected.
|
|
16
|
+
*
|
|
17
|
+
* Bounds applied:
|
|
18
|
+
* - Total raw header value capped at MAX_RAW_HEADER_LENGTH bytes (returns null
|
|
19
|
+
* if exceeded so the request is treated as if the header were absent).
|
|
20
|
+
* - Each token capped at MAX_TOKEN_LENGTH bytes.
|
|
21
|
+
* - Token count capped at MAX_SLOT_TOKENS (extras are dropped after sort + dedup).
|
|
22
|
+
* - Each token must match the legitimate slot-id shape, as defined by the
|
|
23
|
+
* AppElements wire codec (`AppElementsWire.isSlotId`). Wire-format details
|
|
24
|
+
* are intentionally kept inside the codec so this module does not duplicate
|
|
25
|
+
* them. Malformed tokens are dropped silently rather than rejecting the
|
|
26
|
+
* whole request — this matches the prior forgiving behavior for browsers
|
|
27
|
+
* that send legitimate but stale formats during rolling deploys.
|
|
28
|
+
*
|
|
9
29
|
* Consumed by:
|
|
10
30
|
* - app-rsc-request-normalization (request lifecycle, reads incoming header)
|
|
11
31
|
* - app-elements (outgoing x-vinext-mounted-slots construction)
|
|
12
32
|
* - isr-cache (RSC cache key generation)
|
|
13
33
|
*/
|
|
34
|
+
/** Hard cap on the raw header value byte length. Real values are <1 KB. */
|
|
35
|
+
const MAX_RAW_HEADER_LENGTH = 4096;
|
|
36
|
+
/** Hard cap on a single slot token byte length. */
|
|
37
|
+
const MAX_TOKEN_LENGTH = 256;
|
|
38
|
+
/** Hard cap on the number of slot tokens kept after normalization. */
|
|
39
|
+
const MAX_SLOT_TOKENS = 16;
|
|
40
|
+
/**
|
|
41
|
+
* Validate a single mounted-slot token. Shape validation is delegated to the
|
|
42
|
+
* AppElements wire codec so the wire format definition lives in exactly one
|
|
43
|
+
* place. This module only enforces the additional security cap on token byte
|
|
44
|
+
* length to bound cache-key cardinality.
|
|
45
|
+
*/
|
|
46
|
+
function isValidSlotToken(token) {
|
|
47
|
+
if (token.length === 0 || token.length > MAX_TOKEN_LENGTH) return false;
|
|
48
|
+
return AppElementsWire.isSlotId(token);
|
|
49
|
+
}
|
|
14
50
|
function normalizeMountedSlotsHeader(raw) {
|
|
15
51
|
if (!raw) return null;
|
|
16
|
-
|
|
52
|
+
if (raw.length > MAX_RAW_HEADER_LENGTH) return null;
|
|
53
|
+
const validTokens = raw.split(/\s+/).filter((token) => token && isValidSlotToken(token));
|
|
54
|
+
if (validTokens.length === 0) return null;
|
|
55
|
+
return Array.from(new Set(validTokens)).sort().slice(0, MAX_SLOT_TOKENS).join(" ") || null;
|
|
17
56
|
}
|
|
18
57
|
//#endregion
|
|
19
58
|
export { normalizeMountedSlotsHeader };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-mounted-slots-header.js","names":[],"sources":["../../src/server/app-mounted-slots-header.ts"],"sourcesContent":["/**\n * Normalize the `x-vinext-mounted-slots` header for request handling and cache keying.\n *\n * The browser sends mounted slot ids as a space-separated list in the order slots were\n * rendered, which changes across navigations. This normalizes to a canonical form\n * (sorted, deduplicated) so equivalent slot sets map to the same RSC cache entry.\n *\n * Consumed by:\n * - app-rsc-request-normalization (request lifecycle, reads incoming header)\n * - app-elements (outgoing x-vinext-mounted-slots construction)\n * - isr-cache (RSC cache key generation)\n */\nexport function normalizeMountedSlotsHeader(raw: string | null | undefined): string | null {\n if (!raw) return null;\n const
|
|
1
|
+
{"version":3,"file":"app-mounted-slots-header.js","names":[],"sources":["../../src/server/app-mounted-slots-header.ts"],"sourcesContent":["/**\n * Normalize the `x-vinext-mounted-slots` header for request handling and cache keying.\n *\n * The browser sends mounted slot ids as a space-separated list in the order slots were\n * rendered, which changes across navigations. This normalizes to a canonical form\n * (sorted, deduplicated) so equivalent slot sets map to the same RSC cache entry.\n *\n * Security: the value flows into the ISR RSC cache key (`appIsrRscKey`). Without\n * bounds, an attacker who controls this header can fabricate unbounded distinct\n * values to fan out KV writes (per-write billing) or fragment the cache. See\n * `SECURITY-AUDIT-2026-05.md` finding F-PROD-1. The legitimate wire format is a\n * whitespace-separated list of `slot:<name>:<treePath>` tokens (see\n * `createAppPayloadSlotId` in `app-elements-wire.ts`); anything else is rejected.\n *\n * Bounds applied:\n * - Total raw header value capped at MAX_RAW_HEADER_LENGTH bytes (returns null\n * if exceeded so the request is treated as if the header were absent).\n * - Each token capped at MAX_TOKEN_LENGTH bytes.\n * - Token count capped at MAX_SLOT_TOKENS (extras are dropped after sort + dedup).\n * - Each token must match the legitimate slot-id shape, as defined by the\n * AppElements wire codec (`AppElementsWire.isSlotId`). Wire-format details\n * are intentionally kept inside the codec so this module does not duplicate\n * them. Malformed tokens are dropped silently rather than rejecting the\n * whole request — this matches the prior forgiving behavior for browsers\n * that send legitimate but stale formats during rolling deploys.\n *\n * Consumed by:\n * - app-rsc-request-normalization (request lifecycle, reads incoming header)\n * - app-elements (outgoing x-vinext-mounted-slots construction)\n * - isr-cache (RSC cache key generation)\n */\n\nimport { AppElementsWire } from \"./app-elements-wire.js\";\n\n/** Hard cap on the raw header value byte length. Real values are <1 KB. */\nconst MAX_RAW_HEADER_LENGTH = 4096;\n/** Hard cap on a single slot token byte length. */\nconst MAX_TOKEN_LENGTH = 256;\n/** Hard cap on the number of slot tokens kept after normalization. */\nconst MAX_SLOT_TOKENS = 16;\n\n/**\n * Validate a single mounted-slot token. Shape validation is delegated to the\n * AppElements wire codec so the wire format definition lives in exactly one\n * place. This module only enforces the additional security cap on token byte\n * length to bound cache-key cardinality.\n */\nfunction isValidSlotToken(token: string): boolean {\n if (token.length === 0 || token.length > MAX_TOKEN_LENGTH) return false;\n return AppElementsWire.isSlotId(token);\n}\n\nexport function normalizeMountedSlotsHeader(raw: string | null | undefined): string | null {\n if (!raw) return null;\n if (raw.length > MAX_RAW_HEADER_LENGTH) return null;\n const validTokens = raw.split(/\\s+/).filter((token) => token && isValidSlotToken(token));\n if (validTokens.length === 0) return null;\n const normalized = Array.from(new Set(validTokens)).sort().slice(0, MAX_SLOT_TOKENS).join(\" \");\n return normalized || null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,wBAAwB;;AAE9B,MAAM,mBAAmB;;AAEzB,MAAM,kBAAkB;;;;;;;AAQxB,SAAS,iBAAiB,OAAwB;CAChD,IAAI,MAAM,WAAW,KAAK,MAAM,SAAS,kBAAkB,OAAO;CAClE,OAAO,gBAAgB,SAAS,MAAM;;AAGxC,SAAgB,4BAA4B,KAA+C;CACzF,IAAI,CAAC,KAAK,OAAO;CACjB,IAAI,IAAI,SAAS,uBAAuB,OAAO;CAC/C,MAAM,cAAc,IAAI,MAAM,MAAM,CAAC,QAAQ,UAAU,SAAS,iBAAiB,MAAM,CAAC;CACxF,IAAI,YAAY,WAAW,GAAG,OAAO;CAErC,OADmB,MAAM,KAAK,IAAI,IAAI,YAAY,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,gBAAgB,CAAC,KAAK,IACzE,IAAI"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decodeMatchedParams, splitPathnameForRouteMatch } from "../routing/utils.js";
|
|
1
|
+
import { buildParams, decodeMatchedParams, splitPathnameForRouteMatch } from "../routing/utils.js";
|
|
2
2
|
import { stripBasePath } from "../utils/base-path.js";
|
|
3
3
|
import { isUnknownRecord } from "../utils/record.js";
|
|
4
4
|
import { AppElementsWire } from "./app-elements-wire.js";
|
|
@@ -77,35 +77,43 @@ function getRouteTrie(routeManifest) {
|
|
|
77
77
|
routeTrieCache.set(routeManifest, trie);
|
|
78
78
|
return trie;
|
|
79
79
|
}
|
|
80
|
-
function matchNode(node, urlParts, index) {
|
|
80
|
+
function matchNode(node, urlParts, index, entries) {
|
|
81
81
|
if (index === urlParts.length) {
|
|
82
82
|
if (node.route !== null) return {
|
|
83
83
|
route: node.route,
|
|
84
|
-
params:
|
|
84
|
+
params: buildParams(entries)
|
|
85
85
|
};
|
|
86
86
|
if (node.optionalCatchAllChild !== null) return {
|
|
87
87
|
route: node.optionalCatchAllChild.route,
|
|
88
|
-
params:
|
|
88
|
+
params: buildParams(entries)
|
|
89
89
|
};
|
|
90
90
|
return null;
|
|
91
91
|
}
|
|
92
92
|
const segment = urlParts[index];
|
|
93
93
|
const staticChild = node.staticChildren.get(segment);
|
|
94
|
-
if (staticChild !== void 0) return matchNode(staticChild, urlParts, index + 1);
|
|
94
|
+
if (staticChild !== void 0) return matchNode(staticChild, urlParts, index + 1, entries);
|
|
95
95
|
if (node.dynamicChild !== null) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
match
|
|
99
|
-
|
|
96
|
+
entries.push([node.dynamicChild.paramName, segment]);
|
|
97
|
+
const match = matchNode(node.dynamicChild.node, urlParts, index + 1, entries);
|
|
98
|
+
if (match !== null) return match;
|
|
99
|
+
entries.pop();
|
|
100
|
+
}
|
|
101
|
+
if (node.catchAllChild !== null) {
|
|
102
|
+
const params = buildParams(entries);
|
|
103
|
+
params[node.catchAllChild.paramName] = urlParts.slice(index);
|
|
104
|
+
return {
|
|
105
|
+
route: node.catchAllChild.route,
|
|
106
|
+
params
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (node.optionalCatchAllChild !== null) {
|
|
110
|
+
const params = buildParams(entries);
|
|
111
|
+
params[node.optionalCatchAllChild.paramName] = urlParts.slice(index);
|
|
112
|
+
return {
|
|
113
|
+
route: node.optionalCatchAllChild.route,
|
|
114
|
+
params
|
|
115
|
+
};
|
|
100
116
|
}
|
|
101
|
-
if (node.catchAllChild !== null) return {
|
|
102
|
-
route: node.catchAllChild.route,
|
|
103
|
-
params: { [node.catchAllChild.paramName]: urlParts.slice(index) }
|
|
104
|
-
};
|
|
105
|
-
if (node.optionalCatchAllChild !== null) return {
|
|
106
|
-
route: node.optionalCatchAllChild.route,
|
|
107
|
-
params: { [node.optionalCatchAllChild.paramName]: urlParts.slice(index) }
|
|
108
|
-
};
|
|
109
117
|
return null;
|
|
110
118
|
}
|
|
111
119
|
function hrefToRouteParts(href, basePath) {
|
|
@@ -122,7 +130,7 @@ function hrefToRouteParts(href, basePath) {
|
|
|
122
130
|
function matchOptimisticRouteManifestRoute(options) {
|
|
123
131
|
const urlParts = hrefToRouteParts(options.href, options.basePath);
|
|
124
132
|
if (urlParts === null) return null;
|
|
125
|
-
const match = matchNode(getRouteTrie(options.routeManifest), urlParts, 0);
|
|
133
|
+
const match = matchNode(getRouteTrie(options.routeManifest), urlParts, 0, []);
|
|
126
134
|
if (match === null) return null;
|
|
127
135
|
decodeMatchedParams(match.params);
|
|
128
136
|
return match;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-optimistic-routing.js","names":[],"sources":["../../src/server/app-optimistic-routing.ts"],"sourcesContent":["import { createElement, isValidElement, Suspense } from \"react\";\nimport { isUnknownRecord } from \"../utils/record.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport { decodeMatchedParams, splitPathnameForRouteMatch } from \"../routing/utils.js\";\nimport type { RouteManifest, RouteManifestRoute } from \"../routing/app-route-graph.js\";\nimport { stripRscCacheBustingSearchParam, stripRscSuffix } from \"./app-rsc-cache-busting.js\";\nimport {\n AppElementsWire,\n APP_PREFETCH_LOADING_SHELL_MARKER_KEY,\n type AppElementValue,\n type AppElements,\n} from \"./app-elements.js\";\n\ntype OptimisticRouteTrieNode = {\n catchAllChild: { paramName: string; route: RouteManifestRoute } | null;\n dynamicChild: { node: OptimisticRouteTrieNode; paramName: string } | null;\n optionalCatchAllChild: { paramName: string; route: RouteManifestRoute } | null;\n route: RouteManifestRoute | null;\n staticChildren: Map<string, OptimisticRouteTrieNode>;\n};\n\ntype OptimisticRouteMatch = {\n params: Record<string, string | string[]>;\n route: RouteManifestRoute;\n};\n\nexport type OptimisticRouteTemplate = {\n elements: AppElements;\n mountedSlotsHeader: string | null;\n pageElementIds: readonly string[];\n routeId: string;\n};\n\ntype OptimisticNavigationPayload = {\n elements: AppElements;\n params: Record<string, string | string[]>;\n template: OptimisticRouteTemplate;\n};\n\nconst routeTrieCache = new WeakMap<RouteManifest, OptimisticRouteTrieNode>();\n// Shared never-settling thenable used to suspend optimistic page segments until\n// the real RSC payload replaces them.\nconst OPTIMISTIC_ROUTE_SEGMENT_SUSPENSE_TRIGGER = new Promise<never>(() => {});\n\nexport function getOptimisticRouteTemplateKey(options: {\n interceptionContext: string | null;\n mountedSlotsHeader: string | null;\n routeId: string;\n}): string {\n return `${options.routeId}\\0${options.interceptionContext ?? \"\"}\\0${options.mountedSlotsHeader ?? \"\"}`;\n}\n\nexport function getOptimisticPrefetchSourceKey(options: {\n cacheKey: string;\n interceptionContext: string | null;\n mountedSlotsHeader: string | null;\n}): string {\n return `${options.cacheKey}\\0${options.interceptionContext ?? \"\"}\\0${options.mountedSlotsHeader ?? \"\"}`;\n}\n\nfunction createNode(): OptimisticRouteTrieNode {\n return {\n catchAllChild: null,\n dynamicChild: null,\n optionalCatchAllChild: null,\n route: null,\n staticChildren: new Map(),\n };\n}\n\nfunction buildRouteTrie(routeManifest: RouteManifest): OptimisticRouteTrieNode {\n const root = createNode();\n\n for (const route of routeManifest.segmentGraph.routes.values()) {\n let node = root;\n const parts = route.patternParts;\n\n if (parts.length === 0) {\n node.route ??= route;\n continue;\n }\n\n for (const [index, part] of parts.entries()) {\n const isTerminal = index === parts.length - 1;\n if (part.startsWith(\":\") && part.endsWith(\"+\")) {\n if (isTerminal && node.catchAllChild === null) {\n node.catchAllChild = { paramName: part.slice(1, -1), route };\n }\n break;\n }\n\n if (part.startsWith(\":\") && part.endsWith(\"*\")) {\n if (isTerminal && node.optionalCatchAllChild === null) {\n node.optionalCatchAllChild = { paramName: part.slice(1, -1), route };\n }\n break;\n }\n\n if (part.startsWith(\":\")) {\n const paramName = part.slice(1);\n if (node.dynamicChild === null) {\n node.dynamicChild = { node: createNode(), paramName };\n } else if (node.dynamicChild.paramName !== paramName && import.meta.env.DEV) {\n console.warn(\n `[vinext] Optimistic route trie found conflicting dynamic segments at the same level: :${node.dynamicChild.paramName} vs ${part}`,\n );\n }\n node = node.dynamicChild.node;\n if (isTerminal) node.route ??= route;\n continue;\n }\n\n let staticChild = node.staticChildren.get(part);\n if (staticChild === undefined) {\n staticChild = createNode();\n node.staticChildren.set(part, staticChild);\n }\n node = staticChild;\n if (isTerminal) node.route ??= route;\n }\n }\n\n return root;\n}\n\nfunction getRouteTrie(routeManifest: RouteManifest): OptimisticRouteTrieNode {\n const existing = routeTrieCache.get(routeManifest);\n if (existing) return existing;\n\n const trie = buildRouteTrie(routeManifest);\n routeTrieCache.set(routeManifest, trie);\n return trie;\n}\n\nfunction matchNode(\n node: OptimisticRouteTrieNode,\n urlParts: readonly string[],\n index: number,\n): OptimisticRouteMatch | null {\n if (index === urlParts.length) {\n if (node.route !== null) {\n return { route: node.route, params: Object.create(null) };\n }\n if (node.optionalCatchAllChild !== null) {\n return {\n route: node.optionalCatchAllChild.route,\n params: Object.create(null),\n };\n }\n return null;\n }\n\n const segment = urlParts[index];\n const staticChild = node.staticChildren.get(segment);\n if (staticChild !== undefined) {\n // Static children are authoritative for optimistic routing. If a known\n // static subtree does not contain the remaining URL, do not fall through to\n // a catch-all sibling and render the wrong loading boundary.\n return matchNode(staticChild, urlParts, index + 1);\n }\n\n if (node.dynamicChild !== null) {\n const match = matchNode(node.dynamicChild.node, urlParts, index + 1);\n if (match === null) return null;\n match.params[node.dynamicChild.paramName] = segment;\n return match;\n }\n\n if (node.catchAllChild !== null) {\n return {\n route: node.catchAllChild.route,\n params: {\n [node.catchAllChild.paramName]: urlParts.slice(index),\n },\n };\n }\n\n if (node.optionalCatchAllChild !== null) {\n return {\n route: node.optionalCatchAllChild.route,\n params: {\n [node.optionalCatchAllChild.paramName]: urlParts.slice(index),\n },\n };\n }\n\n return null;\n}\n\nfunction hrefToRouteParts(href: string, basePath: string): string[] | null {\n let url: URL;\n try {\n url = new URL(href, \"https://vinext.local\");\n } catch {\n return null;\n }\n\n stripRscCacheBustingSearchParam(url);\n const withoutRscSuffix = stripRscSuffix(url.pathname);\n const appPathname = stripBasePath(withoutRscSuffix, basePath);\n return splitPathnameForRouteMatch(appPathname === \"\" ? \"/\" : appPathname);\n}\n\nexport function matchOptimisticRouteManifestRoute(options: {\n basePath: string;\n href: string;\n routeManifest: RouteManifest;\n}): OptimisticRouteMatch | null {\n const urlParts = hrefToRouteParts(options.href, options.basePath);\n if (urlParts === null) return null;\n\n const match = matchNode(getRouteTrie(options.routeManifest), urlParts, 0);\n if (match === null) return null;\n\n decodeMatchedParams(match.params);\n return match;\n}\n\nfunction elementHasSuspenseFallback(value: unknown, depth = 0): boolean {\n if (depth > 100) return false;\n if (Array.isArray(value)) {\n return value.some((entry) => elementHasSuspenseFallback(entry, depth + 1));\n }\n if (!isValidElement(value)) return false;\n\n const props = Reflect.get(value, \"props\");\n if (value.type === Suspense && isUnknownRecord(props)) {\n const fallback = Reflect.get(props, \"fallback\");\n if (fallback !== null && fallback !== undefined) return true;\n }\n\n if (!isUnknownRecord(props)) return false;\n return elementHasSuspenseFallback(Reflect.get(props, \"children\"), depth + 1);\n}\n\nfunction getPageElementIds(elements: AppElements): string[] {\n return Object.keys(elements)\n .filter((key) => AppElementsWire.parseElementKey(key)?.kind === \"page\")\n .sort();\n}\n\nfunction OptimisticRouteSegment(): null {\n throw OPTIMISTIC_ROUTE_SEGMENT_SUSPENSE_TRIGGER;\n}\n\nexport function createOptimisticRouteTemplate(options: {\n allowLoadingShell?: boolean;\n basePath: string;\n elements: AppElements;\n href: string;\n interceptionContext: string | null;\n mountedSlotsHeader: string | null;\n routeManifest: RouteManifest;\n}): OptimisticRouteTemplate | null {\n const match = matchOptimisticRouteManifestRoute({\n basePath: options.basePath,\n href: options.href,\n routeManifest: options.routeManifest,\n });\n if (match === null || !match.route.isDynamic) return null;\n if (options.interceptionContext !== null) return null;\n\n const metadata = AppElementsWire.readMetadata(options.elements);\n if (metadata.interception !== null || metadata.interceptionContext !== null) return null;\n\n const routeElement = options.elements[metadata.routeId];\n // Full-prefetch learning is intentionally heuristic: legacy full prefetches\n // are accepted only when the serialized route subtree still contains a\n // Suspense fallback. Authoritative loading-shell prefetches use the marker\n // check below instead.\n if (!options.allowLoadingShell && !elementHasSuspenseFallback(routeElement)) return null;\n if (\n options.allowLoadingShell &&\n options.elements[APP_PREFETCH_LOADING_SHELL_MARKER_KEY] !== \"LoadingBoundary\"\n ) {\n return null;\n }\n // Shell prefetches must include the eagerly-rendered loading component. A\n // null route element means the server had no route loading boundary.\n if (options.allowLoadingShell && (routeElement === undefined || routeElement === null))\n return null;\n\n const pageElementIds = getPageElementIds(options.elements);\n if (pageElementIds.length === 0) return null;\n\n return {\n elements: options.elements,\n mountedSlotsHeader: options.mountedSlotsHeader,\n pageElementIds,\n routeId: match.route.id,\n };\n}\n\nexport function createOptimisticRouteElements(template: OptimisticRouteTemplate): AppElements {\n const elements: Record<string, AppElementValue> = { ...template.elements };\n for (const pageElementId of template.pageElementIds) {\n elements[pageElementId] = createElement(OptimisticRouteSegment);\n }\n return elements;\n}\n\nexport function resolveOptimisticNavigationPayload(options: {\n basePath: string;\n href: string;\n interceptionContext: string | null;\n mountedSlotsHeader: string | null;\n routeManifest: RouteManifest;\n templates: ReadonlyMap<string, OptimisticRouteTemplate>;\n}): OptimisticNavigationPayload | null {\n if (options.interceptionContext !== null) return null;\n\n const match = matchOptimisticRouteManifestRoute({\n basePath: options.basePath,\n href: options.href,\n routeManifest: options.routeManifest,\n });\n if (match === null || !match.route.isDynamic) return null;\n\n const template = options.templates.get(\n getOptimisticRouteTemplateKey({\n interceptionContext: options.interceptionContext,\n mountedSlotsHeader: options.mountedSlotsHeader,\n routeId: match.route.id,\n }),\n );\n if (template === undefined) return null;\n if (template.mountedSlotsHeader !== options.mountedSlotsHeader) return null;\n\n return {\n elements: createOptimisticRouteElements(template),\n params: match.params,\n template,\n };\n}\n"],"mappings":";;;;;;;;AAuCA,MAAM,iCAAiB,IAAI,SAAiD;AAG5E,MAAM,4CAA4C,IA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;EACtB,CAAC,CACH;CACD,IAAI,aAAa,KAAA,GAAW,OAAO;CACnC,IAAI,SAAS,uBAAuB,QAAQ,oBAAoB,OAAO;CAEvE,OAAO;EACL,UAAU,8BAA8B,SAAS;EACjD,QAAQ,MAAM;EACd;EACD"}
|
|
1
|
+
{"version":3,"file":"app-optimistic-routing.js","names":[],"sources":["../../src/server/app-optimistic-routing.ts"],"sourcesContent":["import { createElement, isValidElement, Suspense } from \"react\";\nimport { isUnknownRecord } from \"../utils/record.js\";\nimport { stripBasePath } from \"../utils/base-path.js\";\nimport { buildParams, decodeMatchedParams, splitPathnameForRouteMatch } from \"../routing/utils.js\";\nimport type { RouteManifest, RouteManifestRoute } from \"../routing/app-route-graph.js\";\nimport { stripRscCacheBustingSearchParam, stripRscSuffix } from \"./app-rsc-cache-busting.js\";\nimport {\n AppElementsWire,\n APP_PREFETCH_LOADING_SHELL_MARKER_KEY,\n type AppElementValue,\n type AppElements,\n} from \"./app-elements.js\";\n\ntype OptimisticRouteTrieNode = {\n catchAllChild: { paramName: string; route: RouteManifestRoute } | null;\n dynamicChild: { node: OptimisticRouteTrieNode; paramName: string } | null;\n optionalCatchAllChild: { paramName: string; route: RouteManifestRoute } | null;\n route: RouteManifestRoute | null;\n staticChildren: Map<string, OptimisticRouteTrieNode>;\n};\n\ntype OptimisticRouteMatch = {\n params: Record<string, string | string[]>;\n route: RouteManifestRoute;\n};\n\nexport type OptimisticRouteTemplate = {\n elements: AppElements;\n mountedSlotsHeader: string | null;\n pageElementIds: readonly string[];\n routeId: string;\n};\n\ntype OptimisticNavigationPayload = {\n elements: AppElements;\n params: Record<string, string | string[]>;\n template: OptimisticRouteTemplate;\n};\n\nconst routeTrieCache = new WeakMap<RouteManifest, OptimisticRouteTrieNode>();\n// Shared never-settling thenable used to suspend optimistic page segments until\n// the real RSC payload replaces them.\nconst OPTIMISTIC_ROUTE_SEGMENT_SUSPENSE_TRIGGER = new Promise<never>(() => {});\n\nexport function getOptimisticRouteTemplateKey(options: {\n interceptionContext: string | null;\n mountedSlotsHeader: string | null;\n routeId: string;\n}): string {\n return `${options.routeId}\\0${options.interceptionContext ?? \"\"}\\0${options.mountedSlotsHeader ?? \"\"}`;\n}\n\nexport function getOptimisticPrefetchSourceKey(options: {\n cacheKey: string;\n interceptionContext: string | null;\n mountedSlotsHeader: string | null;\n}): string {\n return `${options.cacheKey}\\0${options.interceptionContext ?? \"\"}\\0${options.mountedSlotsHeader ?? \"\"}`;\n}\n\nfunction createNode(): OptimisticRouteTrieNode {\n return {\n catchAllChild: null,\n dynamicChild: null,\n optionalCatchAllChild: null,\n route: null,\n staticChildren: new Map(),\n };\n}\n\nfunction buildRouteTrie(routeManifest: RouteManifest): OptimisticRouteTrieNode {\n const root = createNode();\n\n for (const route of routeManifest.segmentGraph.routes.values()) {\n let node = root;\n const parts = route.patternParts;\n\n if (parts.length === 0) {\n node.route ??= route;\n continue;\n }\n\n for (const [index, part] of parts.entries()) {\n const isTerminal = index === parts.length - 1;\n if (part.startsWith(\":\") && part.endsWith(\"+\")) {\n if (isTerminal && node.catchAllChild === null) {\n node.catchAllChild = { paramName: part.slice(1, -1), route };\n }\n break;\n }\n\n if (part.startsWith(\":\") && part.endsWith(\"*\")) {\n if (isTerminal && node.optionalCatchAllChild === null) {\n node.optionalCatchAllChild = { paramName: part.slice(1, -1), route };\n }\n break;\n }\n\n if (part.startsWith(\":\")) {\n const paramName = part.slice(1);\n if (node.dynamicChild === null) {\n node.dynamicChild = { node: createNode(), paramName };\n } else if (node.dynamicChild.paramName !== paramName && import.meta.env.DEV) {\n console.warn(\n `[vinext] Optimistic route trie found conflicting dynamic segments at the same level: :${node.dynamicChild.paramName} vs ${part}`,\n );\n }\n node = node.dynamicChild.node;\n if (isTerminal) node.route ??= route;\n continue;\n }\n\n let staticChild = node.staticChildren.get(part);\n if (staticChild === undefined) {\n staticChild = createNode();\n node.staticChildren.set(part, staticChild);\n }\n node = staticChild;\n if (isTerminal) node.route ??= route;\n }\n }\n\n return root;\n}\n\nfunction getRouteTrie(routeManifest: RouteManifest): OptimisticRouteTrieNode {\n const existing = routeTrieCache.get(routeManifest);\n if (existing) return existing;\n\n const trie = buildRouteTrie(routeManifest);\n routeTrieCache.set(routeManifest, trie);\n return trie;\n}\n\nfunction matchNode(\n node: OptimisticRouteTrieNode,\n urlParts: readonly string[],\n index: number,\n entries: Array<[string, string | string[]]>,\n): OptimisticRouteMatch | null {\n if (index === urlParts.length) {\n if (node.route !== null) {\n return { route: node.route, params: buildParams(entries) };\n }\n if (node.optionalCatchAllChild !== null) {\n return {\n route: node.optionalCatchAllChild.route,\n params: buildParams(entries),\n };\n }\n return null;\n }\n\n const segment = urlParts[index];\n const staticChild = node.staticChildren.get(segment);\n if (staticChild !== undefined) {\n // Static children are authoritative for optimistic routing. If a known\n // static subtree does not contain the remaining URL, do not fall through to\n // a catch-all sibling and render the wrong loading boundary.\n return matchNode(staticChild, urlParts, index + 1, entries);\n }\n\n if (node.dynamicChild !== null) {\n entries.push([node.dynamicChild.paramName, segment]);\n const match = matchNode(node.dynamicChild.node, urlParts, index + 1, entries);\n if (match !== null) return match;\n entries.pop();\n }\n\n if (node.catchAllChild !== null) {\n const params = buildParams(entries);\n params[node.catchAllChild.paramName] = urlParts.slice(index);\n return { route: node.catchAllChild.route, params };\n }\n\n // At this point index < urlParts.length, so remaining always has ≥1 segment.\n if (node.optionalCatchAllChild !== null) {\n const params = buildParams(entries);\n params[node.optionalCatchAllChild.paramName] = urlParts.slice(index);\n return { route: node.optionalCatchAllChild.route, params };\n }\n\n return null;\n}\n\nfunction hrefToRouteParts(href: string, basePath: string): string[] | null {\n let url: URL;\n try {\n url = new URL(href, \"https://vinext.local\");\n } catch {\n return null;\n }\n\n stripRscCacheBustingSearchParam(url);\n const withoutRscSuffix = stripRscSuffix(url.pathname);\n const appPathname = stripBasePath(withoutRscSuffix, basePath);\n return splitPathnameForRouteMatch(appPathname === \"\" ? \"/\" : appPathname);\n}\n\nexport function matchOptimisticRouteManifestRoute(options: {\n basePath: string;\n href: string;\n routeManifest: RouteManifest;\n}): OptimisticRouteMatch | null {\n const urlParts = hrefToRouteParts(options.href, options.basePath);\n if (urlParts === null) return null;\n\n const match = matchNode(getRouteTrie(options.routeManifest), urlParts, 0, []);\n if (match === null) return null;\n\n decodeMatchedParams(match.params);\n return match;\n}\n\nfunction elementHasSuspenseFallback(value: unknown, depth = 0): boolean {\n if (depth > 100) return false;\n if (Array.isArray(value)) {\n return value.some((entry) => elementHasSuspenseFallback(entry, depth + 1));\n }\n if (!isValidElement(value)) return false;\n\n const props = Reflect.get(value, \"props\");\n if (value.type === Suspense && isUnknownRecord(props)) {\n const fallback = Reflect.get(props, \"fallback\");\n if (fallback !== null && fallback !== undefined) return true;\n }\n\n if (!isUnknownRecord(props)) return false;\n return elementHasSuspenseFallback(Reflect.get(props, \"children\"), depth + 1);\n}\n\nfunction getPageElementIds(elements: AppElements): string[] {\n return Object.keys(elements)\n .filter((key) => AppElementsWire.parseElementKey(key)?.kind === \"page\")\n .sort();\n}\n\nfunction OptimisticRouteSegment(): null {\n throw OPTIMISTIC_ROUTE_SEGMENT_SUSPENSE_TRIGGER;\n}\n\nexport function createOptimisticRouteTemplate(options: {\n allowLoadingShell?: boolean;\n basePath: string;\n elements: AppElements;\n href: string;\n interceptionContext: string | null;\n mountedSlotsHeader: string | null;\n routeManifest: RouteManifest;\n}): OptimisticRouteTemplate | null {\n const match = matchOptimisticRouteManifestRoute({\n basePath: options.basePath,\n href: options.href,\n routeManifest: options.routeManifest,\n });\n if (match === null || !match.route.isDynamic) return null;\n if (options.interceptionContext !== null) return null;\n\n const metadata = AppElementsWire.readMetadata(options.elements);\n if (metadata.interception !== null || metadata.interceptionContext !== null) return null;\n\n const routeElement = options.elements[metadata.routeId];\n // Full-prefetch learning is intentionally heuristic: legacy full prefetches\n // are accepted only when the serialized route subtree still contains a\n // Suspense fallback. Authoritative loading-shell prefetches use the marker\n // check below instead.\n if (!options.allowLoadingShell && !elementHasSuspenseFallback(routeElement)) return null;\n if (\n options.allowLoadingShell &&\n options.elements[APP_PREFETCH_LOADING_SHELL_MARKER_KEY] !== \"LoadingBoundary\"\n ) {\n return null;\n }\n // Shell prefetches must include the eagerly-rendered loading component. A\n // null route element means the server had no route loading boundary.\n if (options.allowLoadingShell && (routeElement === undefined || routeElement === null))\n return null;\n\n const pageElementIds = getPageElementIds(options.elements);\n if (pageElementIds.length === 0) return null;\n\n return {\n elements: options.elements,\n mountedSlotsHeader: options.mountedSlotsHeader,\n pageElementIds,\n routeId: match.route.id,\n };\n}\n\nexport function createOptimisticRouteElements(template: OptimisticRouteTemplate): AppElements {\n const elements: Record<string, AppElementValue> = { ...template.elements };\n for (const pageElementId of template.pageElementIds) {\n elements[pageElementId] = createElement(OptimisticRouteSegment);\n }\n return elements;\n}\n\nexport function resolveOptimisticNavigationPayload(options: {\n basePath: string;\n href: string;\n interceptionContext: string | null;\n mountedSlotsHeader: string | null;\n routeManifest: RouteManifest;\n templates: ReadonlyMap<string, OptimisticRouteTemplate>;\n}): OptimisticNavigationPayload | null {\n if (options.interceptionContext !== null) return null;\n\n const match = matchOptimisticRouteManifestRoute({\n basePath: options.basePath,\n href: options.href,\n routeManifest: options.routeManifest,\n });\n if (match === null || !match.route.isDynamic) return null;\n\n const template = options.templates.get(\n getOptimisticRouteTemplateKey({\n interceptionContext: options.interceptionContext,\n mountedSlotsHeader: options.mountedSlotsHeader,\n routeId: match.route.id,\n }),\n );\n if (template === undefined) return null;\n if (template.mountedSlotsHeader !== options.mountedSlotsHeader) return null;\n\n return {\n elements: createOptimisticRouteElements(template),\n params: match.params,\n template,\n };\n}\n"],"mappings":";;;;;;;;AAuCA,MAAM,iCAAiB,IAAI,SAAiD;AAG5E,MAAM,4CAA4C,IAAI,cAAqB,GAAG;AAE9E,SAAgB,8BAA8B,SAInC;CACT,OAAO,GAAG,QAAQ,QAAQ,IAAI,QAAQ,uBAAuB,GAAG,IAAI,QAAQ,sBAAsB;;AAGpG,SAAgB,+BAA+B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AAI,aAAa,KAAA,GAAW,OAAO;CACnC,IAAI,SAAS,uBAAuB,QAAQ,oBAAoB,OAAO;CAEvE,OAAO;EACL,UAAU,8BAA8B,SAAS;EACjD,QAAQ,MAAM;EACd;EACD"}
|
|
@@ -34,6 +34,7 @@ type AppPageBoundaryRenderCommonOptions<TModule extends AppPageModule = AppPageM
|
|
|
34
34
|
getFontStyles: () => string[];
|
|
35
35
|
getNavigationContext: () => unknown;
|
|
36
36
|
globalErrorModule?: TModule | null;
|
|
37
|
+
isEdgeRuntime?: boolean;
|
|
37
38
|
isRscRequest: boolean;
|
|
38
39
|
loadSsrHandler: () => Promise<AppPageSsrHandler>;
|
|
39
40
|
makeThenableParams: (params: AppPageParams) => unknown;
|
|
@@ -93,6 +93,7 @@ async function renderAppPageBoundaryElementResponse(options) {
|
|
|
93
93
|
clearRequestContext: options.clearRequestContext,
|
|
94
94
|
fontData,
|
|
95
95
|
fontLinkHeader: options.buildFontLinkHeader(fontData.preloads),
|
|
96
|
+
isEdgeRuntime: options.isEdgeRuntime,
|
|
96
97
|
middlewareHeaders: options.middlewareContext.headers,
|
|
97
98
|
navigationContext: options.getNavigationContext(),
|
|
98
99
|
rscStream,
|
|
@@ -110,6 +111,7 @@ async function renderAppPageBoundaryElementResponse(options) {
|
|
|
110
111
|
pathname,
|
|
111
112
|
route: options.route
|
|
112
113
|
}),
|
|
114
|
+
isEdgeRuntime: options.isEdgeRuntime,
|
|
113
115
|
isRscRequest: options.isRscRequest,
|
|
114
116
|
middlewareHeaders: options.middlewareContext.headers,
|
|
115
117
|
renderToReadableStream: options.renderToReadableStream,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-page-boundary-render.js","names":[],"sources":["../../src/server/app-page-boundary-render.ts"],"sourcesContent":["import { Fragment, createElement, type ComponentType, type ReactNode } from \"react\";\nimport { buildClientHookErrorMessage } from \"vinext/shims/client-hook-error\";\nimport { ErrorBoundary } from \"vinext/shims/error-boundary\";\nimport { LayoutSegmentProvider } from \"vinext/shims/layout-segment-context\";\nimport { MetadataHead, ViewportHead } from \"vinext/shims/metadata\";\nimport type { AppPageFontPreload } from \"./app-page-execution.js\";\nimport type { AppPageMiddlewareContext } from \"./app-page-response.js\";\nimport type { MetadataFileRoute } from \"./metadata-routes.js\";\nimport { resolveAppPageHead } from \"./app-page-head.js\";\nimport {\n renderAppPageBoundaryResponse,\n resolveAppPageErrorBoundary,\n resolveAppPageHttpAccessBoundaryComponent,\n wrapAppPageBoundaryElement,\n type AppPageParams,\n} from \"./app-page-boundary.js\";\nimport {\n createAppPageFontData,\n renderAppPageHtmlResponse,\n type AppPageSsrHandler,\n} from \"./app-page-stream.js\";\nimport { AppElementsWire, type AppElements } from \"./app-elements.js\";\nimport { createAppPageLayoutEntries } from \"./app-page-route-wiring.js\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype AppPageComponent = ComponentType<any>;\ntype AppPageModule = Record<string, unknown> & {\n default?: AppPageComponent | null | undefined;\n};\ntype AppPageBoundaryOnError = (\n error: unknown,\n requestInfo: unknown,\n errorContext: unknown,\n) => unknown;\n\ntype AppPageBoundaryRscPayloadOptions<TModule extends AppPageModule = AppPageModule> = {\n element: ReactNode;\n layoutModules: readonly (TModule | null | undefined)[];\n pathname: string;\n route?: AppPageBoundaryRoute<TModule> | null;\n};\n\ntype AppPageBoundaryLayoutEntry = {\n id: string;\n treePath: string;\n};\n\nexport type AppPageBoundaryRoute<TModule extends AppPageModule = AppPageModule> = {\n error?: TModule | null;\n errorPaths?: readonly TModule[] | null;\n errors?: readonly (TModule | null | undefined)[] | null;\n forbidden?: TModule | null;\n layoutTreePositions?: readonly number[] | null;\n layouts?: readonly (TModule | null | undefined)[];\n notFound?: TModule | null;\n params?: AppPageParams;\n pattern?: string;\n routeSegments?: readonly string[];\n unauthorized?: TModule | null;\n};\n\ntype AppPageBoundaryRenderCommonOptions<TModule extends AppPageModule = AppPageModule> = {\n buildFontLinkHeader: (preloads: readonly AppPageFontPreload[] | null | undefined) => string;\n clearRequestContext: () => void;\n createRscOnErrorHandler: (pathname: string, routePath: string) => AppPageBoundaryOnError;\n getFontLinks: () => string[];\n getFontPreloads: () => AppPageFontPreload[];\n getFontStyles: () => string[];\n getNavigationContext: () => unknown;\n globalErrorModule?: TModule | null;\n isRscRequest: boolean;\n loadSsrHandler: () => Promise<AppPageSsrHandler>;\n makeThenableParams: (params: AppPageParams) => unknown;\n middlewareContext: AppPageMiddlewareContext;\n metadataRoutes: MetadataFileRoute[];\n /** Configured next.config `basePath`, threaded into file-based metadata href emission. */\n basePath?: string;\n renderToReadableStream: (\n element: ReactNode | AppElements,\n options: { onError: AppPageBoundaryOnError },\n ) => ReadableStream<Uint8Array>;\n requestUrl: string;\n resolveChildSegments: (\n routeSegments: readonly string[],\n treePosition: number,\n params: AppPageParams,\n ) => string[];\n rootLayouts: readonly (TModule | null | undefined)[];\n scriptNonce?: string;\n};\n\ntype RenderAppPageHttpAccessFallbackOptions<TModule extends AppPageModule = AppPageModule> = {\n boundaryComponent?: AppPageComponent | null;\n layoutModules?: readonly (TModule | null | undefined)[] | null;\n matchedParams: AppPageParams;\n rootForbiddenModule?: TModule | null;\n rootNotFoundModule?: TModule | null;\n rootUnauthorizedModule?: TModule | null;\n route?: AppPageBoundaryRoute<TModule> | null;\n /**\n * When true, the resolved boundary is rendered without wrapping it in the\n * route's layouts. Used by `global-not-found.tsx`, which provides its own\n * `<html>`/`<body>` and intentionally replaces the root layout.\n * Mirrors Next.js's `createNotFoundLoaderTree` behavior for `hasGlobalNotFound`.\n * @see https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/app-render.tsx#L495-L520\n */\n skipLayoutWrapping?: boolean;\n statusCode: number;\n} & AppPageBoundaryRenderCommonOptions<TModule>;\n\ntype RenderAppPageErrorBoundaryOptions<TModule extends AppPageModule = AppPageModule> = {\n error: unknown;\n matchedParams?: AppPageParams | null;\n route?: AppPageBoundaryRoute<TModule> | null;\n sanitizeErrorForClient: (error: Error) => Error;\n} & AppPageBoundaryRenderCommonOptions<TModule>;\n\nfunction getDefaultExport<TModule extends AppPageModule>(\n module: TModule | null | undefined,\n): AppPageComponent | null {\n return module?.default ?? null;\n}\n\nfunction wrapRenderedBoundaryElement<TModule extends AppPageModule>(\n options: Pick<\n AppPageBoundaryRenderCommonOptions<TModule>,\n \"globalErrorModule\" | \"isRscRequest\" | \"makeThenableParams\" | \"resolveChildSegments\"\n > & {\n element: ReactNode;\n includeGlobalErrorBoundary: boolean;\n layoutModules: readonly (TModule | null | undefined)[];\n layoutTreePositions?: readonly number[] | null;\n matchedParams: AppPageParams;\n routeSegments?: readonly string[];\n skipLayoutWrapping?: boolean;\n },\n): ReactNode {\n return wrapAppPageBoundaryElement({\n element: options.element,\n getDefaultExport,\n globalErrorComponent: getDefaultExport(options.globalErrorModule),\n includeGlobalErrorBoundary: options.includeGlobalErrorBoundary,\n isRscRequest: options.isRscRequest,\n layoutModules: options.layoutModules,\n layoutTreePositions: options.layoutTreePositions,\n makeThenableParams: options.makeThenableParams,\n matchedParams: options.matchedParams,\n renderErrorBoundary(GlobalErrorComponent, children) {\n return createElement(ErrorBoundary, {\n fallback: GlobalErrorComponent,\n // oxlint-disable-next-line react/no-children-prop\n children,\n });\n },\n renderLayout(LayoutComponent, children, asyncParams) {\n return createElement(LayoutComponent as AppPageComponent, {\n // oxlint-disable-next-line react/no-children-prop\n children,\n params: asyncParams,\n });\n },\n renderLayoutSegmentProvider(segmentMap, children) {\n return createElement(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n LayoutSegmentProvider as ComponentType<any>,\n { segmentMap },\n children,\n );\n },\n resolveChildSegments: options.resolveChildSegments,\n routeSegments: options.routeSegments ?? [],\n skipLayoutWrapping: options.skipLayoutWrapping,\n });\n}\n\nfunction createAppPageBoundaryLayoutEntries<TModule extends AppPageModule>(\n route: AppPageBoundaryRoute<TModule> | null | undefined,\n layoutModules: readonly (TModule | null | undefined)[],\n): readonly AppPageBoundaryLayoutEntry[] {\n if (!route || layoutModules.length === 0) return [];\n\n return createAppPageLayoutEntries({\n errors: route.errors,\n layoutTreePositions: route.layoutTreePositions,\n layouts: layoutModules,\n notFounds: null,\n routeSegments: route.routeSegments,\n });\n}\n\nfunction resolveHttpAccessFallbackHeadRouteSegments<TModule extends AppPageModule>(\n route: AppPageBoundaryRoute<TModule> | null | undefined,\n layoutModules: readonly (TModule | null | undefined)[],\n): readonly string[] | undefined {\n if (!route?.routeSegments) {\n return undefined;\n }\n\n if (!route.layouts || layoutModules.length >= route.layouts.length) {\n return route.routeSegments;\n }\n\n const lastIncludedLayoutIndex = layoutModules.length - 1;\n if (lastIncludedLayoutIndex < 0) {\n return [];\n }\n\n const segmentCount = route.layoutTreePositions?.[lastIncludedLayoutIndex] ?? 0;\n return route.routeSegments.slice(0, segmentCount);\n}\n\nfunction resolveHttpAccessFallbackHeadLayoutTreePositions<TModule extends AppPageModule>(\n route: AppPageBoundaryRoute<TModule> | null | undefined,\n layoutModules: readonly (TModule | null | undefined)[],\n): readonly number[] | null | undefined {\n if (!route?.layouts || layoutModules.length >= route.layouts.length) {\n return route?.layoutTreePositions;\n }\n\n return route.layoutTreePositions?.slice(0, layoutModules.length);\n}\n\nfunction createAppPageBoundaryRscPayload<TModule extends AppPageModule>(\n options: AppPageBoundaryRscPayloadOptions<TModule>,\n): AppElements {\n const routeId = AppElementsWire.encodeRouteId(options.pathname, null);\n const layoutEntries = createAppPageBoundaryLayoutEntries(options.route, options.layoutModules);\n\n return {\n ...AppElementsWire.createMetadataEntries({\n interceptionContext: null,\n layoutIds: layoutEntries.map((entry) => entry.id),\n rootLayoutTreePath: layoutEntries[0]?.treePath ?? null,\n routeId,\n }),\n [routeId]: options.element,\n };\n}\n\nasync function renderAppPageBoundaryElementResponse<TModule extends AppPageModule>(\n options: AppPageBoundaryRenderCommonOptions<TModule> & {\n element: ReactNode;\n layoutModules: readonly (TModule | null | undefined)[];\n route?: AppPageBoundaryRoute<TModule> | null;\n routePattern?: string;\n status: number;\n },\n): Promise<Response> {\n const pathname = new URL(options.requestUrl).pathname;\n const payload = createAppPageBoundaryRscPayload({\n element: options.element,\n layoutModules: options.layoutModules,\n pathname,\n route: options.route,\n });\n\n return renderAppPageBoundaryResponse({\n async createHtmlResponse(rscStream, responseStatus) {\n const fontData = createAppPageFontData({\n getLinks: options.getFontLinks,\n getPreloads: options.getFontPreloads,\n getStyles: options.getFontStyles,\n });\n const ssrHandler = await options.loadSsrHandler();\n return renderAppPageHtmlResponse({\n clearRequestContext: options.clearRequestContext,\n fontData,\n fontLinkHeader: options.buildFontLinkHeader(fontData.preloads),\n middlewareHeaders: options.middlewareContext.headers,\n navigationContext: options.getNavigationContext(),\n rscStream,\n scriptNonce: options.scriptNonce,\n ssrHandler,\n status: responseStatus,\n });\n },\n createRscOnErrorHandler() {\n return options.createRscOnErrorHandler(pathname, options.routePattern ?? pathname);\n },\n element: payload,\n isRscRequest: options.isRscRequest,\n middlewareHeaders: options.middlewareContext.headers,\n renderToReadableStream: options.renderToReadableStream,\n status: options.status,\n });\n}\n\nexport async function renderAppPageHttpAccessFallback<TModule extends AppPageModule>(\n options: RenderAppPageHttpAccessFallbackOptions<TModule>,\n): Promise<Response | null> {\n const boundaryComponent =\n options.boundaryComponent ??\n resolveAppPageHttpAccessBoundaryComponent({\n getDefaultExport,\n rootForbiddenModule: options.rootForbiddenModule,\n rootNotFoundModule: options.rootNotFoundModule,\n rootUnauthorizedModule: options.rootUnauthorizedModule,\n routeForbiddenModule: options.route?.forbidden,\n routeNotFoundModule: options.route?.notFound,\n routeUnauthorizedModule: options.route?.unauthorized,\n statusCode: options.statusCode,\n });\n if (!boundaryComponent) {\n return null;\n }\n\n const layoutModules = options.layoutModules ?? options.route?.layouts ?? options.rootLayouts;\n const pathname = new URL(options.requestUrl).pathname;\n const routeSegments = resolveHttpAccessFallbackHeadRouteSegments(options.route, layoutModules);\n const { metadata, viewport } = await resolveAppPageHead({\n basePath: options.basePath ?? \"\",\n layoutModules,\n layoutTreePositions: resolveHttpAccessFallbackHeadLayoutTreePositions(\n options.route,\n layoutModules,\n ),\n metadataRoutes: options.metadataRoutes,\n params: options.matchedParams,\n routePath: options.route?.pattern ?? pathname,\n routeSegments,\n });\n\n const headElements: ReactNode[] = [\n createElement(\"meta\", { charSet: \"utf-8\", key: \"charset\" }),\n createElement(\"meta\", { content: \"noindex\", key: \"robots\", name: \"robots\" }),\n ];\n if (metadata) {\n headElements.push(createElement(MetadataHead, { key: \"metadata\", metadata, pathname }));\n }\n headElements.push(createElement(ViewportHead, { key: \"viewport\", viewport }));\n\n const skipLayoutWrapping = options.skipLayoutWrapping ?? false;\n const element = wrapRenderedBoundaryElement({\n element: createElement(Fragment, null, ...headElements, createElement(boundaryComponent)),\n globalErrorModule: options.globalErrorModule,\n includeGlobalErrorBoundary: true,\n isRscRequest: options.isRscRequest,\n layoutModules,\n layoutTreePositions: options.route?.layoutTreePositions,\n makeThenableParams: options.makeThenableParams,\n matchedParams: options.matchedParams,\n resolveChildSegments: options.resolveChildSegments,\n routeSegments: options.route?.routeSegments,\n skipLayoutWrapping,\n });\n\n return renderAppPageBoundaryElementResponse({\n ...options,\n // When global-not-found owns the document, no layouts should contribute to\n // the RSC payload's layout entries either — otherwise the SSR pipeline\n // would expect a root-layout tree path that doesn't exist in the markup.\n element,\n layoutModules: skipLayoutWrapping ? [] : layoutModules,\n route: skipLayoutWrapping ? null : options.route,\n routePattern: options.route?.pattern,\n status: options.statusCode,\n });\n}\n\nexport async function renderAppPageErrorBoundary<TModule extends AppPageModule>(\n options: RenderAppPageErrorBoundaryOptions<TModule>,\n): Promise<Response | null> {\n const errorBoundary = resolveAppPageErrorBoundary({\n getDefaultExport,\n errorModules: options.route?.errorPaths,\n globalErrorModule: options.globalErrorModule,\n layoutErrorModules: options.route?.errors,\n pageErrorModule: options.route?.error,\n });\n if (!errorBoundary.component) {\n return null;\n }\n\n const rawError =\n options.error instanceof Error ? options.error : new Error(String(options.error));\n rewriteClientHookError(rawError);\n const errorObject = options.sanitizeErrorForClient(rawError);\n const matchedParams = options.matchedParams ?? options.route?.params ?? {};\n const layoutModules = options.route?.layouts ?? options.rootLayouts;\n const pathname = new URL(options.requestUrl).pathname;\n\n const headElements: ReactNode[] = [createElement(\"meta\", { charSet: \"utf-8\", key: \"charset\" })];\n if (!errorBoundary.isGlobalError) {\n try {\n const { metadata, viewport } = await resolveAppPageHead({\n basePath: options.basePath ?? \"\",\n fallbackOnFileMetadataError: true,\n layoutModules,\n layoutTreePositions: options.route?.layoutTreePositions,\n metadataRoutes: options.metadataRoutes,\n params: matchedParams,\n routePath: options.route?.pattern ?? pathname,\n routeSegments: options.route?.routeSegments,\n });\n if (metadata) {\n headElements.push(createElement(MetadataHead, { key: \"metadata\", metadata, pathname }));\n }\n headElements.push(createElement(ViewportHead, { key: \"viewport\", viewport }));\n } catch (error) {\n console.error(\n `[vinext] App page error boundary head resolution failed for ${options.route?.pattern ?? pathname}:`,\n error,\n );\n }\n }\n\n const element = wrapRenderedBoundaryElement({\n element: createElement(\n Fragment,\n null,\n ...headElements,\n createElement(errorBoundary.component, {\n error: errorObject,\n }),\n ),\n globalErrorModule: options.globalErrorModule,\n includeGlobalErrorBoundary: !errorBoundary.isGlobalError,\n isRscRequest: options.isRscRequest,\n layoutModules,\n layoutTreePositions: options.route?.layoutTreePositions,\n makeThenableParams: options.makeThenableParams,\n matchedParams,\n resolveChildSegments: options.resolveChildSegments,\n routeSegments: options.route?.routeSegments,\n skipLayoutWrapping: errorBoundary.isGlobalError,\n });\n\n return renderAppPageBoundaryElementResponse({\n ...options,\n element,\n layoutModules,\n route: options.route,\n routePattern: options.route?.pattern,\n status: 200,\n });\n}\n\n// React client-only hooks that are absent from the `react-server` export\n// condition. When called in a Server Component they produce a TypeError like\n// \"useState is not a function\". Rewrite into an actionable message matching\n// the format used by the next/navigation shims (see client-hook-error.ts).\nconst _clientHookPattern =\n /\\b(useState|useEffect|useReducer|useRef|useContext|useLayoutEffect|useInsertionEffect|useSyncExternalStore|useTransition|useImperativeHandle|useDeferredValue|useActionState|useOptimistic|useEffectEvent)\\b.*is not a function/;\n\nfunction rewriteClientHookError(error: Error): void {\n const match = error.message.match(_clientHookPattern);\n if (match) {\n error.message = buildClientHookErrorMessage(`${match[1]}()`);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAqHA,SAAS,iBACP,QACyB;CACzB,OAAO,QAAQ,WAAW;;AAG5B,SAAS,4BACP,SAYW;CACX,OAAO,2BAA2B;EAChC,SAAS,QAAQ;EACjB;EACA,sBAAsB,iBAAiB,QAAQ,kBAAkB;EACjE,4BAA4B,QAAQ;EACpC,cAAc,QAAQ;EACtB,eAAe,QAAQ;EACvB,qBAAqB,QAAQ;EAC7B,oBAAoB,QAAQ;EAC5B,eAAe,QAAQ;EACvB,oBAAoB,sBAAsB,UAAU;GAClD,OAAO,cAAc,eAAe;IAClC,UAAU;IAEV;IACD,CAAC;;EAEJ,aAAa,iBAAiB,UAAU,aAAa;GACnD,OAAO,cAAc,iBAAqC;IAExD;IACA,QAAQ;IACT,CAAC;;EAEJ,4BAA4B,YAAY,UAAU;GAChD,OAAO,cAEL,uBACA,EAAE,YAAY,EACd,SACD;;EAEH,sBAAsB,QAAQ;EAC9B,eAAe,QAAQ,iBAAiB,EAAE;EAC1C,oBAAoB,QAAQ;EAC7B,CAAC;;AAGJ,SAAS,mCACP,OACA,eACuC;CACvC,IAAI,CAAC,SAAS,cAAc,WAAW,GAAG,OAAO,EAAE;CAEnD,OAAO,2BAA2B;EAChC,QAAQ,MAAM;EACd,qBAAqB,MAAM;EAC3B,SAAS;EACT,WAAW;EACX,eAAe,MAAM;EACtB,CAAC;;AAGJ,SAAS,2CACP,OACA,eAC+B;CAC/B,IAAI,CAAC,OAAO,eACV;CAGF,IAAI,CAAC,MAAM,WAAW,cAAc,UAAU,MAAM,QAAQ,QAC1D,OAAO,MAAM;CAGf,MAAM,0BAA0B,cAAc,SAAS;CACvD,IAAI,0BAA0B,GAC5B,OAAO,EAAE;CAGX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F,aAAa,KAAK,cAAc,cAAc;GAAE,KAAK;GAAY;GAAU,CAAC,CAAC;UACtE,OAAO;EACd,QAAQ,MACN,+DAA+D,QAAQ,OAAO,WAAW,SAAS,IAClG,MACD;;CAIL,MAAM,UAAU,4BAA4B;EAC1C,SAAS,cACP,UACA,MACA,GAAG,cACH,cAAc,cAAc,WAAW,EACrC,OAAO,aACR,CAAC,CACH;EACD,mBAAmB,QAAQ;EAC3B,4BAA4B,CAAC,cAAc;EAC3C,cAAc,QAAQ;EACtB;EACA,qBAAqB,QAAQ,OAAO;EACpC,oBAAoB,QAAQ;EAC5B;EACA,sBAAsB,QAAQ;EAC9B,eAAe,QAAQ,OAAO;EAC9B,oBAAoB,cAAc;EACnC,CAAC;CAEF,OAAO,qCAAqC;EAC1C,GAAG;EACH;EACA;EACA,OAAO,QAAQ;EACf,cAAc,QAAQ,OAAO;EAC7B,QAAQ;EACT,CAAC;;AAOJ,MAAM,qBACJ;AAEF,SAAS,uBAAuB,OAAoB;CAClD,MAAM,QAAQ,MAAM,QAAQ,MAAM,mBAAmB;CACrD,IAAI,OACF,MAAM,UAAU,4BAA4B,GAAG,MAAM,GAAG,IAAI"}
|
|
1
|
+
{"version":3,"file":"app-page-boundary-render.js","names":[],"sources":["../../src/server/app-page-boundary-render.ts"],"sourcesContent":["import { Fragment, createElement, type ComponentType, type ReactNode } from \"react\";\nimport { buildClientHookErrorMessage } from \"vinext/shims/client-hook-error\";\nimport { ErrorBoundary } from \"vinext/shims/error-boundary\";\nimport { LayoutSegmentProvider } from \"vinext/shims/layout-segment-context\";\nimport { MetadataHead, ViewportHead } from \"vinext/shims/metadata\";\nimport type { AppPageFontPreload } from \"./app-page-execution.js\";\nimport type { AppPageMiddlewareContext } from \"./app-page-response.js\";\nimport type { MetadataFileRoute } from \"./metadata-routes.js\";\nimport { resolveAppPageHead } from \"./app-page-head.js\";\nimport {\n renderAppPageBoundaryResponse,\n resolveAppPageErrorBoundary,\n resolveAppPageHttpAccessBoundaryComponent,\n wrapAppPageBoundaryElement,\n type AppPageParams,\n} from \"./app-page-boundary.js\";\nimport {\n createAppPageFontData,\n renderAppPageHtmlResponse,\n type AppPageSsrHandler,\n} from \"./app-page-stream.js\";\nimport { AppElementsWire, type AppElements } from \"./app-elements.js\";\nimport { createAppPageLayoutEntries } from \"./app-page-route-wiring.js\";\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype AppPageComponent = ComponentType<any>;\ntype AppPageModule = Record<string, unknown> & {\n default?: AppPageComponent | null | undefined;\n};\ntype AppPageBoundaryOnError = (\n error: unknown,\n requestInfo: unknown,\n errorContext: unknown,\n) => unknown;\n\ntype AppPageBoundaryRscPayloadOptions<TModule extends AppPageModule = AppPageModule> = {\n element: ReactNode;\n layoutModules: readonly (TModule | null | undefined)[];\n pathname: string;\n route?: AppPageBoundaryRoute<TModule> | null;\n};\n\ntype AppPageBoundaryLayoutEntry = {\n id: string;\n treePath: string;\n};\n\nexport type AppPageBoundaryRoute<TModule extends AppPageModule = AppPageModule> = {\n error?: TModule | null;\n errorPaths?: readonly TModule[] | null;\n errors?: readonly (TModule | null | undefined)[] | null;\n forbidden?: TModule | null;\n layoutTreePositions?: readonly number[] | null;\n layouts?: readonly (TModule | null | undefined)[];\n notFound?: TModule | null;\n params?: AppPageParams;\n pattern?: string;\n routeSegments?: readonly string[];\n unauthorized?: TModule | null;\n};\n\ntype AppPageBoundaryRenderCommonOptions<TModule extends AppPageModule = AppPageModule> = {\n buildFontLinkHeader: (preloads: readonly AppPageFontPreload[] | null | undefined) => string;\n clearRequestContext: () => void;\n createRscOnErrorHandler: (pathname: string, routePath: string) => AppPageBoundaryOnError;\n getFontLinks: () => string[];\n getFontPreloads: () => AppPageFontPreload[];\n getFontStyles: () => string[];\n getNavigationContext: () => unknown;\n globalErrorModule?: TModule | null;\n isEdgeRuntime?: boolean;\n isRscRequest: boolean;\n loadSsrHandler: () => Promise<AppPageSsrHandler>;\n makeThenableParams: (params: AppPageParams) => unknown;\n middlewareContext: AppPageMiddlewareContext;\n metadataRoutes: MetadataFileRoute[];\n /** Configured next.config `basePath`, threaded into file-based metadata href emission. */\n basePath?: string;\n renderToReadableStream: (\n element: ReactNode | AppElements,\n options: { onError: AppPageBoundaryOnError },\n ) => ReadableStream<Uint8Array>;\n requestUrl: string;\n resolveChildSegments: (\n routeSegments: readonly string[],\n treePosition: number,\n params: AppPageParams,\n ) => string[];\n rootLayouts: readonly (TModule | null | undefined)[];\n scriptNonce?: string;\n};\n\ntype RenderAppPageHttpAccessFallbackOptions<TModule extends AppPageModule = AppPageModule> = {\n boundaryComponent?: AppPageComponent | null;\n layoutModules?: readonly (TModule | null | undefined)[] | null;\n matchedParams: AppPageParams;\n rootForbiddenModule?: TModule | null;\n rootNotFoundModule?: TModule | null;\n rootUnauthorizedModule?: TModule | null;\n route?: AppPageBoundaryRoute<TModule> | null;\n /**\n * When true, the resolved boundary is rendered without wrapping it in the\n * route's layouts. Used by `global-not-found.tsx`, which provides its own\n * `<html>`/`<body>` and intentionally replaces the root layout.\n * Mirrors Next.js's `createNotFoundLoaderTree` behavior for `hasGlobalNotFound`.\n * @see https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/app-render.tsx#L495-L520\n */\n skipLayoutWrapping?: boolean;\n statusCode: number;\n} & AppPageBoundaryRenderCommonOptions<TModule>;\n\ntype RenderAppPageErrorBoundaryOptions<TModule extends AppPageModule = AppPageModule> = {\n error: unknown;\n matchedParams?: AppPageParams | null;\n route?: AppPageBoundaryRoute<TModule> | null;\n sanitizeErrorForClient: (error: Error) => Error;\n} & AppPageBoundaryRenderCommonOptions<TModule>;\n\nfunction getDefaultExport<TModule extends AppPageModule>(\n module: TModule | null | undefined,\n): AppPageComponent | null {\n return module?.default ?? null;\n}\n\nfunction wrapRenderedBoundaryElement<TModule extends AppPageModule>(\n options: Pick<\n AppPageBoundaryRenderCommonOptions<TModule>,\n \"globalErrorModule\" | \"isRscRequest\" | \"makeThenableParams\" | \"resolveChildSegments\"\n > & {\n element: ReactNode;\n includeGlobalErrorBoundary: boolean;\n layoutModules: readonly (TModule | null | undefined)[];\n layoutTreePositions?: readonly number[] | null;\n matchedParams: AppPageParams;\n routeSegments?: readonly string[];\n skipLayoutWrapping?: boolean;\n },\n): ReactNode {\n return wrapAppPageBoundaryElement({\n element: options.element,\n getDefaultExport,\n globalErrorComponent: getDefaultExport(options.globalErrorModule),\n includeGlobalErrorBoundary: options.includeGlobalErrorBoundary,\n isRscRequest: options.isRscRequest,\n layoutModules: options.layoutModules,\n layoutTreePositions: options.layoutTreePositions,\n makeThenableParams: options.makeThenableParams,\n matchedParams: options.matchedParams,\n renderErrorBoundary(GlobalErrorComponent, children) {\n return createElement(ErrorBoundary, {\n fallback: GlobalErrorComponent,\n // oxlint-disable-next-line react/no-children-prop\n children,\n });\n },\n renderLayout(LayoutComponent, children, asyncParams) {\n return createElement(LayoutComponent as AppPageComponent, {\n // oxlint-disable-next-line react/no-children-prop\n children,\n params: asyncParams,\n });\n },\n renderLayoutSegmentProvider(segmentMap, children) {\n return createElement(\n // oxlint-disable-next-line @typescript-eslint/no-explicit-any\n LayoutSegmentProvider as ComponentType<any>,\n { segmentMap },\n children,\n );\n },\n resolveChildSegments: options.resolveChildSegments,\n routeSegments: options.routeSegments ?? [],\n skipLayoutWrapping: options.skipLayoutWrapping,\n });\n}\n\nfunction createAppPageBoundaryLayoutEntries<TModule extends AppPageModule>(\n route: AppPageBoundaryRoute<TModule> | null | undefined,\n layoutModules: readonly (TModule | null | undefined)[],\n): readonly AppPageBoundaryLayoutEntry[] {\n if (!route || layoutModules.length === 0) return [];\n\n return createAppPageLayoutEntries({\n errors: route.errors,\n layoutTreePositions: route.layoutTreePositions,\n layouts: layoutModules,\n notFounds: null,\n routeSegments: route.routeSegments,\n });\n}\n\nfunction resolveHttpAccessFallbackHeadRouteSegments<TModule extends AppPageModule>(\n route: AppPageBoundaryRoute<TModule> | null | undefined,\n layoutModules: readonly (TModule | null | undefined)[],\n): readonly string[] | undefined {\n if (!route?.routeSegments) {\n return undefined;\n }\n\n if (!route.layouts || layoutModules.length >= route.layouts.length) {\n return route.routeSegments;\n }\n\n const lastIncludedLayoutIndex = layoutModules.length - 1;\n if (lastIncludedLayoutIndex < 0) {\n return [];\n }\n\n const segmentCount = route.layoutTreePositions?.[lastIncludedLayoutIndex] ?? 0;\n return route.routeSegments.slice(0, segmentCount);\n}\n\nfunction resolveHttpAccessFallbackHeadLayoutTreePositions<TModule extends AppPageModule>(\n route: AppPageBoundaryRoute<TModule> | null | undefined,\n layoutModules: readonly (TModule | null | undefined)[],\n): readonly number[] | null | undefined {\n if (!route?.layouts || layoutModules.length >= route.layouts.length) {\n return route?.layoutTreePositions;\n }\n\n return route.layoutTreePositions?.slice(0, layoutModules.length);\n}\n\nfunction createAppPageBoundaryRscPayload<TModule extends AppPageModule>(\n options: AppPageBoundaryRscPayloadOptions<TModule>,\n): AppElements {\n const routeId = AppElementsWire.encodeRouteId(options.pathname, null);\n const layoutEntries = createAppPageBoundaryLayoutEntries(options.route, options.layoutModules);\n\n return {\n ...AppElementsWire.createMetadataEntries({\n interceptionContext: null,\n layoutIds: layoutEntries.map((entry) => entry.id),\n rootLayoutTreePath: layoutEntries[0]?.treePath ?? null,\n routeId,\n }),\n [routeId]: options.element,\n };\n}\n\nasync function renderAppPageBoundaryElementResponse<TModule extends AppPageModule>(\n options: AppPageBoundaryRenderCommonOptions<TModule> & {\n element: ReactNode;\n layoutModules: readonly (TModule | null | undefined)[];\n route?: AppPageBoundaryRoute<TModule> | null;\n routePattern?: string;\n status: number;\n },\n): Promise<Response> {\n const pathname = new URL(options.requestUrl).pathname;\n const payload = createAppPageBoundaryRscPayload({\n element: options.element,\n layoutModules: options.layoutModules,\n pathname,\n route: options.route,\n });\n\n return renderAppPageBoundaryResponse({\n async createHtmlResponse(rscStream, responseStatus) {\n const fontData = createAppPageFontData({\n getLinks: options.getFontLinks,\n getPreloads: options.getFontPreloads,\n getStyles: options.getFontStyles,\n });\n const ssrHandler = await options.loadSsrHandler();\n return renderAppPageHtmlResponse({\n clearRequestContext: options.clearRequestContext,\n fontData,\n fontLinkHeader: options.buildFontLinkHeader(fontData.preloads),\n isEdgeRuntime: options.isEdgeRuntime,\n middlewareHeaders: options.middlewareContext.headers,\n navigationContext: options.getNavigationContext(),\n rscStream,\n scriptNonce: options.scriptNonce,\n ssrHandler,\n status: responseStatus,\n });\n },\n createRscOnErrorHandler() {\n return options.createRscOnErrorHandler(pathname, options.routePattern ?? pathname);\n },\n element: payload,\n isEdgeRuntime: options.isEdgeRuntime,\n isRscRequest: options.isRscRequest,\n middlewareHeaders: options.middlewareContext.headers,\n renderToReadableStream: options.renderToReadableStream,\n status: options.status,\n });\n}\n\nexport async function renderAppPageHttpAccessFallback<TModule extends AppPageModule>(\n options: RenderAppPageHttpAccessFallbackOptions<TModule>,\n): Promise<Response | null> {\n const boundaryComponent =\n options.boundaryComponent ??\n resolveAppPageHttpAccessBoundaryComponent({\n getDefaultExport,\n rootForbiddenModule: options.rootForbiddenModule,\n rootNotFoundModule: options.rootNotFoundModule,\n rootUnauthorizedModule: options.rootUnauthorizedModule,\n routeForbiddenModule: options.route?.forbidden,\n routeNotFoundModule: options.route?.notFound,\n routeUnauthorizedModule: options.route?.unauthorized,\n statusCode: options.statusCode,\n });\n if (!boundaryComponent) {\n return null;\n }\n\n const layoutModules = options.layoutModules ?? options.route?.layouts ?? options.rootLayouts;\n const pathname = new URL(options.requestUrl).pathname;\n const routeSegments = resolveHttpAccessFallbackHeadRouteSegments(options.route, layoutModules);\n const { metadata, viewport } = await resolveAppPageHead({\n basePath: options.basePath ?? \"\",\n layoutModules,\n layoutTreePositions: resolveHttpAccessFallbackHeadLayoutTreePositions(\n options.route,\n layoutModules,\n ),\n metadataRoutes: options.metadataRoutes,\n params: options.matchedParams,\n routePath: options.route?.pattern ?? pathname,\n routeSegments,\n });\n\n const headElements: ReactNode[] = [\n createElement(\"meta\", { charSet: \"utf-8\", key: \"charset\" }),\n createElement(\"meta\", { content: \"noindex\", key: \"robots\", name: \"robots\" }),\n ];\n if (metadata) {\n headElements.push(createElement(MetadataHead, { key: \"metadata\", metadata, pathname }));\n }\n headElements.push(createElement(ViewportHead, { key: \"viewport\", viewport }));\n\n const skipLayoutWrapping = options.skipLayoutWrapping ?? false;\n const element = wrapRenderedBoundaryElement({\n element: createElement(Fragment, null, ...headElements, createElement(boundaryComponent)),\n globalErrorModule: options.globalErrorModule,\n includeGlobalErrorBoundary: true,\n isRscRequest: options.isRscRequest,\n layoutModules,\n layoutTreePositions: options.route?.layoutTreePositions,\n makeThenableParams: options.makeThenableParams,\n matchedParams: options.matchedParams,\n resolveChildSegments: options.resolveChildSegments,\n routeSegments: options.route?.routeSegments,\n skipLayoutWrapping,\n });\n\n return renderAppPageBoundaryElementResponse({\n ...options,\n // When global-not-found owns the document, no layouts should contribute to\n // the RSC payload's layout entries either — otherwise the SSR pipeline\n // would expect a root-layout tree path that doesn't exist in the markup.\n element,\n layoutModules: skipLayoutWrapping ? [] : layoutModules,\n route: skipLayoutWrapping ? null : options.route,\n routePattern: options.route?.pattern,\n status: options.statusCode,\n });\n}\n\nexport async function renderAppPageErrorBoundary<TModule extends AppPageModule>(\n options: RenderAppPageErrorBoundaryOptions<TModule>,\n): Promise<Response | null> {\n const errorBoundary = resolveAppPageErrorBoundary({\n getDefaultExport,\n errorModules: options.route?.errorPaths,\n globalErrorModule: options.globalErrorModule,\n layoutErrorModules: options.route?.errors,\n pageErrorModule: options.route?.error,\n });\n if (!errorBoundary.component) {\n return null;\n }\n\n const rawError =\n options.error instanceof Error ? options.error : new Error(String(options.error));\n rewriteClientHookError(rawError);\n const errorObject = options.sanitizeErrorForClient(rawError);\n const matchedParams = options.matchedParams ?? options.route?.params ?? {};\n const layoutModules = options.route?.layouts ?? options.rootLayouts;\n const pathname = new URL(options.requestUrl).pathname;\n\n const headElements: ReactNode[] = [createElement(\"meta\", { charSet: \"utf-8\", key: \"charset\" })];\n if (!errorBoundary.isGlobalError) {\n try {\n const { metadata, viewport } = await resolveAppPageHead({\n basePath: options.basePath ?? \"\",\n fallbackOnFileMetadataError: true,\n layoutModules,\n layoutTreePositions: options.route?.layoutTreePositions,\n metadataRoutes: options.metadataRoutes,\n params: matchedParams,\n routePath: options.route?.pattern ?? pathname,\n routeSegments: options.route?.routeSegments,\n });\n if (metadata) {\n headElements.push(createElement(MetadataHead, { key: \"metadata\", metadata, pathname }));\n }\n headElements.push(createElement(ViewportHead, { key: \"viewport\", viewport }));\n } catch (error) {\n console.error(\n `[vinext] App page error boundary head resolution failed for ${options.route?.pattern ?? pathname}:`,\n error,\n );\n }\n }\n\n const element = wrapRenderedBoundaryElement({\n element: createElement(\n Fragment,\n null,\n ...headElements,\n createElement(errorBoundary.component, {\n error: errorObject,\n }),\n ),\n globalErrorModule: options.globalErrorModule,\n includeGlobalErrorBoundary: !errorBoundary.isGlobalError,\n isRscRequest: options.isRscRequest,\n layoutModules,\n layoutTreePositions: options.route?.layoutTreePositions,\n makeThenableParams: options.makeThenableParams,\n matchedParams,\n resolveChildSegments: options.resolveChildSegments,\n routeSegments: options.route?.routeSegments,\n skipLayoutWrapping: errorBoundary.isGlobalError,\n });\n\n return renderAppPageBoundaryElementResponse({\n ...options,\n element,\n layoutModules,\n route: options.route,\n routePattern: options.route?.pattern,\n status: 200,\n });\n}\n\n// React client-only hooks that are absent from the `react-server` export\n// condition. When called in a Server Component they produce a TypeError like\n// \"useState is not a function\". Rewrite into an actionable message matching\n// the format used by the next/navigation shims (see client-hook-error.ts).\nconst _clientHookPattern =\n /\\b(useState|useEffect|useReducer|useRef|useContext|useLayoutEffect|useInsertionEffect|useSyncExternalStore|useTransition|useImperativeHandle|useDeferredValue|useActionState|useOptimistic|useEffectEvent)\\b.*is not a function/;\n\nfunction rewriteClientHookError(error: Error): void {\n const match = error.message.match(_clientHookPattern);\n if (match) {\n error.message = buildClientHookErrorMessage(`${match[1]}()`);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAsHA,SAAS,i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SAAS,cACP,UACA,MACA,GAAG,cACH,cAAc,cAAc,WAAW,EACrC,OAAO,aACR,CAAC,CACH;EACD,mBAAmB,QAAQ;EAC3B,4BAA4B,CAAC,cAAc;EAC3C,cAAc,QAAQ;EACtB;EACA,qBAAqB,QAAQ,OAAO;EACpC,oBAAoB,QAAQ;EAC5B;EACA,sBAAsB,QAAQ;EAC9B,eAAe,QAAQ,OAAO;EAC9B,oBAAoB,cAAc;EACnC,CAAC;CAEF,OAAO,qCAAqC;EAC1C,GAAG;EACH;EACA;EACA,OAAO,QAAQ;EACf,cAAc,QAAQ,OAAO;EAC7B,QAAQ;EACT,CAAC;;AAOJ,MAAM,qBACJ;AAEF,SAAS,uBAAuB,OAAoB;CAClD,MAAM,QAAQ,MAAM,QAAQ,MAAM,mBAAmB;CACrD,IAAI,OACF,MAAM,UAAU,4BAA4B,GAAG,MAAM,GAAG,IAAI"}
|
|
@@ -55,6 +55,7 @@ type RenderAppPageBoundaryResponseOptions<TElement> = {
|
|
|
55
55
|
createHtmlResponse: (rscStream: ReadableStream<Uint8Array>, status: number) => Promise<Response>;
|
|
56
56
|
createRscOnErrorHandler: () => AppPageBoundaryOnError;
|
|
57
57
|
element: TElement;
|
|
58
|
+
isEdgeRuntime?: boolean;
|
|
58
59
|
isRscRequest: boolean;
|
|
59
60
|
middlewareHeaders?: Headers | null;
|
|
60
61
|
renderToReadableStream: (element: TElement, options: {
|
|
@@ -2,6 +2,7 @@ import { runWithFetchDedupe } from "../shims/fetch-cache.js";
|
|
|
2
2
|
import { VINEXT_RSC_CONTENT_TYPE, VINEXT_RSC_VARY_HEADER, applyRscCompatibilityIdHeader } from "./app-rsc-cache-busting.js";
|
|
3
3
|
import { resolveAppPageSegmentParams } from "./app-page-params.js";
|
|
4
4
|
import { mergeMiddlewareResponseHeaders } from "./middleware-response-headers.js";
|
|
5
|
+
import { applyEdgeRuntimeHeader } from "./app-page-response.js";
|
|
5
6
|
//#region src/server/app-page-boundary.ts
|
|
6
7
|
function resolveAppPageHttpAccessBoundaryComponent(options) {
|
|
7
8
|
let boundaryModule;
|
|
@@ -69,6 +70,7 @@ async function renderAppPageBoundaryResponse(options) {
|
|
|
69
70
|
"Content-Type": VINEXT_RSC_CONTENT_TYPE,
|
|
70
71
|
Vary: VINEXT_RSC_VARY_HEADER
|
|
71
72
|
});
|
|
73
|
+
applyEdgeRuntimeHeader(headers, options.isEdgeRuntime);
|
|
72
74
|
mergeMiddlewareResponseHeaders(headers, options.middlewareHeaders ?? null);
|
|
73
75
|
applyRscCompatibilityIdHeader(headers);
|
|
74
76
|
return new Response(rscStream, {
|