diff --git a/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts b/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts index 6a1e7c44b3f1e..de1dd5095d032 100644 --- a/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts +++ b/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts @@ -97,14 +97,14 @@ const __default__ = proxy.default; let cnt = 0 for (const ref of clientRefs) { if (ref === '') { - esmSource += `\nexports[''] = proxy[''];` + esmSource += `\nexports[''] = createProxy(String.raw\`${this.resourcePath}#\`);` } else if (ref === 'default') { esmSource += ` export { __esModule, $$typeof }; export default __default__;` } else { esmSource += ` -const e${cnt} = proxy["${ref}"]; +const e${cnt} = createProxy(String.raw\`${this.resourcePath}#${ref}\`); export { e${cnt++} as ${ref} };` } } diff --git a/test/e2e/app-dir/mdx/app/client.tsx b/test/e2e/app-dir/mdx/app/client.tsx new file mode 100644 index 0000000000000..e0708c7350ac1 --- /dev/null +++ b/test/e2e/app-dir/mdx/app/client.tsx @@ -0,0 +1,5 @@ +'use client' + +export function Client() { + return

This is a client component

+} diff --git a/test/e2e/app-dir/mdx/app/page.mdx b/test/e2e/app-dir/mdx/app/page.mdx index 5371f3deebc75..dd2cf23f48ca2 100644 --- a/test/e2e/app-dir/mdx/app/page.mdx +++ b/test/e2e/app-dir/mdx/app/page.mdx @@ -1,3 +1,7 @@ # Hello World This is MDX! + +import { Client } from './client' + + diff --git a/test/e2e/app-dir/mdx/mdx.test.ts b/test/e2e/app-dir/mdx/mdx.test.ts index 344fc425d5831..33dc0aea63ca4 100644 --- a/test/e2e/app-dir/mdx/mdx.test.ts +++ b/test/e2e/app-dir/mdx/mdx.test.ts @@ -54,6 +54,11 @@ for (const type of [ 'rgb(255, 0, 0)' ) }) + + it('should allow importing client components', async () => { + const $ = await next.render$('/') + expect($('h2').text()).toBe('This is a client component') + }) }) describe('pages directory', () => {