diff --git a/lib/useKResponsiveWindow/MediaQuery.js b/lib/useKResponsiveWindow/MediaQuery.js index 239310cb1..e919566a8 100644 --- a/lib/useKResponsiveWindow/MediaQuery.js +++ b/lib/useKResponsiveWindow/MediaQuery.js @@ -32,8 +32,8 @@ export default class MediaQuery { * @returns {Object} Containing mediaQueryList, eventHandler, and stopListening */ startListening() { - //Prevent function execution if Nuxt is server side rendering - if (this.isNuxtServerSideRendering()) { + // Prevent function execution if Nuxt is server side rendering + if (this.isNuxtServerSideRendering() || !window.matchMedia) { return; } @@ -48,6 +48,10 @@ export default class MediaQuery { * Stop listening for media query events */ stopListening() { + // Prevent function execution if Nuxt is server side rendering + if (this.isNuxtServerSideRendering() || !window.matchMedia) { + return; + } if (this.mediaQueryList.removeEventListener) { this.mediaQueryList.removeEventListener('change', this.eventHandler); } else {