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(() => ...@@ -236,6 +236,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
experimental: z experimental: z
.strictObject({ .strictObject({
appDocumentPreloading: z.boolean().optional(), appDocumentPreloading: z.boolean().optional(),
allServerChunksPreloading: z.boolean().optional(),
adjustFontFallbacks: z.boolean().optional(), adjustFontFallbacks: z.boolean().optional(),
adjustFontFallbacksWithSizeAdjust: z.boolean().optional(), adjustFontFallbacksWithSizeAdjust: z.boolean().optional(),
allowedRevalidateHeaderKeys: z.array(z.string()).optional(), allowedRevalidateHeaderKeys: z.array(z.string()).optional(),
......
...@@ -184,6 +184,7 @@ export interface ExperimentalConfig { ...@@ -184,6 +184,7 @@ export interface ExperimentalConfig {
linkNoTouchStart?: boolean linkNoTouchStart?: boolean
caseSensitiveRoutes?: boolean caseSensitiveRoutes?: boolean
appDocumentPreloading?: boolean appDocumentPreloading?: boolean
allServerChunksPreloading?: boolean
strictNextHead?: boolean strictNextHead?: boolean
clientRouterFilter?: boolean clientRouterFilter?: boolean
clientRouterFilterRedirects?: boolean clientRouterFilterRedirects?: boolean
...@@ -881,6 +882,7 @@ export const defaultConfig: NextConfig = { ...@@ -881,6 +882,7 @@ export const defaultConfig: NextConfig = {
linkNoTouchStart: false, linkNoTouchStart: false,
caseSensitiveRoutes: false, caseSensitiveRoutes: false,
appDocumentPreloading: undefined, appDocumentPreloading: undefined,
allServerChunksPreloading: undefined,
clientRouterFilter: true, clientRouterFilter: true,
clientRouterFilterRedirects: false, clientRouterFilterRedirects: false,
fetchCacheKeyPrefix: '', fetchCacheKeyPrefix: '',
......
...@@ -228,6 +228,33 @@ export default class NextNodeServer extends BaseServer { ...@@ -228,6 +228,33 @@ export default class NextNodeServer extends BaseServer {
}).catch(() => {}) }).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) { if (!options.dev) {
const { dynamicRoutes = [] } = this.getRoutesManifest() ?? {} const { dynamicRoutes = [] } = this.getRoutesManifest() ?? {}
this.dynamicRoutes = dynamicRoutes.map((r) => { 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