[recovery] fix(date): normalize whitespace in formatDate to prevent hydration mismatch - #19191
Draft
ethorg-agent-code[bot] wants to merge 1 commit into
Draft
[recovery] fix(date): normalize whitespace in formatDate to prevent hydration mismatch#19191ethorg-agent-code[bot] wants to merge 1 commit into
ethorg-agent-code[bot] wants to merge 1 commit into
Conversation
…smatch formatDateRange already normalizes whitespace to work around Node vs browser ICU differences (narrow no-break space vs regular space) that otherwise trip React's hydration check. formatDate never got the same fix, and is called directly during render by LatestArticlesGrid, a client component SSR'd on /latest, causing hydration mismatches for locales/browsers where ICU output differs.
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.

Production error
Error: Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:/:locale/latest— https://ethereumorg-ow.sentry.io/issues/7704895191/Root cause
app/[locale]/latest/_components/LatestArticlesGrid.tsxis a"use client"component that's SSR'd on the/latestpage. It callsformatDate(article.date, locale, { month: "short" })directly during render for each card's date label.formatDate(insrc/lib/utils/date.ts) formats viaIntl.DateTimeFormatbut did no whitespace normalization. Node's ICU and a browser's ICU can render the same date with different space characters around date parts (e.g. U+202F narrow no-break space vs a regular U+0020) depending on locale/platform. Those differ byte-for-byte even though they look identical, which trips React's hydration text-mismatch check when the component re-renders on the client after SSR.This exact class of bug was already fixed once in this file:
formatDateRangenormalizes whitespace with.replace(/\s+/g, " ")and has a comment explaining precisely this Node-vs-browser ICU divergence.formatDate— used by the same/latestclient component — never got the equivalent fix.Fix
Applied the same whitespace-normalization step to
formatDatethatformatDateRangealready uses, with a comment cross-referencing it, so the two stay in sync going forward. Single-file change, no behavior change to the rendered text itself (only collapses different whitespace characters to a plain space).Verification
pnpm type-check— passedpnpm exec eslint src/lib/utils/date.ts— clean (no errors/warnings)