Commit a5def42a authored by Jiachi Liu's avatar Jiachi Liu Committed by Janka Uryga

Remove rsc esm client module extra exports (#65519)

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 }`

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 f7d4dbd1
......@@ -99,14 +99,6 @@ export default function transformSource(
let esmSource = `\
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
for (const ref of clientRefs) {
......@@ -114,7 +106,6 @@ const __default__ = proxy.default;
esmSource += `\nexports[''] = createProxy(String.raw\`${resourceKey}#\`);`
} else if (ref === 'default') {
esmSource += `\
export { __esModule, $$typeof };
export default createProxy(String.raw\`${resourceKey}#default\`);
`
} else {
......
export function isClientReference(reference: any): boolean {
return reference?.$$typeof === Symbol.for('react.client.reference')
export function isClientReference(mod: any): boolean {
const defaultExport = mod?.default || mod
return defaultExport?.$$typeof === Symbol.for('react.client.reference')
}
......@@ -54,9 +54,9 @@ describe('Error overlay for hydration errors', () => {
if (isTurbopack) {
expect(pseudoHtml).toMatchInlineSnapshot(`
"...
<RedirectBoundary>
<RedirectErrorBoundary>
<InnerLayoutRouter>
<RedirectErrorBoundary>
<InnerLayoutRouter>
<ClientPageRoot>
<Mismatch>
<div>
<main>
......@@ -251,16 +251,16 @@ describe('Error overlay for hydration errors', () => {
if (isTurbopack) {
expect(pseudoHtml).toMatchInlineSnapshot(`
"...
<NotFoundErrorBoundary>
<RedirectBoundary>
<RedirectErrorBoundary>
<InnerLayoutRouter>
<Mismatch>
<div>
<div>
"only""
`)
"...
<RedirectBoundary>
<RedirectErrorBoundary>
<InnerLayoutRouter>
<ClientPageRoot>
<Mismatch>
<div>
<div>
"only""
`)
} else {
expect(pseudoHtml).toMatchInlineSnapshot(`
"<Mismatch>
......@@ -643,44 +643,45 @@ describe('Error overlay for hydration errors', () => {
const fullPseudoHtml = await session.getRedboxComponentStack()
if (isTurbopack) {
expect(fullPseudoHtml).toMatchInlineSnapshot(`
"<Root>
<ServerRoot>
<AppRouter>
<ErrorBoundary>
<ErrorBoundaryHandler>
<Router>
<HotReload>
<ReactDevOverlay>
<DevRootNotFoundBoundary>
<NotFoundBoundary>
<NotFoundErrorBoundary>
<RedirectBoundary>
<RedirectErrorBoundary>
<RootLayout>
<html>
<body>
<OuterLayoutRouter>
<RenderFromTemplateContext>
<ScrollAndFocusHandler>
<InnerScrollAndFocusHandler>
<ErrorBoundary>
<LoadingBoundary>
<NotFoundBoundary>
<NotFoundErrorBoundary>
<RedirectBoundary>
<RedirectErrorBoundary>
<InnerLayoutRouter>
<Page>
"<Root>
<ServerRoot>
<AppRouter>
<ErrorBoundary>
<ErrorBoundaryHandler>
<Router>
<HotReload>
<ReactDevOverlay>
<DevRootNotFoundBoundary>
<NotFoundBoundary>
<NotFoundErrorBoundary>
<RedirectBoundary>
<RedirectErrorBoundary>
<RootLayout>
<html>
<body>
<OuterLayoutRouter>
<RenderFromTemplateContext>
<ScrollAndFocusHandler>
<InnerScrollAndFocusHandler>
<ErrorBoundary>
<LoadingBoundary>
<NotFoundBoundary>
<NotFoundErrorBoundary>
<RedirectBoundary>
<RedirectErrorBoundary>
<InnerLayoutRouter>
<ClientPageRoot>
<Page>
<div>
<div>
<div>
<div>
<div>
<div>
<Mismatch>
<p>
<span>
"server"
"client""
`)
<Mismatch>
<p>
<span>
"server"
"client""
`)
} else {
expect(fullPseudoHtml).toMatchInlineSnapshot(`
"<Page>
......
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