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

Remove the special _document-concurrent component #35242

Merged
merged 8 commits into from Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 10 additions & 2 deletions packages/next/pages/_document.tsx
Expand Up @@ -171,7 +171,7 @@ export default class Document<P = {}> extends Component<DocumentProps & P> {
return ctx.defaultGetInitialProps(ctx)
}

static render() {
render() {
return (
<Html>
<Head />
Expand All @@ -186,7 +186,15 @@ export default class Document<P = {}> extends Component<DocumentProps & P> {

// Add a speical property to the built-in `Document` component so later we can
// identify if a user customized `Document` is used or not.
;(Document as any).__next_internal_document = true
;(Document as any).__next_internal_document = () => (
shuding marked this conversation as resolved.
Show resolved Hide resolved
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)

export function Html(
props: React.DetailedHTMLProps<
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/base-server.ts
Expand Up @@ -1177,7 +1177,7 @@ export default abstract class Server {
if (opts.supportsDynamicHTML === true) {
const isBotRequest = isBot(req.headers['user-agent'] || '')
const isSupportedDocument =
(components.Document as any).__next_internal_document ||
!!(components.Document as any).__next_internal_document ||
typeof components.Document?.getInitialProps !== 'function'

// Disable dynamic HTML in cases that we know it won't be generated,
Expand Down
10 changes: 6 additions & 4 deletions packages/next/server/render.tsx
Expand Up @@ -1238,21 +1238,23 @@ export async function renderToHTML(
// 1. Using `Document.getInitialProps` in the Edge runtime.
// 2. Using the class component `Document` with concurrent features.

const isBuiltinDocument = !!(Document as any).__next_internal_document
const builtinDocument = (Document as any).__next_internal_document as
| typeof Document
| undefined

if (runtime === 'edge' && Document.getInitialProps) {
// In the Edge runtime, `Document.getInitialProps` isn't supported.
// We throw an error here if it's customized.
if (!isBuiltinDocument) {
if (!builtinDocument) {
throw new Error(
'`getInitialProps` in Document component is not supported with the Edge Runtime.'
)
}
}

// We make it a function component to enable streaming.
if (hasConcurrentFeatures && isBuiltinDocument) {
Document = (Document as any).render
if (hasConcurrentFeatures && builtinDocument) {
Document = builtinDocument
}

if (!hasConcurrentFeatures && Document.getInitialProps) {
Expand Down