sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
38 lines (35 loc) • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: !0 });
var React = require("react"), version = require("./_chunks-cjs/version.js");
const MISSING_CONTEXT_HELP_URL = "https://www.sanity.io/help/missing-context-error";
function createGlobalScopedContext(key, defaultValue) {
const symbol = Symbol.for(key);
if (typeof document > "u" || typeof window < "u" && typeof window.navigator < "u" && window.navigator.userAgent.includes("jsdom")) {
const context = React.createContext(defaultValue);
return context.displayName = key, context;
}
if (!globalScope[symbol])
globalScope[symbol] = {
context: React.createContext(defaultValue),
version: version.SANITY_VERSION
};
else {
if (globalScope[symbol].version !== version.SANITY_VERSION)
throw new TypeError(`Duplicate instances of context "${key}" with incompatible versions detected: Expected ${version.SANITY_VERSION} but got ${globalScope[symbol].version}.
For more information, please visit ${MISSING_CONTEXT_HELP_URL}`);
warned.has(version.SANITY_VERSION) || (console.warn(`Duplicate instances of context "${key}" detected. This is likely a mistake and may cause unexpected behavior.
For more information, please visit ${MISSING_CONTEXT_HELP_URL}`), warned.add(version.SANITY_VERSION));
}
return globalScope[symbol].context;
}
const warned = /* @__PURE__ */ new Set();
function getGlobalScope() {
if (typeof globalThis < "u") return globalThis;
if (typeof window < "u") return window;
if (typeof self < "u") return self;
if (typeof global < "u") return global;
throw new Error("sanity: could not locate global scope");
}
const globalScope = getGlobalScope();
exports.createContext = createGlobalScopedContext;
//# sourceMappingURL=_createContext.js.map