Skip to content

Commit

Permalink
Fix webpack chunks handling in traces (#59498)
Browse files Browse the repository at this point in the history
This ensures we don't include all chunks in `nft` traces un-necessarily
as our webpack plugin already tracks which are needed per-entry.

x-ref: [slack
thread](https://vercel.slack.com/archives/C0591D8EN4C/p1702318184832319?thread_ts=1701815919.923639&cid=C0591D8EN4C)

Closes NEXT-1847
  • Loading branch information
ijjk authored Dec 11, 2023
1 parent 618c728 commit c7a29bd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/next/src/build/collect-build-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ export async function collectBuildTraces({

const routesIgnores = [
...sharedIgnores,
// server chunks are provided via next-trace-entrypoints-plugin plugin
// as otherwise all chunks are traced here and included for all pages
// whether they are needed or not
'**/.next/server/chunks/**',
'**/next/dist/server/optimize-amp.js',
'**/next/dist/server/post-process.js',
].filter(nonNullable)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Button() {
return <button>click me</button>
}
4 changes: 4 additions & 0 deletions test/integration/build-trace-extra-entries/app/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { fetchData } from '../lib/fetch-data'

import('../lib/my-component').then((mod) => {
console.log(mod.Button)
})

export default function Page() {
return 'index page'
}
Expand Down
16 changes: 16 additions & 0 deletions test/integration/build-trace-extra-entries/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ describe('build trace with extra entries', () => {
expect(appTrace.files.some((file) => file.endsWith('hello.json'))).toBe(
true
)
expect(
appTrace.files.filter(
(file) => file.includes('chunks') && file.endsWith('.js')
).length
).toBe(0)

expect(
indexTrace.files.filter(
(file) => file.includes('chunks') && file.endsWith('.js')
).length
).toBeGreaterThan(
anotherTrace.files.filter(
(file) => file.includes('chunks') && file.endsWith('.js')
).length
)

expect(
appTrace.files.some((file) => file.endsWith('lib/get-data.js'))
).toBe(true)
Expand Down

0 comments on commit c7a29bd

Please sign in to comment.