Skip to content

fix(core): Capture uncaught render errors on React Native 0.78+ - #7078

Open
alwx wants to merge 2 commits into
mainfrom
alwx/bugfix/7043
Open

alwx wants to merge 2 commits into
mainfrom
alwx/bugfix/7043

Conversation

@alwx

@alwx alwx commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

The ReactNativeErrorHandlers integration now also wraps React Native's ExceptionsManager.handleException. Fatal calls go through the same capture path as ErrorUtils fatals (level fatal, mechanism onerror, flush, then report to React Native). Non-fatal calls, such as errors that an error boundary catches, pass through. A fatal that the integration already forwarded to React Native passes through too, so each crash is captured once.

💡 Motivation and Context

Since React 19 (React Native 0.78), a render error that no error boundary catches skips ErrorUtils. React Native reports it from the root onUncaughtError callback directly to ExceptionsManager. The native SDKs drop the resulting crash because they expect the JS layer to report it, so Sentry gets nothing on Android and iOS. Fixes #7043.

💚 How did you test it?

Added unit tests for the render path, the error boundary path, and both duplicate guards. On the React Native sample (0.88.1, New Architecture, Android release build, emulator), a render error outside any error boundary was lost before this change and is captured as a fatal event after it. A fatal thrown in a button handler is still captured once.

📝 Checklist

  • I added tests to verify changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.
  • No breaking changes.

🔮 Next steps

Update the error boundary docs. They say that only some render errors on Android skip the global handler, but on React Native 0.78+ every uncaught render error does.

alwx added 2 commits November 20, 2026 10:23
React 19 does not rethrow a render error that no error boundary catches.
React Native passes it from the root onUncaughtError callback straight to
ExceptionsManager.handleException as a fatal, so the ErrorUtils global
handler never runs. The native SDKs then drop the crash because they expect
the JS layer to report every fatal JS error (JavascriptException on Android,
"Unhandled JS Exception" on iOS). The app crashes and Sentry gets nothing.

The ReactNativeErrorHandlers integration now also wraps
ExceptionsManager.handleException. Fatal calls go through the same capture
path as ErrorUtils fatals (level fatal, mechanism onerror, flush, then report
to React Native). Non-fatal calls, such as errors that an error boundary
catches, pass straight through.

The ErrorUtils handler forwards its fatal to React Native's default handler,
which calls handleException too. To capture each fatal once, a fatal that
the integration forwards passes straight through. A flag covers the
synchronous forward, and a WeakSet covers a previous handler that reports
the error to React Native later.

ExceptionsManager is read through ReactNativeLibraries, so web bundles do
not include it.

Fixes #7043
Replace the placeholder PR number in the CHANGELOG entry with #7078.
@github-actions

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

⚪ None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • fix(core): Capture uncaught render errors on React Native 0.78+ by alwx in #7078
  • chore(sample): Remove unused Detox setup from the React Native sample by antonis and claude in #7072
  • ci(ios): Build TestFlight sample with Xcode 27 by philprime with sentry-junior in #7065
  • perf(android): Create SDK view managers on demand by alwx in #7049
  • fix(core): Remove web Replay and Feedback from native bundles by default by huextrat, claude and antonis in #7062
  • fix(core): Define UnsafeObject locally instead of deep importing it by alwx in #7061
  • chore(deps): update Android SDK to v8.65.0 by github-actions in #7058

🤖 This preview updates automatically when you update the PR.

Comment on lines +16 to 19
import { ReactNativeLibraries } from '../utils/rnlibraries';
import { RN_GLOBAL_OBJ } from '../utils/worldwide';
import { hasInterestedSubscribers, publishGlobalError } from './globalErrorBus';
import { checkPromiseAndWarn, polyfillPromise, requireRejectionTracking } from './reactnativeerrorhandlersutils';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A rejected fatal-event flush prevents React Native from handling the crash

When a fatal reaches the wrapper with no interested GlobalErrorBoundary and client.flush() rejects, the original React Native ExceptionsManager.handleException is never called; the rejection branch only logs and resets the latch. Ensure the fatal is reported to React Native when Sentry handling fails.

Evidence
  • The new ExceptionsManager.handleException wrapper passes fatal errors to handleError with report as the callback for invoking React Native’s original handler.
  • In production, handleError calls report from the flush fulfillment path when no interested boundary exists; its flush rejection handler only logs and resets handlingFatal.
  • Therefore, if the flush rejects for a fatal with no interested boundary, the original handler is skipped. The test for the normal path expects it to be called after the flush resolves.

Identified by Warden · code-review · UGK-TYK

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks valid but probably an edge case 🤔

@alwx
alwx marked this pull request as ready for review November 20, 2026 11:21
@alwx alwx added the ready-to-merge Triggers the full CI test suite label Nov 20, 2026
@sentry

sentry Bot commented Nov 20, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Sentry RN io.sentry.reactnative.sample 8.36.0 (116) Release

⚙️ sentry-react-native Build Distribution Settings

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2f5fd5a. Configure here.

}
handleError(error, isFatal, report).catch((e: unknown) => {
debug.error('[ReactNativeErrorHandlers] Failed to handle the fatal error.', e);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed fatals skip native reporting

Medium Severity

The new ExceptionsManager.handleException wrapper intercepts fatals and only calls the original handler through report(). If handleError rejects, the .catch() logs and returns, so React Native never sees the exception. A render error that this change intercepts is then dropped: no Sentry event, no native crash, and a broken tree left on screen.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 2f5fd5a. Configure here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@antonis antonis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Added a couple of comments along with the bot feedback.

Added unit tests for the render path, the error boundary path, and both duplicate guards. On the React Native sample (0.88.1, New Architecture, Android release build, emulator), a render error outside any error boundary was lost before this change and is captured as a fatal event after it. A fatal thrown in a button handler is still captured once.

Let's also add Sentry links for the above tests

Comment on lines +16 to 19
import { ReactNativeLibraries } from '../utils/rnlibraries';
import { RN_GLOBAL_OBJ } from '../utils/worldwide';
import { hasInterestedSubscribers, publishGlobalError } from './globalErrorBus';
import { checkPromiseAndWarn, polyfillPromise, requireRejectionTracking } from './reactnativeerrorhandlersutils';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks valid but probably an edge case 🤔

}
handleError(error, isFatal, report).catch((e: unknown) => {
debug.error('[ReactNativeErrorHandlers] Failed to handle the fatal error.', e);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const exceptionsManager = ReactNativeLibraries.ExceptionsManager;
const handleException = exceptionsManager?.handleException;
if (exceptionsManager && handleException) {
exceptionsManager.handleException = (error: unknown, isFatal: boolean): void => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: Could we use a fillTyped like

fillTyped(AppRegistry, 'runApplication', originalRunApplication => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] A render error no error boundary catches is reported neither by the JS handler nor natively (React 19 / React Native ≥ 0.78)

2 participants