Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert support for render prop in <Main /> #32184

Merged
merged 3 commits into from Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/next/pages/_document.tsx
Expand Up @@ -756,15 +756,11 @@ export class Head extends Component<
}
}

export function Main({
children,
}: {
children?: (content: JSX.Element) => JSX.Element
}) {
const { docComponentsRendered, useMainContent } = useContext(HtmlContext)
const content = useMainContent(children)
export function Main() {
const { docComponentsRendered } = useContext(HtmlContext)
docComponentsRendered.Main = true
return content
// @ts-ignore
return <next-js-internal-body-render-target />
}

export class NextScript extends Component<OriginProps> {
Expand Down
45 changes: 7 additions & 38 deletions packages/next/server/render.tsx
Expand Up @@ -1048,20 +1048,6 @@ export async function renderToHTML(
return inAmpMode ? children : <div id="__next">{children}</div>
}

const appWrappers: Array<(content: JSX.Element) => JSX.Element> = []
const getWrappedApp = (app: JSX.Element) => {
// Prevent wrappers from reading/writing props by rendering inside an
// opaque component. Wrappers should use context instead.
const InnerApp = () => app
return (
<AppContainerWithIsomorphicFiberStructure>
{appWrappers.reduceRight((innerContent, fn) => {
return fn(innerContent)
}, <InnerApp />)}
</AppContainerWithIsomorphicFiberStructure>
)
}

/**
* Rules of Static & Dynamic HTML:
*
Expand Down Expand Up @@ -1106,13 +1092,13 @@ export async function renderToHTML(

const html = ReactDOMServer.renderToString(
<Body>
{getWrappedApp(
<AppContainerWithIsomorphicFiberStructure>
<EnhancedApp
Component={EnhancedComponent}
router={router}
{...props}
/>
)}
</AppContainerWithIsomorphicFiberStructure>
</Body>
)
return { html, head }
Expand All @@ -1137,15 +1123,6 @@ export async function renderToHTML(
documentElement: (htmlProps: HtmlProps) => (
<Document {...htmlProps} {...docProps} />
),
useMainContent: (fn?: (content: JSX.Element) => JSX.Element) => {
if (fn) {
throw new Error(
'The `children` property is not supported by non-functional custom Document components'
)
}
// @ts-ignore
return <next-js-internal-body-render-target />
},
head: docProps.head,
headTags: await headTags(documentCtx),
styles: docProps.styles,
Expand All @@ -1164,9 +1141,9 @@ export async function renderToHTML(
</Body>
) : (
<Body>
{getWrappedApp(
<AppContainerWithIsomorphicFiberStructure>
<App {...props} Component={Component} router={router} />
)}
</AppContainerWithIsomorphicFiberStructure>
</Body>
)
return process.browser
Expand All @@ -1181,9 +1158,9 @@ export async function renderToHTML(
</Body>
) : (
<Body>
{getWrappedApp(
<AppContainerWithIsomorphicFiberStructure>
<App {...props} Component={Component} router={router} />
)}
</AppContainerWithIsomorphicFiberStructure>
</Body>
)
// for non-concurrent rendering we need to ensure App is rendered
Expand All @@ -1196,13 +1173,6 @@ export async function renderToHTML(
return {
bodyResult,
documentElement: () => (Document as any)(),
useMainContent: (fn?: (_content: JSX.Element) => JSX.Element) => {
if (fn) {
appWrappers.push(fn)
}
// @ts-ignore
return <next-js-internal-body-render-target />
},
head,
headTags: [],
styles: jsxStyleRegistry.styles(),
Expand Down Expand Up @@ -1243,7 +1213,7 @@ export async function renderToHTML(
locales,
runtimeConfig,
} = renderOpts
const htmlProps: any = {
const htmlProps: HtmlProps = {
__NEXT_DATA__: {
props, // The result of getInitialProps
page: pathname, // The rendered page
Expand Down Expand Up @@ -1297,7 +1267,6 @@ export async function renderToHTML(
head: documentResult.head,
headTags: documentResult.headTags,
styles: documentResult.styles,
useMainContent: documentResult.useMainContent,
useMaybeDeferContent,
crossOrigin: renderOpts.crossOrigin,
optimizeCss: renderOpts.optimizeCss,
Expand Down
1 change: 0 additions & 1 deletion packages/next/shared/lib/utils.ts
Expand Up @@ -221,7 +221,6 @@ export type HtmlProps = {
styles?: React.ReactElement[] | React.ReactFragment
head?: Array<JSX.Element | null>
useMaybeDeferContent: MaybeDeferContentHook
useMainContent: (fn?: (content: JSX.Element) => JSX.Element) => JSX.Element
crossOrigin?: string
optimizeCss?: boolean
optimizeFonts?: boolean
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.