-
Notifications
You must be signed in to change notification settings - Fork 49.7k
Description
React version: 19
Steps To Reproduce
- Clone the reproduction
npm inpm run dev- Open http://localhost:3000/ and observe error
Link to code example: https://github.com/darthmaim-reproductions/vercel-next.js-72034
The current behavior
When using cloneElement in a client component, and the children is an async server component, this error is thrown:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method ofClientComponent.
When the server component is not async (or a client component), this just works.
Additionally, adding this line to the client component also makes this work:
if(children.$$typeof === Symbol.for('react.lazy')) { children = use(children._payload); }The expected behavior
Since cloneElement works for client components and non-async server components, I expected this to work with async server components as well.
Additional context
With react 18 the children was reported as <Lazy/> in react-dev-tools and cloneElement was working, now it is shown as { $$typeof: Symbol(react.lazy) } (when not using cloneElement to avoid the error).
I initially reported this is in the Next.js repo (vercel/next.js#72034), but I keep running into this bug and suspect its a react bug and not related to Next.js.