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'
import { teardownTraceSubscriber } from '../swc'
import * as Log from './log'
const MAX_LOG_SKIP_DURATION = 500 // 500ms
const MAX_LOG_SKIP_DURATION_MS = 3000
export type OutputState =
| {
......@@ -109,7 +109,7 @@ store.subscribe((state) => {
trigger: trigger,
})
if (!loadingLogTimer) {
// Only log compiling if compiled is not finished in 3 seconds
// Only log compiling if compiled is not finished quickly
loadingLogTimer = setTimeout(() => {
if (
triggerUrl &&
......@@ -120,7 +120,7 @@ store.subscribe((state) => {
} else {
Log.wait(`Compiling ${trigger} ...`)
}
}, MAX_LOG_SKIP_DURATION)
}, MAX_LOG_SKIP_DURATION_MS)
}
}
}
......@@ -182,9 +182,6 @@ store.subscribe((state) => {
traceSpan.stop()
traceSpan = null
}
Log.event(
`Compiled${trigger ? ' ' + trigger : ''}${timeMessage}${modulesMessage}`
)
trigger = ''
}
......
......@@ -94,7 +94,7 @@ describe('Cache Components Dev Errors', () => {
})
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. ` +
`See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense` +
'\n at Page (app/no-accessed-data/page.js:1:31)' +
......
......@@ -21,26 +21,13 @@ import { assertNoRedbox } from 'next-test-utils'
})
it('should support MUI', async () => {
let logs = ''
next.on('stdout', (log) => {
logs += log
})
// Ensure that MUI is working
const $ = await next.render$('/mui')
expect(await $('#button').text()).toContain('button')
expect(await $('#typography').text()).toContain('typography')
expect($('#button').text()).toContain('button')
expect($('#typography').text()).toContain('typography')
const browser = await next.browser('/mui')
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'
},
})
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 () => {
const html = await next.render('/recursive')
expect(html).toContain('<h1>42</h1>')
......
......@@ -10,7 +10,7 @@ export function runBasicHmrTest(nextConfig: {
basePath: string
assetPrefix: string
}) {
const { next } = nextTestSetup({
const { next, isTurbopack } = nextTestSetup({
files: __dirname,
nextConfig,
patchFileDelay: 500,
......@@ -48,25 +48,26 @@ export function runBasicHmrTest(nextConfig: {
hello: 'world',
})
})
it('should have correct compile timing after fixing error', async () => {
const pageName = 'pages/auto-export-is-ready.js'
const originalContent = await next.readFile(pageName)
try {
;(isTurbopack ? it : it.skip)(
'should have correct compile timing after fixing error',
async () => {
const browser = await next.browser(basePath + '/auto-export-is-ready')
const outputLength = next.cliOutput.length
let outputLength
await next.patchFile(
pageName,
`import hello from 'non-existent'\n` + originalContent
'pages/auto-export-is-ready.js',
(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)
await next.patchFile(pageName, originalContent)
let compileTimeStr
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 = [
...compileTimeStr.match(/Compiled.*? in ([\d.]{1,})\s?(?:s|ms)/i),
......@@ -78,10 +79,8 @@ export function runBasicHmrTest(nextConfig: {
compileTimeMs = compileTimeMs * 1000
}
expect(compileTimeMs).toBeLessThan(3000)
} finally {
await next.patchFile(pageName, originalContent)
}
})
)
it('should reload the page when the server restarts', async () => {
const browser = await next.browser(basePath + '/hmr/about')
......
......@@ -22,6 +22,9 @@ export function runHotModuleReloadHmrTest(nextConfig: {
const text = await browser.elementByCss('p').text()
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
await next.renameFile(contactPagePath, newContactPagePath)
......@@ -30,6 +33,10 @@ export function runHotModuleReloadHmrTest(nextConfig: {
/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
await next.renameFile(newContactPagePath, contactPagePath)
......@@ -40,8 +47,9 @@ export function runHotModuleReloadHmrTest(nextConfig: {
/This is the contact page/
)
})
expect(next.cliOutput).toContain('Compiled /_error')
expect(next.cliOutput.slice(cliOutputLength)).toMatch(
/GET .*\/hmr\/contact 200/
)
} finally {
await next
.renameFile(newContactPagePath, contactPagePath)
......
......@@ -266,7 +266,7 @@ describe('middleware - development errors', () => {
await next.patchFile('middleware.js', `export default function () {}`)
retry(() => {
expect(next.cliOutput.slice(lengthOfLogs)).toContain('✓ Compiled')
expect(next.cliOutput.slice(lengthOfLogs)).toContain('GET / 200')
}, 10000) // middleware rebuild takes a while in CI
await assertNoRedbox(browser)
......
......@@ -37,7 +37,9 @@ describe('app dir', () => {
)
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
......
......@@ -10,9 +10,11 @@ describe('app-dir with proxy', () => {
})
if (isNextDev) {
it('should log Compiled proxy in', async () => {
it('should log compilation time', async () => {
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 { getPrerenderOutput } from './utils'
import stripAnsi from 'strip-ansi'
describe('Cache Components Errors', () => {
const { next, isTurbopack, isNextStart, skipped } = nextTestSetup({
......@@ -32,15 +33,17 @@ describe('Cache Components Errors', () => {
if (isNextDev) {
it('does not warn about sync IO if console.log is patched to call new Date() internally', async () => {
await next.browser('/')
let output = next.cliOutput
expect(output).toContain('[<timestamp>] ✓ Compiled')
let index = output.indexOf('[<timestamp>] ✓ Compiled')
output = output.slice(index).trim()
index = output.indexOf('\n')
output = output.slice(index).trim()
let output = stripAnsi(next.cliOutput)
// trim off Next.js's startup logs
const compilationMarker = /Ready in.*(\n.*Compiling.*)?/
expect(output).toMatch(compilationMarker)
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')
index = output.indexOf('GET / 200')
const snapshot = output.slice(0, index).trim()
const snapshot = output.slice(0, output.indexOf('GET / 200')).trim()
expect(snapshot).toMatchInlineSnapshot(`
"[<timestamp>] This is a console log from a server component page
......
......@@ -367,7 +367,7 @@ describe('app-dir - logging', () => {
await retry(() => {
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('[__metadata_id__]')
expect(output).not.toContain('/route')
......
......@@ -320,7 +320,7 @@ describe('app-dir - server source maps', () => {
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
expect(cliOutput).toContain(
'\n ⨯ Error: ssr-throw' +
'⨯ Error: ssr-throw' +
'\n at throwError (app/ssr-throw/Thrower.js:4:9)' +
'\n at Thrower (app/ssr-throw/Thrower.js:8:3)' +
'\n 2 |' +
......@@ -441,8 +441,7 @@ describe('app-dir - server source maps', () => {
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
if (isTurbopack) {
expect(cliOutput).toContain(
'' +
'\nError: module-evaluation' +
'Error: module-evaluation' +
// 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)' +
// 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', () => {
)
} else {
expect(cliOutput).toContain(
'' +
'\nError: module-evaluation' +
'Error: module-evaluation' +
// TODO(veil): Should map to no name like you'd get with native stacks without a bundler.
// TODO(veil): Location should be sourcemapped
'\n at eval (app/module-evaluation/module.js:1:22)' +
......
......@@ -149,7 +149,7 @@ describe('use-cache-dev', () => {
)
await retry(async () => {
expect(next.cliOutput.slice(cliOutputLength)).toInclude('✓ Compiled')
expect(next.cliOutput.slice(cliOutputLength)).toInclude('GET / 200')
}, 10_000)
cliOutputLength = next.cliOutput.length
......@@ -160,7 +160,7 @@ describe('use-cache-dev', () => {
)
await retry(async () => {
expect(next.cliOutput.slice(cliOutputLength)).toInclude('✓ Compiled')
expect(next.cliOutput.slice(cliOutputLength)).toInclude('GET / 200')
}, 10_000)
})
......
......@@ -29,8 +29,7 @@ describe('fetch failures have good stack traces in edge runtime', () => {
} else if (isNextDev) {
// eslint-disable-next-line jest/no-standalone-expect
expect(stripAnsi(next.cliOutput.slice(outputIndex))).toContain(
'' +
'\n ⨯ Error [TypeError]: fetch failed' +
'⨯ Error [TypeError]: fetch failed' +
'\n at anotherFetcher (src/fetcher.js:6:16)' +
'\n at fetcher (src/fetcher.js:2:16)' +
'\n at UnknownDomainEndpoint (pages/api/unknown-domain.js:6:16)' +
......
......@@ -135,8 +135,7 @@ describe.each(['default', 'babelrc'] as const)(
// TODO(NDX-663): Unhelpful error message.
// Should say that the library should have a react-server entrypoint that doesn't use the React Compiler.
expect(cliOutput).toContain(
'' +
"\n ⨯ TypeError: Cannot read properties of undefined (reading 'H')" +
"⨯ TypeError: Cannot read properties of undefined (reading 'H')" +
// location not important. Just that this is the only frame.
// TODO: Stack should start at product code. Possible React limitation.
'\n at Container (**)' +
......
/* eslint-env jest */
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'
const appDir = join(__dirname, '../')
......@@ -34,7 +34,9 @@ describe('Image with middleware in edge func', () => {
Attempted import error: 'preload' is not exported from 'react-dom' (imported as 'preload').
*/
await webdriver(appPort, '/')
await check(() => output, /compiled \//i)
await retry(async () => {
expect(output).toContain('GET /')
})
expect(output).not.toContain(
`'preload' is not exported from 'react-dom'`
)
......
/* eslint-env jest */
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'
const appDir = join(__dirname, '../')
......@@ -33,7 +33,9 @@ describe('Image is intercepted by Middleware', () => {
await browser.waitForIdleNetwork()
await check(() => output, /compiled \//i)
await retry(async () => {
expect(output).toContain('GET /')
})
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