From f21814b11ea31c8b74d01dc9564bb504a987c71e Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Wed, 5 Jul 2023 08:26:59 -0700 Subject: [PATCH] fix: support browsers that don't implement 'prefers-contrast' media query --- src/lib/system-preferences-hoc.jsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib/system-preferences-hoc.jsx b/src/lib/system-preferences-hoc.jsx index c38cd9f37..a67273ce8 100644 --- a/src/lib/system-preferences-hoc.jsx +++ b/src/lib/system-preferences-hoc.jsx @@ -14,12 +14,18 @@ const systemPreferencesHOC = function (WrappedComponent) { componentDidMount () { this.preferencesListener = () => this.props.onSetTheme(detectTheme()); - this.highContrastMatchMedia = window.matchMedia(prefersHighContrastQuery); - this.highContrastMatchMedia.addEventListener('change', this.preferencesListener); + if (window.matchMedia) { + this.highContrastMatchMedia = window.matchMedia(prefersHighContrastQuery); + if (this.highContrastMatchMedia) { + this.highContrastMatchMedia.addEventListener('change', this.preferencesListener); + } + } } componentWillUnmount () { - this.highContrastMatchMedia.removeEventListener('change', this.preferencesListener); + if (this.highContrastMatchMedia) { + this.highContrastMatchMedia.removeEventListener('change', this.preferencesListener); + } } render () {