Is it just me, or is there a bug in Safari on iOS 17 where the event listener added by window.matchMedia("(prefers-color-scheme: dark)") is not triggered? There was no such issue in Safari on iOS 16. The issue occurs only when the web app is installed on the home screen as a PWA. In the browser, everything is working fine.
The code:
useEffect(() => {
function handleColorSchemeChange(event) {
// this listener won't trigger when the web app is installed as PWA on the iPhone's home screen
const newColorScheme = event.matches ? "dark" : "light";
setCurrentDarkMode(newColorScheme);
}
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", handleColorSchemeChange);
return () => {
window
.matchMedia("(prefers-color-scheme: dark)")
.removeEventListener("change", handleColorSchemeChange);
};
}, []);
I tried installing the PWA application (for example, timezones.digital) on an iPhone and toggled the system's dark/light mode