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

Handle recursive metadata in ReactNative #1673

Merged
merged 7 commits into from
Feb 2, 2022

Conversation

lemnik
Copy link
Contributor

@lemnik lemnik commented Jan 24, 2022

Goal

Re-introduce the changes made in #1643 with fixes to the tests, and an additional makeSafe call in plugin-react-native-client-sync to ensure that metadata included in Breadcrumbs is also safe to cross the React Native JS Bridge.

Make it safe to specify complex and recursive objects as metadata for breadcrumbs and events in react native applications.

Design

Added a new makeSafe function to the delivery-react-native which behaves similarly to the safe-json-stringify module but specifically for the react native JS bridge, which does not invoke toJSON functions.

Testing

New unit tests to cover the makeSafe function, and adjustments to the existing Mazerunner tests to ensure circular references are correctly flattened and don't cause a crash.

# Conflicts:
#	packages/delivery-react-native/test/make-safe.test.ts
#	packages/plugin-react-native-client-sync/package.json
@github-actions
Copy link

github-actions bot commented Jan 24, 2022

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 42.85 kB 13.07 kB
After 42.85 kB 13.07 kB
± No change No change

code coverage diff

Ok File Lines Branches Functions Statements
/home/runner/work/bugsnag-js/bugsnag-js/packages/core/lib/derecursify.js 97.37%
(+97.37%)
96.15%
(+96.15%)
100%
(+100%)
97.5%
(+97.5%)
/home/runner/work/bugsnag-js/bugsnag-js/packages/delivery-react-native/delivery.js 72.73%
(+2.73%)
42.86%
(+0%)
60%
(+0%)
75%
(+2.27%)
/home/runner/work/bugsnag-js/bugsnag-js/packages/plugin-react-native-client-sync/client-sync.js 85.71%
(+0.2%)
47.06%
(+0%)
100%
(+0%)
86.11%
(+0.19%)

Total:

Lines Branches Functions Statements
82.03%(+0.14%) 71.73%(+0.29%) 83.17%(+0.09%) 81.1%(+0.14%)

Generated by 🚫 dangerJS against b4956cb

@lemnik lemnik marked this pull request as ready for review January 25, 2022 10:19
@lemnik lemnik force-pushed the PLAT-7711/rn-recursive-metadata branch from bccfe5b to c647b22 Compare January 25, 2022 10:20
@@ -1,4 +1,5 @@
const { DeviceEventEmitter, NativeEventEmitter, NativeModules, Platform } = require('react-native')
const makeSafe = require('@bugsnag/delivery-react-native/make-safe')
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it makes sense for this to import something from delivery-react-native

Should make-safe be a new plugin? We could put it in core, but that would increase the browser bundle size, so maybe it could go in @bugsnag/react-native?

Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be good to give it a better name now it's being used in multiple places as well; maybe something like "resolve recursive references" (or something less alliterative!)

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 mostly agree with moving it out of delivery, but moving it into @bugsnag/react-native leads us to a circular dependency. Given how tied to the react-native bridge this logic is, it should definitely be kept away from core.

Also agree on changing the name, maybe bridgeSafe?

Alternatively it needs to become more generic and move completely to its own module?

Copy link
Contributor

Choose a reason for hiding this comment

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

Given how tied to the react-native bridge this logic is…

I'm not sure it is tied to the react-native bridge; it just resolves recursive references in any JS value, it isn't RN specific AFAICT

Copy link
Contributor Author

@lemnik lemnik Jan 25, 2022

Choose a reason for hiding this comment

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

In the abstract, yes. On the other hand it also converts Date objects to strings, changes how Error objects are represented, etc. while those are probably useful behaviours everywhere, it's been build with the react native bridge in mind and is baked in logic.

…e meta-data in React Native applications

This reverts commit 99a0cb4
@lemnik lemnik force-pushed the PLAT-7711/rn-recursive-metadata branch from c647b22 to 69bdd2a Compare January 27, 2022 15:56
Copy link
Contributor

@imjoehaines imjoehaines left a comment

Choose a reason for hiding this comment

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

LGTM, but could use a changelog entry

@lemnik lemnik merged commit e334b57 into next Feb 2, 2022
@lemnik lemnik deleted the PLAT-7711/rn-recursive-metadata branch February 2, 2022 09:27
@djskinner djskinner mentioned this pull request Feb 2, 2022
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