Unverified Commit 05a9e0ac authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix conflict when re-exporting multiple Client References (#49468)

Closes #49324. Default export should only be added in the loader
generated boundary file when it actually exists.

fix NEXT-1112
parent 2dade5df
......@@ -247,6 +247,12 @@ impl<C: Comments> ReactServerComponents<C> {
})) => {
self.export_names.push("default".to_string());
}
ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultExpr(ExportDefaultExpr {
expr: _,
..
})) => {
self.export_names.push("default".to_string());
}
ModuleItem::ModuleDecl(ModuleDecl::ExportAll(_)) => {
self.export_names.push("*".to_string());
}
......
......@@ -70,17 +70,21 @@ const proxy = createProxy(String.raw\`${this.resourcePath}\`)
// The __esModule getter forces the proxy target to create the default export
// and the $$typeof value is for rendering logic to determine if the module
// is a client boundary.
export const { __esModule, $$typeof } = proxy;
export default proxy.default;
const { __esModule, $$typeof } = proxy;
const __default__ = proxy.default;
`
let cnt = 0
for (const ref of clientRefs) {
if (ref !== '' && ref !== 'default') {
if (ref === '') {
esmSource += `\nexports[''] = proxy[''];`
} else if (ref === 'default') {
esmSource += `
export { __esModule, $$typeof };
export default __default__;`
} else {
esmSource += `
const e${cnt} = proxy["${ref}"];
export { e${cnt++} as ${ref} };`
} else if (ref === '') {
esmSource += `\nexports[''] = proxy[''];`
}
}
......
......@@ -183,6 +183,11 @@ createNextDescribe(
expect(html).toContain('hello')
})
it('should support exporting multiple star re-exports', async () => {
const html = await next.render('/wildcard')
expect(html).toContain('Foo')
})
if ((global as any).isNextDev) {
it('should error for wildcard exports of client module references in esm', async () => {
const page = 'app/esm-client-ref/page.js'
......
import { Foo } from 'client-esm-module-wildcard-2'
export default function Page() {
return <Foo />
}
{
"name": "client-esm-module-wildcard-2",
"type": "module",
"exports": {
"default": "./index.js"
}
}
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