Repository: vercel/next.js
File: packages/next/src/server/app-render/app-render.tsx (TypeScript)

Code before:
    requestId,
    flightRouterState,
    workStore,
    url,
  } = ctx

  const serveStreamingMetadata = !!ctx.renderOpts.serveStreamingMetadata

  if (!options?.skipPageRendering) {
    const preloadCallbacks: PreloadCallbacks = []

    // If we're performing instant validation, we need to render the whole tree,
    // without skipping shared layouts.
    const needsFullTree =
      process.env.__NEXT_DEV_SERVER &&
      ctx.renderOpts.cacheComponents &&
      !options?.actionResult && // Only for navigations
      (await anySegmentNeedsInstantValidation(loaderTree))

    const metadataIsRuntimePrefetchable =
      await anySegmentHasRuntimePrefetchEnabled(loaderTree)
    const { Viewport, Metadata, MetadataOutlet } = createMetadataComponents({
      tree: loaderTree,
      parsedQuery: query,
      pathname: url.pathname,
      metadataContext: createMetadataContext(ctx.renderOpts),
      getDynamicParamFromSegment,
      workStore,
      serveStreamingMetadata,
      isRuntimePrefetchable: metadataIsRuntimePrefetchable,
    })

    const rscHead = createElement(
      Fragment,
      {
        key: flightDataPathHeadKey,
      },
      createElement(NonIndex, {
        createElement,
        pagePath: ctx.pagePath,
        statusCode: ctx.res.statusCode,
        isPossibleServerAction: ctx.isPossibleServerAction,
      }),
      createElement(Viewport, {
        key: getFlightViewportKey(requestId),
      }),
      createElement(Metadata, {
        key: getFlightMetadataKey(requestId),
      })
    )


Review comment (bug):
hmm. i guess the thinking is that if `page.tsx` is under a runtime prefetchable layout (or is runtime prefetchable itself), then we'd render its metadata as part of a runtime prefetch. but i think this might be wrong if we have a runtime prefetchable parallel route:
```
app/
  @slot/
    foo/
      page.tsx // `prefetch: 'runtime'`
  foo/
    page.tsx // `prefetch: 'static'`
```
for `/foo`, this'd pass `anySegmentHasRuntimePrefetchEnabled` but `/foo/page.tsx` would never get runtime prefetched. but honestly i don't think i have a good grasp on how we handle `generateMetadata` from parallel routes...




Code after:
      createElement,
      createMetadataComponents,
      Fragment,
    },
    query,
    requestId,
    flightRouterState,
    workStore,
    url,
  } = ctx

  const serveStreamingMetadata = !!ctx.renderOpts.serveStreamingMetadata

  if (!options?.skipPageRendering) {
    const preloadCallbacks: PreloadCallbacks = []

    // If we're performing instant validation, we need to render the whole tree,
    // without skipping shared layouts.
    const needsFullTree =
      process.env.__NEXT_DEV_SERVER &&
      ctx.renderOpts.cacheComponents &&
      !options?.actionResult && // Only for navigations
      (await anySegmentNeedsInstantValidation(loaderTree))

    const metadataIsRuntimePrefetchable =
      await anySegmentHasRuntimePrefetchEnabled(loaderTree)
    const { Viewport, Metadata, MetadataOutlet } = createMetadataComponents({
      tree: loaderTree,
      parsedQuery: query,
      pathname: url.pathname,
      metadataContext: createMetadataContext(ctx.renderOpts),
      interpolatedParams: ctx.interpolatedParams,
      serveStreamingMetadata,
      isRuntimePrefetchable: metadataIsRuntimePrefetchable,
    })

    const rscHead = createElement(
      Fragment,
      {
        key: flightDataPathHeadKey,
      },
      createElement(NonIndex, {
        createElement,
        pagePath: ctx.pagePath,
        statusCode: ctx.res.statusCode,
        isPossibleServerAction: ctx.isPossibleServerAction,
      }),
      createElement(Viewport, {
        key: getFlightViewportKey(requestId),
      }),
      createElement(Metadata, {