Unverified Commit a9f85d14 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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
parent c502308b
......@@ -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) => {
......
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