Skip to content

Commit

Permalink
[useMediaQuery] Workaround Safari wrong implementation of matchMedia (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
momentpaul authored and oliviertassinari committed Sep 5, 2019
1 parent f812cb8 commit 93e9ab6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/material-ui/src/useMediaQuery/useMediaQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function useMediaQuery(queryInput, options = {}) {
});

React.useEffect(() => {
let active = true;
hydrationCompleted = true;

if (!supportMatchMedia) {
Expand All @@ -59,11 +60,17 @@ function useMediaQuery(queryInput, options = {}) {

const queryList = window.matchMedia(query);
const updateMatch = () => {
setMatch(queryList.matches);
// Workaround Safari wrong implementation of matchMedia
// TODO can we remove it?
// https://github.com/mui-org/material-ui/pull/17315#issuecomment-528286677
if (active) {
setMatch(queryList.matches);
}
};
updateMatch();
queryList.addListener(updateMatch);
return () => {
active = false;
queryList.removeListener(updateMatch);
};
}, [query, supportMatchMedia]);
Expand Down

0 comments on commit 93e9ab6

Please sign in to comment.