Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure App Router and Pages Router modules can't share chunks #50327

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,10 @@ export default async function getBaseWebpackConfig(
framework: {
chunks: 'all',
name: 'framework',
// Ensures the framework chunk is not created for App Router.
layer(layer: any) {
return layer === null || layer === undefined
},
test(module: any) {
const resource = module.nameForCondition?.()
return resource
Expand All @@ -1696,6 +1700,7 @@ export default async function getBaseWebpackConfig(
)
},
name(module: {
layer: string | null | undefined
type: string
libIdent?: Function
updateHash: (hash: crypto.Hash) => void
Expand All @@ -1712,6 +1717,13 @@ export default async function getBaseWebpackConfig(
hash.update(module.libIdent({ context: dir }))
}

// Ensures the name of the chunk is not the same between two modules in different layers
// E.g. if you import 'button-library' in App Router and Pages Router we don't want these to be bundled in the same chunk
// as they're never used on the same page.
if (module.layer) {
hash.update(module.layer)
}

return hash.digest('hex').substring(0, 8)
},
priority: 30,
Expand Down