Unverified Commit 2f567da8 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Rework experimental preload entries handling (#64125)

Follow-up to https://github.com/vercel/next.js/pull/64084 this refactors
it a bit and renames the flag.

Closes NEXT-3018
parent f6baf61b
...@@ -236,7 +236,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => ...@@ -236,7 +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(), preloadEntriesOnStart: 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,7 +184,7 @@ export interface ExperimentalConfig { ...@@ -184,7 +184,7 @@ export interface ExperimentalConfig {
linkNoTouchStart?: boolean linkNoTouchStart?: boolean
caseSensitiveRoutes?: boolean caseSensitiveRoutes?: boolean
appDocumentPreloading?: boolean appDocumentPreloading?: boolean
allServerChunksPreloading?: boolean preloadEntriesOnStart?: boolean
strictNextHead?: boolean strictNextHead?: boolean
clientRouterFilter?: boolean clientRouterFilter?: boolean
clientRouterFilterRedirects?: boolean clientRouterFilterRedirects?: boolean
...@@ -882,7 +882,7 @@ export const defaultConfig: NextConfig = { ...@@ -882,7 +882,7 @@ export const defaultConfig: NextConfig = {
linkNoTouchStart: false, linkNoTouchStart: false,
caseSensitiveRoutes: false, caseSensitiveRoutes: false,
appDocumentPreloading: undefined, appDocumentPreloading: undefined,
allServerChunksPreloading: undefined, preloadEntriesOnStart: undefined,
clientRouterFilter: true, clientRouterFilter: true,
clientRouterFilterRedirects: false, clientRouterFilterRedirects: false,
fetchCacheKeyPrefix: '', fetchCacheKeyPrefix: '',
......
...@@ -228,31 +228,8 @@ export default class NextNodeServer extends BaseServer { ...@@ -228,31 +228,8 @@ export default class NextNodeServer extends BaseServer {
}).catch(() => {}) }).catch(() => {})
} }
if ( if (!options.dev && this.nextConfig.experimental.preloadEntriesOnStart) {
!options.dev && this.unstable_preloadEntries()
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) {
...@@ -295,6 +272,32 @@ export default class NextNodeServer extends BaseServer { ...@@ -295,6 +272,32 @@ export default class NextNodeServer extends BaseServer {
} }
} }
public async unstable_preloadEntries(): Promise<void> {
const appPathsManifest = this.getAppPathsManifest()
const pagesManifest = this.getPagesManifest()
for (const page of Object.keys(pagesManifest || {})) {
await loadComponents({
distDir: this.distDir,
page,
isAppPath: false,
}).catch(() => {})
}
for (const page of Object.keys(appPathsManifest || {})) {
await loadComponents({ distDir: this.distDir, page, isAppPath: true })
.then(async ({ ComponentMod }) => {
const webpackRequire = ComponentMod.__next_app__.require
if (webpackRequire?.m) {
for (const id of Object.keys(webpackRequire.m)) {
await webpackRequire(id)
}
}
})
.catch(() => {})
}
}
protected async handleUpgrade(): Promise<void> { protected async handleUpgrade(): Promise<void> {
// The web server does not support web sockets, it's only used for HMR in // The web server does not support web sockets, it's only used for HMR in
// development. // development.
......
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