diff --git a/.changeset/shy-chicken-smash.md b/.changeset/shy-chicken-smash.md new file mode 100644 index 0000000000..7524a50580 --- /dev/null +++ b/.changeset/shy-chicken-smash.md @@ -0,0 +1,5 @@ +--- +'@backstage/ui': patch +--- + +Removed the need to mock `window.matchMedia` in tests, falling back to default breakpoint values instead. diff --git a/.github/vale/config/vocabularies/Backstage/accept.txt b/.github/vale/config/vocabularies/Backstage/accept.txt index 516eec516f..b0225be547 100644 --- a/.github/vale/config/vocabularies/Backstage/accept.txt +++ b/.github/vale/config/vocabularies/Backstage/accept.txt @@ -38,6 +38,7 @@ Bitrise Blackbox bool boolean +breakpoint Brex broadcasted bugfixes diff --git a/packages/ui/src/hooks/useMediaQuery.ts b/packages/ui/src/hooks/useMediaQuery.ts index 9e2cc9ef0b..659ea4a418 100644 --- a/packages/ui/src/hooks/useMediaQuery.ts +++ b/packages/ui/src/hooks/useMediaQuery.ts @@ -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