@sanity/ui 2.1.2 → 2.1.3-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
@@ -514,9 +514,11 @@ function getGlobalScope() {
514
514
  return global;
515
515
  throw new Error("@sanity/ui: could not locate global scope");
516
516
  }
517
- const globalScope = getGlobalScope(), key$8 = Symbol.for("@sanity/ui/context/theme");
518
- globalScope[key$8] = globalScope[key$8] || react.createContext(null);
519
- const ThemeContext = globalScope[key$8];
517
+ const globalScope = getGlobalScope();
518
+ function createGlobalScopedContext(key2, defaultValue) {
519
+ return typeof document > "u" ? react.createContext(defaultValue) : (globalScope[key2] = globalScope[key2] || react.createContext(defaultValue), globalScope[key2]);
520
+ }
521
+ const key$8 = Symbol.for("@sanity/ui/context/theme"), ThemeContext = createGlobalScopedContext(key$8, null);
520
522
  function ThemeProvider(props) {
521
523
  const parentTheme = react.useContext(ThemeContext), {
522
524
  children,
@@ -3088,17 +3090,21 @@ function _isEqual(objA, objB) {
3088
3090
  const keysA = Object.keys(objA), keysB = Object.keys(objB);
3089
3091
  return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
3090
3092
  }
3091
- const __BROWSER__ = typeof document < "u";
3092
3093
  function PortalProvider(props) {
3093
- const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), value = react.useMemo(() => ({
3094
+ const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), fallbackElement = react.useSyncExternalStore(
3095
+ emptySubscribe$1,
3096
+ () => document.body,
3097
+ () => null
3098
+ ), value = react.useMemo(() => ({
3094
3099
  version: 0,
3095
3100
  boundaryElement: boundaryElement || null,
3096
- element: element || __BROWSER__ && document.body || null,
3101
+ element: element || fallbackElement,
3097
3102
  elements
3098
- }), [boundaryElement, element, elements]);
3103
+ }), [boundaryElement, element, elements, fallbackElement]);
3099
3104
  return /* @__PURE__ */ jsxRuntime.jsx(PortalContext.Provider, { value, children });
3100
3105
  }
3101
- const Root$i = styledComponents.styled.div`
3106
+ const emptySubscribe$1 = () => () => {
3107
+ }, Root$i = styledComponents.styled.div`
3102
3108
  display: block;
3103
3109
  width: 0;
3104
3110
  height: 0;
@@ -5054,9 +5060,9 @@ function animationDialogStyle(props) {
5054
5060
  }
5055
5061
  ` : styledComponents.css``;
5056
5062
  }
5057
- const key$3 = Symbol.for("@sanity/ui/context/dialog");
5058
- globalScope[key$3] = globalScope[key$3] || react.createContext({ version: 0 });
5059
- const DialogContext = globalScope[key$3];
5063
+ const key$3 = Symbol.for("@sanity/ui/context/dialog"), DialogContext = createGlobalScopedContext(key$3, {
5064
+ version: 0
5065
+ });
5060
5066
  function useDialog() {
5061
5067
  return react.useContext(DialogContext);
5062
5068
  }