react icon indicating copy to clipboard operation
react copied to clipboard

Bug: `renderToStaticMarkup` throws error on client components

Open jonathanhefner opened this issue 9 months ago • 5 comments

React version: 19.0.0

Steps To Reproduce

  1. Create a client component with the 'use client' directive.
  2. Create a server (universal) component that uses the client component.
  3. Call renderToStaticMarkup with the server component.

Link to code example: https://codesandbox.io/p/devbox/keen-williamson-wg9p8w (using Next.js to demonstrate 'use client')

The current behavior

renderToStaticMarkup throws an Error when it encounters a client component:

Error: Attempted to call MyClientComponent() from the server but MyClientComponent is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.

The expected behavior

When renderToStaticMarkup encounters a client component, it renders non-interactive HTML for the component, just as pre-rendering would during SSR.

jonathanhefner avatar Mar 23 '25 20:03 jonathanhefner

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Jun 21 '25 21:06 github-actions[bot]

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open.

Bump.

jonathanhefner avatar Jun 22 '25 19:06 jonathanhefner

Same problem here. Bump.

gustavotoyota avatar Aug 29 '25 18:08 gustavotoyota

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Dec 01 '25 17:12 github-actions[bot]

Bump.

jonathanhefner avatar Dec 05 '25 02:12 jonathanhefner