Unverified Commit 3fa9cb7b authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

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
parent c251de87
......@@ -225,8 +225,6 @@ async function getBarrelMapping(
if (targetMatches) {
// Merge the export list
exportList = exportList.concat(targetMatches.exportList)
// Inherit the client boundary from the target matched file
isClientEntry = isClientEntry || targetMatches.isClientEntry
}
})
)
......
import { buttonStyle, Button } from 'mixed-lib'
export default function Page() {
return (
<div>
<Button id="component" style={buttonStyle()} />
</div>
)
}
......@@ -8,10 +8,14 @@ describe('Skipped in Turbopack', () => {
},
({ next }) => {
it('should build successfully', async () => {
// Ensure that MUI is working
const $ = await next.render$('/')
expect(await $('#client-mod').text()).toContain('client:default')
})
it('should handle mixed imports from barrel optimized lib correctly', async () => {
const $ = await next.render$('/mixed-barrel-imports')
expect(await $('#component').attr('style')).toContain('color:blue')
})
}
)
})
module.exports = {
experimental: {
optimizePackageImports: ['my-lib'],
optimizePackageImports: ['my-lib', 'mixed-lib'],
},
}
import React from 'react'
export function Button(props) {
return React.createElement('button', props, 'button')
}
export function buttonStyle() {
return {
color: 'blue',
}
}
{
"name": "mixed-lib",
"type": "module",
"exports": "./index.js"
}
'use client'
export { default } from './client-module'
export * from './client-module'
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