Case file 07Frontend8 min read

Two bugs that hit every user and looked like noise

Cleaning up a noisy error feed without hiding our own failures, and the two hydration bugs hiding inside it.

Read by an AI voice of Sajib. Words light up as he reads.

I opened our error dashboard on a Monday and saw 1,669 errors from the last two weeks. Most of them were not ours: a browser extension had crashed, a Safari script had failed, and ad blockers had stopped some analytics requests.

Hidden under all of that were two real bugs. One broke the public share page for every visitor outside one time zone. The other broke every single page in production. Both looked exactly like the noise around them.

This article is about cleaning up the noise without hiding our own failures, finding the two real bugs under it, and the one “fix” I made that I had to undo the same afternoon.

Why the real bugs were easy to miss

The app is an AI chat assistant built with Next.js and React. We use Sentry, a service that collects errors from users’ browsers and groups them so you can see what is breaking. It had been on this app since the year before.

By now the Sentry feed was noisy again, and a noisy feed teaches people to stop reading it.

To understand the two bugs, you need one term: hydration. When a user opens a page, the server sends ready-made HTML so the page appears quickly. Then React runs in the browser and attaches itself to that HTML, adding click handlers and state; that step is hydration. For it to work, the HTML that React renders in the browser must match the HTML the server sent. If it doesn’t, React reports a hydration error.

Both of our bugs were hydration errors, and three things made them easy to ignore.

First, the message was generic. In production, React only says “Minified React error #418”, with no component name. On public websites, this error is often caused by browser extensions that change the page before React hydrates.

Second, the stack trace did not point to our code. After the mismatch, React threw away the server HTML, and then React’s own script crashed while looking for a page element that no longer existed. None of the lines in the error came from our application.

Third, neither bug happened on my machine. One needed the server and the browser to be in different time zones. The other only happened in production.

So the first job was to make the feed readable.

Clearing the noise without hiding our own failures

I grouped two weeks of errors by message and by where they came from. Three patterns made up about 1,050 of the 1,669 errors:

  • About 1,000 errors from a Safari autofill script, using a variable name that appears nowhere in our code.
  • Errors inside a browser extension’s own script.
  • Failed requests to Google Analytics, blocked by ad blockers, and to a known adware site.

The last filter was the dangerous one. “Failed to fetch” is also what our own API failures look like. If the filter was too broad, we would stop seeing our own outages.

So the filter matches only exact third-party host names, and the tests check the opposite cases too. Each message in the list below must still be reported, even though it looks a lot like the noise.

it.each([
  "TypeError: Failed to fetch",                    // ours, no host
  "TypeError: Failed to fetch (app.our-domain.com)", // our own API
  "TypeError: Failed to fetch (notanalytics.tracker.com.evil.test)", // lookalike
])("still reports: %s", (msg) => {
  expect(isIgnored(msg)).toBe(false);
});

The other filters needed the same care. One in-app browser produced an error whose text was exactly the same as an error our own encryption code can throw. So I matched that one by the name of the browser’s function in the stack trace, not by the message.

Then I looked at errors that were not crashes at all. An expired share link threw an error instead of showing the “this link has expired” screen. And seven different error groups came from browsers that block site storage. The fix was a small storage wrapper whose reads and writes never throw.

That wrapper found a hidden loop. We had logic that reloads the page once if an old file fails to load after a new deploy. It saved a flag in storage so it would not reload twice. If storage was blocked, the flag could not be saved, and the page could reload forever. Now, when storage is blocked, it shows an “update available” message instead.

With the feed cleaner, a cluster of share-page errors stood out. They came from about 50 users, and they were all hydration errors.

Bug one: the share page broke outside UTC

The public share page shows “Shared on Oct 12, 2026”, plus a time on each message. Both were formatted during render with the format() function from date-fns, a date library.

format() uses the time zone of whatever machine runs it. Our server runs in UTC. A visitor in New York or Berlin gets a different string in the browser. React compares the two, finds different text, and throws a hydration error.

So every visitor outside UTC hit the bug. Visitors in UTC never did. And a developer running the server and the browser on one laptop never did either, because both use the same time zone.

Fig. 7.1 · The server and the browser formatted the same moment in different time zones.

The fix is a small component that shows the local time only after hydration is done. The trick is in useSyncExternalStore: React uses the third function (false) on the server and during hydration, and the second function (true) after that.

const noop = () => () => {};

export function ClientTime({ iso, pattern }) {
  const hydrated = useSyncExternalStore(noop, () => true, () => false);
  const date = new Date(iso);
  return (
    <time dateTime={iso}>
      {hydrated && isValid(date) ? format(date, pattern) : null}
    </time>
  );
}

The dateTime attribute is the same everywhere, so it can safely stay in the server HTML. The visible text appears a moment later, in the user’s own time zone.

The regression test renders the component to HTML, hydrates that HTML, and checks that React reported no hydration errors.

The detour: fixing a bug that didn’t exist

While I was in the analytics code, I noticed a custom route tracker. It sent a page view to Google Analytics on every navigation inside the app. I knew that Google Analytics 4 already records these navigations by itself, so I decided we were counting every page view twice and removed the tracker.

Then I checked production with Google Tag Assistant, a tool that shows what analytics data a page really sends. There were no duplicate page views, because Google Analytics already skips the extra one in this case.

I reverted my change the same afternoon. The commit message said it plainly: the change fixed a bug that doesn’t exist.

I’m including this mistake because of what happened next.

Bug two: a span in the head

The time zone fix did not explain all the errors. Some hydration errors came from every production page, not only the share page.

The cause was the route tracker I had just put back. The Google Analytics component sat inside the page’s <head> tag. It rendered two script tags, which are fine there. It also rendered the tracker, and the tracker returned a hidden <span>.

A <span> is not allowed in <head>. When the browser’s HTML parser finds one there, it closes <head> immediately and starts <body>. So the page title and the meta tags that came after it ended up in the wrong place. When React hydrated, the page structure did not match what React expected, so it threw error #418 on every production page.

Fig. 7.2 · The browser closed <head> at the first tag it did not allow there.

Why had nobody seen it? The analytics component renders nothing unless the app is in production. That is a sensible rule, because it keeps test traffic out of the analytics data. But it also meant that development, staging and every automated test had a perfectly valid <head>.

The fix was to move one component from <head> to the top of <body>. Its scripts load after hydration anyway, so the move did not change their timing.

The test was the more useful part. It turns on the production setting and a fake analytics ID, then renders the root layout to HTML. First it checks that the tracker really rendered, so the test can’t pass just because analytics is off. Then it checks that <head> contains only tags that HTML allows there.

Making the tests see production

Both bugs existed only in production builds.

The day before, for unrelated memory reasons, our local end-to-end tests had moved from the development server to a production build. After these fixes, the test build went one step further and now uses the production setting and a fake analytics ID, so production-only markup shows up in tests.

There is also a share-page test now. It opens a shared chat as a logged-out visitor, with the browser set to a time zone 14 hours ahead of UTC. That is as far from the server as it gets. The test fails on any page error or console error, and it checks that the times appear after hydration. On the old layout, it fails with error #418.

What I learned

A generic error is not an extension error until you prove it. React error #418, with none of our code in the stack trace, looked like third-party noise. It was two of our worst bugs.

Anything formatted from a clock or a locale during server rendering will not match for someone. Show it after hydration, and keep the machine-readable value in the HTML.

A component that only runs in production needs a test that turns production on. Otherwise “production only” also means “never tested”.

Write noise filters together with tests for what must still be reported. And check production before you fix something in analytics. Tag Assistant took minutes and proved my theory wrong. I should have looked before I wrote the change, not after.

Product names and some details are changed or left out. The engineering is real.