Unverified Commit 7fc89cc0 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Fix `config.reactProductionProfiling` for Webpack (#90430)

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
parent 5f26a684
...@@ -151,7 +151,6 @@ export async function webpackBuildImpl( ...@@ -151,7 +151,6 @@ export async function webpackBuildImpl(
rewrites: NextBuildContext.rewrites!, rewrites: NextBuildContext.rewrites!,
originalRewrites: NextBuildContext.originalRewrites, originalRewrites: NextBuildContext.originalRewrites,
originalRedirects: NextBuildContext.originalRedirects, originalRedirects: NextBuildContext.originalRedirects,
reactProductionProfiling: NextBuildContext.reactProductionProfiling!,
noMangling: NextBuildContext.noMangling!, noMangling: NextBuildContext.noMangling!,
clientRouterFilters: NextBuildContext.clientRouterFilters!, clientRouterFilters: NextBuildContext.clientRouterFilters!,
previewProps: NextBuildContext.previewProps!, previewProps: NextBuildContext.previewProps!,
......
...@@ -324,7 +324,6 @@ export default async function getBaseWebpackConfig( ...@@ -324,7 +324,6 @@ export default async function getBaseWebpackConfig(
deferredEntrypoints, deferredEntrypoints,
isDevFallback = false, isDevFallback = false,
pagesDir, pagesDir,
reactProductionProfiling = false,
rewrites, rewrites,
originalRewrites, originalRewrites,
originalRedirects, originalRedirects,
...@@ -352,7 +351,6 @@ export default async function getBaseWebpackConfig( ...@@ -352,7 +351,6 @@ export default async function getBaseWebpackConfig(
deferredEntrypoints?: webpack.EntryObject deferredEntrypoints?: webpack.EntryObject
isDevFallback?: boolean isDevFallback?: boolean
pagesDir: string | undefined pagesDir: string | undefined
reactProductionProfiling?: boolean
rewrites: CustomRoutes['rewrites'] rewrites: CustomRoutes['rewrites']
originalRewrites: CustomRoutes['rewrites'] | undefined originalRewrites: CustomRoutes['rewrites'] | undefined
originalRedirects: CustomRoutes['redirects'] | undefined originalRedirects: CustomRoutes['redirects'] | undefined
...@@ -401,6 +399,8 @@ export default async function getBaseWebpackConfig( ...@@ -401,6 +399,8 @@ export default async function getBaseWebpackConfig(
? '-experimental' ? '-experimental'
: '' : ''
const reactProductionProfiling = config.reactProductionProfiling ?? false
const babelConfigFile = getBabelConfigFile(dir) const babelConfigFile = getBabelConfigFile(dir)
if (!dev && hasCustomExportOutput(config)) { if (!dev && hasCustomExportOutput(config)) {
......
/* 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'
)
})
})
}
)
})
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'
)
})
})
})
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