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 type { NextRouter } from "next/dist/shared/lib/router/router"; import { getDisplayName, loadGetInitialProps, type AppType, type ComponentsEnhancer, type DocumentInitialProps, type DocumentProps, type DocumentType, type NextComponentType, type RenderPage, type RenderPageResult, } from "next/dist/shared/lib/utils"; import * as NextUtils from "next/dist/shared/lib/utils"; import type { 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 { packageVersion } from "macro:./packageVersion.ts"; const nextVersion = packageVersion("next"); var HtmlContext; // HtmlContext is in different places depending on the next version if ("HtmlContext" in NextUtils) { HtmlContext = NextUtils.HtmlContext; } else { try { HtmlContext = require("next/dist/shared/lib/html-context").HtmlContext; } catch (err) { throw err; } } function appendNextBody(documentHTML: string, pageContent: string) { if (nextVersion.startsWith("12.0")) { const NEXT_12_0_BODY_RENDER_TARGET = "__NEXT_BODY_RENDER_TARGET__"; const bodyRenderIdx = documentHTML.indexOf(NEXT_12_0_BODY_RENDER_TARGET); if (!documentHTML.startsWith("")) { documentHTML = "" + documentHTML; } return ( documentHTML.substring(0, bodyRenderIdx) + pageContent + documentHTML.substring( bodyRenderIdx + NEXT_12_0_BODY_RENDER_TARGET.length ) ); } else { var [renderTargetPrefix, renderTargetSuffix] = documentHTML.split( "" ); if (!renderTargetPrefix || !renderTargetSuffix) { 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" + documentHTML ); } if (!renderTargetPrefix.startsWith("")) { renderTargetPrefix = "" + renderTargetPrefix; } return ( renderTargetPrefix + `
${pageContent || ""}
` + renderTargetSuffix ); } } 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) ?? []; var entryPointIndex = -1; const scripts = [...normalScripts, ...lowPriorityScripts].map( (file, index) => { // if (file.includes(".entry.")) { // entryPointIndex = index; // } return (