Skip to content

Commit

Permalink
fix(ui): check for addEventListener on MediaQueryList (#12448)
Browse files Browse the repository at this point in the history
In Safari < 14, `MediaQueryList` does not inherit from `EventTarget`,
which triggers an uncaught error, causing a blank page.
  • Loading branch information
caugner authored Feb 3, 2025
1 parent fa24e84 commit cd92674
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client/src/ui-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export function UIProvider(props: any) {
if (dark.matches) {
setColorScheme("dark");
}

if (!("addEventListener" in dark)) {
// MediaQueryList doesn't inherit EventTarget in Safari < 14.
return;
}

dark.addEventListener("change", setDark);
const light = window.matchMedia("(prefers-color-scheme: light)");
light.addEventListener("change", setLight);
Expand Down

0 comments on commit cd92674

Please sign in to comment.