Skip to content

Commit 04cc13c

Browse files
committed
Fix mixed exports in server component with barrel optimization (#64894)
### What * Remove the change added in #64467, but still kept tests. * Add more tests for mixed imports (component and function) from shared component with `optimizePackageImports` ### Why The fix in #64467 was not correct, as mixing `export *` with `"use client"` should error if Next.js detect it properly. When there's mixed exports, that a shared function will become a client reference if the target file inherits the client boundary. The original issue #64467 fixed was actually related to tree-shaking, which is fixed in #64681. Closes NEXT-3197
1 parent 8d01d49 commit 04cc13c

File tree

8 files changed

+32
-6
lines changed

8 files changed

+32
-6
lines changed

packages/next/src/build/webpack/loaders/next-barrel-loader.ts

-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ async function getBarrelMapping(
225225
if (targetMatches) {
226226
// Merge the export list
227227
exportList = exportList.concat(targetMatches.exportList)
228-
// Inherit the client boundary from the target matched file
229-
isClientEntry = isClientEntry || targetMatches.isClientEntry
230228
}
231229
})
232230
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { buttonStyle, Button } from 'mixed-lib'
2+
3+
export default function Page() {
4+
return (
5+
<div>
6+
<Button id="component" style={buttonStyle()} />
7+
</div>
8+
)
9+
}

test/production/app-dir/barrel-optimization/basic/index.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ describe('Skipped in Turbopack', () => {
88
},
99
({ next }) => {
1010
it('should build successfully', async () => {
11-
// Ensure that MUI is working
1211
const $ = await next.render$('/')
1312
expect(await $('#client-mod').text()).toContain('client:default')
1413
})
14+
15+
it('should handle mixed imports from barrel optimized lib correctly', async () => {
16+
const $ = await next.render$('/mixed-barrel-imports')
17+
expect(await $('#component').attr('style')).toContain('color:blue')
18+
})
1519
}
1620
)
1721
})
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
experimental: {
3-
optimizePackageImports: ['my-lib'],
3+
optimizePackageImports: ['my-lib', 'mixed-lib'],
44
},
55
}

test/production/app-dir/barrel-optimization/basic/node_modules/mixed-lib/button.js

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/production/app-dir/barrel-optimization/basic/node_modules/mixed-lib/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/production/app-dir/barrel-optimization/basic/node_modules/mixed-lib/package.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/production/app-dir/barrel-optimization/basic/node_modules/my-lib/client/index.js

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)