Conditional className is not properly updated in production
See original GitHub issueThanks for all your work, react-static is awesome!
Describe the bug While trying to store some state in localStorage, I’ve identified an issue with a conditional className for a component. While the state of the component is correct, it doesn’t seem to update the className property as expected.
To Reproduce Steps to reproduce the behavior:
- Clone https://github.com/JohnBerlin/hydrate-does-not-work-on-classname
- Run
npm i
- Run
npm run stage
- Run
npm run serve
- Go to http://localhost:3000
- Click on one of the toggles
- Reload the page
- The text of the toggle is correct (“isOn” or “isOFF”) but the style applied doesn’t match the “.isON” CSS class
Expected behavior The className property should be correctly updated once the page is loaded.
Screenshots
Desktop (please complete the following information):
- OS: KUbuntu 18.04
- Browser: Firefox & Chrome
- Version: Latest
Thanks for all your work, react-static is awesome!
Am I doing anything wrong with this?
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Conditional className is not properly updated in production
The className property should be correctly updated once the page is loaded. Screenshots screensghot. Desktop (please complete the following ...
Read more >React: Conditional className is not updated in DOM
When I refresh the page (not changing the location), it renders properly, and class name is removed from dom. So how can I...
Read more >Why I Don't Like Tailwind CSS | Aleksandr Hovhannisyan
This may not seem like an issue to those who are used to working with Tailwind, but it becomes one when you have...
Read more >Just-in-Time Mode - Tailwind CSS
This means you can no longer expect transforms and filters to be dormant by default, and conditionally activated by adding transform , filter...
Read more >Conditional Rendering in React using Ternaries and Logical ...
The first bang operator will coerce the value of stars into a boolean and then perform a NOT operation. If stars is 0...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi Ben,
Tanner is no longer around; you may write this up, but in reality, code like Kevin posted is problematic to begin with. If you really can’t use media queries, you should run that code in a
useEffect
, and hook on a “document on size change” handler. That will resolve the issue to begin with – regardless of hydration, SSR, or what’s not.As for your hook: it doesn’t work “only” on hydrate. It will always double re-render on mount, (where hydration can be the first mount). It’s probably not the most optimal solution if you were to go that route.
Using a class based component +
componentDidMount
as a workaround isn’t working for me on the latest version (7.0.10)Here are two simple example components that don’t work correctly. One is a functional component and one is a class based component. The content renders correctly but not the
className
.and