bugsnag / bugsnag-js-performance

Monitor the performance of your JavaScript (web and React Native) and see the results in your BugSnag dashboard.
https://docs.bugsnag.com/performance/integration-guides
MIT License
5 stars 3 forks source link

Set initial background state to foreground if initial app state is 'inactive' #491

Closed yousif-bugsnag closed 2 months ago

yousif-bugsnag commented 2 months ago

Goal

In React Native 0.74+, when an iOS app launches the initial AppStateStatus changed from unknown to inactive. This wasn't being accounted for in the backgrounding listener, so the initial background state was incorrectly being set to in-background.

This PR updates the React Native backgrounding listener so that the app is considered in foreground on launch unless the initial app state is background.

Design

When the backgrounding listener is created the initial app state is now only set to in-background if the initial app state status is explicitly background - any other initial state (active, inactive, or unknown) is considered in-foreground until an app state change event occurs.

Testing

Covered by unit tests and manual testing.

The current structure of the end-to-end test fixture means that we can't test this effectively since the app state status is always 'active' when the scenario runs. This will be addressed in a later PR.

github-actions[bot] commented 2 months ago

Browser bundle size

NPM build

Package
Before 193.47 kB
After 193.47 kB
± No change

CDN build

Unminified Minfied Minified + gzipped
Before 96.91 kB 36.36 kB 10.97 kB
After 96.91 kB 36.36 kB 10.97 kB
± No change No change No change

Code coverage

Ok File (✨=New File) Lines Branches Functions Statements
🔴 /home/runner/work/bugsnag-js-performance/bugsnag-js-performance/packages/platforms/react-native/lib/backgrounding-listener.ts 100%
(+0%)
85.71%
(-14.29%)
100%
(+0%)
100%
(+0%)

Total:

Lines Branches Functions Statements
86.74%(+0%) 77.18%(-0.21%) 87.84%(+0%) 83.54%(+0%)

Generated against 4cd5ca7d97fee59ddd07e4fa206e9af3cdc7fa67 on 20 August 2024 at 08:27:13 UTC