fix(react): Remove unnecessary withScope wrapper in captureReact#20123
fix(react): Remove unnecessary withScope wrapper in captureReact#20123harshit078 wants to merge 2 commits intogetsentry:developfrom
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Core
Deps
Other
Bug Fixes 🐛Core
Other
Internal Changes 🔧Core
Deps
Other
🤖 This preview updates automatically when you update the PR. |
| return captureException(error, hint); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ef55354. Configure here.
| scope.setContext('react', { componentStack }); | ||
| return captureException(error, hint); | ||
| }); | ||
| return captureException(error, hint); |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit ef55354. Configure here.
| scope.setContext('react', { componentStack }); | ||
| return captureException(error, hint); | ||
| }); | ||
| return captureException(error, hint); |
There was a problem hiding this comment.
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.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit ef55354. Configure here.
|
This PR simply removes some functionality, the call was not unnecessary but actually does something! |


Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint) & (yarn test).Closes #20094