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

Fix barrel optimization to ignore layers #59254

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/next/src/build/webpack/loaders/next-barrel-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ const barrelTransformMappingCache = new Map<
>()

async function getBarrelMapping(
layer: string | null | undefined,
resourcePath: string,
swcCacheDir: string,
resolve: (context: string, request: string) => Promise<string>,
Expand Down Expand Up @@ -135,9 +134,6 @@ async function getBarrelMapping(
optimizeBarrelExports: {
wildcard: isWildcard,
},
serverComponents: {
isReactServerLayer: layer === WEBPACK_LAYERS.reactServerComponents,
},
jsc: {
parser: {
syntax: isTypeScript ? 'typescript' : 'ecmascript',
Expand Down Expand Up @@ -249,7 +245,6 @@ const NextBarrelLoader = async function (
})

const mapping = await getBarrelMapping(
this._module?.layer,
this.resourcePath,
swcCacheDir,
resolve,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ createNextDescribe(
'@heroicons/react': '2.0.18',
'@visx/visx': '3.3.0',
'recursive-barrel': '1.0.0',
'@mui/material': '5.14.19',
'@emotion/styled': '11.11.0',
'@emotion/react': '11.11.1',
},
},
({ next }) => {
Expand Down Expand Up @@ -127,6 +130,30 @@ createNextDescribe(
expect(html).toContain('<linearGradient')
})

it('should support MUI', async () => {
let logs = ''
next.on('stdout', (log) => {
logs += log
})

// Ensure that MUI is working
const html = await next.render('/mui')
expect(html).toContain('test_mui')

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 1000 - otherwise we're
// importing the entire library.
expect(parseInt(moduleCount)).toBeLessThan(1000)
}
})

it('should not break "use client" directive in optimized packages', async () => {
const html = await next.render('/client')
expect(html).toContain('this is a client component')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Button } from '@mui/material'

export default function Page() {
return <Button>test_mui</Button>
}
Loading