How a Sale Countdown Formatted in UTC Made React Throw Away Our Server HTML and Pushed Mobile LCP From 1.9s to 4.6s
09:12 IST, Tuesday. Datadog Synthetics: product-page LCP p75 > 4000ms (mobile). It has
been red for eleven minutes. Last night the same monitor sat at 1.9s.
the scramble
Four of us end up in the channel. Growth is already asking, because the Tuesday email went out at 09:00 and the landing traffic is hitting pages that now take over four seconds to show the product photo. Add-to-cart rate on mobile is down from 6.1% to 4.3% on the hourly chart.
First theory, unanimous: last night's deploy. It shipped a "flash sale" banner at 22:40 and nothing else of note. Somebody says the banner must have pulled in a heavy dependency. That is testable in two minutes, so I test it.
the hunt
Dead end one: bundle size. I diff the build output of the previous release against the current one. First-load JS for the product route went from 212 kB to 214 kB. The banner is a small client component and added two kilobytes. Nothing there explains 2.7 seconds.
Dead end two: the CDN. If HTML were being served stale or uncached, time to first byte would move. I pull TTFB from the same synthetic runs. It is 180 ms before the deploy and 190 ms after. The server is fast. The slowness happens after the HTML arrives.
Dead end three: the image itself. LCP on these pages is the hero product photo. I check whether
someone changed the image loader or dropped priority. Nobody did. The element is still
the LCP candidate, it is still preloaded, and the bytes land at around 1.1s on the throttled run.
But the LCP timestamp in the trace is 4.6s. The image downloaded early and was painted late.
That gap bothers me. An image that was already downloaded but painted late means the browser had
the bytes and something replaced the DOM node. I open the trace in Chrome DevTools and look at what happens around
3.8 seconds on the main thread. There is one long task, 640 ms, and inside it a call stack that
starts at hydrateRoot and ends in recoverFromConcurrentError. I have seen
that function name before and it never means anything good.
I load the page in a normal browser with the console open. There it is, in red:
Two different strings for the same sale end time. The server printed 11:00 PM and my browser printed
4:30 AM. My browser is in India. The server is in a container with TZ unset, which
means UTC. The difference is exactly 5 hours 30 minutes.
the find
Here is the banner, simplified:
'use client' does not mean client only. Next.js still renders this component to HTML on
the server first. toLocaleString without a timeZone option uses the
runtime's default zone. On the server that is UTC. In the browser it is whatever the visitor's device
says. So the server HTML and the first client render disagree, for every visitor not in UTC.
A text mismatch in React 18 was a console warning and a patched-up text node. In React 19 it is treated as a recoverable error. When hydration fails inside a boundary, React discards the server HTML for that boundary and renders it again from scratch on the client. The banner sits in the product layout, above the hero, and the layout is one Suspense boundary wide. So the whole product header, including the hero image element, was thrown away and rebuilt on the client.
That explains the trace. The browser parsed the server HTML, started the image download, and hit first paint with the original image. Then hydration failed, React deleted the DOM subtree and created a fresh image element. The new element had to decode and paint again, and the browser recorded the later paint as the LCP. TTFB was fine and the bytes were early. The page painted its most important element twice and the second paint is the one that counted.
Why did it not show in staging? Our staging containers and every engineer's laptop are on the same zone as each other, and QA ran with a VPN exit in UTC. The synthetic monitor runs from a Frankfurt probe, which is UTC+1, so it mismatched too, but only the mobile profile alerts and it had not been re-baselined since the banner existed.
the fix
Two options. Render the time only on the client, or make the server and client agree. We want the text in the HTML for crawlers and for the first paint, so agreement wins. The sale end time is a business fact in one zone, so format it in that zone, with an explicit locale:
With timeZone and locale pinned, the output is a pure function of the input
string on both sides. The component also lost its 'use client' line, because nothing in
it needed interactivity. The live countdown, which does need the browser clock, moved into a small
child that renders a static placeholder on the server and fills in after mount.
The first client render matches the server (a non-breaking space), and the real value arrives in an effect, which never participates in hydration comparison.
Patch went out at 10:41 IST. LCP p75 on mobile was back to 1.9s on the next synthetic run and the field data (CrUX-style RUM from our own beacon) recovered over the following hour.
the aftermath
The bad build was live for about 12 hours (22:40 to 10:41), but only the 09:00 email burst and the morning traffic did real damage. Mobile add-to-cart rate dropped from 6.1% to 4.3% during the worst two hours, which on that traffic is roughly 310 orders we did not get. We saw 1,140 hydration errors per hour in the RUM beacon at the peak, and zero in the hour after the patch.
What changed afterward:
-
The RUM beacon now reports
onRecoverableErrorfromhydrateRootas its own metric, and a monitor pages if the rate exceeds 0.5% of page views. We had been logging those errors to the console only. -
An ESLint rule bans
toLocaleString,toLocaleDateString, andIntl.DateTimeFormatcalls with notimeZonekey insideapp/andcomponents/. -
CI runs the Playwright smoke suite once with
TZ=Asia/Kolkataand once withTZ=America/Los_Angelesagainst a server started in UTC, and fails on any console message containing "Hydration". - The synthetic monitor baseline now has a separate alert on the gap between LCP and the time the LCP element's bytes finished downloading. A gap above one second means something repainted it.
What I took from it: when LCP regresses and TTFB and download times do not, the network is innocent. Something deleted and recreated the element. Hydration recovery does that quietly, and its only visible symptom is a console line nobody opens.