import App from "next/app"; import { AmpStateContext } from "next/dist/shared/lib/amp-context"; import { HeadManagerContext } from "next/dist/shared/lib/head-manager-context"; import Loadable from "next/dist/shared/lib/loadable"; import { LoadableContext } from "next/dist/shared/lib/loadable-context"; import { RouterContext } from "next/dist/shared/lib/router-context"; import { NextRouter } from "next/dist/shared/lib/router/router"; import { AppType, ComponentsEnhancer, DocumentInitialProps, DocumentProps, DocumentType, getDisplayName, loadGetInitialProps, NextComponentType, RenderPage, RenderPageResult, HtmlContext, } from "next/dist/shared/lib/utils"; import { RenderOpts } from "next/dist/server/render"; import * as NextDocument from "next/document"; import * as ReactDOMServer from "react-dom/server.browser"; import * as React from "react"; import * as ReactIs from "react-is"; import nextPackage from "next/package.json"; function appendNextBody(html: string, docPropsHtml) { if (nextPackage.version.startsWith("12.0")) { const NEXT_12_0_BODY_RENDER_TARGET = "__NEXT_BODY_RENDER_TARGET__"; const bodyRenderIdx = html.indexOf(NEXT_12_0_BODY_RENDER_TARGET); return ( html.substring(0, bodyRenderIdx) + docPropsHtml + html.substring(bodyRenderIdx + NEXT_12_0_BODY_RENDER_TARGET.length) ); } else { const end = html.lastIndexOf(""); const start = html.lastIndexOf( "", end ); if (start === -1 || end === -1) { throw new Error( "Can't find where your starts or where the ends. \nThis is probably a version incompatibility. Please mention this error in Bun's discord\n\n" + html ); } return ( html.substring(0, start) + `
${docPropsHtml || ""}
` + html.substring(end) ); } } const dev = process.env.NODE_ENV === "development"; type ParsedUrlQuery = Record; const isJSFile = (file: string) => file.endsWith(".js") || file.endsWith(".jsx") || file.endsWith(".mjs") || file.endsWith(".ts") || file.endsWith(".tsx"); type DocumentFiles = { sharedFiles: readonly string[]; pageFiles: readonly string[]; allFiles: readonly string[]; }; function getScripts(files: DocumentFiles) { const { context, props } = this; const { assetPrefix, buildManifest, isDevelopment, devOnlyCacheBusterQueryString, } = context; const normalScripts = files?.allFiles?.filter(isJSFile) ?? []; const lowPriorityScripts = buildManifest?.lowPriorityFiles?.filter(isJSFile) ?? []; return [...normalScripts, ...lowPriorityScripts].map((file) => { return (