From 2a6edf00cdb1326267d9099adc2986c94f048134 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 7 Sep 2021 22:08:18 -0700 Subject: lotta changes --- .../bun-framework-next/renderDocument.tsx | 722 +++++++++++++++++++++ 1 file changed, 722 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..356ff788b --- /dev/null +++ b/examples/hello-next/bun-framework-next/renderDocument.tsx @@ -0,0 +1,722 @@ +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, + HtmlContext, +} 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"; +import * as ReactIs from "react-is"; +import { BODY_RENDER_TARGET } from "next/constants"; + +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"); + +const notImplementedProxy = (base) => + new Proxy( + {}, + { + deleteProperty: function (target, prop) { + return undefined; + }, + enumerate: function (oTarget, sKey) { + return [].entries(); + }, + ownKeys: function (oTarget, sKey) { + return [].values(); + }, + has: function (oTarget, sKey) { + return false; + }, + defineProperty: function (oTarget, sKey, oDesc) { + return undefined; + }, + getOwnPropertyDescriptor: function (oTarget, sKey) { + return undefined; + }, + get(this, prop) { + throw new ReferenceError( + `${base} is not available for this environment.` + ); + }, + set(this, prop, value) { + throw new ReferenceError( + `${base} is not available for this environment.` + ); + }, + } + ); + +globalThis.fetch = (url, options) => { + return Promise.reject(new Error(`fetch is not implemented yet. sorry!!`)); +}; + +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 ( +