fix(browser/v7): Don't assume window.document is available#11598
Conversation
size-limit report 📦
|
|
I'm wondering if it's feasible to drop the DOM-lib in this project's tsconfig, to prevent accidental breakage for WebWorkers? 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) |
| if (WINDOW.document) { | ||
| WINDOW.document.addEventListener('visibilitychange', () => { |
There was a problem hiding this comment.
l/feel free to ignore: This should be safe here, right?
| 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)) { |
There was a problem hiding this comment.
l: does TS not infer the definedness of WINDOW.document from above? maybe not because of the callback?
Optional chaining transpiles into larger bundle size than we want if you don't target es2020 (which we don't atm). |
Relates to #5289 (comment)
We technically support webworkers so we cannot assume that document API is available.