rollbar-react-native
rollbar-react-native copied to clipboard
Add Support for React Native for Web
What
This PR introduces React Native for Web support to pure/vanilla (not Expo) React Native projects using Rollbar, and is dependent on another PR for the Rollbar.js repository that updates its React Native target.
It's important to understand that Expo & React Native have fundamental differences, Expo is not vanilla React Native, and thus does not support any custom native libraries and cannot use this rollbar-react-native
package, for this reason the ErrorUtils layer has been moved to rollbar.js repository layer and can be initialized directly - so this change will benefit Expo users - although the Configuration
object still resides in this repository's ./src/Rollbar.js
, and may be useful to import and use when initializing it from Expo, or be moved to Rollbar.js repo at a later stage.
The second important difference to understand is that React Native for Web is not compatible with ErrorUtils
used by native app's JS layer, ErrorUtils is a custom global object of react-native
itself, and designed for the JavaScriptCore
headless engine that runs the JS code on Android & iOS devices. React Native for Web, however, runs on any web browser, re-using the code of the consumer's project - it can support ignoring the native libraries, unlike Expo. But it also means that it cannot depend on ErrorUtils for catching global errors, this is catered for in the dependent PR by leveraging some of the existing code used by Rollbar.js browser target.
Changes
-
Platform checks to avoid initializing the native libraries when platform is
web
- Moved ErrorUtils / JS error handlers to rollbar.js
- Adding
captureUnhandledRejections
&captureUncaught
into toJSON for passing configuration to Rollbar.js library
Notes
I have not understood the best way to handle the dependency in the package file for Rollbar.js
package as you do releases the other PR would be a prerequisite, I hope you can help me with this @waltjones. I look forward to finalizing this as you review it for your merge consideration - I have tested it in Android, iOS and Web (all using the same repo).