Repository navigation
ref(core): Use DEBUG_BUILD ternaries so esbuild drops debug-only code - #26142
Open
sentry-junior[bot] wants to merge 1 commit into
Open
sentry-junior[bot] wants to merge 1 commit into
sentry-junior[bot] wants to merge 1 commit into
Conversation
esbuild inlines the imported DEBUG_BUILD constant after its dead-code pass, so early-return guards and guarded blocks with declarations stayed in non-debug bundles. Also adds an esbuild size-limit entry. Closes #26140 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
sentry-junior
Bot
requested review from
Lms24,
andreiborza,
logaretm,
mydea and
s1gr1d
and removed request for
a team
November 5, 2026 13:28
Contributor
size-limit report 📦Compared: 0f36283 (PR test merge using develop at c054e7a) Against: c054e7a (develop) · base run #65086 ✅ Baseline matches: this diff contains only this PR's changes.
|
Contributor
Optional E2E testsSome optional checks were not successful. They do not block the merge. 6 not successful, 50 successful. See the run.
Successful checks
|
This branch has not been deployed
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.
Why: esbuild inlines the imported
DEBUG_BUILDconstant only after its dead-code pass. So with__SENTRY_DEBUG__: false,logSpanStart/logSpanEnd,validateDsnand oneidleSpandebug block stayed in the bundle asif(!!1)return;…/if(!1){let …}. Switching to the positiveif (DEBUG_BUILD) { … }form doesn't fix it: esbuild still keeps the block whenever it declareslet/const. What does work is the module-levelDEBUG_BUILD ? fn : () => {}ternary already used indouble-wrap-warning.ts, plus guarded blocks that contain no declarations. Thedebug-logger.tsearly returns already compile away (no declarations follow them), so I left them alone. Behavior in debug builds is unchanged.Savings with esbuild 0.27.7 (minify, ESM, browser,
__SENTRY_DEBUG__: false) on a tracing-only setup (BrowserClient+browserTracingIntegration): 1,273 B raw / 329 B br-11 (131,185 → 129,912 B raw).This PR adds an esbuild size-limit entry, because every current entry uses webpack + terser and can't see this. On the new entry, gzip goes from 53,333 to 52,906 B. The webpack entries with treeshaking flags don't change. Those without a define grow by about 11–14 B gzip from the ternary wrappers.
How to review: Most of the
logSpans.ts/dsn.tsdiff is re-indentation (view with whitespace hidden).dsn.test.tsnow re-imports the module withvi.resetModules()to test the non-debug path, because the ternary is evaluated at import time.double-wrap-warning.test.tsdoes the same.Unsure about: Whether you want the new esbuild size-limit entry, or would rather track this some other way.
Closes #26140
via @BYK.
--
View Session in Sentry