Open charlie-at-deaglo opened 3 months ago
+1. It looks like the only way to avoid console spam with warnings right now is to use $transientProps
Actually it does work.
The issue you're facing is caused by the fact you're returning the children on client, as is, without any props filtering.
if (typeof window !== "undefined") return <>{children}</>;
While many docs suggest writing that, it's not doing any filtering.
You can leverage the StyleSheetManager to also filter props on the client like below:
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet());
useServerInsertedHTML(() => {
const styles = styledComponentsStyleSheet.getStyleElement();
styledComponentsStyleSheet.instance.clearTag();
return styles;
});
const shouldForwardProp = (propName: string, target: any) => {
return typeof target === "string" ? isPropValid(propName) : true;
};
if (typeof window !== "undefined") {
return (
<StyleSheetManager
enableVendorPrefixes
shouldForwardProp={shouldForwardProp}
>
{children}
</StyleSheetManager>
);
}
System:
Binaries:
npmPackages:
Reproduction
Code Sandbox
Steps to reproduce
Expected Behavior
The Next application in the linked Code Sandbox is configured to use the app directory with
StyleSheetManager
to enable SSR, as is described in the Next.js docs. In v6, prop forwarding is controlled via theshouldForwardProp
prop on theStyleSheetManager
. To prevent invalid props from being sent to the DOM, the FAQs section of the docs recommends usingisPropValid
from@emotion/is-prop-valid
to validate props, which I have setup in the Code Sandbox. Providing this callback to theStyleSheetManager
should prevent invalid props from being forwarded to the DOM. In the Code Sandbox, this would mean that thesomeProp
prop on the<Component />
component is not sent to the DOM.Actual Behavior
someProp
is forwarded to the DOM, which causes the following warnings to be printed to the console: