refactor(browser): Reduce browser package bundle size#19856
Open
HazAT wants to merge 1 commit intoautoresearch/browser-bundle-size-2026-03-17from
Open
refactor(browser): Reduce browser package bundle size#19856HazAT wants to merge 1 commit intoautoresearch/browser-bundle-size-2026-03-17from
HazAT wants to merge 1 commit intoautoresearch/browser-bundle-size-2026-03-17from
Conversation
A collection of small, safe optimizations across the browser package: - helpers.ts: Rename internal `sentryWrapped` function to `sW` in the wrap() helper. Update the frame stripping regex in core/stacktrace.ts to match both names for backwards compatibility. Saves ~10B gzipped. - breadcrumbs.ts: Remove unused `breadcrumbData` variable from the fetch breadcrumb handler — it was constructed but never used in either branch. - browserapierrors.ts: Encode DEFAULT_EVENT_TARGET as comma-separated string.split() instead of array literal. Saves 51B raw. - globalhandlers.ts: Remove redundant intermediate variable aliases in _enhanceEventWithInitialFrame. - detectBrowserExtension.ts: Replace array.some(startsWith) with a single regex test for extension protocol detection. - eventbuilder.ts: Simplify getErrorPropertyFromObject to use Object.values().find() instead of manual for-in loop. - lazyLoadIntegration.ts: Derive CDN bundle filenames from integration names instead of storing duplicate key-value pairs. Uses a 3-entry exceptions map for hyphenated names (replay-canvas, feedback-modal, feedback-screenshot). Saves ~30B gzipped. All changes are behavior-preserving. No public API modifications. Co-Authored-By: Claude claude@anthropic.com
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| const sentryWrapped = function (this: unknown, ...args: unknown[]): unknown { | ||
| // It is important that `sW` is not an arrow function to preserve the context of `this` | ||
| // The name `sW` is matched by the frame stripping regex in stacktrace.ts | ||
| const sW = function (this: unknown, ...args: unknown[]): unknown { |
There was a problem hiding this comment.
Wrapper rename breaks minified frame stripping
High Severity
Renaming the wrapper function to sW changes the stack-frame marker, but terser still only reserves sentryWrapped. In minified CDN builds, sW can be mangled, so stripSentryFramesAndReverse no longer recognizes and removes the internal wrapper frame.
Additional Locations (1)
Contributor
size-limit report 📦
|
Contributor
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
A collection of small, safe optimizations across the browser package. Combined saves ~60 bytes gzipped.
Changes
helpers.ts+stacktrace.tssentryWrapped→sWin wrap(). Update frame stripping regex to match both names.breadcrumbs.tsbreadcrumbDatavariable from fetch handlerbrowserapierrors.tsDEFAULT_EVENT_TARGETasstring.split(",")instead of array literalglobalhandlers.ts_enhanceEventWithInitialFramedetectBrowserExtension.tsarray.some(startsWith)with single regex testeventbuilder.tsgetErrorPropertyFromObjecttoObject.values().find()lazyLoadIntegration.tslazyLoadIntegration detail
The
LazyLoadableIntegrationsobject stored 21 key-value pairs where values were mostly derivable from keys (strip"Integration", lowercase). Replaced with:string.split(","))replay-canvas,feedback-modal,feedback-screenshot)All changes are behavior-preserving. No public API modifications.
Part of #19833.
Co-Authored-By: Claude claude@anthropic.com