import { __commonJS, __export, __toESM, require_react } from "./chunk-2YIMICFJ.js"; // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js var require_use_sync_external_store_shim_development = __commonJS({ "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) { "use strict"; (function() { function is(x, y) { return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y; } function useSyncExternalStore$2(subscribe, getSnapshot) { didWarnOld18Alpha || void 0 === React4.startTransition || (didWarnOld18Alpha = true, console.error( "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release." )); var value = getSnapshot(); if (!didWarnUncachedGetSnapshot) { var cachedValue = getSnapshot(); objectIs(value, cachedValue) || (console.error( "The result of getSnapshot should be cached to avoid an infinite loop" ), didWarnUncachedGetSnapshot = true); } cachedValue = useState({ inst: { value, getSnapshot } }); var inst = cachedValue[0].inst, forceUpdate = cachedValue[1]; useLayoutEffect2( function() { inst.value = value; inst.getSnapshot = getSnapshot; checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }, [subscribe, value, getSnapshot] ); useEffect2( function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); return subscribe(function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }); }, [subscribe] ); useDebugValue2(value); return value; } function checkIfSnapshotChanged(inst) { var latestGetSnapshot = inst.getSnapshot; inst = inst.value; try { var nextValue = latestGetSnapshot(); return !objectIs(inst, nextValue); } catch (error) { return true; } } function useSyncExternalStore$1(subscribe, getSnapshot) { return getSnapshot(); } "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); var React4 = require_react(), objectIs = "function" === typeof Object.is ? Object.is : is, useState = React4.useState, useEffect2 = React4.useEffect, useLayoutEffect2 = React4.useLayoutEffect, useDebugValue2 = React4.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2; exports.useSyncExternalStore = void 0 !== React4.useSyncExternalStore ? React4.useSyncExternalStore : shim; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); })(); } }); // node_modules/use-sync-external-store/shim/index.js var require_shim = __commonJS({ "node_modules/use-sync-external-store/shim/index.js"(exports, module) { "use strict"; if (false) { module.exports = null; } else { module.exports = require_use_sync_external_store_shim_development(); } } }); // node_modules/swr/dist/index/index.mjs var import_react3 = __toESM(require_react(), 1); var import_shim = __toESM(require_shim(), 1); // node_modules/swr/dist/_internal/config-context-client-BoS53ST9.mjs var import_react = __toESM(require_react(), 1); // node_modules/swr/dist/_internal/events.mjs var events_exports = {}; __export(events_exports, { ERROR_REVALIDATE_EVENT: () => ERROR_REVALIDATE_EVENT, FOCUS_EVENT: () => FOCUS_EVENT, MUTATE_EVENT: () => MUTATE_EVENT, RECONNECT_EVENT: () => RECONNECT_EVENT }); var FOCUS_EVENT = 0; var RECONNECT_EVENT = 1; var MUTATE_EVENT = 2; var ERROR_REVALIDATE_EVENT = 3; // node_modules/dequal/lite/index.mjs var has = Object.prototype.hasOwnProperty; function dequal(foo, bar) { var ctor, len; if (foo === bar) return true; if (foo && bar && (ctor = foo.constructor) === bar.constructor) { if (ctor === Date) return foo.getTime() === bar.getTime(); if (ctor === RegExp) return foo.toString() === bar.toString(); if (ctor === Array) { if ((len = foo.length) === bar.length) { while (len-- && dequal(foo[len], bar[len])) ; } return len === -1; } if (!ctor || typeof foo === "object") { len = 0; for (ctor in foo) { if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false; if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false; } return Object.keys(bar).length === len; } } return foo !== foo && bar !== bar; } // node_modules/swr/dist/_internal/config-context-client-BoS53ST9.mjs var SWRGlobalState = /* @__PURE__ */ new WeakMap(); var noop = () => { }; var UNDEFINED = ( /*#__NOINLINE__*/ noop() ); var OBJECT = Object; var isUndefined = (v) => v === UNDEFINED; var isFunction = (v) => typeof v == "function"; var mergeObjects = (a, b) => ({ ...a, ...b }); var isPromiseLike = (x) => isFunction(x.then); var EMPTY_CACHE = {}; var INITIAL_CACHE = {}; var STR_UNDEFINED = "undefined"; var isWindowDefined = typeof window != STR_UNDEFINED; var isDocumentDefined = typeof document != STR_UNDEFINED; var isLegacyDeno = isWindowDefined && "Deno" in window; var hasRequestAnimationFrame = () => isWindowDefined && typeof window["requestAnimationFrame"] != STR_UNDEFINED; var createCacheHelper = (cache2, key) => { const state = SWRGlobalState.get(cache2); return [ // Getter () => !isUndefined(key) && cache2.get(key) || EMPTY_CACHE, // Setter (info) => { if (!isUndefined(key)) { const prev = cache2.get(key); if (!(key in INITIAL_CACHE)) { INITIAL_CACHE[key] = prev; } state[5](key, mergeObjects(prev, info), prev || EMPTY_CACHE); } }, // Subscriber state[6], // Get server cache snapshot () => { if (!isUndefined(key)) { if (key in INITIAL_CACHE) return INITIAL_CACHE[key]; } return !isUndefined(key) && cache2.get(key) || EMPTY_CACHE; } ]; }; var online = true; var isOnline = () => online; var [onWindowEvent, offWindowEvent] = isWindowDefined && window.addEventListener ? [ window.addEventListener.bind(window), window.removeEventListener.bind(window) ] : [ noop, noop ]; var isVisible = () => { const visibilityState = isDocumentDefined && document.visibilityState; return isUndefined(visibilityState) || visibilityState !== "hidden"; }; var initFocus = (callback) => { if (isDocumentDefined) { document.addEventListener("visibilitychange", callback); } onWindowEvent("focus", callback); return () => { if (isDocumentDefined) { document.removeEventListener("visibilitychange", callback); } offWindowEvent("focus", callback); }; }; var initReconnect = (callback) => { const onOnline = () => { online = true; callback(); }; const onOffline = () => { online = false; }; onWindowEvent("online", onOnline); onWindowEvent("offline", onOffline); return () => { offWindowEvent("online", onOnline); offWindowEvent("offline", onOffline); }; }; var preset = { isOnline, isVisible }; var defaultConfigOptions = { initFocus, initReconnect }; var IS_REACT_LEGACY = !import_react.default.useId; var IS_SERVER = !isWindowDefined || isLegacyDeno; var rAF = (f) => hasRequestAnimationFrame() ? window["requestAnimationFrame"](f) : setTimeout(f, 1); var useIsomorphicLayoutEffect = IS_SERVER ? import_react.useEffect : import_react.useLayoutEffect; var navigatorConnection = typeof navigator !== "undefined" && navigator.connection; var slowConnection = !IS_SERVER && navigatorConnection && ([ "slow-2g", "2g" ].includes(navigatorConnection.effectiveType) || navigatorConnection.saveData); var table = /* @__PURE__ */ new WeakMap(); var getTypeName = (value) => OBJECT.prototype.toString.call(value); var isObjectTypeName = (typeName, type) => typeName === `[object ${type}]`; var counter = 0; var stableHash = (arg) => { const type = typeof arg; const typeName = getTypeName(arg); const isDate = isObjectTypeName(typeName, "Date"); const isRegex = isObjectTypeName(typeName, "RegExp"); const isPlainObject = isObjectTypeName(typeName, "Object"); let result; let index; if (OBJECT(arg) === arg && !isDate && !isRegex) { result = table.get(arg); if (result) return result; result = ++counter + "~"; table.set(arg, result); if (Array.isArray(arg)) { result = "@"; for (index = 0; index < arg.length; index++) { result += stableHash(arg[index]) + ","; } table.set(arg, result); } if (isPlainObject) { result = "#"; const keys = OBJECT.keys(arg).sort(); while (!isUndefined(index = keys.pop())) { if (!isUndefined(arg[index])) { result += index + ":" + stableHash(arg[index]) + ","; } } table.set(arg, result); } } else { result = isDate ? arg.toJSON() : type == "symbol" ? arg.toString() : type == "string" ? JSON.stringify(arg) : "" + arg; } return result; }; var serialize = (key) => { if (isFunction(key)) { try { key = key(); } catch (err) { key = ""; } } const args = key; key = typeof key == "string" ? key : (Array.isArray(key) ? key.length : key) ? stableHash(key) : ""; return [ key, args ]; }; var __timestamp = 0; var getTimestamp = () => ++__timestamp; async function internalMutate(...args) { const [cache2, _key, _data, _opts] = args; const options = mergeObjects({ populateCache: true, throwOnError: true }, typeof _opts === "boolean" ? { revalidate: _opts } : _opts || {}); let populateCache = options.populateCache; const rollbackOnErrorOption = options.rollbackOnError; let optimisticData = options.optimisticData; const rollbackOnError = (error) => { return typeof rollbackOnErrorOption === "function" ? rollbackOnErrorOption(error) : rollbackOnErrorOption !== false; }; const throwOnError = options.throwOnError; if (isFunction(_key)) { const keyFilter = _key; const matchedKeys = []; const it = cache2.keys(); for (const key of it) { if ( // Skip the special useSWRInfinite and useSWRSubscription keys. !/^\$(inf|sub)\$/.test(key) && keyFilter(cache2.get(key)._k) ) { matchedKeys.push(key); } } return Promise.all(matchedKeys.map(mutateByKey)); } return mutateByKey(_key); async function mutateByKey(_k) { const [key] = serialize(_k); if (!key) return; const [get, set] = createCacheHelper(cache2, key); const [EVENT_REVALIDATORS, MUTATION, FETCH, PRELOAD] = SWRGlobalState.get(cache2); const startRevalidate = () => { const revalidators = EVENT_REVALIDATORS[key]; const revalidate = isFunction(options.revalidate) ? options.revalidate(get().data, _k) : options.revalidate !== false; if (revalidate) { delete FETCH[key]; delete PRELOAD[key]; if (revalidators && revalidators[0]) { return revalidators[0](MUTATE_EVENT).then(() => get().data); } } return get().data; }; if (args.length < 3) { return startRevalidate(); } let data = _data; let error; let isError = false; const beforeMutationTs = getTimestamp(); MUTATION[key] = [ beforeMutationTs, 0 ]; const hasOptimisticData = !isUndefined(optimisticData); const state = get(); const displayedData = state.data; const currentData = state._c; const committedData = isUndefined(currentData) ? displayedData : currentData; if (hasOptimisticData) { optimisticData = isFunction(optimisticData) ? optimisticData(committedData, displayedData) : optimisticData; set({ data: optimisticData, _c: committedData }); } if (isFunction(data)) { try { data = data(committedData); } catch (err) { error = err; isError = true; } } if (data && isPromiseLike(data)) { data = await data.catch((err) => { error = err; isError = true; }); if (beforeMutationTs !== MUTATION[key][0]) { if (isError) throw error; return data; } else if (isError && hasOptimisticData && rollbackOnError(error)) { populateCache = true; set({ data: committedData, _c: UNDEFINED }); } } if (populateCache) { if (!isError) { if (isFunction(populateCache)) { const populateCachedData = populateCache(data, committedData); set({ data: populateCachedData, error: UNDEFINED, _c: UNDEFINED }); } else { set({ data, error: UNDEFINED, _c: UNDEFINED }); } } } MUTATION[key][1] = getTimestamp(); Promise.resolve(startRevalidate()).then(() => { set({ _c: UNDEFINED }); }); if (isError) { if (throwOnError) throw error; return; } return data; } } var revalidateAllKeys = (revalidators, type) => { for (const key in revalidators) { if (revalidators[key][0]) revalidators[key][0](type); } }; var initCache = (provider, options) => { if (!SWRGlobalState.has(provider)) { const opts = mergeObjects(defaultConfigOptions, options); const EVENT_REVALIDATORS = /* @__PURE__ */ Object.create(null); const mutate2 = internalMutate.bind(UNDEFINED, provider); let unmount = noop; const subscriptions = /* @__PURE__ */ Object.create(null); const subscribe = (key, callback) => { const subs = subscriptions[key] || []; subscriptions[key] = subs; subs.push(callback); return () => subs.splice(subs.indexOf(callback), 1); }; const setter = (key, value, prev) => { provider.set(key, value); const subs = subscriptions[key]; if (subs) { for (const fn of subs) { fn(value, prev); } } }; const initProvider = () => { if (!SWRGlobalState.has(provider)) { SWRGlobalState.set(provider, [ EVENT_REVALIDATORS, /* @__PURE__ */ Object.create(null), /* @__PURE__ */ Object.create(null), /* @__PURE__ */ Object.create(null), mutate2, setter, subscribe ]); if (!IS_SERVER) { const releaseFocus = opts.initFocus(setTimeout.bind(UNDEFINED, revalidateAllKeys.bind(UNDEFINED, EVENT_REVALIDATORS, FOCUS_EVENT))); const releaseReconnect = opts.initReconnect(setTimeout.bind(UNDEFINED, revalidateAllKeys.bind(UNDEFINED, EVENT_REVALIDATORS, RECONNECT_EVENT))); unmount = () => { releaseFocus && releaseFocus(); releaseReconnect && releaseReconnect(); SWRGlobalState.delete(provider); }; } } }; initProvider(); return [ provider, mutate2, initProvider, unmount ]; } return [ provider, SWRGlobalState.get(provider)[4] ]; }; var onErrorRetry = (_, __, config, revalidate, opts) => { const maxRetryCount = config.errorRetryCount; const currentRetryCount = opts.retryCount; const timeout = ~~((Math.random() + 0.5) * (1 << (currentRetryCount < 8 ? currentRetryCount : 8))) * config.errorRetryInterval; if (!isUndefined(maxRetryCount) && currentRetryCount > maxRetryCount) { return; } setTimeout(revalidate, timeout, opts); }; var compare = dequal; var [cache, mutate] = initCache(/* @__PURE__ */ new Map()); var defaultConfig = mergeObjects( { // events onLoadingSlow: noop, onSuccess: noop, onError: noop, onErrorRetry, onDiscarded: noop, // switches revalidateOnFocus: true, revalidateOnReconnect: true, revalidateIfStale: true, shouldRetryOnError: true, // timeouts errorRetryInterval: slowConnection ? 1e4 : 5e3, focusThrottleInterval: 5 * 1e3, dedupingInterval: 2 * 1e3, loadingTimeout: slowConnection ? 5e3 : 3e3, // providers compare, isPaused: () => false, cache, mutate, fallback: {} }, // use web preset by default preset ); var mergeConfigs = (a, b) => { const v = mergeObjects(a, b); if (b) { const { use: u1, fallback: f1 } = a; const { use: u2, fallback: f2 } = b; if (u1 && u2) { v.use = u1.concat(u2); } if (f1 && f2) { v.fallback = mergeObjects(f1, f2); } } return v; }; var SWRConfigContext = (0, import_react.createContext)({}); var SWRConfig = (props) => { const { value } = props; const parentConfig = (0, import_react.useContext)(SWRConfigContext); const isFunctionalConfig = isFunction(value); const config = (0, import_react.useMemo)(() => isFunctionalConfig ? value(parentConfig) : value, [ isFunctionalConfig, parentConfig, value ]); const extendedConfig = (0, import_react.useMemo)(() => isFunctionalConfig ? config : mergeConfigs(parentConfig, config), [ isFunctionalConfig, parentConfig, config ]); const provider = config && config.provider; const cacheContextRef = (0, import_react.useRef)(UNDEFINED); if (provider && !cacheContextRef.current) { cacheContextRef.current = initCache(provider(extendedConfig.cache || cache), config); } const cacheContext = cacheContextRef.current; if (cacheContext) { extendedConfig.cache = cacheContext[0]; extendedConfig.mutate = cacheContext[1]; } useIsomorphicLayoutEffect(() => { if (cacheContext) { cacheContext[2] && cacheContext[2](); return cacheContext[3]; } }, []); return (0, import_react.createElement)(SWRConfigContext.Provider, mergeObjects(props, { value: extendedConfig })); }; // node_modules/swr/dist/_internal/constants.mjs var INFINITE_PREFIX = "$inf$"; // node_modules/swr/dist/_internal/index.mjs var import_react2 = __toESM(require_react(), 1); var enableDevtools = isWindowDefined && window.__SWR_DEVTOOLS_USE__; var use = enableDevtools ? window.__SWR_DEVTOOLS_USE__ : []; var setupDevTools = () => { if (enableDevtools) { window.__SWR_DEVTOOLS_REACT__ = import_react2.default; } }; var normalize = (args) => { return isFunction(args[1]) ? [ args[0], args[1], args[2] || {} ] : [ args[0], null, (args[1] === null ? args[2] : args[1]) || {} ]; }; var useSWRConfig = () => { const parentConfig = (0, import_react2.useContext)(SWRConfigContext); const mergedConfig = (0, import_react2.useMemo)(() => mergeObjects(defaultConfig, parentConfig), [ parentConfig ]); return mergedConfig; }; var preload = (key_, fetcher) => { const [key, fnArg] = serialize(key_); const [, , , PRELOAD] = SWRGlobalState.get(cache); if (PRELOAD[key]) return PRELOAD[key]; const req = fetcher(fnArg); PRELOAD[key] = req; return req; }; var middleware = (useSWRNext) => (key_, fetcher_, config) => { const fetcher = fetcher_ && ((...args) => { const [key] = serialize(key_); const [, , , PRELOAD] = SWRGlobalState.get(cache); if (key.startsWith(INFINITE_PREFIX)) { return fetcher_(...args); } const req = PRELOAD[key]; if (isUndefined(req)) return fetcher_(...args); delete PRELOAD[key]; return req; }); return useSWRNext(key_, fetcher, config); }; var BUILT_IN_MIDDLEWARE = use.concat(middleware); var withArgs = (hook) => { return function useSWRArgs(...args) { const fallbackConfig = useSWRConfig(); const [key, fn, _config] = normalize(args); const config = mergeConfigs(fallbackConfig, _config); let next = hook; const { use: use3 } = config; const middleware2 = (use3 || []).concat(BUILT_IN_MIDDLEWARE); for (let i = middleware2.length; i--; ) { next = middleware2[i](next); } return next(key, fn || config.fetcher || null, config); }; }; var subscribeCallback = (key, callbacks, callback) => { const keyedRevalidators = callbacks[key] || (callbacks[key] = []); keyedRevalidators.push(callback); return () => { const index = keyedRevalidators.indexOf(callback); if (index >= 0) { keyedRevalidators[index] = keyedRevalidators[keyedRevalidators.length - 1]; keyedRevalidators.pop(); } }; }; setupDevTools(); // node_modules/swr/dist/index/index.mjs var noop2 = () => { }; var UNDEFINED2 = ( /*#__NOINLINE__*/ noop2() ); var OBJECT2 = Object; var isUndefined2 = (v) => v === UNDEFINED2; var isFunction2 = (v) => typeof v == "function"; var table2 = /* @__PURE__ */ new WeakMap(); var getTypeName2 = (value) => OBJECT2.prototype.toString.call(value); var isObjectTypeName2 = (typeName, type) => typeName === `[object ${type}]`; var counter2 = 0; var stableHash2 = (arg) => { const type = typeof arg; const typeName = getTypeName2(arg); const isDate = isObjectTypeName2(typeName, "Date"); const isRegex = isObjectTypeName2(typeName, "RegExp"); const isPlainObject = isObjectTypeName2(typeName, "Object"); let result; let index; if (OBJECT2(arg) === arg && !isDate && !isRegex) { result = table2.get(arg); if (result) return result; result = ++counter2 + "~"; table2.set(arg, result); if (Array.isArray(arg)) { result = "@"; for (index = 0; index < arg.length; index++) { result += stableHash2(arg[index]) + ","; } table2.set(arg, result); } if (isPlainObject) { result = "#"; const keys = OBJECT2.keys(arg).sort(); while (!isUndefined2(index = keys.pop())) { if (!isUndefined2(arg[index])) { result += index + ":" + stableHash2(arg[index]) + ","; } } table2.set(arg, result); } } else { result = isDate ? arg.toJSON() : type == "symbol" ? arg.toString() : type == "string" ? JSON.stringify(arg) : "" + arg; } return result; }; var serialize2 = (key) => { if (isFunction2(key)) { try { key = key(); } catch (err) { key = ""; } } const args = key; key = typeof key == "string" ? key : (Array.isArray(key) ? key.length : key) ? stableHash2(key) : ""; return [ key, args ]; }; var unstable_serialize = (key) => serialize2(key)[0]; var use2 = import_react3.default.use || // This extra generic is to avoid TypeScript mixing up the generic and JSX sytax // and emitting an error. // We assume that this is only for the `use(thenable)` case, not `use(context)`. // https://github.com/facebook/react/blob/aed00dacfb79d17c53218404c52b1c7aa59c4a89/packages/react-server/src/ReactFizzThenable.js#L45 ((thenable) => { switch (thenable.status) { case "pending": throw thenable; case "fulfilled": return thenable.value; case "rejected": throw thenable.reason; default: thenable.status = "pending"; thenable.then((v) => { thenable.status = "fulfilled"; thenable.value = v; }, (e) => { thenable.status = "rejected"; thenable.reason = e; }); throw thenable; } }); var WITH_DEDUPE = { dedupe: true }; var resolvedUndef = Promise.resolve(UNDEFINED); var useSWRHandler = (_key, fetcher, config) => { const { cache: cache2, compare: compare2, suspense, fallbackData, revalidateOnMount, revalidateIfStale, refreshInterval, refreshWhenHidden, refreshWhenOffline, keepPreviousData } = config; const [EVENT_REVALIDATORS, MUTATION, FETCH, PRELOAD] = SWRGlobalState.get(cache2); const [key, fnArg] = serialize(_key); const initialMountedRef = (0, import_react3.useRef)(false); const unmountedRef = (0, import_react3.useRef)(false); const keyRef = (0, import_react3.useRef)(key); const fetcherRef = (0, import_react3.useRef)(fetcher); const configRef = (0, import_react3.useRef)(config); const getConfig = () => configRef.current; const isActive = () => getConfig().isVisible() && getConfig().isOnline(); const [getCache, setCache, subscribeCache, getInitialCache] = createCacheHelper(cache2, key); const stateDependencies = (0, import_react3.useRef)({}).current; const fallback = isUndefined(fallbackData) ? isUndefined(config.fallback) ? UNDEFINED : config.fallback[key] : fallbackData; const isEqual = (prev, current) => { for (const _ in stateDependencies) { const t = _; if (t === "data") { if (!compare2(prev[t], current[t])) { if (!isUndefined(prev[t])) { return false; } if (!compare2(returnedData, current[t])) { return false; } } } else { if (current[t] !== prev[t]) { return false; } } } return true; }; const getSnapshot = (0, import_react3.useMemo)(() => { const shouldStartRequest = (() => { if (!key) return false; if (!fetcher) return false; if (!isUndefined(revalidateOnMount)) return revalidateOnMount; if (getConfig().isPaused()) return false; if (suspense) return false; return revalidateIfStale !== false; })(); const getSelectedCache = (state) => { const snapshot = mergeObjects(state); delete snapshot._k; if (!shouldStartRequest) { return snapshot; } return { isValidating: true, isLoading: true, ...snapshot }; }; const cachedData2 = getCache(); const initialData = getInitialCache(); const clientSnapshot = getSelectedCache(cachedData2); const serverSnapshot = cachedData2 === initialData ? clientSnapshot : getSelectedCache(initialData); let memorizedSnapshot = clientSnapshot; return [ () => { const newSnapshot = getSelectedCache(getCache()); const compareResult = isEqual(newSnapshot, memorizedSnapshot); if (compareResult) { memorizedSnapshot.data = newSnapshot.data; memorizedSnapshot.isLoading = newSnapshot.isLoading; memorizedSnapshot.isValidating = newSnapshot.isValidating; memorizedSnapshot.error = newSnapshot.error; return memorizedSnapshot; } else { memorizedSnapshot = newSnapshot; return newSnapshot; } }, () => serverSnapshot ]; }, [ cache2, key ]); const cached = (0, import_shim.useSyncExternalStore)((0, import_react3.useCallback)( (callback) => subscribeCache(key, (current, prev) => { if (!isEqual(prev, current)) callback(); }), // eslint-disable-next-line react-hooks/exhaustive-deps [ cache2, key ] ), getSnapshot[0], getSnapshot[1]); const isInitialMount = !initialMountedRef.current; const hasRevalidator = EVENT_REVALIDATORS[key] && EVENT_REVALIDATORS[key].length > 0; const cachedData = cached.data; const data = isUndefined(cachedData) ? fallback && isPromiseLike(fallback) ? use2(fallback) : fallback : cachedData; const error = cached.error; const laggyDataRef = (0, import_react3.useRef)(data); const returnedData = keepPreviousData ? isUndefined(cachedData) ? isUndefined(laggyDataRef.current) ? data : laggyDataRef.current : cachedData : data; const shouldDoInitialRevalidation = (() => { if (hasRevalidator && !isUndefined(error)) return false; if (isInitialMount && !isUndefined(revalidateOnMount)) return revalidateOnMount; if (getConfig().isPaused()) return false; if (suspense) return isUndefined(data) ? false : revalidateIfStale; return isUndefined(data) || revalidateIfStale; })(); const defaultValidatingState = !!(key && fetcher && isInitialMount && shouldDoInitialRevalidation); const isValidating = isUndefined(cached.isValidating) ? defaultValidatingState : cached.isValidating; const isLoading = isUndefined(cached.isLoading) ? defaultValidatingState : cached.isLoading; const revalidate = (0, import_react3.useCallback)( async (revalidateOpts) => { const currentFetcher = fetcherRef.current; if (!key || !currentFetcher || unmountedRef.current || getConfig().isPaused()) { return false; } let newData; let startAt; let loading = true; const opts = revalidateOpts || {}; const shouldStartNewRequest = !FETCH[key] || !opts.dedupe; const callbackSafeguard = () => { if (IS_REACT_LEGACY) { return !unmountedRef.current && key === keyRef.current && initialMountedRef.current; } return key === keyRef.current; }; const finalState = { isValidating: false, isLoading: false }; const finishRequestAndUpdateState = () => { setCache(finalState); }; const cleanupState = () => { const requestInfo = FETCH[key]; if (requestInfo && requestInfo[1] === startAt) { delete FETCH[key]; } }; const initialState = { isValidating: true }; if (isUndefined(getCache().data)) { initialState.isLoading = true; } try { if (shouldStartNewRequest) { setCache(initialState); if (config.loadingTimeout && isUndefined(getCache().data)) { setTimeout(() => { if (loading && callbackSafeguard()) { getConfig().onLoadingSlow(key, config); } }, config.loadingTimeout); } FETCH[key] = [ currentFetcher(fnArg), getTimestamp() ]; } ; [newData, startAt] = FETCH[key]; newData = await newData; if (shouldStartNewRequest) { setTimeout(cleanupState, config.dedupingInterval); } if (!FETCH[key] || FETCH[key][1] !== startAt) { if (shouldStartNewRequest) { if (callbackSafeguard()) { getConfig().onDiscarded(key); } } return false; } finalState.error = UNDEFINED; const mutationInfo = MUTATION[key]; if (!isUndefined(mutationInfo) && // case 1 (startAt <= mutationInfo[0] || // case 2 startAt <= mutationInfo[1] || // case 3 mutationInfo[1] === 0)) { finishRequestAndUpdateState(); if (shouldStartNewRequest) { if (callbackSafeguard()) { getConfig().onDiscarded(key); } } return false; } const cacheData = getCache().data; finalState.data = compare2(cacheData, newData) ? cacheData : newData; if (shouldStartNewRequest) { if (callbackSafeguard()) { getConfig().onSuccess(newData, key, config); } } } catch (err) { cleanupState(); const currentConfig = getConfig(); const { shouldRetryOnError } = currentConfig; if (!currentConfig.isPaused()) { finalState.error = err; if (shouldStartNewRequest && callbackSafeguard()) { currentConfig.onError(err, key, currentConfig); if (shouldRetryOnError === true || isFunction(shouldRetryOnError) && shouldRetryOnError(err)) { if (!getConfig().revalidateOnFocus || !getConfig().revalidateOnReconnect || isActive()) { currentConfig.onErrorRetry(err, key, currentConfig, (_opts) => { const revalidators = EVENT_REVALIDATORS[key]; if (revalidators && revalidators[0]) { revalidators[0](events_exports.ERROR_REVALIDATE_EVENT, _opts); } }, { retryCount: (opts.retryCount || 0) + 1, dedupe: true }); } } } } } loading = false; finishRequestAndUpdateState(); return true; }, // `setState` is immutable, and `eventsCallback`, `fnArg`, and // `keyValidating` are depending on `key`, so we can exclude them from // the deps array. // // FIXME: // `fn` and `config` might be changed during the lifecycle, // but they might be changed every render like this. // `useSWR('key', () => fetch('/api/'), { suspense: true })` // So we omit the values from the deps array // even though it might cause unexpected behaviors. // eslint-disable-next-line react-hooks/exhaustive-deps [ key, cache2 ] ); const boundMutate = (0, import_react3.useCallback)( // Use callback to make sure `keyRef.current` returns latest result every time (...args) => { return internalMutate(cache2, keyRef.current, ...args); }, // eslint-disable-next-line react-hooks/exhaustive-deps [] ); useIsomorphicLayoutEffect(() => { fetcherRef.current = fetcher; configRef.current = config; if (!isUndefined(cachedData)) { laggyDataRef.current = cachedData; } }); useIsomorphicLayoutEffect(() => { if (!key) return; const softRevalidate = revalidate.bind(UNDEFINED, WITH_DEDUPE); let nextFocusRevalidatedAt = 0; if (getConfig().revalidateOnFocus) { const initNow = Date.now(); nextFocusRevalidatedAt = initNow + getConfig().focusThrottleInterval; } const onRevalidate = (type, opts = {}) => { if (type == events_exports.FOCUS_EVENT) { const now = Date.now(); if (getConfig().revalidateOnFocus && now > nextFocusRevalidatedAt && isActive()) { nextFocusRevalidatedAt = now + getConfig().focusThrottleInterval; softRevalidate(); } } else if (type == events_exports.RECONNECT_EVENT) { if (getConfig().revalidateOnReconnect && isActive()) { softRevalidate(); } } else if (type == events_exports.MUTATE_EVENT) { return revalidate(); } else if (type == events_exports.ERROR_REVALIDATE_EVENT) { return revalidate(opts); } return; }; const unsubEvents = subscribeCallback(key, EVENT_REVALIDATORS, onRevalidate); unmountedRef.current = false; keyRef.current = key; initialMountedRef.current = true; setCache({ _k: fnArg }); if (shouldDoInitialRevalidation) { if (!FETCH[key]) { if (isUndefined(data) || IS_SERVER) { softRevalidate(); } else { rAF(softRevalidate); } } } return () => { unmountedRef.current = true; unsubEvents(); }; }, [ key ]); useIsomorphicLayoutEffect(() => { let timer; function next() { const interval = isFunction(refreshInterval) ? refreshInterval(getCache().data) : refreshInterval; if (interval && timer !== -1) { timer = setTimeout(execute, interval); } } function execute() { if (!getCache().error && (refreshWhenHidden || getConfig().isVisible()) && (refreshWhenOffline || getConfig().isOnline())) { revalidate(WITH_DEDUPE).then(next); } else { next(); } } next(); return () => { if (timer) { clearTimeout(timer); timer = -1; } }; }, [ refreshInterval, refreshWhenHidden, refreshWhenOffline, key ]); (0, import_react3.useDebugValue)(returnedData); if (suspense) { const hasKeyButNoData = key && isUndefined(data); if (!IS_REACT_LEGACY && IS_SERVER && hasKeyButNoData) { throw new Error("Fallback data is required when using Suspense in SSR."); } if (hasKeyButNoData) { fetcherRef.current = fetcher; configRef.current = config; unmountedRef.current = false; } const req = PRELOAD[key]; const mutateReq = !isUndefined(req) && hasKeyButNoData ? boundMutate(req) : resolvedUndef; use2(mutateReq); if (!isUndefined(error) && hasKeyButNoData) { throw error; } const revalidation = hasKeyButNoData ? revalidate(WITH_DEDUPE) : resolvedUndef; if (!isUndefined(returnedData) && hasKeyButNoData) { revalidation.status = "fulfilled"; revalidation.value = true; } use2(revalidation); } const swrResponse = { mutate: boundMutate, get data() { stateDependencies.data = true; return returnedData; }, get error() { stateDependencies.error = true; return error; }, get isValidating() { stateDependencies.isValidating = true; return isValidating; }, get isLoading() { stateDependencies.isLoading = true; return isLoading; } }; return swrResponse; }; var SWRConfig2 = OBJECT.defineProperty(SWRConfig, "defaultValue", { value: defaultConfig }); var useSWR = withArgs(useSWRHandler); export { SWRConfig2 as SWRConfig, useSWR as default, mutate, preload, unstable_serialize, useSWRConfig }; /*! Bundled license information: use-sync-external-store/cjs/use-sync-external-store-shim.development.js: (** * @license React * use-sync-external-store-shim.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. *) */ //# sourceMappingURL=swr.js.map