ui: fix matchMedia fallback

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-09-15 12:09:46 +02:00
parent 8a6393a43e
commit 0ffa4c7955
3 changed files with 11 additions and 1 deletions
+5
View File
@@ -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
+5 -1
View File
@@ -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