-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
registerClientReference
for ESM client component modules
When registering a client reference for a client component module, React offers two distinct functions: - `registerClientReference`: Register a named or default export of an ES module as a client reference. - `createClientModuleProxy`: Create a client module proxy for a CJS module that registers every module export as a client reference. Until this PR, we were using the client module proxy for both kinds of modules, which is incorrect. It was especially problematic because in the Node.js runtime we were always awaiting the client module proxy. This was a workaround for handling async modules (see #66990), but led to issues like #71840. With this PR, we are now using `registerClientReference` if we detect that a module is an ES module. This aligns the Webpack implementation with the one in Turbopack. fixes #71840
- Loading branch information
1 parent
655b808
commit 3713b3a
Showing
10 changed files
with
157 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client' | ||
|
||
export function Button() { | ||
return <button>submit</button> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ReactNode } from 'react' | ||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// x-ref: https://github.com/vercel/next.js/issues/71840 | ||
|
||
import { ElementType } from 'react' | ||
|
||
async function getImport( | ||
slug: string, | ||
exportName: string | ||
): Promise<ElementType> { | ||
const moduleExports = await import(`./${slug}`) | ||
return moduleExports[exportName] | ||
} | ||
|
||
export default async function Home() { | ||
const Button = await getImport('button', 'Button') | ||
return <Button /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('dynamic-import', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should render the dynamically imported component', async () => { | ||
const browser = await next.browser('/') | ||
expect(await browser.elementByCss('button').text()).toBe('submit') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |
Oops, something went wrong.