question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rendering hours from datetime breaks styled components

See original GitHub issue

What 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:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
alexalexyangcommented, Jul 8, 2022

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.

0reactions
kilimancommented, Aug 5, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found