Parallelize requirePage when loading components (#29494)

We can potentially speed it up a little bit by using `Promise.all` here. This was raised by @devknoll in https://github.com/vercel/next.js/pull/29470#pullrequestreview-766039044.
This commit is contained in:
Shu Ding 2021-09-29 16:42:35 +02:00 committed by GitHub
parent 27b4681922
commit df6df1959e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -92,19 +92,21 @@ export async function loadComponents(
} as LoadComponentsReturnType
}
const DocumentMod = await requirePage('/_document', distDir, serverless)
const AppMod = await requirePage('/_app', distDir, serverless)
const ComponentMod = await requirePage(pathname, distDir, serverless)
const [DocumentMod, AppMod, ComponentMod] = await Promise.all([
requirePage('/_document', distDir, serverless),
requirePage('/_app', distDir, serverless),
requirePage(pathname, distDir, serverless),
])
const [buildManifest, reactLoadableManifest, Component, Document, App] =
await Promise.all([
const [buildManifest, reactLoadableManifest] = await Promise.all([
require(join(distDir, BUILD_MANIFEST)),
require(join(distDir, REACT_LOADABLE_MANIFEST)),
interopDefault(ComponentMod),
interopDefault(DocumentMod),
interopDefault(AppMod),
])
const Component = interopDefault(ComponentMod)
const Document = interopDefault(DocumentMod)
const App = interopDefault(AppMod)
const { getServerSideProps, getStaticProps, getStaticPaths } = ComponentMod
return {