diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx index 9d601b89bd55762..26564e04cc50bde 100644 --- a/packages/next/pages/_document.tsx +++ b/packages/next/pages/_document.tsx @@ -1,4 +1,4 @@ -import React, { Component, ReactElement, ReactNode, useContext } from 'react' +import React, { ReactElement, ReactNode, useContext } from 'react' import { OPTIMIZED_FONT_PROVIDERS, NEXT_BUILTIN_DOCUMENT, @@ -353,7 +353,13 @@ function getAmpPath(ampPath: string, asPath: string): string { return ampPath || `${asPath}${asPath.includes('?') ? '&' : '?'}amp=1` } -export class Head extends Component { +// Use `React.Component` to avoid errors from the RSC checks because +// it can't be imported directly in Server Components: +// +// import { Component } from 'react' +// +// More info: https://github.com/vercel/next.js/pull/40686 +export class Head extends React.Component { static contextType = HtmlContext context!: React.ContextType @@ -899,7 +905,7 @@ function handleDocumentScriptLoaderItems( __NEXT_DATA__.scriptLoader = scriptLoaderItems } -export class NextScript extends Component { +export class NextScript extends React.Component { static contextType = HtmlContext context!: React.ContextType @@ -1104,7 +1110,9 @@ export function Main() { * `Document` component handles the initial `document` markup and renders only on the server side. * Commonly used for implementing server side rendering for `css-in-js` libraries. */ -export default class Document

extends Component { +export default class Document

extends React.Component< + DocumentProps & P +> { /** * `getInitialProps` hook returns the context object with the addition of `renderPage`. * `renderPage` callback executes `React` rendering logic synchronously to support server-rendering wrappers diff --git a/packages/next/shared/lib/flush-effects.tsx b/packages/next/shared/lib/flush-effects.tsx index 4aae4f1d73ff458..7d9a0c1ae42d0be 100644 --- a/packages/next/shared/lib/flush-effects.tsx +++ b/packages/next/shared/lib/flush-effects.tsx @@ -1,8 +1,14 @@ -import React, { createContext, useContext } from 'react' +import React, { useContext } from 'react' export type FlushEffectsHook = (callbacks: () => React.ReactNode) => void -export const FlushEffectsContext = createContext( +// Use `React.createContext` to avoid errors from the RSC checks because +// it can't be imported directly in Server Components: +// +// import { createContext } from 'react' +// +// More info: https://github.com/vercel/next.js/pull/40686 +export const FlushEffectsContext = React.createContext( null as any )