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

Refactor @bugsnag/browser #2252

Draft
wants to merge 51 commits into
base: integration/typescript
Choose a base branch
from

Conversation

gingerbenw
Copy link
Member

@gingerbenw gingerbenw commented Nov 12, 2024

Goal

This PR converts the last of the internal browser plugins and the browser client to TypeScript, using Rollup to bundle both common js and es modules

Following this work, we can then validate a flattened module (fesm) with a modern angular app

Design

Changeset

Testing

Existing test suite

@gingerbenw gingerbenw force-pushed the integration/typescript branch from 9a4591e to 7bbbff9 Compare December 5, 2024 16:04
@gingerbenw gingerbenw changed the title Plat 12163/browser Refactor @bugsnag/browser Dec 5, 2024
Copy link

github-actions bot commented Dec 10, 2024

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 46.15 kB 13.86 kB
After 48.86 kB 15.14 kB
± ⚠️ +2,710 bytes ⚠️ +1,275 bytes

code coverage diff

<temporarily disabled>

Generated by 🚫 dangerJS against 3196415

jest.config.js Outdated
@@ -49,7 +49,9 @@ module.exports = {
'plugin-simple-throttle',
'plugin-console-breadcrumbs',
'plugin-browser-session'
]),
], {
setupFiles: ['<rootDir>/jest/setup/mockEventTarget.js']
Copy link
Contributor

Choose a reason for hiding this comment

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

See jsdom/jsdom#2156

This is needed to fix the TypeError: 'addEventListener' called on an object that is not a valid instance of EventTarget. seen in the integration tests following the rollup changes

Comment on lines 34 to 35
"build:dist": "cross-env NODE_ENV=production bash -c '../../bin/bundle src/notifier.js --standalone=Bugsnag | ../../bin/extract-source-map dist/bugsnag.js'",
"build:dist:min": "cross-env NODE_ENV=production bash -c '../../bin/bundle src/notifier.js --standalone=Bugsnag | ../../bin/minify dist/bugsnag.min.js'",
Copy link
Contributor

Choose a reason for hiding this comment

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

can these be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep - and possibly the minification scripts, too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not yet as they are being used for e.g. plugin-react and others

export default assign(Bugsnag, { Client, Event, Session, Breadcrumb })
export type { BrowserBugsnagStatic, BrowserConfig } from './bugsnag'

export type { Client, Event, Session, Breadcrumb, Plugin } from '@bugsnag/core'
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we would do export type * from '@bugsnag/core' but that's not supported with the current version of TypeScript we're using

Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: Check what other types need exporting here

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I don't think any types need exporting from cjs/umd entry points

import pluginNavigationBreadcrumbs from '@bugsnag/plugin-navigation-breadcrumbs'
import pluginInteractionBreadcrumbs from '@bugsnag/plugin-interaction-breadcrumbs'
// @ts-ignore
import pluginInlineScriptContent from '@bugsnag/plugin-inline-script-content'
Copy link
Contributor

Choose a reason for hiding this comment

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

I reverted the TS conversion of this plugin from this PR because it was broken


const sharedOutput = {
...commonSharedOutput,
strict: false, // 'use strict' in WebKit enables Tail Call Optimization, which breaks stack trace handling
Copy link
Contributor

Choose a reason for hiding this comment

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

There is one tail call in out stack and our depth handling does not handle it. With TCO enabled the stack frame for the tail call is removed, which then causes problems with stack processing leading to unexpected results (only in WebKit browsers since that's the only one supporting TCO):

Screenshot 2024-12-27 at 10 14 05

Dropping 'use strict' prevents TCO being enabled and resolves the issue

Dan Skinner added 2 commits December 27, 2024 10:38
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-replace": "^6.0.2",
"@rollup/plugin-terser": "^0.4.4",
"tslib": "^2.8.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

tslib is required for target: es3

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