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

Warning: "Prop className did not match" #333

Open
jdevries3133 opened this issue Jun 9, 2021 · 1 comment
Open

Warning: "Prop className did not match" #333

jdevries3133 opened this issue Jun 9, 2021 · 1 comment

Comments

@jdevries3133
Copy link

Hello,

It seems like when a variable name is not unique, a className did not match warning is generated, and the style is not ultimately applied in the browser because of the mismatch.

Here is a minimal example of what I am experiencing:

Non-unique name "A" causes the error and not-applied styles.

import styled from "styled-components";

const A = styled.a`
  color: aquamarine;
  text-decoration: wavy underline lime;
`;

/* causes warning, style is not applied on frontend */
export const MyLink = () => <A>Hello, world!</A>;

If I change the variable name like this, the issue goes away and everything behaves as expected.

import styled from "styled-components";

const UniquelyNamedA = styled.a`
  color: aquamarine;
  text-decoration: wavy underline lime;
`;

/* causes warning, style is not applied on frontend */
export const MyLink = () => <UniquelyNamedA>Hello, world!</UniquelyNamedA>;

For additional information, this is the error in the console:
Screen Shot 2021-06-09 at 10 20 16 AM

Thanks in advance and let me know if I can provide any additional information!

@quantizor
Copy link
Collaborator

This error happens 99% of the time because either ssr is not enabled in the babel plugin options and/or there is some other confounding factor like an if statement or ternary in the styling that switches props based on client vs server.

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