Add flag for preloading all server chunks (#64084)
This adds an experimental flag to allow testing preloading all server chunks including webpack chunks during the server initialization. It is disabled by default and only opt-in for experimenting. Closes NEXT-3005
This commit is contained in:
parent
c502308bca
commit
a9f85d14c0
3 changed files with 30 additions and 0 deletions
|
@ -236,6 +236,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
|
|||
experimental: z
|
||||
.strictObject({
|
||||
appDocumentPreloading: z.boolean().optional(),
|
||||
allServerChunksPreloading: z.boolean().optional(),
|
||||
adjustFontFallbacks: z.boolean().optional(),
|
||||
adjustFontFallbacksWithSizeAdjust: z.boolean().optional(),
|
||||
allowedRevalidateHeaderKeys: z.array(z.string()).optional(),
|
||||
|
|
|
@ -184,6 +184,7 @@ export interface ExperimentalConfig {
|
|||
linkNoTouchStart?: boolean
|
||||
caseSensitiveRoutes?: boolean
|
||||
appDocumentPreloading?: boolean
|
||||
allServerChunksPreloading?: boolean
|
||||
strictNextHead?: boolean
|
||||
clientRouterFilter?: boolean
|
||||
clientRouterFilterRedirects?: boolean
|
||||
|
@ -881,6 +882,7 @@ export const defaultConfig: NextConfig = {
|
|||
linkNoTouchStart: false,
|
||||
caseSensitiveRoutes: false,
|
||||
appDocumentPreloading: undefined,
|
||||
allServerChunksPreloading: undefined,
|
||||
clientRouterFilter: true,
|
||||
clientRouterFilterRedirects: false,
|
||||
fetchCacheKeyPrefix: '',
|
||||
|
|
|
@ -228,6 +228,33 @@ export default class NextNodeServer extends BaseServer {
|
|||
}).catch(() => {})
|
||||
}
|
||||
|
||||
if (
|
||||
!options.dev &&
|
||||
this.nextConfig.experimental.allServerChunksPreloading
|
||||
) {
|
||||
const appPathsManifest = this.getAppPathsManifest()
|
||||
const pagesManifest = this.getPagesManifest()
|
||||
|
||||
for (const page of Object.keys(pagesManifest || {})) {
|
||||
loadComponents({ distDir: this.distDir, page, isAppPath: false }).catch(
|
||||
() => {}
|
||||
)
|
||||
}
|
||||
|
||||
for (const page of Object.keys(appPathsManifest || {})) {
|
||||
loadComponents({ distDir: this.distDir, page, isAppPath: true })
|
||||
.then(({ ComponentMod }) => {
|
||||
const webpackRequire = ComponentMod.__next_app__.require
|
||||
if (webpackRequire?.m) {
|
||||
for (const id of Object.keys(webpackRequire.m)) {
|
||||
webpackRequire(id)
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.dev) {
|
||||
const { dynamicRoutes = [] } = this.getRoutesManifest() ?? {}
|
||||
this.dynamicRoutes = dynamicRoutes.map((r) => {
|
||||
|
|
Loading…
Reference in a new issue