Skip to content

ref(utils): Simplify isDebugBuild logging guard #4696

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

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Mar 9, 2022

This simplifies the isDebugBuild check used to strip logging from minified bundles in two ways:

  • It makes the return value independent of the value of __SENTRY_BROWSER_BUNDLE__, since we want to be able to have debug and non-debug browser bundles.

  • It switches the variable on which it's based from one preventing debug logging which defaults to being unset to one enabling debug logging which defaults to being true. The effect is the same, but eliminating the double negative makes the intention clearer.

Note: This increases the bundle size because it turns off the fact that we've been unintentionally already stripping some logging from our bundles. (The old flag, __SENTRY_NO_DEBUG__, is set to false in our rollup config, but until this change isDebugBuild() has only been checking for a value (any value), not a truthy value, so setting it to false has had the same effect as setting it to true.) The increase is only temporary, though, as this change is really just prework for an improved debug/no-debug bundle generation system.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2022

size-limit report

Path Base Size (3784ee1) Current Size Change
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.78 KB 20.42 KB +3.24% 🔺
@sentry/browser - ES5 CDN Bundle (minified) 63.33 KB 65.23 KB +3.01% 🔺
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.43 KB 19 KB +3.11% 🔺
@sentry/browser - ES6 CDN Bundle (minified) 56.35 KB 58.25 KB +3.36% 🔺
@sentry/browser - Webpack (gzipped + minified) 22.26 KB 22.25 KB -0.07% 🔽
@sentry/browser - Webpack (minified) 76.32 KB 76.26 KB -0.09% 🔽
@sentry/react - Webpack (gzipped + minified) 22.29 KB 22.28 KB -0.07% 🔽
@sentry/nextjs Client - Webpack (gzipped + minified) 46.42 KB 46.4 KB -0.04% 🔽
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.67 KB 27.25 KB +2.18% 🔺
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25 KB 25.61 KB +2.46% 🔺

* constants, which can be overridden during build. By guarding certain pieces of code with functions that return these
* constants, we can control whether or not they appear in the final bundle. (Any code guarded by a false condition will
* never run, and will hence be dropped during treeshaking.) The two primary uses for this are stripping out calls to
* `logger` and preventing node-related code from appearing in browser bundles.
*/

declare const __SENTRY_BROWSER_BUNDLE__: boolean | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Are we going to do the same for __SENTRY_BROWSER_BUNDLE__?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably it makes sense to do so, yes. That's a future-me problem, though. 🙂

@lobsterkatie lobsterkatie merged commit 21a623b into master Mar 9, 2022
@lobsterkatie lobsterkatie deleted the kmclb-simplify-isDebugBuild branch March 9, 2022 15:01
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