-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Prop className
did not match.
#212
Comments
Hello @nphmuller, Thank you for the detailed issue and the reproduction repository. It helped me discover a bug that wasn't directly tied to your issue. Regarding your specific problem, the documentation was not clear enough about it, but in SSR setups, you must provide a unique ID to your useStyles using nested selectors: -const useStyles = makeStyles<void, "icon">()(
+const useStyles = makeStyles<void, "icon">({ uniqId: "xDsMbr" })(
(_theme, _props, classes) => ({
link: {
// Removing this fixes the issue
[`& .${classes.icon}`]: {
color: "blue",
},
},
icon: {},
})
); https://docs.tss-react.dev/nested-selectors#ssr This solution is quite clunky; I also encourage you to try out the modern API instead of using makeStyles. It's much better in every way. import { tss } from "tss-react/mui";
const useStyles = tss
.withName("ComponentWithIssue")
.withNestedSelectors<"icon">()
.create(({ theme, classes })=> ({
link: {
[`& .${classes.icon}`]: {
color: "blue",
},
},
icon: {},
})); Giving a name is required in SSR setups when you use nested selectors. Anyway, giving a name to the useStyles is good practice since it makes finding the source code of the style from the browser debug tool much easier. Don't forget to update to the latest version; I published a patch. Best, |
Thank you so much for the lightning fast response. I should have suspected it was a usage error. It usually is 😁. I'll make the necessary changes and I'll close this issue now. Thanks again! |
No, no! You did good opening this issue, as I said revisiting the code made me found another bug! |
Hello, @garronej I think this issue is still relevant in version 4.9.10. Every time nested selectors are used, both classes (nested selected & the class that uses it) lose their id during hydration. Here are a couple of code samples that cause the error in NextJs with app directory
|
Hello @ArtemAstakhov, Sorry I can't reproduce. Screen.Recording.2024-05-09.at.02.24.45.movCan you please try do fork and modify the repo to make the issue your experiencing appear: https://github.com/garronej/tss-issue-212 If I can reproduce I will adress it switfly. |
@garronej I apologize, I've added .withName to all styles in the project that use .withNestedSelectors and the errors no longer appear |
@ArtemAstakhov Great! Thank you for the update! |
When migrating a create-react-app project to Next I stumbled upon the following error during hydration. Maybe I'm doing something wrong, but I think it might be a bug in tss-react. After a lot of tinkering I managed to make the following minimal repro. It's a little bit contrived, to make it as small as possible.
You can reproduce it the following way:
Now when opening the page in the browser the following error gets logged:
Some details on how I got the error
The
[`& .${classes.icon}`]:
clause seems to cause the different classname to be generated server-side vs client-side.Additional details
Mui was setup the following way (via layout.tsx):
The text was updated successfully, but these errors were encountered: