Skip to content
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

TimeAgo + SSR somewhat problematic #288

Open
adamschwartz opened this issue Oct 13, 2020 · 2 comments
Open

TimeAgo + SSR somewhat problematic #288

adamschwartz opened this issue Oct 13, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@adamschwartz
Copy link
Contributor

Our use of <TimeAgo/> is slightly wonky with SSR:

<TimeAgo date={tutorial.updated} formatter={(value, unit) => (
<React.Fragment>
{value} {unit}{value > 1 ? "s" : ""}<span className="DocsTutorials--ago-text"> ago</span>
</React.Fragment>
)} minPeriod={60}/>

It can flash "N hours ago" and then switch to "3 days ago" on page load for example. This is because the SSR time will be locked in at the last time it was built, but upon hydration it will be from now.

We could potentially use HTMLRewriter to set on the fly.

@kristianfreeman
Copy link
Contributor

@adamschwartz and i synced up on this in chat, we're leaning towards:

  1. hiding this element via a CSS data attribute
  2. refreshing the text content via an initial render
  3. removing the data attribute once the initial render has completed

in the situation where the user isn't running javascript, we can use noscript to just show the SSR time:

<style>[data-hide-ssr] { display: none }</style>
<noscript><style>[data-hide-ssr] { display: unset }</style></noscript>

@adamschwartz
Copy link
Contributor Author

adamschwartz commented Oct 13, 2020

Also re noscript, maybe the SSR time should then just be more like 10/13/2020 (as opposed to 2 months ago)?

@adamschwartz adamschwartz added the bug Something isn't working label Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants