Skip to content

Conversation

@lforst
Copy link
Contributor

@lforst lforst commented Apr 15, 2024

Relates to #5289 (comment)

We technically support webworkers so we cannot assume that document API is available.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 15, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 80.59 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 71.57 KB (+0.04% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 75.59 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 65.2 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 35.51 KB (+0.05% 🔺)
@sentry/browser (incl. browserTracingIntegration) - Webpack (gzipped) 35.39 KB (+0.06% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.57 KB (0%)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 31.58 KB (0%)
@sentry/browser - Webpack (gzipped) 22.78 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 78.77 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 70.13 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 35.9 KB (+0.03% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 25.27 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 220.82 KB (+0.05% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 108.63 KB (+0.1% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 75.79 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 39.18 KB (+0.03% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 72.06 KB (+0.04% 🔺)
@sentry/react - Webpack (gzipped) 22.81 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 89.89 KB (+0.02% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 54.03 KB (+0.03% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17.32 KB (0%)

@lforst lforst changed the title fix(browser): Don't assume window.document is available fix(browser/v7): Don't assume window.document is available Apr 15, 2024
Luca Forstner added 2 commits April 15, 2024 12:12
@lforst lforst requested review from AbhiPrasad, Lms24 and mydea April 15, 2024 13:40
@Gregoor
Copy link

Gregoor commented Apr 15, 2024

I'm wondering if it's feasible to drop the DOM-lib in this project's tsconfig, to prevent accidental breakage for WebWorkers?
I suppose it also purges some APIs which are available in WebWorkers, so this might be sub-optimal.

And a small review nudge: I personally really like optional chaining to turn

if (WINDOW.document) WINDOW.document.addEventListener(...)

into

WINDOW.document?.addEventListener(...)

(Might not apply here due to code style or something. Putting it out here just in case)

Comment on lines +13 to 14
if (WINDOW.document) {
WINDOW.document.addEventListener('visibilitychange', () => {
Copy link
Member

Choose a reason for hiding this comment

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

l/feel free to ignore: This should be safe here, right?

Suggested change
if (WINDOW.document) {
WINDOW.document.addEventListener('visibilitychange', () => {
if (WINDOW.document) {
addEventListener('visibilitychange', () => {

if (isPageloadTransaction && WINDOW.document) {
WINDOW.document.addEventListener('readystatechange', () => {
if (['interactive', 'complete'].includes(WINDOW.document.readyState)) {
if (['interactive', 'complete'].includes(WINDOW.document!.readyState)) {
Copy link
Member

Choose a reason for hiding this comment

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

l: does TS not infer the definedness of WINDOW.document from above? maybe not because of the callback?

@AbhiPrasad
Copy link
Member

And a small review nudge: I personally really like optional chaining to turn

Optional chaining transpiles into larger bundle size than we want if you don't target es2020 (which we don't atm).

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.

5 participants