Skip to content
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

Mismatch of styles when using dynamic styles #135

Open
Kyderman opened this issue Dec 16, 2022 · 3 comments
Open

Mismatch of styles when using dynamic styles #135

Kyderman opened this issue Dec 16, 2022 · 3 comments

Comments

@Kyderman
Copy link

Kyderman commented Dec 16, 2022

Hey,

I am currently converting on app over to use Next.js / TSS, we have a bunch of styling that is done dynamically using classNames

Now I have something like so.

<Avatar
  className={classNames(classes.titleAvatar, {
    [classes.titleAvatarEmpty]: isLoadedEmpty,
  })}
>
  <EventIcon></EventIcon>
</Avatar>

On the server, one style is used, on the client another is used therefore I get the hydration error.

My question here is do I just need to have the component not render in SSR or can I have this mismatch handled better?
Thanks

@garronej
Copy link
Owner

garronej commented Dec 16, 2022

Hey @Kyderman,

You can't the classNames utility anymore. You have to use cx that is returned by useStyles(): const {classes, cx} = useStyles().
The good news is that TSS is able to give higher priority to the last classes in the list which is an increadibly powerfull feature.

Also have setup MUI for SSR or used the tooling provided by TSS? https://docs.tss-react.dev/ssr/next.js#single-emotion-cache

@Kyderman
Copy link
Author

Hey, ive setup for use with SSR / MUI.

Ive just changed to cx and the problem persists where the dynamic class is applied on server vs not on client, probably because theres a graphql call made which changes that logic, so I think ill just have to render client side in these cases, thanks

@garronej
Copy link
Owner

Thanks for the update.
Are you using Next 13 beta feature like appdir or server component? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants