diff options
author | 2022-03-30 18:54:52 -0700 | |
---|---|---|
committer | 2022-03-30 18:54:52 -0700 | |
commit | c4c94731e142c7c3a74cd3771bc779673db011cb (patch) | |
tree | b04605eb4d8d3a6ee8025905785af15e520bc76f /packages/bun-framework-next/renderDocument.tsx | |
parent | e2f5a742cab7f166404315f237bf234e7ecc062a (diff) | |
download | bun-c4c94731e142c7c3a74cd3771bc779673db011cb.tar.gz bun-c4c94731e142c7c3a74cd3771bc779673db011cb.tar.zst bun-c4c94731e142c7c3a74cd3771bc779673db011cb.zip |
[bun-framework-next] Support Next 12.1.3 & React 18
Diffstat (limited to 'packages/bun-framework-next/renderDocument.tsx')
-rw-r--r-- | packages/bun-framework-next/renderDocument.tsx | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/packages/bun-framework-next/renderDocument.tsx b/packages/bun-framework-next/renderDocument.tsx index 1eed8d989..4b299c149 100644 --- a/packages/bun-framework-next/renderDocument.tsx +++ b/packages/bun-framework-next/renderDocument.tsx @@ -4,29 +4,43 @@ 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 { type NextRouter } from "next/dist/shared/lib/router/router"; import { - AppType, - ComponentsEnhancer, - DocumentInitialProps, - DocumentProps, - DocumentType, getDisplayName, loadGetInitialProps, - NextComponentType, - RenderPage, - RenderPageResult, - HtmlContext, + type AppType, + type ComponentsEnhancer, + type DocumentInitialProps, + type DocumentProps, + type DocumentType, + type NextComponentType, + type RenderPage, + type RenderPageResult, } from "next/dist/shared/lib/utils"; -import { RenderOpts } from "next/dist/server/render"; +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 nextPackage from "next/package.json"; +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(html: string, docPropsHtml) { - if (nextPackage.version.startsWith("12.0")) { + if (nextVersion.startsWith("12.0")) { const NEXT_12_0_BODY_RENDER_TARGET = "__NEXT_BODY_RENDER_TARGET__"; const bodyRenderIdx = html.indexOf(NEXT_12_0_BODY_RENDER_TARGET); @@ -228,6 +242,7 @@ function renderDocument( useMaybeDeferContent, ...docProps, }; + return ( "<!DOCTYPE html>" + ReactDOMServer.renderToStaticMarkup( |