@sanity/ui 2.7.0 → 2.7.1-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -515,13 +515,21 @@ function useGlobalKeyDown(onKeyDown) {
515
515
  function useMatchMedia(mediaQueryString, getServerSnapshot2) {
516
516
  const { subscribe: subscribe2, getSnapshot } = react.useMemo(() => {
517
517
  let MEDIA_QUERY_CACHE;
518
- const getMatchMedia = () => (MEDIA_QUERY_CACHE || (MEDIA_QUERY_CACHE = window.matchMedia(mediaQueryString)), MEDIA_QUERY_CACHE);
518
+ function getMatchMedia() {
519
+ return MEDIA_QUERY_CACHE === void 0 && (MEDIA_QUERY_CACHE = window.matchMedia(mediaQueryString)), MEDIA_QUERY_CACHE;
520
+ }
519
521
  return {
520
522
  subscribe: (onStoreChange) => {
521
523
  const matchMedia = getMatchMedia();
522
524
  return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
523
525
  },
524
- getSnapshot: () => getMatchMedia().matches
526
+ getSnapshot: () => {
527
+ try {
528
+ return getMatchMedia().matches;
529
+ } catch (err) {
530
+ throw new Error(`Failed to match media query: ${mediaQueryString}`, { cause: err });
531
+ }
532
+ }
525
533
  };
526
534
  }, [mediaQueryString]);
527
535
  return react.useDebugValue(mediaQueryString), react.useSyncExternalStore(subscribe2, getSnapshot, getServerSnapshot2);