Unverified Commit af9ac76a authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Remove rsc esm client module extra exports (#65519)

### What

Remove the extra `__esModule` and `$$typeof` export for ESM client
module

For a client page reference, it changed on server side in renderer:

Previous: `{ __esModule, $$typeof, default }`
Now: `{ default }`

### Why

The Module object itself appears as a client reference but it can't be
rendered since it's not a real reference. I'm not sure why it was added
but I think the right thing for an ESM module is to not treat the module
itself as a client reference but only the objects inside of it. E.g. the
"default" export. That's what React does upstream for ESM modules.

Closes NEXT-3360
parent bd110c61
...@@ -99,14 +99,6 @@ export default function transformSource( ...@@ -99,14 +99,6 @@ export default function transformSource(
let esmSource = `\ let esmSource = `\
import { createProxy } from "${MODULE_PROXY_PATH}" import { createProxy } from "${MODULE_PROXY_PATH}"
const proxy = createProxy(String.raw\`${resourceKey}\`)
// Accessing the __esModule property and exporting $$typeof are required here.
// 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.
const { __esModule, $$typeof } = proxy;
const __default__ = proxy.default;
` `
let cnt = 0 let cnt = 0
for (const ref of clientRefs) { for (const ref of clientRefs) {
...@@ -114,7 +106,6 @@ const __default__ = proxy.default; ...@@ -114,7 +106,6 @@ const __default__ = proxy.default;
esmSource += `\nexports[''] = createProxy(String.raw\`${resourceKey}#\`);` esmSource += `\nexports[''] = createProxy(String.raw\`${resourceKey}#\`);`
} else if (ref === 'default') { } else if (ref === 'default') {
esmSource += `\ esmSource += `\
export { __esModule, $$typeof };
export default createProxy(String.raw\`${resourceKey}#default\`); export default createProxy(String.raw\`${resourceKey}#default\`);
` `
} else { } else {
......
export function isClientReference(reference: any): boolean { export function isClientReference(mod: any): boolean {
return reference?.$$typeof === Symbol.for('react.client.reference') const defaultExport = mod?.default || mod
return defaultExport?.$$typeof === Symbol.for('react.client.reference')
} }
...@@ -604,11 +604,11 @@ describe('Error overlay for hydration errors', () => { ...@@ -604,11 +604,11 @@ describe('Error overlay for hydration errors', () => {
if (isTurbopack) { if (isTurbopack) {
expect(fullPseudoHtml).toMatchInlineSnapshot(` expect(fullPseudoHtml).toMatchInlineSnapshot(`
"... "...
<NotFoundBoundary notFound={[...]} notFoundStyles={[...]}> <NotFoundErrorBoundary pathname="/" notFound={[...]} notFoundStyles={[...]} asNotFound={undefined} missingSlots={Set}>
<NotFoundErrorBoundary pathname="/" notFound={[...]} notFoundStyles={[...]} asNotFound={undefined} ...> <RedirectBoundary>
<RedirectBoundary> <RedirectErrorBoundary router={{...}}>
<RedirectErrorBoundary router={{...}}> <InnerLayoutRouter parallelRouterKey="children" url="/" tree={[...]} childNodes={Map} segmentPath={[...]} ...>
<InnerLayoutRouter parallelRouterKey="children" url="/" tree={[...]} childNodes={Map} segmentPath={[...]} ...> <ClientPageRoot props={{params:{}, ...}} Component={function Page}>
<Page params={{}} searchParams={{}}> <Page params={{}} searchParams={{}}>
<div> <div>
<div> <div>
......
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