fix: use-mobile hook crashes on older Safari without MediaQueryList.addEventListener - #235
Conversation
…ddEventListener
useIsMobile() called mql.addEventListener('change', onChange) directly
on a MediaQueryList. Older Safari (Catalina and before) only implements
the deprecated addListener/removeListener pair, causing a runtime crash.
The sibling hook useMediaQuery.ts already has an attachMediaListener
helper with a try/catch fallback for this exact case. Use the same
pattern here for consistency and cross-browser compatibility.
Used by Sidebar and Dropdrawer components.
|
Thanks for this, @Ayush7614 — the problem is real and the instinct to reuse the pattern we already had is the right one. 🙏 I checked the claims before reading the prose:
Two things before this can go in. 1. The
|
useIsMobile() called mql.addEventListener('change', onChange) directly on a MediaQueryList. Older Safari (Catalina and before) only implements the deprecated addListener/removeListener pair, causing a runtime crash.
The sibling hook useMediaQuery.ts already has an attachMediaListener helper with a try/catch fallback for this exact case. Use the same pattern here for consistency and cross-browser compatibility.
Used by Sidebar and Dropdrawer components.