Skip to content

feat(replay): Capture hydration error breadcrumb #9759

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

Merged
merged 13 commits into from
Dec 12, 2023
28 changes: 27 additions & 1 deletion packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-lines */ // TODO: We might want to split this file up
import { EventType, record } from '@sentry-internal/rrweb';
import { captureException, getClient, getCurrentHub } from '@sentry/core';
import type { ReplayRecordingMode, Transaction } from '@sentry/types';
import type { Event as SentryEvent, ReplayRecordingMode, Transaction } from '@sentry/types';
import { logger } from '@sentry/utils';

import {
Expand Down Expand Up @@ -823,6 +823,32 @@ export class ReplayContainer implements ReplayContainerInterface {
}

this._performanceCleanupCallback = setupPerformanceObserver(this);

const client = getClient();
// Start listening for errors that occur in the core SDK
client && client.on && client.on('beforeSendEvent', (event: SentryEvent) => {
// eslint-disable-next-line @sentry-internal/sdk/no-optional-chaining
const exceptionValue = event.exception?.values?.[0]?.value;
if (typeof exceptionValue !== 'string') {
return;
}

const isHydrationError =
// development
exceptionValue.match(/nextjs.org\/docs\/messages\/react-hydration-error/) ||
// production
exceptionValue.match(/https:\/\/reactjs\.org\/docs\/error-decoder\.html\?invariant=(418|419|422|423|425)/);

// There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.
if (isHydrationError) {
console.log('Found hydration error')
const breadcrumb = createBreadcrumb({
category: 'replay.hydrate',
data: {}
})
this._createCustomBreadcrumb(breadcrumb);
}
})
}

/**
Expand Down