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

Additional style on reload, css prop, styled-components #5988

Closed
dmitweb opened this issue Jan 4, 2019 · 6 comments · Fixed by #6001
Closed

Additional style on reload, css prop, styled-components #5988

dmitweb opened this issue Jan 4, 2019 · 6 comments · Fixed by #6001
Labels
examples Issue was opened via the examples template. good first issue Easy to fix issues, good for newcomers

Comments

@dmitweb
Copy link

dmitweb commented Jan 4, 2019

Bug report

Describe the bug

When i change styles in css prop and reload page i get error "Warning: Prop className did not match.". In head style section i see two same styles (old and new). Problem only on client side.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Change styles in css prop
  2. Refresh page (error in console on client)

Expected behavior

Console without error about className

Screenshots

2019-01-04_221622
On screenshot we can see 3 classes in style tag, but in code we have only 2.

System information

  • OS: Windows
  • Browser: Chrome
  • Version of Next.js: 7.0.2

Additional context

I also updated packages to latest versions.
Git repo with bug: https://github.com/dmitweb/with-styled-components-app-bug

@timneutkens timneutkens added help wanted good first issue Easy to fix issues, good for newcomers examples Issue was opened via the examples template. labels Jan 4, 2019
@ztanner
Copy link
Member

ztanner commented Jan 6, 2019

The babel plugin configuration in .babelrc is missing the { "ssr": true } setting. I've created a PR to fix this in the example. Read more here: https://www.styled-components.com/docs/tooling#serverside-rendering

timneutkens pushed a commit that referenced this issue Jan 6, 2019
Enables SSR for styled-components babel-plugin to prevent HTML attribute mismatch warnings during rehydration.
@dmitweb
Copy link
Author

dmitweb commented Jan 6, 2019

@ztanner @timneutkens issue still didn't solved. I have already tried this before submit issue. Please check again. Error still exists.
Steps to reproduce the behavior:

  1. Add css={'padding: 20px;'} to <Title>
  2. Refresh page
  3. Change padding: 20px; to padding: 10px; (hot reload)
  4. Refresh page and see error

@ztanner
Copy link
Member

ztanner commented Jan 7, 2019

Sorry, you're right - I misread the docs, as SSR is actually enabled by default. I'll keep looking at this.

@dmitweb
Copy link
Author

dmitweb commented Jan 10, 2019

Hey @timneutkens, can you please reopen issue, maybe somebody will help with error

@kusold
Copy link

kusold commented Mar 1, 2019

Having the same issue. Would this apply to NextJS?

Note
⚠️ The plugin call order in your .babelrc file matters. If you're using the env property in your babel configuration, then putting this plugin into the plugins array won't suffice. Instead it needs to be put into each env's plugins array to maintain it being executed first. See this for more information.

https://www.styled-components.com/docs/tooling#babel-plugin

@dmitweb
Copy link
Author

dmitweb commented Mar 3, 2019

@kusold it dosn't help, u can use emotion as workaround, same func without issue

@lock lock bot locked as resolved and limited conversation to collaborators Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue was opened via the examples template. good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants