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
v6: using styled(Component)
results in looks like an unknown prop is being sent through to the DOM
#4071
Comments
Same as #4049. I also created a really simple codesandbox similar to your example. We are waiting for an answer but the warning seems to not be accurate. |
same issue here, using mui v5. export const RCPasswordField = styled(({ InputProps, ...rest }) => <TextField {...rest} InputProps={InputProps} />)`` tried transient props, is-prop-valid from @emotion, withConfig and nothing solved. still having this issue. |
I faced the same issue and managed to work around it with the use of Here's what my provider looks like <StyleSheetManager
enableVendorPrefixes
shouldForwardProp={(propName, elementToBeRendered) => {
return typeof elementToBeRendered === 'string' ? isPropValid(propName) : true;
}}
{...props}
>
<ThemeProvider theme={theme}>
{...}
</ThemeProvider>
</StyleSheetManager> Works well so far; still need to check the wide usage in production |
All of them were result in recent changes in styled-components: styled-components/styled-components#4071
Hello, can you provide the complete code? For example, where does "isPropValid" come from? I have this code below: registry.tsx
layout.tsx
|
Does this have any performance implications? Is this check |
@arsinclair The Maybe memorization can help. Though I tried digging in the old version of styled components to see how it was handled, and it is at runtime |
|
This should be fixed by this PR #4084. The warning will only be displayed on standard HTML elements and not when styling a React component. |
This is fixed on my end. Thanks @woodreamz! |
Was having same issue and wanted to omit some other attributes that are been forwarded to the DOM, below code was helpful. Packages comes from standard "use client";
import React, { useState } from "react";
import { useServerInsertedHTML } from "next/navigation";
import { ServerStyleSheet, StyleSheetManager } from "styled-components";
import isPropValid from "@emotion/is-prop-valid";
export default function StyledComponentsRegistry({
children,
}: {
children: React.ReactNode;
}) {
// Only create stylesheet once with lazy initial state
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet());
useServerInsertedHTML(() => {
const styles = styledComponentsStyleSheet.getStyleElement();
styledComponentsStyleSheet.instance.clearTag();
return <>{styles}</>;
});
if (typeof window !== "undefined") return <>{children}</>;
return (
<StyleSheetManager
sheet={styledComponentsStyleSheet.instance}
shouldForwardProp={(propName, elementToBeRendered) => {
return typeof elementToBeRendered === "string"
? isPropValid(propName) && !["height", "width"].includes(propName)
: true;
}}
>
{children}
</StyleSheetManager>
);
} |
I have noticed that some of my custom components that I attempt to style later with
styled(MyComponent)
are resulting inlooks like an unknown prop is being sent through to the DOM
messages. As far as I understand from reading the migration guide, that feature is still supported, but wanted to still know if this is a bug or I'm missing something. It seems to be different than #4058.Take this simple demonstration component for example, I know that passing this message prop will result in it appearing in the DOM:
And that is exactly what I see:
But the behavior of wrapping an existing component in a
styled()
statement doesn't cause the props to display in the DOM:But now I get the following:
I saw the shouldForwardProp changes in the migration guide and I tried it just for fun, though I know it's meant for filtering props out, and got the following:
though it did get rid of the warning
Reproduction
Here are 2 repros: v5 and v6. Both with examples in the App.tsx
v5: https://stackblitz.com/edit/vite-react-ts-keymr5?file=src%2FApp.tsx
v6: https://stackblitz.com/edit/vite-react-ts-vscvhm?file=src%2FApp.tsx
The text was updated successfully, but these errors were encountered: