Exclude system entrypoints from client manifest's chunk list (#46010)

System entrypoints such as like `amp` can be included in the same chunk group of a module we are trying to load, but they are guaranteed to be existing and there's no need to list them in the manifest's chunks.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
This commit is contained in:
Shu Ding 2023-02-16 19:07:49 +01:00 committed by GitHub
parent 9d94c43fa4
commit 903e74be11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 28 deletions

View file

@ -1,10 +1,8 @@
import { webpack, sources } from 'next/dist/compiled/webpack/webpack'
import {
APP_BUILD_MANIFEST,
CLIENT_STATIC_FILES_RUNTIME_AMP,
CLIENT_STATIC_FILES_RUNTIME_MAIN,
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP,
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,
SYSTEM_ENTRYPOINTS,
} from '../../../shared/lib/constants'
import { getEntrypointFiles } from './build-manifest-plugin'
import getAppRouteFromEntrypoint from '../../../server/get-app-route-from-entrypoint'
@ -57,13 +55,6 @@ export class AppBuildManifestPlugin {
pages: {},
}
const systemEntrypoints = new Set<string>([
CLIENT_STATIC_FILES_RUNTIME_MAIN,
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,
CLIENT_STATIC_FILES_RUNTIME_AMP,
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP,
])
const mainFiles = new Set(
getEntrypointFiles(
compilation.entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_MAIN_APP)
@ -75,7 +66,7 @@ export class AppBuildManifestPlugin {
continue
}
if (systemEntrypoints.has(entrypoint.name)) {
if (SYSTEM_ENTRYPOINTS.has(entrypoint.name)) {
continue
}

View file

@ -10,6 +10,7 @@ import {
CLIENT_STATIC_FILES_RUNTIME_POLYFILLS_SYMBOL,
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,
CLIENT_STATIC_FILES_RUNTIME_AMP,
SYSTEM_ENTRYPOINTS,
} from '../../../shared/lib/constants'
import { BuildManifest } from '../../../server/get-page-files'
import getRouteFromEntrypoint from '../../../server/get-route-from-entrypoint'
@ -188,15 +189,8 @@ export default class BuildManifestPlugin {
entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_AMP)
)
const systemEntrypoints = new Set([
CLIENT_STATIC_FILES_RUNTIME_MAIN,
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,
CLIENT_STATIC_FILES_RUNTIME_AMP,
...(this.appDirEnabled ? [CLIENT_STATIC_FILES_RUNTIME_MAIN_APP] : []),
])
for (const entrypoint of compilation.entrypoints.values()) {
if (systemEntrypoints.has(entrypoint.name)) continue
if (SYSTEM_ENTRYPOINTS.has(entrypoint.name)) continue
const pagePath = getRouteFromEntrypoint(entrypoint.name)
if (!pagePath) {

View file

@ -6,7 +6,10 @@
*/
import { webpack, sources } from 'next/dist/compiled/webpack/webpack'
import { CLIENT_REFERENCE_MANIFEST } from '../../../shared/lib/constants'
import {
CLIENT_REFERENCE_MANIFEST,
SYSTEM_ENTRYPOINTS,
} from '../../../shared/lib/constants'
import { relative, sep } from 'path'
import { isClientComponentModule, regexCSS } from '../loaders/utils'
@ -16,6 +19,7 @@ import {
} from './flight-client-entry-plugin'
import { traverseModules } from '../utils'
import { nonNullable } from '../../../lib/non-nullable'
// This is the module that will be used to anchor all client references to.
// I.e. it will have all the client files as async deps from this point on.
@ -247,14 +251,20 @@ export class FlightManifestPlugin {
]
function getAppPathRequiredChunks() {
return chunkGroup.chunks.map((requiredChunk: webpack.Chunk) => {
return (
requiredChunk.id +
':' +
(requiredChunk.name || requiredChunk.id) +
(dev ? '' : '-' + requiredChunk.hash)
)
})
return chunkGroup.chunks
.map((requiredChunk: webpack.Chunk) => {
if (SYSTEM_ENTRYPOINTS.has(requiredChunk.name)) {
return null
}
return (
requiredChunk.id +
':' +
(requiredChunk.name || requiredChunk.id) +
(dev ? '' : '-' + requiredChunk.hash)
)
})
.filter(nonNullable)
}
const moduleExportedKeys = ['', '*']

View file

@ -148,3 +148,10 @@ export const EDGE_UNSUPPORTED_NODE_APIS = [
'TransformStreamDefaultController',
'WritableStreamDefaultController',
]
export const SYSTEM_ENTRYPOINTS = new Set<string>([
CLIENT_STATIC_FILES_RUNTIME_MAIN,
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,
CLIENT_STATIC_FILES_RUNTIME_AMP,
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP,
])