Render dates in the user's time zone on the server too - #2
Merged
Merged
Conversation
Since pages arrive with their data, the server renders dates and "today", and it runs in UTC. For anyone elsewhere the HTML disagreed with the browser ("2 Oct" against "3 Oct", no due count), and React threw the server's HTML away.
The notebook layout now works out the user's zone (the lk-tz cookie, UTC without one) and the time once, and hands both to the browser through a clock (app/components/clock.tsx). Every component that renders a date or works out today reads that clock, through date-fns's in option with @date-fns/tz, so server and browser agree; the prefetch keys today the same way. If the browser is in a different zone than the cookie said, it saves its own and renders again. Relative times ("4 minutes ago") use the server's now until hydration for the same reason.
Shared pages get the same clock. Sorting lists give dnd-kit a stable id, since its global counter differs between server and browser.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1. Pages now arrive with their data, so the server renders dates, and on Vercel it runs in UTC. For anyone outside UTC the HTML disagreed with the browser: "2 Oct" against "3 Oct", and no "due today" count. React then threw the server HTML away (minified error #418 in production).
lk-tzcookie, UTC without one) and the current time, and passes both toClockProvider(app/components/clock.tsx). Components that render dates or work out "today" use it through date-fns'sinoption with@date-fns/tz, so the server and the browser agree. The prefetch keys "today" the same way.ago()takes the clock'snow, which matches the server's render until hydration.SortableListgives dnd-kit a stableid.Checked against a production build on a server with
TZ=UTC: