-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Rendering hours from datetime breaks styled components #3645
Comments
Suggestion : do all the date related operation server side, eg. your loader, and return the current date from it. This way you'll avoid any local vs server side date reconciliation issues |
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. |
How are you doing this? Let say I want to show something like Good Morning, Good Afternoon based on the time of day. This should only be done using the client side time and not the server side time. I am a bit puzzled as to how this should be done only in the client |
You can use function greeting() {
const hour = new Date().getHours()
const message = hour > 6 && hour < 12 ? 'Good Morning'
: hour >= 12 && hour < 18 ? 'Good Afternoon'
: 'Good Evening'
return message
}
export default function Greeting() {
// greeting() called only on client
return <ClientOnly>{() => <p>{greeting()}</p>}</ClientOnly>
} |
oh oh this is awesome. Did not know about this. |
@msevestre, my use case requires that the time be saved in a database beforehand. So my solution uses
Two things. I've not tried @kiliman's solution. Looks good, could work for you. And, there's been new talk about how |
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. |
What version of Remix are you using?
1.6.3
Steps to Reproduce
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.
The text was updated successfully, but these errors were encountered: