Unverified Commit 85e578a9 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Enable default functional document when concurrentFeatures is enabled (#31954)

## Bug

Fixes: #31675 

Functional document without gIP should be enabled when streaming is enabled, even without rsc

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent 6e6bd215
...@@ -64,9 +64,9 @@ Features that require a Node.js server, or dynamic logic that cannot be computed ...@@ -64,9 +64,9 @@ Features that require a Node.js server, or dynamic logic that cannot be computed
It's possible to use the [`getInitialProps`](/docs/api-reference/data-fetching/getInitialProps.md) API instead of `getStaticProps`, but it comes with a few caveats: It's possible to use the [`getInitialProps`](/docs/api-reference/data-fetching/getInitialProps.md) API instead of `getStaticProps`, but it comes with a few caveats:
- `getInitialProps` cannot be used alongside `getStaticProps` or `getStaticPaths` on any given page. If you have dynamic routes, instead of using `getStaticPaths` you'll need to configure the [`exportPathMap`](/docs/api-reference/next.config.js/exportPathMap.md) parameter in your [`next.config.js`](/docs/api-reference/next.config.js/introduction.md) file to let the exporter know which HTML files it should output. - `getInitialProps` cannot be used alongside `getStaticProps` or `getStaticPaths` on any given page. If you have dynamic routes, instead of using `getStaticPaths` you'll need to configure the [`exportPathMap`](/docs/api-reference/next.config.js/exportPathMap.md) parameter in your [`next.config.js`](/docs/api-reference/next.config.js/introduction.md) file to let the exporter know which HTML files it should output.
- When `getInitialProps` is called during export, the `req` and `res` fields of its [`context`](/docs/api-reference/data-fetching/getInitialProps.md#context-object) parameter will be empty objects, since during export there is no server running. - When `getInitialProps` is called during export, the `req` and `res` fields of its [`context`](/docs/api-reference/data-fetching/getInitialProps.md#context-object) parameter will be empty objects, since during export there is no server running.
- `getInitialProps` **will be called on every client-side navigation**, if you'd like to only fetch data at build-time, switch to `getStaticProps`. - `getInitialProps` **will be called on every client-side navigation**, if you'd like to only fetch data at build-time, switch to `getStaticProps`.
- `getInitialProps` should fetch from an API and cannot use Node.js-specific libraries or the file system like `getStaticProps` can. - `getInitialProps` should fetch from an API and cannot use Node.js-specific libraries or the file system like `getStaticProps` can.
We recommend migrating towards `getStaticProps` over `getInitialProps` whenever possible. We recommend migrating towards `getStaticProps` over `getInitialProps` whenever possible.
...@@ -25,8 +25,15 @@ export type PagesMapping = { ...@@ -25,8 +25,15 @@ export type PagesMapping = {
export function createPagesMapping( export function createPagesMapping(
pagePaths: string[], pagePaths: string[],
extensions: string[], extensions: string[],
isDev: boolean, {
hasServerComponents: boolean isDev,
hasServerComponents,
hasConcurrentFeatures,
}: {
isDev: boolean
hasServerComponents: boolean
hasConcurrentFeatures: boolean
}
): PagesMapping { ): PagesMapping {
const previousPages: PagesMapping = {} const previousPages: PagesMapping = {}
const pages: PagesMapping = pagePaths.reduce( const pages: PagesMapping = pagePaths.reduce(
...@@ -65,7 +72,7 @@ export function createPagesMapping( ...@@ -65,7 +72,7 @@ export function createPagesMapping(
// we alias these in development and allow webpack to // we alias these in development and allow webpack to
// allow falling back to the correct source file so // allow falling back to the correct source file so
// that HMR can work properly when a file is added/removed // that HMR can work properly when a file is added/removed
const documentPage = `_document${hasServerComponents ? '-web' : ''}` const documentPage = `_document${hasConcurrentFeatures ? '-web' : ''}`
if (isDev) { if (isDev) {
pages['/_app'] = `${PAGES_DIR_ALIAS}/_app` pages['/_app'] = `${PAGES_DIR_ALIAS}/_app`
pages['/_error'] = `${PAGES_DIR_ALIAS}/_error` pages['/_error'] = `${PAGES_DIR_ALIAS}/_error`
......
...@@ -281,12 +281,11 @@ export default async function build( ...@@ -281,12 +281,11 @@ export default async function build(
const mappedPages = nextBuildSpan const mappedPages = nextBuildSpan
.traceChild('create-pages-mapping') .traceChild('create-pages-mapping')
.traceFn(() => .traceFn(() =>
createPagesMapping( createPagesMapping(pagePaths, config.pageExtensions, {
pagePaths, isDev: false,
config.pageExtensions, hasServerComponents,
false, hasConcurrentFeatures,
hasServerComponents })
)
) )
const entrypoints = nextBuildSpan const entrypoints = nextBuildSpan
......
...@@ -570,7 +570,7 @@ export default async function getBaseWebpackConfig( ...@@ -570,7 +570,7 @@ export default async function getBaseWebpackConfig(
prev.push(path.join(pagesDir, `_document.${ext}`)) prev.push(path.join(pagesDir, `_document.${ext}`))
return prev return prev
}, [] as string[]), }, [] as string[]),
`next/dist/pages/_document${hasServerComponents ? '-web' : ''}.js`, `next/dist/pages/_document${webServerRuntime ? '-web' : ''}.js`,
] ]
} }
......
...@@ -318,8 +318,11 @@ export default class HotReloader { ...@@ -318,8 +318,11 @@ export default class HotReloader {
createPagesMapping( createPagesMapping(
pagePaths.filter((i) => i !== null) as string[], pagePaths.filter((i) => i !== null) as string[],
this.config.pageExtensions, this.config.pageExtensions,
true, {
this.hasServerComponents isDev: true,
hasConcurrentFeatures: this.webServerRuntime,
hasServerComponents: this.hasServerComponents,
}
) )
) )
......
import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment