From c06e34c687187a528d0da39eddec71323b56e77a Mon Sep 17 00:00:00 2001 From: Jack Hanford Date: Mon, 22 Nov 2021 10:23:14 -0800 Subject: misc --- packages/bun-framework-next/renderDocument.tsx | 24 +++++++++--------------- packages/bun-framework-next/server-polyfills.tsx | 7 ++----- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/packages/bun-framework-next/renderDocument.tsx b/packages/bun-framework-next/renderDocument.tsx index 5b4cab0ce..661bebdc0 100644 --- a/packages/bun-framework-next/renderDocument.tsx +++ b/packages/bun-framework-next/renderDocument.tsx @@ -1,4 +1,4 @@ -import * as App from "next/app"; +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"; @@ -23,7 +23,9 @@ 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 { BODY_RENDER_TARGET } from "next/constants"; + +// This constant was removed from Next, Is it doing anything? +const BODY_RENDER_TARGET = "__NEXT_BODY_RENDER_TARGET__"; const dev = process.env.NODE_ENV === "development"; @@ -362,11 +364,8 @@ export async function render({ pages["/_app"] = []; } - const AppComponent = AppComponent_ || App.default; - const Document = - (DocumentNamespace && DocumentNamespace.default) || NextDocument.default; - // Document.Html.prototype.getScripts = getScripts; - // } + const AppComponent = AppComponent_ || App; + const Document = (DocumentNamespace as any)?.default || NextDocument.default; const callMiddleware = async (method: string, args: any[], props = false) => { let results: any = props ? {} : []; @@ -422,7 +421,7 @@ export async function render({ delete query.__nextLocale; delete query.__nextDefaultLocale; - const isSSG = !!getStaticProps; + // const isSSG = !!getStaticProps; const defaultAppGetInitialProps = App.getInitialProps === (App as any).origGetInitialProps; @@ -518,7 +517,7 @@ export async function render({ ); }, defaultGetInitialProps: async ( - docCtx: DocumentContext + docCtx: NextDocument.DocumentContext ): Promise => { const enhanceApp = (AppComp: any) => { return (props: any) => ; @@ -696,13 +695,7 @@ export async function render({ const renderOpts = { params: route.params, }; - // renderOpts.params = _params || params; - // parsedUrl.pathname = denormalizePagePath(parsedUrl.pathname!); - // renderOpts.resolvedUrl = formatUrl({ - // ...parsedUrl, - // query: origQuery, - // }); const docComponentsRendered: DocumentProps["docComponentsRendered"] = {}; let html = renderDocument(Document, { @@ -752,6 +745,7 @@ export async function render({ nextExport: nextExport, useMaybeDeferContent, }); + // __NEXT_BODY_RENDER_TARGET__ const bodyRenderIdx = html.indexOf(BODY_RENDER_TARGET); html = html.substring(0, bodyRenderIdx) + diff --git a/packages/bun-framework-next/server-polyfills.tsx b/packages/bun-framework-next/server-polyfills.tsx index 887621978..57960e4fa 100644 --- a/packages/bun-framework-next/server-polyfills.tsx +++ b/packages/bun-framework-next/server-polyfills.tsx @@ -3,12 +3,9 @@ globalThis.global = globalThis; import { Buffer } from "buffer"; import { URL } from "url-polyfill"; import { TextEncoder, TextDecoder } from "fast-text-encoding"; - -globalThis.Buffer = Buffer; - import * as React from "react"; -var onlyChildPolyfill = React.Children.only; +const onlyChildPolyfill = React.Children.only; React.Children.only = function (children) { if ( @@ -22,7 +19,7 @@ React.Children.only = function (children) { return onlyChildPolyfill(children); }; +globalThis.Buffer = Buffer; globalThis.URL = URL; - globalThis.TextEncoder ||= TextEncoder; globalThis.TextDecoder ||= TextDecoder; -- cgit v1.2.3