-
Notifications
You must be signed in to change notification settings - Fork 673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom React components with an sx prop can’t live alongside HTML elements using the @jsxImportSource theme-ui pragma #2454
Comments
Thank you for the issue! What framework are you using? And what version of Theme UI do you have? What I mean by it, this is weird and not intended. Both the tests here and all my apps using Theme UI would entirely break if this happened to me, so let's try to figure out why it happens, what kind of setup do you have. |
Hi, and thanks for the prompt reply! We’re using theme-ui 0.15.5, and the bug is exhibited both in a couple of applications that consume these components; one is a Gatsby application, and the other is a craco app. The components we build using Theme UI are part of a design system monorepo which are published as private npm packages (containing CJS/ESM), then consumed by various internal applications (mostly some variety of create react app), as well as the two main apps I mentioned above (one is used as our internal documentation site, the other is essentially for visual regression testing). To try and streamline the experience for internal developers, we publish our own theme package which wraps most of the theme-ui dependencies, along with providing our theme defaults. Does that answer your questions, or are there any other specifics that would be helpful? |
If this is closed source, I'd like to see the Gatsby config and Babel and TypeScript configs. It seems that the issue is somewhere around JSX runtime configuration, so the config files might lead us towards the cause. |
I have the same problem with NextJs 14. In fact I have to change the name to
export default function Comp({ children, ssx }: Props) {
return <div sx={ssx}>{children}</div>
} I'm using the tsconfig in order to avoid putting the pragma at every .tsx file The reason is probably here. It just check if // theme-ui/packages/core/src/parseProps.tsx
export function parseProps(props: any) {
if (!props || (!props.sx && !props.css)) return props
const next: Record<string, unknown> = {}
for (let key in props) {
if (key === 'sx') continue
next[key] = props[key]
}
next.css = getCSS(props)
return next
} |
If a custom React component has an API with a prop called
sx
, that prop is ignored if the component is called alongside any other HTML element with ansx
prop augmented using the/** @jsxImportSource theme-ui */
pragma.To Reproduce
Let’s say I have some arbitrary JSX on a page, where I’m styling arbitrary HTML elements using the
sx
prop, and the/** @jsxImportSource theme-ui */
pragma:Let’s also say that I have a custom React component which accepts an
sx
prop as part of its own API, because I want to be able to pass those styles through to some part of the component’s internal implementation:If I then try to use these two components together, like this:
…I would expect this to set the inner text to have a color property of
red
, but instead the value passed to this innersx
prop acts as if it’sundefined
:Expected behavior
I would expect the style object passed to the
sx
prop of the custom component to correctly be passed through to the child.Additional context
The problem only seems to be manifest when mixing these two types of usage of the
sx
prop, however; if in the scope of a single source file you are exclusively passing thesx
prop to custom components, or exclusively passing it to plain HTML objects, they will work (and so as a workaround we will often split up the code, but this is sometimes not convenient).The text was updated successfully, but these errors were encountered: