ui: fix matchMedia fallback
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/ui': patch
|
||||
---
|
||||
|
||||
Removed the need to mock `window.matchMedia` in tests, falling back to default breakpoint values instead.
|
||||
@@ -38,6 +38,7 @@ Bitrise
|
||||
Blackbox
|
||||
bool
|
||||
boolean
|
||||
breakpoint
|
||||
Brex
|
||||
broadcasted
|
||||
bugfixes
|
||||
|
||||
@@ -22,7 +22,8 @@ type UseMediaQueryOptions = {
|
||||
initializeWithValue?: boolean;
|
||||
};
|
||||
|
||||
const IS_SERVER = typeof window === 'undefined';
|
||||
const IS_SERVER =
|
||||
typeof window === 'undefined' || typeof window.matchMedia === 'undefined';
|
||||
|
||||
export function useMediaQuery(
|
||||
query: string,
|
||||
@@ -51,6 +52,9 @@ export function useMediaQuery(
|
||||
}
|
||||
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
if (IS_SERVER) {
|
||||
return;
|
||||
}
|
||||
const matchMedia = window.matchMedia(query);
|
||||
|
||||
// Triggered at the first client-side load and if query changes
|
||||
|
||||
Reference in New Issue
Block a user