Commit 78c2533e authored by Jiachi Liu's avatar Jiachi Liu Committed by Zack Tanner

Fix client boundary inheritance for barrel optimization (#64467)

### What

Inherit the client boudaries from the found matched target in load
barrel

### Why
The root cause with the barrel transform, we missed the client boundary
directive during the transform.
Since the new version of mui's case looks like this:

Import path
page.js (server module) -> `<module>/index.js` (shared module) ->
`<module/subpath>/index.js` (client module) ->
`<module/subpath/sub-module.js> (client module)

After our transform, we lost the `"use client"` which causes the
mismatch of the transform:

In `rsc` layer: the file pointing to the sub module entry
(`<module/subpath>/index.js`), but without the client boundary.


Fixes #64369 
Closes NEXT-3101
parent 97a55867
...@@ -221,9 +221,12 @@ async function getBarrelMapping( ...@@ -221,9 +221,12 @@ async function getBarrelMapping(
true, true,
isClientEntry isClientEntry
) )
if (targetMatches) { if (targetMatches) {
// Merge the export list // Merge the export list
exportList = exportList.concat(targetMatches.exportList) exportList = exportList.concat(targetMatches.exportList)
// Inherit the client boundary from the target matched file
isClientEntry = isClientEntry || targetMatches.isClientEntry
} }
}) })
) )
......
...@@ -14,7 +14,7 @@ import { hasRedbox } from 'next-test-utils' ...@@ -14,7 +14,7 @@ import { hasRedbox } from 'next-test-utils'
files: join(__dirname, 'fixture'), files: join(__dirname, 'fixture'),
dependencies: { dependencies: {
'@mui/material': '5.15.4', '@mui/material': '5.15.15',
'@emotion/react': '11.11.1', '@emotion/react': '11.11.1',
'@emotion/styled': '11.11.0', '@emotion/styled': '11.11.0',
}, },
......
export default function RootLayout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { ClientDefault } from 'my-lib'
export default function Home() {
return (
<div id="client-mod">
<ClientDefault />
</div>
)
}
import { createNextDescribe } from 'e2e-utils'
describe('Skipped in Turbopack', () => {
createNextDescribe(
'app-dir - optimizePackageImports - basic',
{
files: __dirname,
},
({ next }) => {
it('should build successfully', async () => {
// Ensure that MUI is working
const $ = await next.render$('/')
expect(await $('#client-mod').text()).toContain('client:default')
})
}
)
})
module.exports = {
experimental: {
optimizePackageImports: ['my-lib'],
},
}
'use client'
export default function ClientDefault() {
return 'client:default'
}
export function ClientFoo() {
return 'client:foo'
}
'use client'
export { default } from './client-module'
export * from './client-module'
export { default as ClientDefault } from './client'
export * from './client'
{
"name": "my-lib",
"type": "module",
"exports": "./index.js"
}
export default function RootLayout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { Typography } from '@mui/material'
export default function Home() {
return (
<div id="typography">
<Typography id="typography" variant="h1">
typography
</Typography>
</div>
)
}
import { createNextDescribe } from 'e2e-utils'
describe('Skipped in Turbopack', () => {
createNextDescribe(
'app-dir - optimizePackageImports - mui',
{
files: __dirname,
dependencies: {
'@mui/material': '5.15.15',
'@emotion/react': '11.11.1',
'@emotion/styled': '11.11.0',
},
},
({ next }) => {
it('should build successfully', async () => {
// Ensure that MUI is working
const $ = await next.render$('/')
expect(await $('#typography').text()).toContain('typography')
})
}
)
})
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