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( ...@@ -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')
} }
...@@ -54,9 +54,9 @@ describe('Error overlay for hydration errors', () => { ...@@ -54,9 +54,9 @@ describe('Error overlay for hydration errors', () => {
if (isTurbopack) { if (isTurbopack) {
expect(pseudoHtml).toMatchInlineSnapshot(` expect(pseudoHtml).toMatchInlineSnapshot(`
"... "...
<RedirectBoundary> <RedirectErrorBoundary>
<RedirectErrorBoundary> <InnerLayoutRouter>
<InnerLayoutRouter> <ClientPageRoot>
<Mismatch> <Mismatch>
<div> <div>
<main> <main>
...@@ -251,16 +251,16 @@ describe('Error overlay for hydration errors', () => { ...@@ -251,16 +251,16 @@ describe('Error overlay for hydration errors', () => {
if (isTurbopack) { if (isTurbopack) {
expect(pseudoHtml).toMatchInlineSnapshot(` expect(pseudoHtml).toMatchInlineSnapshot(`
"... "...
<NotFoundErrorBoundary> <RedirectBoundary>
<RedirectBoundary> <RedirectErrorBoundary>
<RedirectErrorBoundary> <InnerLayoutRouter>
<InnerLayoutRouter> <ClientPageRoot>
<Mismatch> <Mismatch>
<div> <div>
<div> <div>
"only"" "only""
`) `)
} else { } else {
expect(pseudoHtml).toMatchInlineSnapshot(` expect(pseudoHtml).toMatchInlineSnapshot(`
"<Mismatch> "<Mismatch>
...@@ -643,44 +643,45 @@ describe('Error overlay for hydration errors', () => { ...@@ -643,44 +643,45 @@ describe('Error overlay for hydration errors', () => {
const fullPseudoHtml = await session.getRedboxComponentStack() const fullPseudoHtml = await session.getRedboxComponentStack()
if (isTurbopack) { if (isTurbopack) {
expect(fullPseudoHtml).toMatchInlineSnapshot(` expect(fullPseudoHtml).toMatchInlineSnapshot(`
"<Root> "<Root>
<ServerRoot> <ServerRoot>
<AppRouter> <AppRouter>
<ErrorBoundary> <ErrorBoundary>
<ErrorBoundaryHandler> <ErrorBoundaryHandler>
<Router> <Router>
<HotReload> <HotReload>
<ReactDevOverlay> <ReactDevOverlay>
<DevRootNotFoundBoundary> <DevRootNotFoundBoundary>
<NotFoundBoundary> <NotFoundBoundary>
<NotFoundErrorBoundary> <NotFoundErrorBoundary>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary> <RedirectErrorBoundary>
<RootLayout> <RootLayout>
<html> <html>
<body> <body>
<OuterLayoutRouter> <OuterLayoutRouter>
<RenderFromTemplateContext> <RenderFromTemplateContext>
<ScrollAndFocusHandler> <ScrollAndFocusHandler>
<InnerScrollAndFocusHandler> <InnerScrollAndFocusHandler>
<ErrorBoundary> <ErrorBoundary>
<LoadingBoundary> <LoadingBoundary>
<NotFoundBoundary> <NotFoundBoundary>
<NotFoundErrorBoundary> <NotFoundErrorBoundary>
<RedirectBoundary> <RedirectBoundary>
<RedirectErrorBoundary> <RedirectErrorBoundary>
<InnerLayoutRouter> <InnerLayoutRouter>
<Page> <ClientPageRoot>
<Page>
<div>
<div>
<div> <div>
<div> <div>
<div> <Mismatch>
<div> <p>
<Mismatch> <span>
<p> "server"
<span> "client""
"server" `)
"client""
`)
} else { } else {
expect(fullPseudoHtml).toMatchInlineSnapshot(` expect(fullPseudoHtml).toMatchInlineSnapshot(`
"<Page> "<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