Repository: vercel/next.js
Pull request: Fix `config.reactProductionProfiling` for Webpack

Absolutely no idea how this was passing in the integration test setup

For Webpack, setting it via the config was previously completely ignored and only the `--profile` flag was respected
Turbopack was already working correctly: https://github.com/vercel/next.js/pull/84920

Changed files:
filename: packages/next/src/build/webpack-build/impl.ts
patch: @@ -151,7 +151,6 @@ export async function webpackBuildImpl(
     rewrites: NextBuildContext.rewrites!,
     originalRewrites: NextBuildContext.originalRewrites,
     originalRedirects: NextBuildContext.originalRedirects,
-    reactProductionProfiling: NextBuildContext.reactProductionProfiling!,
     noMangling: NextBuildContext.noMangling!,
     clientRouterFilters: NextBuildContext.clientRouterFilters!,
     previewProps: NextBuildContext.previewProps!,

filename: packages/next/src/build/webpack-config.ts
patch: @@ -324,7 +324,6 @@ export default async function getBaseWebpackConfig(
     deferredEntrypoints,
     isDevFallback = false,
     pagesDir,
-    reactProductionProfiling = false,
     rewrites,
     originalRewrites,
     originalRedirects,
@@ -352,7 +351,6 @@ export default async function getBaseWebpackConfig(
     deferredEntrypoints?: webpack.EntryObject
     isDevFallback?: boolean
     pagesDir: string | undefined
-    reactProductionProfiling?: boolean
     rewrites: CustomRoutes['rewrites']
     originalRewrites: CustomRoutes['rewrites'] | undefined
     originalRedirects: CustomRoutes['redirects'] | undefined
@@ -401,6 +399,8 @@ export default async function getBaseWebpackConfig(
     ? '-experimental'
     : ''
 
+  const reactProductionProfiling = config.reactProductionProfiling ?? false
+
   const babelConfigFile = getBabelConfigFile(dir)
 
   if (!dev && hasCustomExportOutput(config)) {

filename: test/integration/react-profiling-mode/test/index.test.ts
patch: @@ -1,75 +0,0 @@
-/* eslint-env jest */
-
-import { join } from 'path'
-import webdriver from 'next-webdriver'
-import { nextBuild, nextStart, findPort, killApp } from 'next-test-utils'
-
-const appDir = join(__dirname, '..')
-
-let appPort
-let app
-
-describe('React Profiling Mode', () => {
-  ;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
-    'production mode',
-    () => {
-      describe('without config enabled', () => {
-        beforeAll(async () => {
-          await nextBuild(appDir, [], {
-            env: { TEST_REACT_PRODUCTION_PROFILING: 'false' },
-          })
-          appPort = await findPort()
-          app = await nextStart(appDir, appPort)
-        })
-        afterAll(async () => {
-          await killApp(app)
-        })
-
-        it('should not have used the react-dom profiling bundle', async () => {
-          const browser = await webdriver(appPort, '/')
-          const results = await browser.eval('window.profileResults')
-
-          expect(results).toBeFalsy()
-        })
-      })
-
-      describe('with config enabled', () => {
-        beforeAll(async () => {
-          await nextBuild(appDir, ['--profile'], {
-            env: { TEST_REACT_PRODUCTION_PROFILING: 'true' },
-          })
-          appPort = await findPort()
-          app = await nextStart(appDir, appPort)
-        })
-        afterAll(async () => {
-          await killApp(app)
-        })
-
-        it('should have used the react-dom profiling bundle for pages', async () => {
-          const browser = await webdriver(appPort, '/')
-          const results = await browser.eval('window.profileResults')
-
-          expect(results.length).toBe(1)
-          expect(results[0] && results[0][0]).toBe('hello')
-        })
-
-        it('should have used the react-dom profiling bundle for client component', async () => {
-          const browser = await webdriver(appPort, '/client')
-          const results = await browser.eval('window.profileResults')
-
-          expect(results.length).toBe(1)
-          expect(results[0] && results[0][0]).toBe('hello-app-client')
-        })
-
-        it('should have used the react-dom profiling bundle for server component', async () => {
-          // Can't test react Profiler API in server components but make sure rendering works
-          const browser = await webdriver(appPort, '/server')
-
-          expect(await browser.waitForElementByCss('p').text()).toBe(
-            'hello app server'
-          )
-        })
-      })
-    }
-  )
-})

filename: test/production/react-profiling-mode/react-profiling-mode.test.ts
patch: @@ -0,0 +1,65 @@
+import { nextTestSetup } from 'e2e-utils'
+import { retry } from 'next-test-utils'
+import { NextInstanceOpts } from '../../lib/next-modes/base'
+
+describe('React Profiling Mode', () => {
+  describe('default is disabled', () => {
+    const { next } = nextTestSetup({
+      files: __dirname,
+    })
+
+    it('should not have used the react-dom profiling bundle', async () => {
+      const browser = await next.browser('/')
+      const results = await browser.eval('window.profileResults')
+
+      expect(results).toBeFalsy()
+    })
+  })
+
+  describe.each([
+    {
+      name: 'config setting',
+      opts: {
+        env: { TEST_REACT_PRODUCTION_PROFILING: 'true' },
+      } satisfies Partial<NextInstanceOpts>,
+    },
+    {
+      name: 'CLI flag',
+      opts: { buildArgs: ['--profile'] } satisfies Partial<NextInstanceOpts>,
+    },
+  ])('enabled with $name', ({ opts }) => {
+    const { next } = nextTestSetup({
+      files: __dirname,
+      ...opts,
+    })
+
+    it('should have used the react-dom profiling bundle for pages', async () => {
+      const browser = await next.browser('/')
+      await retry(async () => {
+        const results = await browser.eval('window.profileResults')
+
+        expect(results.length).toBe(1)
+        expect(results[0] && results[0][0]).toBe('hello')
+      })
+    })
+
+    it('should have used the react-dom profiling bundle for client component', async () => {
+      const browser = await next.browser('/client')
+      await retry(async () => {
+        const results = await browser.eval('window.profileResults')
+
+        expect(results.length).toBe(1)
+        expect(results[0] && results[0][0]).toBe('hello-app-client')
+      })
+    })
+
+    it('should have used the react-dom profiling bundle for server component', async () => {
+      // Can't test react Profiler API in server components but make sure rendering works
+      const browser = await next.browser('/server')
+
+      expect(await browser.waitForElementByCss('p').text()).toBe(
+        'hello app server'
+      )
+    })
+  })
+})