Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mui/material-ui
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 38ae20e40d8fce20a78865d9d1d8904be889c91e
Choose a base ref
..
head repository: mui/material-ui
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a7c7c1cc3f2bea53fac8f868554b390d6e34cd7d
Choose a head ref
Showing with 10 additions and 10 deletions.
  1. +10 −10 packages/mui-material/src/useMediaQuery/useMediaQuery.ts
20 changes: 10 additions & 10 deletions packages/mui-material/src/useMediaQuery/useMediaQuery.ts
Original file line number Diff line number Diff line change
@@ -93,6 +93,16 @@ function useMediaQueryNew(
noSsr: boolean | undefined,
): boolean {
const getDefaultSnapshot = React.useCallback(() => defaultMatches, [defaultMatches]);
const getServerSnapshot = React.useMemo(() => {
if (noSsr && matchMedia) {
return () => matchMedia!(query).matches;
}
if (ssrMatchMedia !== null) {
const { matches } = ssrMatchMedia(query);
return () => matches;
}
return getDefaultSnapshot;
}, [noSsr, matchMedia, getDefaultSnapshot, query, ssrMatchMedia]);
const [getSnapshot, subscribe] = React.useMemo(() => {
if (matchMedia === null) {
return [getDefaultSnapshot, () => () => {}];
@@ -111,16 +121,6 @@ function useMediaQueryNew(
},
];
}, [getDefaultSnapshot, matchMedia, query]);
const getServerSnapshot = React.useMemo(() => {
if (noSsr && matchMedia) {
return () => matchMedia!(query).matches;
}
if (ssrMatchMedia !== null) {
const { matches } = ssrMatchMedia(query);
return () => matches;
}
return getDefaultSnapshot;
}, [noSsr, matchMedia, getDefaultSnapshot, query, ssrMatchMedia]);
const match = maybeReactUseSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);

return match;