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
4 stars 1 forks source link

Export noops from browser package when window or document is undefined #390

Closed yousif-bugsnag closed 6 months ago

yousif-bugsnag commented 6 months ago

Goal

Prevent the SDK from crashing when used in SSR frameworks such as Next or Nuxt.

Currently window and document are accessed when the library is imported which causes a crash when the code is executed server-side as these are not defined.

This PR aims to prevent this and allow the SDK to be used in SSR apps, by exporting a noop client, onSettle and routing provider if window and document are undefined.

Testing

Added unit tests for the onSettle and routing provider noops, and tested manually with a Next.js app

github-actions[bot] commented 6 months ago

Browser bundle size

NPM build

Package
Before 175.95 kB
After 177.45 kB
± +1,497 bytes ⚠️

CDN build

Unminified Minfied Minified + gzipped
Before 84.94 kB 31.99 kB 9.84 kB
After 85.98 kB 32.33 kB 9.93 kB
± +1,039 bytes ⚠️ +335 bytes ⚠️ +91 bytes ⚠️

Code coverage

Ok File (✨=New File) Lines Branches Functions Statements
🔴 /home/runner/work/bugsnag-js-performance/bugsnag-js-performance/packages/platforms/browser/lib/browser.ts 87.5%
(-8.92%)
75%
(-25%)
50%
(+0%)
87.5%
(-8.92%)
🔴 /home/runner/work/bugsnag-js-performance/bugsnag-js-performance/packages/platforms/browser/lib/default-routing-provider.ts 100%
(+0%)
60%
(-15%)
100%
(+0%)
100%
(+0%)

Total:

Lines Branches Functions Statements
92.06%(-0.15%) 80.9%(-0.2%) 93.98%(+0.09%) 90.13%(-0.11%)

Generated against d18dca8edb8e208dbbca83648bef93afe7bafc0d on 2 January 2024 at 10:29:11 UTC