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
This commit is contained in:
parent
f6baf61b61
commit
2f567da817
3 changed files with 31 additions and 28 deletions
|
@ -236,7 +236,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
|
|||
experimental: z
|
||||
.strictObject({
|
||||
appDocumentPreloading: z.boolean().optional(),
|
||||
allServerChunksPreloading: z.boolean().optional(),
|
||||
preloadEntriesOnStart: z.boolean().optional(),
|
||||
adjustFontFallbacks: z.boolean().optional(),
|
||||
adjustFontFallbacksWithSizeAdjust: z.boolean().optional(),
|
||||
allowedRevalidateHeaderKeys: z.array(z.string()).optional(),
|
||||
|
|
|
@ -184,7 +184,7 @@ export interface ExperimentalConfig {
|
|||
linkNoTouchStart?: boolean
|
||||
caseSensitiveRoutes?: boolean
|
||||
appDocumentPreloading?: boolean
|
||||
allServerChunksPreloading?: boolean
|
||||
preloadEntriesOnStart?: boolean
|
||||
strictNextHead?: boolean
|
||||
clientRouterFilter?: boolean
|
||||
clientRouterFilterRedirects?: boolean
|
||||
|
@ -882,7 +882,7 @@ export const defaultConfig: NextConfig = {
|
|||
linkNoTouchStart: false,
|
||||
caseSensitiveRoutes: false,
|
||||
appDocumentPreloading: undefined,
|
||||
allServerChunksPreloading: undefined,
|
||||
preloadEntriesOnStart: undefined,
|
||||
clientRouterFilter: true,
|
||||
clientRouterFilterRedirects: false,
|
||||
fetchCacheKeyPrefix: '',
|
||||
|
|
|
@ -228,31 +228,8 @@ 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 && this.nextConfig.experimental.preloadEntriesOnStart) {
|
||||
this.unstable_preloadEntries()
|
||||
}
|
||||
|
||||
if (!options.dev) {
|
||||
|
@ -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> {
|
||||
// The web server does not support web sockets, it's only used for HMR in
|
||||
// development.
|
||||
|
|
Loading…
Reference in a new issue