Skip to content

Commit

Permalink
Revert "[useMediaQuery] Fix crash in Safari < 14 and IE 11 (mui#29776)"
Browse files Browse the repository at this point in the history
This reverts commit fb9808c.
  • Loading branch information
eps1lon committed Nov 25, 2021
1 parent f3e41f0 commit f7b698d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions packages/mui-material/src/useMediaQuery/useMediaQuery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ function createMatchMedia(width, ref) {
matches: mediaQuery.match(query, {
width,
}),
// Mocking matchMedia in Safari < 14 where MediaQueryList doesn't inherit from EventTarget
addListener: (listener) => {
addEventListener: (type, listener) => {
listeners.push(listener);
},
removeListener: (listener) => {
removeEventListener: (type, listener) => {
const index = listeners.indexOf(listener);
if (index > -1) {
listeners.splice(index, 1);
Expand Down
10 changes: 4 additions & 6 deletions packages/mui-material/src/useMediaQuery/useMediaQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ function useMediaQueryOld(
}
};
updateMatch();
// TODO: Use `addEventListener` once support for Safari < 14 is dropped
queryList.addListener(updateMatch);
queryList.addEventListener('change', updateMatch);
return () => {
active = false;
queryList.removeListener(updateMatch);
queryList.removeEventListener('change', updateMatch);
};
}, [query, matchMedia, supportMatchMedia]);

Expand Down Expand Up @@ -110,10 +109,9 @@ function useMediaQueryNew(
return [
() => mediaQueryList.matches,
(notify: () => void) => {
// TODO: Use `addEventListener` once support for Safari < 14 is dropped
mediaQueryList.addListener(notify);
mediaQueryList.addEventListener('change', notify);
return () => {
mediaQueryList.removeListener(notify);
mediaQueryList.removeEventListener('change', notify);
};
},
];
Expand Down

0 comments on commit f7b698d

Please sign in to comment.