Skip to content

Commit

Permalink
fix: loaders window guards
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Feb 6, 2023
1 parent beb1e7b commit a8a377b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/loaders/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@ export class Loader<
// addEventListener does not exist in React Native, but window does
// In the future, we might need to invert control here for more adapters
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (window.addEventListener) {
if (typeof window !== 'undefined' && window.addEventListener) {
// Listen to visibilitychange and focus
window.addEventListener(visibilityChangeEvent, this.#reloadAll, false)
window.addEventListener(focusEvent, this.#reloadAll, false)
}
}

dispose = () => {
if (window.removeEventListener) {
if (typeof window !== 'undefined' && window.removeEventListener) {
// Be sure to unsubscribe if a new handler is set

window.removeEventListener(visibilityChangeEvent, this.#reloadAll)
Expand Down

0 comments on commit a8a377b

Please sign in to comment.