mui / mui/base-ui

[RSC] Base UI `render` prop validation fails specifically for styled-components with active styles

Open
#4,155 2 comments 0 reactions 0 assignees View on GitHub
hook: useRender type: bug
Dominant language
TypeScript
Stars
10.9k
Forks
543
Avg merge
1d 20h
Merged PRs (30d)
101

Description

# Bug report

## Current behavior

When a styled component is passed to the `render` prop (like, `}>`), in RSC, Base UI throws an error:
```
Base UI: The `render` prop was provided an invalid React element as `React.isValidElement(render)` is `false`.
A valid React element must be provided to the `render` prop because it is cloned with props to replace the default element.
https://base-ui.com/r/invalid-render-prop
```

However, when I test the component myself, `console.log(React.isValidElement() && "valid react element");`, the element is valid.

The error disappears in 2 cases:
1. there are no styles written in the template literal.
2. the whole component is a client component (use of `'use client'`) directive.

## Expected behavior

There should be no error when the styled component is passed to `render` prop in a RSC, with or without styles.

## Reproducible example

[View on CodeSandbox](https://codesandbox.io/p/devbox/rztjx3)

## Base UI version

v1.0.2

## Which browser are you using?

Firefox

## Which OS are you using?

Windows

## Which assistive tech are you using (if applicable)?

Not applicable

## Additional context

1. [`styled-components` supports RSC natively](https://styled-components.com/docs/advanced#react-server-components)
2. However, for client components, the `StyledComponentsRegistry` still should be used to prevent FOUC. [Next.js docs on `StyledComponentsRegistry`](https://nextjs.org/docs/app/guides/css-in-js#styled-components). I am using this as well.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.