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

Blog post preview list gets inconsistent after hydration #284

Open
dcsaszar opened this issue Feb 7, 2020 · 2 comments
Open

Blog post preview list gets inconsistent after hydration #284

dcsaszar opened this issue Feb 7, 2020 · 2 comments

Comments

@dcsaszar
Copy link
Contributor

dcsaszar commented Feb 7, 2020

Leaving this here for reference and to discuss a fix:

Because of timezone differences on the prerendering server and the client, the list of blog posts, with month separators, can become inconsistent after hydration.
In our case, we had a month separator that moved to another position, because the post was on the last of a month and on the first of the following month in the server-side vs. client-side render.

After hydration this left us with "dead" DOM elements, that were not removed by React, even with a rerender by calling setState.
Quoting from facebook/react#10591:

A rare but plausible scenario is that you have a list or something that depends on time to determine the order. E.g. something that conditionally pushes something on the top of a list if some time has elapsed. Or changes the the class name based on time elapsing. These cases are very theoretical though. I haven't seen one yet.

This is the "plausible scenario" in the wild. 🎉

My suggestion for a fix is twofold:

  1. Force a rerender on the client like I did in Fix prerendering time difference in blog post list #282 (which wasn't good enough for a fix)
  2. Include this.state.hasMounted in the key attributes of the timeline

This fixed the issue in our case, although I'm not sure if the keying according to SSR/CSR is just working by chance. I suspect this fix works because in the current (broken) version we have the same keys pointing to different DOM locations, which triggers the React SSR patching problem.

@apepper
Copy link
Contributor

apepper commented Feb 7, 2020

How about, that we always use UTC dates. when showing "rough" dates such as day of the month? If we do so the prerender and the client rendering should no longer diverge.

@dcsaszar
Copy link
Contributor Author

dcsaszar commented Feb 7, 2020

How about, that we always use UTC dates

This may lead to editor confusion. The editor chooses a date for the blog post. After that, the blog post is listed with a different date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants