From 5db15b6ec7cd41cc15214f4448b064f4dd11f974 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 20 Aug 2021 13:17:57 -0700 Subject: demos -> examples Former-commit-id: 19a5d395bd41b0a0b854cdf749eb96149f91cbe1 --- .../bun-framework-next/renderDocument.tsx | 618 +++++++++++++++++++++ 1 file changed, 618 insertions(+) create mode 100644 examples/hello-next/bun-framework-next/renderDocument.tsx (limited to 'examples/hello-next/bun-framework-next/renderDocument.tsx') diff --git a/examples/hello-next/bun-framework-next/renderDocument.tsx b/examples/hello-next/bun-framework-next/renderDocument.tsx new file mode 100644 index 000000000..67c89efc2 --- /dev/null +++ b/examples/hello-next/bun-framework-next/renderDocument.tsx @@ -0,0 +1,618 @@ +import * as 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, +} from "next/dist/shared/lib/utils"; +import * as NextDocument from "next/document"; +import * as ReactDOMServer from "react-dom/server.browser"; +import * as url from "url"; +import * as React from "react"; + +const dev = process.env.NODE_ENV === "development"; + +type ParsedUrlQuery = Record; + +const isJSFile = (file: string) => + file.endsWith(".js") || + file.endsWith(".mjs") || + file.endsWith(".ts") || + file.endsWith(".tsx"); + +function getScripts(files: DocumentFiles) { + const { context, props } = this; + const { + assetPrefix, + buildManifest, + isDevelopment, + devOnlyCacheBusterQueryString, + disableOptimizedLoading, + } = context; + const normalScripts = files.allFiles.filter(isJSFile); + const lowPriorityScripts = buildManifest.lowPriorityFiles?.filter(isJSFile); + + return [...normalScripts, ...lowPriorityScripts].map((file) => { + return ( +