Unverified Commit df102ae3 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

[Turbopack] dedupe build errors (#85062)

When we run the RSC validation transform, we might take multiple passes
on the same file if the edge runtime is used: once at the RSC layer,
another in the edge RSC layer. This means we'll have reported the error
twice for the same file. This dedupes errors by tracking the seen,
formatted errors and not re-showing them if they've already been
tracked.
parent 98adcb3f
......@@ -200,21 +200,41 @@ export function printBuildErrors(
// Issues that are warnings but should not affect the running of the build
const topLevelWarnings = []
// Track seen formatted error messages to avoid duplicates
const seenFatalIssues = new Set<string>()
const seenErrors = new Set<string>()
const seenWarnings = new Set<string>()
for (const issue of entrypoints.issues) {
// We only want to completely shut down the server
if (issue.severity === 'fatal' || issue.severity === 'bug') {
topLevelFatalIssues.push(formatIssue(issue))
const formatted = formatIssue(issue)
if (!seenFatalIssues.has(formatted)) {
seenFatalIssues.add(formatted)
topLevelFatalIssues.push(formatted)
}
} else if (isRelevantWarning(issue)) {
topLevelWarnings.push(formatIssue(issue))
const formatted = formatIssue(issue)
if (!seenWarnings.has(formatted)) {
seenWarnings.add(formatted)
topLevelWarnings.push(formatted)
}
} else if (issue.severity === 'error') {
const formatted = formatIssue(issue)
if (isDev) {
// We want to treat errors as recoverable in development
// so that we can show the errors in the site and allow users
// to respond to the errors when necessary. In production builds
// though we want to error out and stop the build process.
topLevelErrors.push(formatIssue(issue))
if (!seenErrors.has(formatted)) {
seenErrors.add(formatted)
topLevelErrors.push(formatted)
}
} else {
topLevelFatalIssues.push(formatIssue(issue))
if (!seenFatalIssues.has(formatted)) {
seenFatalIssues.add(formatted)
topLevelFatalIssues.push(formatted)
}
}
}
}
......
import { nextTestSetup } from 'e2e-utils'
// Only Turbopack runs the transform on the layout once in edge and non-edge contexts
// so we only test this on Turbopack
import {
assertHasRedbox,
getRedboxDescription,
getRedboxSource,
} from 'next-test-utils'
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)(
'cache-components-edge-deduplication',
() => {
const { next, skipped, isNextDev } = nextTestSetup({
files: __dirname + '/fixtures/edge-deduplication',
skipStart: true,
skipDeployment: true,
})
if (skipped) {
return
}
it('should not duplicate errors when layout is compiled for both edge and non-edge contexts', async () => {
try {
await next.start()
} catch {
// we expect the build to fail
}
if (isNextDev) {
const browser = await next.browser('/edge-with-layout/edge')
assertHasRedbox(browser)
const redbox = {
description: await getRedboxDescription(browser),
source: await getRedboxSource(browser),
}
expect(redbox.description).toMatchInlineSnapshot(
`"Ecmascript file had an error"`
)
expect(redbox.source).toMatchInlineSnapshot(`
"./app/edge-with-layout/edge/page.tsx (1:14)
Ecmascript file had an error
> 1 | export const runtime = 'edge'
| ^^^^^^^
2 |
3 | export default function Page() {
4 | return <div>Test page under app/</div>
Route segment config "runtime" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."
`)
// Count occurrences of the layout error at the specific location
const layoutErrorMatches = next.cliOutput.match(
/\.\/app\/edge-with-layout\/layout\.tsx:1:14/g
)
// We don't show an error stack, just the individual error messages at each location
expect(layoutErrorMatches?.length).toBe(1)
} else {
// Check that both the layout and edge page errors appear
expect(next.cliOutput).toContain('./app/edge-with-layout/layout.tsx')
expect(next.cliOutput).toContain('./app/edge-with-layout/edge/page.tsx')
expect(next.cliOutput).toContain(
'"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
// Count occurrences of the layout error at the specific location
const layoutErrorMatches = next.cliOutput.match(
/\.\/app\/layout\.tsx:1:14/g
)
// Should appear exactly twice: once in the formatted error message, once in the stack trace
expect(layoutErrorMatches?.length).toBe(2)
}
})
}
)
......@@ -8,7 +8,7 @@ import {
describe('cache-components-segment-configs', () => {
const { next, skipped, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname,
files: __dirname + '/fixtures/default',
skipStart: true,
skipDeployment: true,
})
......
export const runtime = 'edge'
export default function Page() {
return <div>Test page under app/</div>
}
export const dynamic = 'force-dynamic'
export default function Layout({ children }: { children: React.ReactNode }) {
return <div>{children}</div>
}
export const dynamic = 'force-dynamic'
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
<main>{children}</main>
</body>
</html>
)
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
cacheComponents: true,
}
module.exports = nextConfig
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