/// import React, { type JSX } from 'react' import { NEXT_BUILTIN_DOCUMENT } from '../shared/lib/constants' import type { DocumentContext, DocumentInitialProps, DocumentProps, DocumentType, NEXT_DATA, } from '../shared/lib/utils' import type { ScriptProps } from '../client/script' import type { NextFontManifest } from '../build/webpack/plugins/next-font-manifest-plugin' import { getPageFiles } from '../server/get-page-files' import type { BuildManifest } from '../server/get-page-files' import { htmlEscapeJsonString } from '../server/htmlescape' import isError from '../lib/is-error' import { HtmlContext, useHtmlContext, } from '../shared/lib/html-context.shared-runtime' import type { HtmlProps } from '../shared/lib/html-context.shared-runtime' import { encodeURIPath } from '../shared/lib/encode-uri-path' import type { DeepReadonly } from '../shared/lib/deep-readonly' import { getTracer } from '../server/lib/trace/tracer' import { getTracedMetadata } from '../server/lib/trace/utils' export type { DocumentContext, DocumentInitialProps, DocumentProps } export type OriginProps = { nonce?: string crossOrigin?: 'anonymous' | 'use-credentials' | '' | undefined children?: React.ReactNode } type DocumentFiles = { sharedFiles: readonly string[] pageFiles: readonly string[] allFiles: readonly string[] } type HeadHTMLProps = React.DetailedHTMLProps< React.HTMLAttributes, HTMLHeadElement > type HeadProps = OriginProps & HeadHTMLProps /** Set of pages that have triggered a large data warning on production mode. */ const largePageDataWarnings = new Set() function getDocumentFiles( buildManifest: BuildManifest, pathname: string, inAmpMode: boolean ): DocumentFiles { const sharedFiles: readonly string[] = getPageFiles(buildManifest, '/_app') const pageFiles: readonly string[] = process.env.NEXT_RUNTIME !== 'edge' && inAmpMode ? [] : getPageFiles(buildManifest, pathname) return { sharedFiles, pageFiles, allFiles: [...new Set([...sharedFiles, ...pageFiles])], } } function getPolyfillScripts(context: HtmlProps, props: OriginProps) { // polyfills.js has to be rendered as nomodule without async // It also has to be the first script to load const { assetPrefix, buildManifest, assetQueryString, disableOptimizedLoading, crossOrigin, } = context return buildManifest.polyfillFiles .filter( (polyfill) => polyfill.endsWith('.js') && !polyfill.endsWith('.module.js') ) .map((polyfill) => (