Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/react/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { captureException, withScope } from '@sentry/browser';
import { captureException } from '@sentry/browser';
import { isError } from '@sentry/core';
import type { ErrorInfo } from 'react';
import { version } from 'react';
Expand Down Expand Up @@ -64,10 +64,7 @@ export function captureReactException(
setCause(error, errorBoundaryError);
}

return withScope(scope => {
scope.setContext('react', { componentStack });
return captureException(error, hint);
});
return captureException(error, hint);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Removal of componentStack context data from Sentry events

High Severity

Removing the withScope wrapper also removed the scope.setContext('react', { componentStack }) call, which means the React component stack is no longer attached as structured context data on Sentry events. For React < 17, non-Error throws, or when componentStack is falsy (where the setCause linked-error approach doesn't apply), the component stack is now completely lost. Multiple existing tests in errorboundary.test.tsx assert that scopeSetContextSpy is called with the react context — those will now fail.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ef55354. Configure here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fix PR missing regression test for the change

Low Severity

Per project review rules, a fix PR needs at least one unit, integration, or E2E test that tests the regression being fixed (i.e., a test that would have failed prior to the fix and passes with it). This PR doesn't appear to include any new tests validating the behavior change. In fact, existing tests in errorboundary.test.tsx that assert setContext('react', { componentStack }) was called appear incompatible with this change.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit ef55354. Configure here.

}

/**
Comment on lines +67 to 70
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Removing the withScope wrapper in captureReactException loses the componentStack for React < 17 and removes the 'react' context from Sentry events for all versions.
Severity: HIGH

Suggested Fix

Restore the withScope wrapper in the captureReactException function to ensure the componentStack is consistently added to the Sentry event scope via scope.setContext('react', { componentStack }). This will fix the data loss for React < 17 users and restore the 'react' context for all versions, ensuring consistent error reporting behavior and passing existing tests.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/react/src/error.ts#L67-L70

Potential issue: The removal of the `withScope` wrapper from `captureReactException`
eliminates the mechanism that added the React `componentStack` to the Sentry event scope
via `scope.setContext('react', { componentStack })`. For React versions below 17, this
results in the complete loss of component stack information in Sentry error reports, as
there is no alternative mechanism to capture it. For React 17 and above, while the stack
is preserved via `error.cause`, the dedicated `'react'` context is no longer present,
which is a regression. This change will likely cause existing tests that assert the
presence of this context to fail.

Did we get this right? 👍 / 👎 to inform future reviews.

Expand Down
Loading