diff --git a/packages/next/src/export/index.ts b/packages/next/src/export/index.ts index b667808c6c8ec..b52db8cd6d3dd 100644 --- a/packages/next/src/export/index.ts +++ b/packages/next/src/export/index.ts @@ -420,8 +420,8 @@ export async function exportAppImpl( deploymentId: nextConfig.deploymentId, experimental: { isAppPPREnabled: checkIsAppPPREnabled(nextConfig.experimental.ppr), + clientTraceMetadata: nextConfig.experimental.clientTraceMetadata, swrDelta: nextConfig.experimental.swrDelta, - clientTraceMetadata: nextConfig.experimental.clientTraceMetadata === true, }, } diff --git a/packages/next/src/server/app-render/app-render.tsx b/packages/next/src/server/app-render/app-render.tsx index b5a0a1478edf8..23facb23c4902 100644 --- a/packages/next/src/server/app-render/app-render.tsx +++ b/packages/next/src/server/app-render/app-render.tsx @@ -76,7 +76,10 @@ import { appendMutableCookies } from '../web/spec-extension/adapters/request-coo import { createServerInsertedHTML } from './server-inserted-html' import { getRequiredScripts } from './required-scripts' import { addPathPrefix } from '../../shared/lib/router/utils/add-path-prefix' -import { makeGetServerInsertedHTML } from './make-get-server-inserted-html' +import { + getTracedMetadata, + makeGetServerInsertedHTML, +} from './make-get-server-inserted-html' import { walkTreeWithFlightRouterState } from './walk-tree-with-flight-router-state' import { createComponentTree } from './create-component-tree' import { getAssetQueryString } from './get-asset-query-string' @@ -912,6 +915,11 @@ async function renderToHTMLOrFlightImpl( tree, formState, }: RenderToStreamOptions): Promise => { + const tracingMetadata = getTracedMetadata( + getTracer().getTracePropagationData(), + renderOpts.experimental.clientTraceMetadata + ) + const polyfills: JSX.IntrinsicElements['script'][] = buildManifest.polyfillFiles .filter( @@ -995,9 +1003,7 @@ async function renderToHTMLOrFlightImpl( renderServerInsertedHTML, serverCapturedErrors: allCapturedErrors, basePath: renderOpts.basePath, - traceData: renderOpts.experimental.clientTraceMetadata - ? getTracer().getTracePropagationData() - : [], + tracingMetadata: tracingMetadata, }) const renderer = createStaticRenderer({ @@ -1322,9 +1328,7 @@ async function renderToHTMLOrFlightImpl( renderServerInsertedHTML, serverCapturedErrors: [], basePath: renderOpts.basePath, - traceData: renderOpts.experimental.clientTraceMetadata - ? getTracer().getTracePropagationData() - : [], + tracingMetadata: tracingMetadata, }), serverInsertedHTMLToHead: true, validateRootLayout, diff --git a/packages/next/src/server/app-render/make-get-server-inserted-html.tsx b/packages/next/src/server/app-render/make-get-server-inserted-html.tsx index 8571cf949b3c9..624b1df8d7ac7 100644 --- a/packages/next/src/server/app-render/make-get-server-inserted-html.tsx +++ b/packages/next/src/server/app-render/make-get-server-inserted-html.tsx @@ -11,16 +11,24 @@ import { RedirectStatusCode } from '../../client/components/redirect-status-code import { addPathPrefix } from '../../shared/lib/router/utils/add-path-prefix' import type { ClientTraceDataEntry } from '../lib/trace/tracer' +export function getTracedMetadata( + traceData: ClientTraceDataEntry[], + clientTraceMetadata: string[] | undefined +): ClientTraceDataEntry[] | undefined { + if (!clientTraceMetadata) return undefined + return traceData.filter(({ key }) => clientTraceMetadata.includes(key)) +} + export function makeGetServerInsertedHTML({ polyfills, renderServerInsertedHTML, serverCapturedErrors, - traceData, + tracingMetadata, basePath, }: { polyfills: JSX.IntrinsicElements['script'][] renderServerInsertedHTML: () => React.ReactNode - traceData: ClientTraceDataEntry[] + tracingMetadata: ClientTraceDataEntry[] | undefined serverCapturedErrors: Error[] basePath: string }) { @@ -84,14 +92,17 @@ export function makeGetServerInsertedHTML({ return