Rendering hours from datetime breaks styled components
See original GitHub issueWhat version of Remix are you using?
1.6.3
Steps to Reproduce
- Install styled components
- Build something highly visible in styled components just so it’s easier to see it break
- Render hours, eg:
const now = new Date(); const hr = now.getHours(); ... return (<p>{hr}</p>)
- Deploy to something like Vercel or set local dev environment to UTC time before starting up your Remix app
Expected Behavior
Styled components doesn’t break.
Actual Behavior
Styled components breaks with error: “Remix Hydration failed: UI on server and client do not match”.
@noahstegmaier and I suspect that styled components breaks because hours is rendered in UTC time on the server but locale time on the client.
To be honest, we’re not sure if this is a bug or if we’re supposed to handle this ourselves. So, also not sure if this should be asked on Remix or Styled components GitHub issues.
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top Results From Across the Web
Remix Hydration failed: UI on server and client do not match
Our suspicion is styled components breaks because hours is rendered in UTC time on the server but locale time on the client. I'm...
Read more >react-styled-date-time-picker - npm
Start using react-styled-date-time-picker in your project by ... import React, { Component } from 'react'; import DateTimePicker from ...
Read more >FAQs - styled-components
styled -components v5 does not introduce any breaking public API changes, ... styled component <Button /> would render with the same static class...
Read more >React custom datepicker: Step-by-step - LogRocket Blog
The styled-components rendered in the datepicker are styled extensions of the dropdown components from Reactstrap. Update the datepicker ...
Read more >Rendering React App in Shadow DOM with Style ...
At that time the browser support was quirky and very narrow. ... Render in Shadow DOM with SSR and Styled Components. swashata.
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
After enough headspace and hindsight, I believe this issue is not a bug and should be handled ourselves.
One way is as @machour describes it (thanks!). Another way, which fits my use case, is to render the date after everything has mounted.
Since the server won’t render anything, it may cause shift depending on what’s around it… but you won’t see text change. If you need to, you can always set a fallback that reserves some space.