Merge pull request #31148 from backstage/rugvip/nomock

ui: fix matchMedia fallback
This commit is contained in:
Patrik Oldsberg
2025-09-15 13:11:13 +02:00
committed by GitHub
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