Unverified Commit 40f48ebb authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Turbopack: Remove redundant log line, increase delay for compiling log message (#85133)

We've already got output logging for this stuff, and the "compiling" message is too noisy.

Only print `Compiling /...` it if the compilation takes more than 3s, stop printing `Compiled in` altogether.

After this PR:
<img width="1075" height="335" alt="Screenshot 2025-10-20 at 3 15 59 PM" src="https://github.com/user-attachments/assets/34e87d18-8feb-4470-ae11-0d8e4b3a8a6b" />

Removes this line:
<img width="1095" height="254" alt="Screenshot 2025-10-20 at 3 17 56 PM" src="https://github.com/user-attachments/assets/76fb795e-760a-4782-889a-dd98bcf09125" />
parent 337e8a53
...@@ -3,7 +3,7 @@ import { type Span, flushAllTraces, trace } from '../../trace' ...@@ -3,7 +3,7 @@ import { type Span, flushAllTraces, trace } from '../../trace'
import { teardownTraceSubscriber } from '../swc' import { teardownTraceSubscriber } from '../swc'
import * as Log from './log' import * as Log from './log'
const MAX_LOG_SKIP_DURATION = 500 // 500ms const MAX_LOG_SKIP_DURATION_MS = 3000
export type OutputState = export type OutputState =
| { | {
...@@ -109,7 +109,7 @@ store.subscribe((state) => { ...@@ -109,7 +109,7 @@ store.subscribe((state) => {
trigger: trigger, trigger: trigger,
}) })
if (!loadingLogTimer) { if (!loadingLogTimer) {
// Only log compiling if compiled is not finished in 3 seconds // Only log compiling if compiled is not finished quickly
loadingLogTimer = setTimeout(() => { loadingLogTimer = setTimeout(() => {
if ( if (
triggerUrl && triggerUrl &&
...@@ -120,7 +120,7 @@ store.subscribe((state) => { ...@@ -120,7 +120,7 @@ store.subscribe((state) => {
} else { } else {
Log.wait(`Compiling ${trigger} ...`) Log.wait(`Compiling ${trigger} ...`)
} }
}, MAX_LOG_SKIP_DURATION) }, MAX_LOG_SKIP_DURATION_MS)
} }
} }
} }
...@@ -182,9 +182,6 @@ store.subscribe((state) => { ...@@ -182,9 +182,6 @@ store.subscribe((state) => {
traceSpan.stop() traceSpan.stop()
traceSpan = null traceSpan = null
} }
Log.event(
`Compiled${trigger ? ' ' + trigger : ''}${timeMessage}${modulesMessage}`
)
trigger = '' trigger = ''
} }
......
...@@ -94,7 +94,7 @@ describe('Cache Components Dev Errors', () => { ...@@ -94,7 +94,7 @@ describe('Cache Components Dev Errors', () => {
}) })
expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain( expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain(
`\nError: Route "/no-accessed-data": ` + `Error: Route "/no-accessed-data": ` +
`A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. ` + `A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. ` +
`See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense` + `See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense` +
'\n at Page (app/no-accessed-data/page.js:1:31)' + '\n at Page (app/no-accessed-data/page.js:1:31)' +
......
...@@ -21,26 +21,13 @@ import { assertNoRedbox } from 'next-test-utils' ...@@ -21,26 +21,13 @@ import { assertNoRedbox } from 'next-test-utils'
}) })
it('should support MUI', async () => { it('should support MUI', async () => {
let logs = ''
next.on('stdout', (log) => {
logs += log
})
// Ensure that MUI is working // Ensure that MUI is working
const $ = await next.render$('/mui') const $ = await next.render$('/mui')
expect(await $('#button').text()).toContain('button') expect($('#button').text()).toContain('button')
expect(await $('#typography').text()).toContain('typography') expect($('#typography').text()).toContain('typography')
const browser = await next.browser('/mui') const browser = await next.browser('/mui')
await assertNoRedbox(browser) await assertNoRedbox(browser)
const modules = [...logs.matchAll(/\((\d+) modules\)/g)]
expect(modules.length).toBeGreaterThanOrEqual(1)
for (const [, moduleCount] of modules) {
// Ensure that the number of modules is less than 1500 - otherwise we're
// importing the entire library.
expect(parseInt(moduleCount)).toBeLessThan(1500)
}
}) })
}) })
} }
......
...@@ -20,92 +20,6 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -20,92 +20,6 @@ import { nextTestSetup } from 'e2e-utils'
}, },
}) })
it('app - should render the icons correctly without creating all the modules', async () => {
let logs = ''
next.on('stdout', (log) => {
logs += log
})
const html = await next.render('/')
// Ensure the icons are rendered
expect(html).toContain('<svg xmlns="http://www.w3.org/2000/svg"')
const modules = [
...logs.matchAll(
/Compiled (\/[\w-]*)*\s*in \d+(\.\d+)?(s|ms) \((\d+) modules\)/g
),
]
expect(modules.length).toBeGreaterThanOrEqual(1)
for (const [, , , , moduleCount] of modules) {
// Ensure that the number of modules is less than 1500 - otherwise we're
// importing the entire library.
expect(parseInt(moduleCount)).toBeLessThan(1500)
}
})
it('pages - should render the icons correctly without creating all the modules', async () => {
let logs = ''
next.on('stdout', (log) => {
logs += log
})
const html = await next.render('/pages-route')
// Ensure the icons are rendered
expect(html).toContain('<svg xmlns="http://www.w3.org/2000/svg"')
const modules = [
...logs.matchAll(
/Compiled (\/[\w-]+)*\s*in \d+(\.\d+)?(s|ms) \((\d+) modules\)/g
),
]
expect(modules.length).toBeGreaterThanOrEqual(1)
for (const [, , , , moduleCount] of modules) {
// Ensure that the number of modules is less than 1500 - otherwise we're
// importing the entire library.
expect(parseInt(moduleCount)).toBeLessThan(1500)
}
})
it('app - should optimize recursive wildcard export mapping', async () => {
let logs = ''
next.on('stdout', (log) => {
logs += log
})
await next.render('/recursive-barrel-app')
const modules = [...logs.matchAll(/\((\d+) modules\)/g)]
expect(modules.length).toBeGreaterThanOrEqual(1)
for (const [, moduleCount] of modules) {
// Ensure that the number of modules is less than 1500 - otherwise we're
// importing the entire library.
expect(parseInt(moduleCount)).toBeLessThan(1500)
}
})
it('pages - should optimize recursive wildcard export mapping', async () => {
let logs = ''
next.on('stdout', (log) => {
logs += log
})
await next.render('/recursive-barrel')
const modules = [...logs.matchAll(/\((\d+) modules\)/g)]
expect(modules.length).toBeGreaterThanOrEqual(1)
for (const [, moduleCount] of modules) {
// Ensure that the number of modules is less than 1500 - otherwise we're
// importing the entire library.
expect(parseInt(moduleCount)).toBeLessThan(1500)
}
})
it('should handle recursive wildcard exports', async () => { it('should handle recursive wildcard exports', async () => {
const html = await next.render('/recursive') const html = await next.render('/recursive')
expect(html).toContain('<h1>42</h1>') expect(html).toContain('<h1>42</h1>')
......
...@@ -10,7 +10,7 @@ export function runBasicHmrTest(nextConfig: { ...@@ -10,7 +10,7 @@ export function runBasicHmrTest(nextConfig: {
basePath: string basePath: string
assetPrefix: string assetPrefix: string
}) { }) {
const { next } = nextTestSetup({ const { next, isTurbopack } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig, nextConfig,
patchFileDelay: 500, patchFileDelay: 500,
...@@ -48,25 +48,26 @@ export function runBasicHmrTest(nextConfig: { ...@@ -48,25 +48,26 @@ export function runBasicHmrTest(nextConfig: {
hello: 'world', hello: 'world',
}) })
}) })
;(isTurbopack ? it : it.skip)(
it('should have correct compile timing after fixing error', async () => { 'should have correct compile timing after fixing error',
const pageName = 'pages/auto-export-is-ready.js' async () => {
const originalContent = await next.readFile(pageName)
try {
const browser = await next.browser(basePath + '/auto-export-is-ready') const browser = await next.browser(basePath + '/auto-export-is-ready')
const outputLength = next.cliOutput.length let outputLength
await next.patchFile( await next.patchFile(
pageName, 'pages/auto-export-is-ready.js',
`import hello from 'non-existent'\n` + originalContent (content) => `import hello from 'non-existent'\n` + content,
async () => {
await assertHasRedbox(browser)
await waitFor(3000)
outputLength = next.cliOutput.length
}
) )
await assertHasRedbox(browser)
await waitFor(3000) let compileTimeStr
await next.patchFile(pageName, originalContent)
await retry(async () => { await retry(async () => {
expect(next.cliOutput.substring(outputLength)).toMatch(/Compiled.*?/i) compileTimeStr = next.cliOutput.substring(outputLength)
expect(compileTimeStr).toMatch(/Compiled.*?/i)
}) })
const compileTimeStr = next.cliOutput.substring(outputLength)
const matches = [ const matches = [
...compileTimeStr.match(/Compiled.*? in ([\d.]{1,})\s?(?:s|ms)/i), ...compileTimeStr.match(/Compiled.*? in ([\d.]{1,})\s?(?:s|ms)/i),
...@@ -78,10 +79,8 @@ export function runBasicHmrTest(nextConfig: { ...@@ -78,10 +79,8 @@ export function runBasicHmrTest(nextConfig: {
compileTimeMs = compileTimeMs * 1000 compileTimeMs = compileTimeMs * 1000
} }
expect(compileTimeMs).toBeLessThan(3000) expect(compileTimeMs).toBeLessThan(3000)
} finally {
await next.patchFile(pageName, originalContent)
} }
}) )
it('should reload the page when the server restarts', async () => { it('should reload the page when the server restarts', async () => {
const browser = await next.browser(basePath + '/hmr/about') const browser = await next.browser(basePath + '/hmr/about')
......
...@@ -22,6 +22,9 @@ export function runHotModuleReloadHmrTest(nextConfig: { ...@@ -22,6 +22,9 @@ export function runHotModuleReloadHmrTest(nextConfig: {
const text = await browser.elementByCss('p').text() const text = await browser.elementByCss('p').text()
expect(text).toBe('This is the contact page.') expect(text).toBe('This is the contact page.')
expect(next.cliOutput).toMatch(/GET .*\/hmr\/contact 200/)
let cliOutputLength = next.cliOutput.length
// Rename the file to mimic a deleted page // Rename the file to mimic a deleted page
await next.renameFile(contactPagePath, newContactPagePath) await next.renameFile(contactPagePath, newContactPagePath)
...@@ -30,6 +33,10 @@ export function runHotModuleReloadHmrTest(nextConfig: { ...@@ -30,6 +33,10 @@ export function runHotModuleReloadHmrTest(nextConfig: {
/This page could not be found/ /This page could not be found/
) )
}) })
expect(next.cliOutput.slice(cliOutputLength)).toMatch(
/GET .*\/hmr\/contact 404/
)
cliOutputLength = next.cliOutput.length
// Rename the file back to the original filename // Rename the file back to the original filename
await next.renameFile(newContactPagePath, contactPagePath) await next.renameFile(newContactPagePath, contactPagePath)
...@@ -40,8 +47,9 @@ export function runHotModuleReloadHmrTest(nextConfig: { ...@@ -40,8 +47,9 @@ export function runHotModuleReloadHmrTest(nextConfig: {
/This is the contact page/ /This is the contact page/
) )
}) })
expect(next.cliOutput.slice(cliOutputLength)).toMatch(
expect(next.cliOutput).toContain('Compiled /_error') /GET .*\/hmr\/contact 200/
)
} finally { } finally {
await next await next
.renameFile(newContactPagePath, contactPagePath) .renameFile(newContactPagePath, contactPagePath)
......
...@@ -266,7 +266,7 @@ describe('middleware - development errors', () => { ...@@ -266,7 +266,7 @@ describe('middleware - development errors', () => {
await next.patchFile('middleware.js', `export default function () {}`) await next.patchFile('middleware.js', `export default function () {}`)
retry(() => { retry(() => {
expect(next.cliOutput.slice(lengthOfLogs)).toContain('✓ Compiled') expect(next.cliOutput.slice(lengthOfLogs)).toContain('GET / 200')
}, 10000) // middleware rebuild takes a while in CI }, 10000) // middleware rebuild takes a while in CI
await assertNoRedbox(browser) await assertNoRedbox(browser)
......
...@@ -37,7 +37,9 @@ describe('app dir', () => { ...@@ -37,7 +37,9 @@ describe('app dir', () => {
) )
await retry(async () => { await retry(async () => {
expect(next.cliOutput.slice(cliOutputLength)).toInclude('✓ Compiled') expect(next.cliOutput.slice(cliOutputLength)).toInclude(
'GET /page-with-loading 200'
)
}) })
// It should not have an error // It should not have an error
......
...@@ -10,9 +10,11 @@ describe('app-dir with proxy', () => { ...@@ -10,9 +10,11 @@ describe('app-dir with proxy', () => {
}) })
if (isNextDev) { if (isNextDev) {
it('should log Compiled proxy in', async () => { it('should log compilation time', async () => {
await next.browser('/') await next.browser('/')
expect(next.cliOutput).toContain('Compiled proxy in') expect(next.cliOutput).toMatch(
/GET \/ 200 in .* \(compile:.*, proxy.ts:.*, render:.*\)/
)
}) })
} }
......
import { isNextDev, nextTestSetup } from 'e2e-utils' import { isNextDev, nextTestSetup } from 'e2e-utils'
import { getPrerenderOutput } from './utils' import { getPrerenderOutput } from './utils'
import stripAnsi from 'strip-ansi'
describe('Cache Components Errors', () => { describe('Cache Components Errors', () => {
const { next, isTurbopack, isNextStart, skipped } = nextTestSetup({ const { next, isTurbopack, isNextStart, skipped } = nextTestSetup({
...@@ -32,15 +33,17 @@ describe('Cache Components Errors', () => { ...@@ -32,15 +33,17 @@ describe('Cache Components Errors', () => {
if (isNextDev) { if (isNextDev) {
it('does not warn about sync IO if console.log is patched to call new Date() internally', async () => { it('does not warn about sync IO if console.log is patched to call new Date() internally', async () => {
await next.browser('/') await next.browser('/')
let output = next.cliOutput let output = stripAnsi(next.cliOutput)
expect(output).toContain('[<timestamp>] ✓ Compiled')
let index = output.indexOf('[<timestamp>] ✓ Compiled') // trim off Next.js's startup logs
output = output.slice(index).trim() const compilationMarker = /Ready in.*(\n.*Compiling.*)?/
index = output.indexOf('\n') expect(output).toMatch(compilationMarker)
output = output.slice(index).trim() const match = compilationMarker.exec(output)
output = output.slice(match.index + match[0].length).trim()
// trim off any logs after the HTTP request finished
expect(output).toContain('GET / 200') expect(output).toContain('GET / 200')
index = output.indexOf('GET / 200') const snapshot = output.slice(0, output.indexOf('GET / 200')).trim()
const snapshot = output.slice(0, index).trim()
expect(snapshot).toMatchInlineSnapshot(` expect(snapshot).toMatchInlineSnapshot(`
"[<timestamp>] This is a console log from a server component page "[<timestamp>] This is a console log from a server component page
......
...@@ -367,7 +367,7 @@ describe('app-dir - logging', () => { ...@@ -367,7 +367,7 @@ describe('app-dir - logging', () => {
await retry(() => { await retry(() => {
const output = stripAnsi(next.cliOutput.slice(logLength)) const output = stripAnsi(next.cliOutput.slice(logLength))
expect(output).toContain('/dynamic/[slug]/icon') expect(output).toContain('/dynamic/big/icon')
expect(output).not.toContain('/(group)') expect(output).not.toContain('/(group)')
expect(output).not.toContain('[__metadata_id__]') expect(output).not.toContain('[__metadata_id__]')
expect(output).not.toContain('/route') expect(output).not.toContain('/route')
......
...@@ -320,7 +320,7 @@ describe('app-dir - server source maps', () => { ...@@ -320,7 +320,7 @@ describe('app-dir - server source maps', () => {
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
expect(cliOutput).toContain( expect(cliOutput).toContain(
'\n ⨯ Error: ssr-throw' + '⨯ Error: ssr-throw' +
'\n at throwError (app/ssr-throw/Thrower.js:4:9)' + '\n at throwError (app/ssr-throw/Thrower.js:4:9)' +
'\n at Thrower (app/ssr-throw/Thrower.js:8:3)' + '\n at Thrower (app/ssr-throw/Thrower.js:8:3)' +
'\n 2 |' + '\n 2 |' +
...@@ -441,8 +441,7 @@ describe('app-dir - server source maps', () => { ...@@ -441,8 +441,7 @@ describe('app-dir - server source maps', () => {
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
if (isTurbopack) { if (isTurbopack) {
expect(cliOutput).toContain( expect(cliOutput).toContain(
'' + 'Error: module-evaluation' +
'\nError: module-evaluation' +
// TODO(veil): Should map to no name like you'd get with native stacks without a bundler. // TODO(veil): Should map to no name like you'd get with native stacks without a bundler.
'\n at module evaluation (app/module-evaluation/module.js:1:22)' + '\n at module evaluation (app/module-evaluation/module.js:1:22)' +
// TODO(veil): Added frames from bundler should be sourcemapped (https://linear.app/vercel/issue/NDX-509/) // TODO(veil): Added frames from bundler should be sourcemapped (https://linear.app/vercel/issue/NDX-509/)
...@@ -451,8 +450,7 @@ describe('app-dir - server source maps', () => { ...@@ -451,8 +450,7 @@ describe('app-dir - server source maps', () => {
) )
} else { } else {
expect(cliOutput).toContain( expect(cliOutput).toContain(
'' + 'Error: module-evaluation' +
'\nError: module-evaluation' +
// TODO(veil): Should map to no name like you'd get with native stacks without a bundler. // TODO(veil): Should map to no name like you'd get with native stacks without a bundler.
// TODO(veil): Location should be sourcemapped // TODO(veil): Location should be sourcemapped
'\n at eval (app/module-evaluation/module.js:1:22)' + '\n at eval (app/module-evaluation/module.js:1:22)' +
......
...@@ -149,7 +149,7 @@ describe('use-cache-dev', () => { ...@@ -149,7 +149,7 @@ describe('use-cache-dev', () => {
) )
await retry(async () => { await retry(async () => {
expect(next.cliOutput.slice(cliOutputLength)).toInclude('✓ Compiled') expect(next.cliOutput.slice(cliOutputLength)).toInclude('GET / 200')
}, 10_000) }, 10_000)
cliOutputLength = next.cliOutput.length cliOutputLength = next.cliOutput.length
...@@ -160,7 +160,7 @@ describe('use-cache-dev', () => { ...@@ -160,7 +160,7 @@ describe('use-cache-dev', () => {
) )
await retry(async () => { await retry(async () => {
expect(next.cliOutput.slice(cliOutputLength)).toInclude('✓ Compiled') expect(next.cliOutput.slice(cliOutputLength)).toInclude('GET / 200')
}, 10_000) }, 10_000)
}) })
......
...@@ -29,8 +29,7 @@ describe('fetch failures have good stack traces in edge runtime', () => { ...@@ -29,8 +29,7 @@ describe('fetch failures have good stack traces in edge runtime', () => {
} else if (isNextDev) { } else if (isNextDev) {
// eslint-disable-next-line jest/no-standalone-expect // eslint-disable-next-line jest/no-standalone-expect
expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain( expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain(
'' + '⨯ Error [TypeError]: fetch failed' +
'\n ⨯ Error [TypeError]: fetch failed' +
'\n at anotherFetcher (src/fetcher.js:6:16)' + '\n at anotherFetcher (src/fetcher.js:6:16)' +
'\n at fetcher (src/fetcher.js:2:16)' + '\n at fetcher (src/fetcher.js:2:16)' +
'\n at UnknownDomainEndpoint (pages/api/unknown-domain.js:6:16)' + '\n at UnknownDomainEndpoint (pages/api/unknown-domain.js:6:16)' +
......
...@@ -135,8 +135,7 @@ describe.each(['default', 'babelrc'] as const)( ...@@ -135,8 +135,7 @@ describe.each(['default', 'babelrc'] as const)(
// TODO(NDX-663): Unhelpful error message. // TODO(NDX-663): Unhelpful error message.
// Should say that the library should have a react-server entrypoint that doesn't use the React Compiler. // Should say that the library should have a react-server entrypoint that doesn't use the React Compiler.
expect(cliOutput).toContain( expect(cliOutput).toContain(
'' + "⨯ TypeError: Cannot read properties of undefined (reading 'H')" +
"\n ⨯ TypeError: Cannot read properties of undefined (reading 'H')" +
// location not important. Just that this is the only frame. // location not important. Just that this is the only frame.
// TODO: Stack should start at product code. Possible React limitation. // TODO: Stack should start at product code. Possible React limitation.
'\n at Container (**)' + '\n at Container (**)' +
......
/* eslint-env jest */ /* eslint-env jest */
import { join } from 'path' import { join } from 'path'
import { check, findPort, killApp, launchApp } from 'next-test-utils' import { retry, findPort, killApp, launchApp } from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
...@@ -34,7 +34,9 @@ describe('Image with middleware in edge func', () => { ...@@ -34,7 +34,9 @@ describe('Image with middleware in edge func', () => {
Attempted import error: 'preload' is not exported from 'react-dom' (imported as 'preload'). Attempted import error: 'preload' is not exported from 'react-dom' (imported as 'preload').
*/ */
await webdriver(appPort, '/') await webdriver(appPort, '/')
await check(() => output, /compiled \//i) await retry(async () => {
expect(output).toContain('GET /')
})
expect(output).not.toContain( expect(output).not.toContain(
`'preload' is not exported from 'react-dom'` `'preload' is not exported from 'react-dom'`
) )
......
/* eslint-env jest */ /* eslint-env jest */
import { join } from 'path' import { join } from 'path'
import { check, findPort, killApp, launchApp } from 'next-test-utils' import { findPort, killApp, launchApp, retry } from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
...@@ -33,7 +33,9 @@ describe('Image is intercepted by Middleware', () => { ...@@ -33,7 +33,9 @@ describe('Image is intercepted by Middleware', () => {
await browser.waitForIdleNetwork() await browser.waitForIdleNetwork()
await check(() => output, /compiled \//i) await retry(async () => {
expect(output).toContain('GET /')
})
expect(output).toContain(`x-_next-image: /small.jpg`) expect(output).toContain(`x-_next-image: /small.jpg`)
}) })
......
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