Unverified Commit c9564849 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Start client compiler when server components are finished compiling (#44716)

parent 9c6d5612
...@@ -121,7 +121,7 @@ export class FlightClientEntryPlugin { ...@@ -121,7 +121,7 @@ export class FlightClientEntryPlugin {
} }
async createClientEntries(compiler: any, compilation: any) { async createClientEntries(compiler: any, compilation: any) {
const promises: Array< const addClientEntryAndSSRModulesList: Array<
ReturnType<typeof this.injectClientEntryAndSSRModules> ReturnType<typeof this.injectClientEntryAndSSRModules>
> = [] > = []
...@@ -210,7 +210,7 @@ export class FlightClientEntryPlugin { ...@@ -210,7 +210,7 @@ export class FlightClientEntryPlugin {
relativeRequest.replace(/\.(js|ts)x?$/, '').replace(/^src[\\/]/, '') relativeRequest.replace(/\.(js|ts)x?$/, '').replace(/^src[\\/]/, '')
) )
promises.push( addClientEntryAndSSRModulesList.push(
this.injectClientEntryAndSSRModules({ this.injectClientEntryAndSSRModules({
compiler, compiler,
compilation, compilation,
...@@ -222,7 +222,7 @@ export class FlightClientEntryPlugin { ...@@ -222,7 +222,7 @@ export class FlightClientEntryPlugin {
} }
// Create internal app // Create internal app
promises.push( addClientEntryAndSSRModulesList.push(
this.injectClientEntryAndSSRModules({ this.injectClientEntryAndSSRModules({
compiler, compiler,
compilation, compilation,
...@@ -366,14 +366,25 @@ export class FlightClientEntryPlugin { ...@@ -366,14 +366,25 @@ export class FlightClientEntryPlugin {
} }
) )
const res = await Promise.all(promises)
// Invalidate in development to trigger recompilation // Invalidate in development to trigger recompilation
const invalidator = getInvalidator() const invalidator = getInvalidator()
// Check if any of the entry injections need an invalidation // Check if any of the entry injections need an invalidation
if (invalidator && res.includes(true)) { if (
invalidator &&
addClientEntryAndSSRModulesList.some(
([shouldInvalidate]) => shouldInvalidate === true
)
) {
invalidator.invalidate([COMPILER_NAMES.client]) invalidator.invalidate([COMPILER_NAMES.client])
} }
// Client compiler is invalidated before awaiting the compilation of the SSR client component entries
// so that the client compiler is running in parallel to the server compiler.
await Promise.all(
addClientEntryAndSSRModulesList.map(
(addClientEntryAndSSRModules) => addClientEntryAndSSRModules[1]
)
)
} }
collectClientComponentsAndCSSForDependency({ collectClientComponentsAndCSSForDependency({
...@@ -475,7 +486,7 @@ export class FlightClientEntryPlugin { ...@@ -475,7 +486,7 @@ export class FlightClientEntryPlugin {
return [clientComponentImports, serverCSSImports] return [clientComponentImports, serverCSSImports]
} }
async injectClientEntryAndSSRModules({ injectClientEntryAndSSRModules({
compiler, compiler,
compilation, compilation,
entryName, entryName,
...@@ -487,7 +498,7 @@ export class FlightClientEntryPlugin { ...@@ -487,7 +498,7 @@ export class FlightClientEntryPlugin {
entryName: string entryName: string
clientComponentImports: ClientComponentImports clientComponentImports: ClientComponentImports
bundlePath: string bundlePath: string
}): Promise<boolean> { }): [shouldInvalidate: boolean, addEntryPromise: Promise<void>] {
let shouldInvalidate = false let shouldInvalidate = false
const loaderOptions: NextFlightClientEntryLoaderOptions = { const loaderOptions: NextFlightClientEntryLoaderOptions = {
...@@ -549,8 +560,12 @@ export class FlightClientEntryPlugin { ...@@ -549,8 +560,12 @@ export class FlightClientEntryPlugin {
} }
) )
return [
shouldInvalidate,
// Add the dependency to the server compiler. // Add the dependency to the server compiler.
await this.addEntry( // This promise is awaited later using `Promise.all` in order to parallelize adding the entries.
// It ensures we can parallelize the SSR and Client compiler entries.
this.addEntry(
compilation, compilation,
// Reuse compilation context. // Reuse compilation context.
compiler.context, compiler.context,
...@@ -562,9 +577,8 @@ export class FlightClientEntryPlugin { ...@@ -562,9 +577,8 @@ export class FlightClientEntryPlugin {
// This ensures the client components are bundled on client layer // This ensures the client components are bundled on client layer
layer: WEBPACK_LAYERS.client, layer: WEBPACK_LAYERS.client,
} }
) ),
]
return shouldInvalidate
} }
addEntry( addEntry(
......
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