-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
gatsby-plugin-styled-components: Styles not updating #28849
Comments
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
So after further digging it turns out this is another result of hydration mismatches: #17914. This article has helped in resolving the issue: https://www.joshwcomeau.com/react/the-perils-of-rehydration/ The solution is to check if we are in browser before applying the query param (2-pass rendering): ...
const [client, setClient] = useState(false)
useEffect(() => {
setClient(true)
}, [])
return (
<Button type="button" isDisabled={client && !!params.disable}>
click me
</Button>
) This way the class names at compile time and during hydration in browser match. It would be really helpful if Gatsby reported hydration mismatches during builds. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Description
I am not sure if this is an actual bug with styled-components' SSR or just my misunderstanding of how rehydration works. Conditionally applying styles to a button, based on the presence of a query param does not work in production (styles are not applied). It works in development.
Steps to reproduce
Pull down the repository at https://github.com/tmatek/gatsby-styled-components-bug.git. Run
npm i && npm run build && npm run serve
. Go to http://localhost:9000/test/?disable=1. Inspect the button element for CSS rules.Expected result
The button should have
opacity: 0.5; cursor: not-allowed;
CSS rules applied.Actual result
The button does not have the CSS rules applied. The console log shows that the conditional part in the button styled component was called.
Environment
The text was updated successfully, but these errors were encountered: