Skip to content
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

[PLAT-5357] fix(react-native): Ensure plugin usage does not crash debugger #1250

Merged
merged 3 commits into from
Jan 20, 2021

Conversation

bengourley
Copy link
Contributor

Goal

When run in the debugger, the React Native notifier starts asynchronously due to synchronous calls to native not being available in the debugging environment.

The existing workaround involved creating a no-op stubbed client interface, which covered most use cases, but not plugins where the return value of Bugsnag.getPlugin('<name>') was required, resulting in the following bugs: #1143 #1112.

Design

The new solution is to create an actual Client instance so that plugins can be used in the short delay before the notifier starts properly.

Changeset

  • Updated the debugging-env only stub client to use an actual client object
  • Added messaging to the debugging console warning

Testing

The changes were manually tested in the remote debugger on an app using React Navigation.

packages/react-native/src/notifier.js Outdated Show resolved Hide resolved
packages/react-native/src/notifier.js Show resolved Hide resolved
packages/react-native/src/notifier.js Outdated Show resolved Hide resolved
createClientAsync(opts).then(client => {
initialised = true
Bugsnag._client = client
return Reflect.apply(target, thisArg, args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this still be applying to Bugsnag._client if it has initialised?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it has to carry being functional because plugins created and obtained synchronously still have a reference to that stubbed client. If we stopped apply()ing and no-op'ing, it could fail due to a plugin expecting it to return something.

stubClient[m] = new Proxy(stubClient[m], {
apply: (target, thisArg, args) => {
if (!initialised) {
console.log(`Synchronous call to Bugsnag.${m}()`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to a log rather than a warn, so that it doesn't pop up in the app's yellowbox UI.

@github-actions
Copy link

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 40.70 kB 12.54 kB
After 40.70 kB 12.54 kB
± No change No change

Generated by 🚫 dangerJS against 3558ce4

@bengourley bengourley merged commit bb3c9c3 into next Jan 20, 2021
@bengourley bengourley deleted the fix/improve-rn-debugger-support branch January 20, 2021 11:09
@bengourley bengourley mentioned this pull request Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants