Skip to content

[React 19] Bug: cloneElement in client component with async server component as children not working #32392

@darthmaim

Description

@darthmaim

React version: 19

Steps To Reproduce

  1. Clone the reproduction
  2. npm i
  3. npm run dev
  4. 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 of ClientComponent.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions