From d9871831168ae859655de52e3f4643ecad0778de Mon Sep 17 00:00:00 2001 From: Karibash Date: Thu, 10 Apr 2025 16:42:25 +0900 Subject: [PATCH 1/2] bugfix: Fix a bug that caused conflicting assets when adding a child compiler --- .../next/src/build/webpack/plugins/flight-manifest-plugin.ts | 2 +- packages/next/src/build/webpack/plugins/middleware-plugin.ts | 2 +- .../src/build/webpack/plugins/next-trace-entrypoints-plugin.ts | 2 +- .../next/src/build/webpack/plugins/next-types-plugin/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts index 07aa8c75a0a..cebb850c57e 100644 --- a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts @@ -223,7 +223,7 @@ export class ClientReferenceManifestPlugin { } apply(compiler: webpack.Compiler) { - compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { + compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { compilation.hooks.processAssets.tap( { name: PLUGIN_NAME, diff --git a/packages/next/src/build/webpack/plugins/middleware-plugin.ts b/packages/next/src/build/webpack/plugins/middleware-plugin.ts index e6040c77ab1..1d28e5e47a5 100644 --- a/packages/next/src/build/webpack/plugins/middleware-plugin.ts +++ b/packages/next/src/build/webpack/plugins/middleware-plugin.ts @@ -781,7 +781,7 @@ export default class MiddlewarePlugin { } public apply(compiler: webpack.Compiler) { - compiler.hooks.compilation.tap(NAME, (compilation, params) => { + compiler.hooks.thisCompilation.tap(NAME, (compilation, params) => { const { hooks } = params.normalModuleFactory /** * This is the static code analysis phase. diff --git a/packages/next/src/build/webpack/plugins/next-trace-entrypoints-plugin.ts b/packages/next/src/build/webpack/plugins/next-trace-entrypoints-plugin.ts index e29c9c34898..5548c008d97 100644 --- a/packages/next/src/build/webpack/plugins/next-trace-entrypoints-plugin.ts +++ b/packages/next/src/build/webpack/plugins/next-trace-entrypoints-plugin.ts @@ -575,7 +575,7 @@ export class TraceEntryPointsPlugin implements webpack.WebpackPluginInstance { } apply(compiler: webpack.Compiler) { - compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { + compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { const compilationSpan = getCompilationSpan(compilation) || getCompilationSpan(compiler)! const traceEntrypointsPluginSpan = compilationSpan.traceChild( diff --git a/packages/next/src/build/webpack/plugins/next-types-plugin/index.ts b/packages/next/src/build/webpack/plugins/next-types-plugin/index.ts index baaa75f2a96..997d639032b 100644 --- a/packages/next/src/build/webpack/plugins/next-types-plugin/index.ts +++ b/packages/next/src/build/webpack/plugins/next-types-plugin/index.ts @@ -1003,7 +1003,7 @@ export class NextTypesPlugin { } } - compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => { + compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { compilation.hooks.processAssets.tapAsync( { name: PLUGIN_NAME, From 3c58520cc0cd7eaca9df1ec2734766b9948a4f74 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Thu, 8 May 2025 13:08:20 -0700 Subject: [PATCH 2/2] use compiler.hooks.thisCompilation in ProfilingPlugin --- packages/next/src/build/webpack/plugins/profiling-plugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/profiling-plugin.ts b/packages/next/src/build/webpack/plugins/profiling-plugin.ts index a1774671919..2b5e31f5655 100644 --- a/packages/next/src/build/webpack/plugins/profiling-plugin.ts +++ b/packages/next/src/build/webpack/plugins/profiling-plugin.ts @@ -91,7 +91,7 @@ export class ProfilingPlugin { traceTopLevelHooks(compiler: any) { this.traceHookPair( 'webpack-compilation', - compiler.hooks.compilation, + compiler.hooks.thisCompilation, compiler.hooks.afterCompile, { parentSpan: () => @@ -146,7 +146,7 @@ export class ProfilingPlugin { }, }) - compiler.hooks.compilation.tap( + compiler.hooks.thisCompilation.tap( { name: pluginName, stage: -Infinity }, (compilation: any) => { compilation.hooks.buildModule.tap(pluginName, (module: any) => {