@bgub/fig 2.1.0 → 2.2.1

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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"transition-CWjp9qRO.js","names":["currentDataStore","isThenable"],"sources":["../src/context.ts","../src/data.ts","../src/data-store.ts","../src/transition.ts"],"sourcesContent":["import type { FigNode } from \"./element.ts\";\n\n/** Describes Fig context. */\nexport interface FigContext<T> {\n (props: { value: T; children?: FigNode }): FigNode;\n readonly $$typeof: symbol;\n readonly defaultValue: T;\n}\n\n/** The Fig context symbol. */\nexport const FigContextSymbol = Symbol.for(\"fig.context\");\n\n/** Creates context. */\nexport function createContext<T>(defaultValue: T): FigContext<T> {\n return Object.assign(\n (props: { value: T; children?: FigNode }) => props.children,\n {\n $$typeof: FigContextSymbol,\n defaultValue,\n },\n );\n}\n\n/** Checks whether context. */\nexport function isContext(value: unknown): value is FigContext<unknown> {\n return (\n typeof value === \"function\" &&\n \"$$typeof\" in value &&\n value.$$typeof === FigContextSymbol\n );\n}\n","/** Describes data resource key input. */\nexport type DataResourceKeyInput =\n | string\n | number\n | boolean\n | null\n | readonly DataResourceKeyInput[]\n | { readonly [key: string]: DataResourceKeyInput };\n\n/** Describes data resource key. */\nexport type DataResourceKey = readonly [string, ...DataResourceKeyInput[]];\n\n/** Describes data resource load context. */\nexport interface DataResourceLoadContext {\n /**\n * The store running this load. Entries ensured through it stay cached\n * while this load's value is visible.\n */\n data: FigDataStoreHandle;\n signal: AbortSignal;\n}\n\n/** Describes data resource loader. */\nexport type DataResourceLoader<TArgs extends unknown[], TValue> = (\n ...argsAndContext: [...TArgs, DataResourceLoadContext]\n) => TValue | PromiseLike<TValue>;\n\n/**\n * Capabilities a watch receives. Every operation is bound to the watched key\n * and becomes inert once `signal` aborts.\n */\nexport interface DataResourceWatchContext<TValue> {\n /**\n * The store running this watch. Entries ensured through it stay cached\n * while this watch runs.\n */\n data: FigDataStoreHandle;\n signal: AbortSignal;\n /** Replaces the entry's value, as a successful server push would. */\n publish: (value: TValue) => void;\n /** Records a failure: a visible value stays, a missing one rejects. */\n fail: (error: unknown) => void;\n /**\n * Reruns `load` for this key and resolves with the outcome (`unsupported`\n * for push-only resources; `aborted` once the watch has stopped).\n */\n refresh: () => Promise<DataRefreshResult<TValue>>;\n /** Marks this key stale. */\n invalidate: () => void;\n}\n\n/** Describes data resource watcher. */\nexport type DataResourceWatcher<TArgs extends unknown[], TValue> = (\n ...argsAndContext: [...TArgs, DataResourceWatchContext<TValue>]\n) => void;\n\n/** Describes data resource. */\nexport interface DataResource<\n TArgs extends unknown[] = unknown[],\n TValue = unknown,\n> {\n readonly $$typeof: symbol;\n readonly debugArgs?: (...args: TArgs) => DataResourceKeyInput;\n // Decides whether a new value replaces the visible one. Defaults to\n // Object.is; equal values keep the current value and render nothing.\n readonly equals?: (previous: TValue, next: TValue) => boolean;\n // How long an entry with no readers or retainers stays cached before it is\n // evicted and its generation's signal aborts. Overrides the store default.\n readonly inactiveRetentionMs?: number;\n readonly key: (...args: TArgs) => DataResourceKey;\n readonly load?: DataResourceLoader<TArgs, TValue>;\n readonly watch?: DataResourceWatcher<TArgs, TValue>;\n}\n\n/** Describes data refresh result. */\nexport type DataRefreshResult<T> =\n | { status: \"fulfilled\"; value: T }\n | { status: \"rejected\"; error: unknown; staleValue?: T }\n | {\n status: \"aborted\";\n reason: \"superseded\" | \"store-disposed\" | \"evicted\" | \"released\";\n staleValue?: T;\n }\n | {\n status: \"unsupported\";\n reason: \"no-client-loader\";\n staleValue?: T;\n };\n\n/** Describes Fig data hydration entry. */\nexport interface FigDataHydrationEntry {\n key: DataResourceKey;\n value: unknown;\n}\n\n/** Describes Fig data entry status. */\nexport type FigDataEntryStatus =\n | \"pending\"\n | \"fulfilled\"\n | \"rejected\"\n | \"refreshing\";\n\n/** Describes data store entry snapshot. */\nexport interface DataStoreEntrySnapshot {\n canonicalKey: string;\n error?: unknown;\n hasValue: boolean;\n key: DataResourceKey;\n pending: boolean;\n refreshError?: unknown;\n stale: boolean;\n status: FigDataEntryStatus;\n subscriberCount: number;\n value?: unknown;\n /** Present and true while a watch is pushing values into this entry. */\n watching?: boolean;\n}\n\n// The explicit, app-facing store surface (FigRoot.data, readDataStore()).\n// Capture readDataStore() while Fig executes synchronously, or use root.data\n// or a pre-created store. Imperative operations always use these explicit\n// handles and remain available after an await.\n/** Describes Fig data store handle. */\nexport interface FigDataStoreHandle {\n // The awaitable read for code outside render (route loaders, actions after\n // an await): resolve the value this key would render with — the cached\n // value when the entry has one (kicking the same background revalidation a\n // stale readData does), the in-flight load's settlement on a cache miss —\n // and reject with the error readData would throw. Does not subscribe;\n // pair with readData in the component, which claims the settled entry\n // within the preload retention window.\n ensureData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n ...args: TArgs\n ): Promise<TValue>;\n hydrate(entries: readonly FigDataHydrationEntry[]): void;\n invalidateData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n ...args: TArgs\n ): void;\n invalidateDataError(error: unknown): boolean;\n invalidateDataKey(key: DataResourceKey): void;\n invalidateDataPrefix(prefix: DataResourceKey): void;\n preloadData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n ...args: TArgs\n ): void;\n refreshData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n ...args: TArgs\n ): Promise<DataRefreshResult<TValue>>;\n run<T>(callback: () => T): T;\n}\n\n/**\n * A root-neutral data store. A renderer adopts it exactly once, preserving\n * entries loaded before rendering while attaching subscriber scheduling.\n */\nexport interface FigDataStoreController extends FigDataStoreHandle {\n dispose(): void;\n snapshot(): FigDataHydrationEntry[];\n}\n\n/** Describes Fig data store options. */\nexport interface FigDataStoreOptions {\n initialData?: readonly FigDataHydrationEntry[];\n}\n\n// Attempt-owned observations. A missing snapshot records a read that threw;\n// wrapping successful values distinguishes a fulfilled undefined value.\nexport type FigDataReads = Map<string, { value: unknown } | undefined>;\n\n/** Describes Fig data store. */\nexport interface FigDataStore extends FigDataStoreHandle {\n areDataDependenciesConsistent(reads: FigDataReads): boolean;\n // Installs subscriptions, consumes reads, and reports whether they still match.\n commitDataDependencies(\n owner: object,\n previousOwner: object | null,\n reads?: FigDataReads,\n ): boolean;\n deleteDataOwner(owner: object): void;\n // Adds a key to an attempt's read set without a snapshot, holding the key\n // like a read made through readData. Suspense boundaries use it to take\n // over the reads of the content they suspended.\n holdDataRead(reads: FigDataReads, canonicalKey: string): void;\n releaseDataOwner(owner: object): void;\n // A render attempt discarded a read set without committing it. Keys it was\n // holding open while waiting on a load or watch are released.\n releaseDataReads(reads: FigDataReads): void;\n dispose(): void;\n // Streamed server rows during hydration: unlike `hydrate`, an entry that\n // already holds a value keeps it, so a late row never overwrites state the\n // client loaded, refreshed, or published itself.\n hydrateMissing(entries: readonly FigDataHydrationEntry[]): void;\n inspectDataDependencyCanonicalKeys(owner: object): string[];\n inspectDataEntries(): DataStoreEntrySnapshot[];\n snapshot(): FigDataHydrationEntry[];\n // Renderer plumbing, not handle surface: args stay an array because the\n // optional attempt-owned reads trail them. Server reads omit observations.\n readData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n reads?: FigDataReads,\n ): TValue;\n}\n\n// The host callbacks a renderer hands to the data-store factory. Structurally\n// compatible with @bgub/fig's DataStoreHost so its renderer store can\n// register directly.\n/** Describes Fig data store host. */\nexport interface FigDataStoreHost {\n getLane(): unknown;\n schedule(owner: object, lane: unknown): void;\n // Client renderers set this. Server stores never start watches: a server\n // render reads a snapshot through `load` or hydrated values.\n readonly watchSources?: boolean;\n}\n\n/** Describes Fig data store factory. */\nexport type FigDataStoreFactory = (host: FigDataStoreHost) => FigDataStore;\n\n// The internal, generation-guarded metadata a store attaches to each loader\n// context (symbol-keyed: they stay off the public DataResourceLoadContext).\n// Adapters use the resolved key and decode Payload rows through the calling\n// store without recomputing identity or exposing these capabilities to loaders.\n/** Describes load context hydrate. */\nexport type LoadContextHydrate = (\n entries: readonly FigDataHydrationEntry[],\n) => void;\n/** Describes load context attribute error. */\nexport type LoadContextAttributeError = (error: unknown) => void;\n\n/** Describes load context capabilities. */\nexport interface LoadContextCapabilities {\n attributeError: LoadContextAttributeError;\n hydrate: LoadContextHydrate;\n // Store contexts always provide this; optional keeps synthetic decoder\n // contexts usable without pretending they belong to a cache entry.\n key?: DataResourceKey;\n}\n\nconst LoadContextCapabilitiesSymbol = Symbol.for(\"fig.data-load-context\");\ntype DataResourceLoadContextWithCapabilities = DataResourceLoadContext & {\n [LoadContextCapabilitiesSymbol]?: LoadContextCapabilities;\n};\n\n/** Define load context capabilities. */\nexport function defineLoadContextCapabilities(\n context: DataResourceLoadContext,\n capabilities: LoadContextCapabilities,\n): void {\n Object.defineProperty(context, LoadContextCapabilitiesSymbol, {\n configurable: true,\n enumerable: false,\n value: capabilities,\n });\n}\n\n/** Load context capabilities. */\nexport function loadContextCapabilities(\n context: DataResourceLoadContext,\n): LoadContextCapabilities | undefined {\n return (context as DataResourceLoadContextWithCapabilities)[\n LoadContextCapabilitiesSymbol\n ];\n}\n\nconst objectDataErrors = new WeakMap<object, DataResourceKey[]>();\n\nlet currentDataStore: FigDataStore | null = null;\n\n/** Captures an optional data store for synchronous scope re-entry. */\nexport function getCurrentDataStore(): FigDataStore | null {\n return currentDataStore;\n}\n\n/** Resolves current data store. */\nexport function resolveCurrentDataStore(\n message = \"Data resource APIs require a Fig data store.\",\n): FigDataStore {\n if (currentDataStore === null) throw new Error(message);\n return currentDataStore;\n}\n\n/** Sets current data store. */\nexport function setCurrentDataStore(\n store: FigDataStore | null,\n): FigDataStore | null {\n const previousStore = currentDataStore;\n currentDataStore = store;\n return previousStore;\n}\n\n/** Marks data resource error. */\nexport function markDataResourceError(\n error: unknown,\n key: DataResourceKey,\n): void {\n // Only object errors are attributed: the WeakMap keys them by identity, so the\n // registry is GC-safe and cannot cross-attribute. Primitive rejection values\n // would collide by value and accumulate forever in a plain Map, so a thrown\n // primitive simply carries no resource-key metadata.\n if (!isAttributableError(error)) return;\n\n let keys = objectDataErrors.get(error);\n if (keys === undefined) {\n keys = [];\n objectDataErrors.set(error, keys);\n }\n\n if (keys.some((existing) => sameDataResourceKey(existing, key))) return;\n\n keys.push(key);\n}\n\n/** Data resource keys for error. */\nexport function dataResourceKeysForError(\n error: unknown,\n): DataResourceKey[] | undefined {\n if (!isAttributableError(error)) return undefined;\n\n const keys = objectDataErrors.get(error);\n return keys === undefined || keys.length === 0 ? undefined : [...keys];\n}\n\nfunction sameDataResourceKey(a: DataResourceKey, b: DataResourceKey): boolean {\n return (\n a.length === b.length &&\n a.every((value, index) => Object.is(value, b[index]))\n );\n}\n\n// The single rule for which errors can carry attribution: identity-keyed\n// (WeakMap/WeakSet) registries require object errors. Shared with the store's\n// per-generation value-error sets so the two can never disagree.\nexport function isAttributableError(value: unknown): value is object {\n return (\n (typeof value === \"object\" || typeof value === \"function\") && value !== null\n );\n}\n","import {\n type DataRefreshResult,\n type DataResource,\n type DataResourceKey,\n type DataResourceKeyInput,\n type DataResourceLoadContext,\n type DataResourceLoader,\n type DataResourceWatchContext,\n type DataResourceWatcher,\n type DataStoreEntrySnapshot,\n dataResourceKeysForError,\n defineLoadContextCapabilities,\n type FigDataEntryStatus,\n type FigDataHydrationEntry,\n type FigDataReads,\n type FigDataStore,\n type FigDataStoreController,\n type FigDataStoreFactory,\n type FigDataStoreHandle,\n type FigDataStoreHost,\n type FigDataStoreOptions,\n isAttributableError,\n markDataResourceError,\n resolveCurrentDataStore,\n setCurrentDataStore,\n} from \"./data.ts\";\n\ndeclare const __FIG_DEV__: boolean | undefined;\n\n/** Describes data resource options. */\nexport interface DataResourceOptions<TArgs extends unknown[], TValue> {\n key: (...args: TArgs) => DataResourceKey;\n debugArgs?: (...args: TArgs) => DataResourceKeyInput;\n equals?: (previous: TValue, next: TValue) => boolean;\n inactiveRetentionMs?: number;\n load?: DataResourceLoader<TArgs, TValue>;\n watch?: DataResourceWatcher<TArgs, TValue>;\n}\n\n/** Describes data store host. */\nexport interface DataStoreHost<Owner extends object, Lane> {\n getLane(): Lane;\n inactiveRetentionMs?: number;\n onEntryChange?: (entry: DataStoreEntrySnapshot) => void;\n onEntryEvict?: (entry: DataStoreEntrySnapshot) => void;\n preloadRetentionMs?: number;\n schedule(owner: Owner, lane: Lane): void;\n readonly watchSources?: boolean;\n}\n\n/** Describes data store. */\nexport interface DataStore<\n Owner extends object = object,\n Lane = unknown,\n> extends FigDataStore {\n readonly host: DataStoreHost<Owner, Lane>;\n // Settled entries for the given canonical keys, in the given order. Server\n // renderers use it to stream the rows a boundary read.\n snapshotKeys(canonicalKeys: Iterable<string>): FigDataHydrationEntry[];\n}\n\ninterface Entry<Owner extends object, Lane> {\n canonicalKey: string;\n // The authoritative generation's controller — the load whose value the\n // entry holds. Deliberately retained after that loader settles: the\n // signal's lifetime is the generation's authority, not the pending\n // promise's, so loaders that keep streaming into their value (payload\n // decodes filling holes) learn when a SUCCESSOR becomes authoritative, a\n // server push hydrates over them, the entry evicts, or the store is\n // disposed. A superseding load that starts does not abort it — a visible\n // stale value keeps streaming through the refresh window, and a failed\n // refresh leaves it fully alive.\n valueController: AbortController | null;\n // Errors rejected by streamed holes inside the authoritative fulfilled\n // value. Invalidating one retires that broken value instead of serving it\n // stale into a freshly remounted ErrorBoundary.\n valueErrors: WeakSet<object>;\n // Non-subscribing owners: an awaiting ensureData call, a dependent\n // generation's signal, or a speculative read set. Identity makes each\n // owner's hold idempotent without separate counters and read tracking.\n retainers: Set<object> | null;\n error: unknown;\n fingerprint: string | null;\n invalidationVersion: number;\n // The reading resource's own retention, overriding the store default.\n // Hydrated entries use the default until a resource reads them.\n inactiveRetentionMs: number | undefined;\n inactiveTimer: TimerHandle | null;\n key: DataResourceKey;\n lane: Lane | null;\n pending: PendingLoad<unknown> | null;\n preloadTimer: TimerHandle | null;\n refreshError: unknown;\n refreshFailed: boolean;\n resource: DataResource<unknown[], unknown> | null;\n stale: boolean;\n status: FigDataEntryStatus;\n subscribers: Set<Owner>;\n value: unknown;\n // The running watch generation. Independent of load generations: a watch\n // lives while the entry has committed interest, across any number of loads.\n watchController: AbortController | null;\n // The resource and args of the latest read of a watchable resource. Hydrated\n // entries have no resource until a reader names one, so a watch can only\n // start once something has read the key.\n watchSource: WatchSource | null;\n}\n\ninterface WatchSource {\n args: unknown[];\n resource: DataResource<unknown[], unknown>;\n}\n\ninterface PendingLoad<T> {\n controller: AbortController;\n promise: Promise<DataRefreshResult<T>>;\n resolve: (result: DataRefreshResult<T>) => void;\n // A push-only resource's first read waits on its watch instead of a loader.\n watch?: true;\n}\n\ninterface NormalizedKey {\n canonical: string;\n key: DataResourceKey;\n}\n\ninterface EncodePath {\n root: string;\n segments: Array<string | number>;\n}\n\ninterface LoadOptions<Lane> {\n lane: Lane;\n refresh: boolean;\n}\n\n// Why an in-flight load was aborted: \"superseded\" by a newer load, the store was\n// \"store-disposed\", or the entry was \"evicted\" from a live store because nothing\n// retained it (retention window elapsed, or last subscriber released).\ntype AbortReason = \"superseded\" | \"store-disposed\" | \"evicted\";\n// A watch also stops when its entry loses its last committed reader.\ntype WatchAbortReason = AbortReason | \"released\";\n\nconst DataResourceSymbol = Symbol.for(\"fig.data-resource\");\nconst DataStoreFactorySymbol = Symbol.for(\"fig.data-store-factory\");\nconst DataStoreControllerSymbol = Symbol.for(\"fig.data-store-controller\");\nconst DEFAULT_INACTIVE_RETENTION_MS = 5 * 60 * 1000;\nconst DEFAULT_PRELOAD_RETENTION_MS = 30 * 1000;\nconst __DEV__ = typeof __FIG_DEV__ === \"boolean\" ? __FIG_DEV__ : false;\n\ntype TimerHandle = ReturnType<typeof setTimeout>;\n\nconst dataStoreFactory: FigDataStoreFactory = createRendererDataStore;\n\n/** Data resource. */\nexport function dataResource<TArgs extends unknown[], TValue>(\n options: DataResourceOptions<TArgs, TValue>,\n): DataResource<TArgs, TValue> {\n const resource = {\n $$typeof: DataResourceSymbol,\n [DataStoreFactorySymbol]: dataStoreFactory,\n debugArgs: options.debugArgs,\n equals: options.equals,\n inactiveRetentionMs: options.inactiveRetentionMs,\n key: options.key,\n load: options.load,\n watch: options.watch,\n };\n return resource;\n}\n\n// Captures the ambient store as an explicit handle. Call it synchronously\n// wherever Fig is executing — render, event handlers, actions, effects — and\n// keep the reference: its methods still work after an `await`, where the\n// ambient slot is gone.\n/** Reads data store. */\nexport function readDataStore(): FigDataStoreHandle {\n return resolveCurrentDataStore(\n \"readDataStore() must be called synchronously while Fig is executing — \" +\n \"during render, an event handler, an action, or an effect. Capture \" +\n \"the handle there and use it after awaits.\",\n );\n}\n\ninterface DataStoreControllerState {\n host: FigDataStoreHost | null;\n}\n\n/** Creates data store. */\nexport function createDataStore(\n options: FigDataStoreOptions = {},\n): FigDataStoreController {\n const state: DataStoreControllerState = { host: null };\n const store = createRendererDataStore<object, unknown>({\n getLane: () => (state.host === null ? null : state.host.getLane()),\n schedule: (owner, lane) => state.host?.schedule(owner, lane),\n get watchSources() {\n return state.host?.watchSources === true;\n },\n });\n Object.defineProperty(store, DataStoreControllerSymbol, { value: state });\n if (options.initialData !== undefined) store.hydrate(options.initialData);\n return store;\n}\n\n/** Checks whether data store controller. */\nexport function isDataStoreController(\n value: unknown,\n): value is FigDataStoreController {\n return (\n (typeof value === \"object\" || typeof value === \"function\") &&\n value !== null &&\n Object.hasOwn(value, DataStoreControllerSymbol)\n );\n}\n\n/** Attach data store. */\nexport function attachDataStore(\n controller: FigDataStoreController,\n host: FigDataStoreHost,\n initialData?: readonly FigDataHydrationEntry[],\n): DataStore {\n if (initialData !== undefined) {\n throw new Error(\n \"Pass initialData to createDataStore(), not the renderer, when adopting a data store.\",\n );\n }\n const state = (\n controller as FigDataStoreController &\n Record<symbol, DataStoreControllerState | undefined>\n )[DataStoreControllerSymbol];\n if (state === undefined) {\n throw new Error(\"dataStore must be created with createDataStore().\");\n }\n if (state.host !== null) {\n throw new Error(\"A data store can only be adopted by one Fig renderer.\");\n }\n state.host = host;\n return controller as unknown as DataStore;\n}\n\n/** Creates renderer data store. */\nexport function createRendererDataStore<Owner extends object, Lane>(\n host: DataStoreHost<Owner, Lane>,\n): DataStore<Owner, Lane> {\n return new DefaultDataStore(host);\n}\n\n/** Normalizes data resource key. */\nexport function normalizeDataResourceKey(key: DataResourceKey): string {\n return normalizeKey(key).canonical;\n}\n\nclass DefaultDataStore<Owner extends object, Lane> implements DataStore<\n Owner,\n Lane\n> {\n private readonly entries = new Map<string, Entry<Owner, Lane>>();\n private readonly inactiveRetentionMs: number;\n private readonly ownerKeys = new WeakMap<object, Set<string>>();\n private readonly preloadRetentionMs: number;\n private disposed = false;\n private pendingWatchReconciles: Set<Entry<Owner, Lane>> | null = null;\n\n constructor(readonly host: DataStoreHost<Owner, Lane>) {\n this.inactiveRetentionMs =\n host.inactiveRetentionMs ?? DEFAULT_INACTIVE_RETENTION_MS;\n this.preloadRetentionMs =\n host.preloadRetentionMs ?? DEFAULT_PRELOAD_RETENTION_MS;\n }\n\n areDataDependenciesConsistent(reads: FigDataReads): boolean {\n for (const [key, snapshot] of reads) {\n if (snapshot === undefined) continue;\n const entry = this.entries.get(key);\n if (\n entry === undefined ||\n !entryHasValue(entry) ||\n !Object.is(snapshot.value, entry.value)\n )\n return false;\n }\n return true;\n }\n\n commitDataDependencies(\n owner: Owner,\n previousOwner: object | null,\n reads?: FigDataReads,\n ): boolean {\n // Committed subscriptions retain keys, never the speculative values.\n const nextKeys = reads === undefined ? null : new Set(reads.keys());\n const ownerKeys = this.ownerKeys.get(owner) ?? null;\n const previousOwnerKeys =\n previousOwner === null\n ? null\n : (this.ownerKeys.get(previousOwner) ?? null);\n\n if (\n (nextKeys === null || nextKeys.size === 0) &&\n ownerKeys === null &&\n previousOwnerKeys === null\n ) {\n return true;\n }\n\n // Capture the entries this fiber's generations subscribed to before the\n // delete, then abort any that end up with no retainer once the new owner has\n // re-subscribed. Keys the owner still reads keep at least one subscriber, so\n // only genuinely dropped keys are orphaned.\n let orphanCandidates: Set<Entry<Owner, Lane>> | null = null;\n orphanCandidates = this.collectSubscribedEntries(\n ownerKeys,\n orphanCandidates,\n );\n orphanCandidates = this.collectSubscribedEntries(\n previousOwnerKeys,\n orphanCandidates,\n );\n\n this.deleteDataOwner(owner, nextKeys);\n if (previousOwner !== null) this.deleteDataOwner(previousOwner, nextKeys);\n\n if (nextKeys !== null && nextKeys.size > 0) {\n this.ownerKeys.set(owner, nextKeys);\n\n for (const key of nextKeys) {\n const entry = this.entries.get(key);\n if (entry !== undefined) {\n this.clearInactiveTimer(entry);\n entry.subscribers.add(owner);\n // The committed subscription replaces the uncommitted hold.\n if (reads !== undefined) entry.retainers?.delete(reads);\n this.notifyEntryChange(entry);\n }\n }\n }\n\n if (orphanCandidates !== null) {\n for (const entry of orphanCandidates) this.abortOrphanedLoad(entry);\n }\n if (nextKeys !== null) {\n for (const key of nextKeys) {\n const entry = this.entries.get(key);\n if (entry !== undefined) this.scheduleWatchReconcile(entry);\n }\n }\n // Cleanup and subscription callbacks can change an entry before this owner\n // subscribes. Check after installing every subscription so no notification\n // can fall between the catch-up check and subscription establishment.\n const consistent =\n reads === undefined || this.areDataDependenciesConsistent(reads);\n reads?.clear();\n return consistent;\n }\n\n releaseDataOwner(owner: object): void {\n // The genuine-deletion path (fiber unmount). Unlike deleteDataOwner, which\n // is also used for transient commit churn, this aborts in-flight loads left\n // with no retainer so an unmounted subtree does not keep fetching.\n const orphanCandidates = this.collectSubscribedEntries(\n this.ownerKeys.get(owner) ?? null,\n null,\n );\n this.deleteDataOwner(owner);\n if (orphanCandidates !== null) {\n for (const entry of orphanCandidates) this.abortOrphanedLoad(entry);\n }\n }\n\n deleteDataOwner(\n owner: object,\n retainedKeys: ReadonlySet<string> | null = null,\n ): void {\n const keys = this.ownerKeys.get(owner);\n if (keys === undefined) return;\n\n this.ownerKeys.delete(owner);\n for (const key of keys) {\n const entry = this.entries.get(key);\n if (entry === undefined) continue;\n\n entry.subscribers.delete(owner as Owner);\n this.notifyEntryChange(entry);\n if (retainedKeys?.has(key) !== true) {\n this.scheduleInactiveCleanup(entry);\n this.scheduleWatchReconcile(entry);\n }\n }\n }\n\n private collectSubscribedEntries(\n keys: ReadonlySet<string> | null,\n into: Set<Entry<Owner, Lane>> | null,\n ): Set<Entry<Owner, Lane>> | null {\n if (keys === null) return into;\n\n for (const key of keys) {\n const entry = this.entries.get(key);\n if (entry !== undefined) {\n into ??= new Set();\n into.add(entry);\n }\n }\n\n return into;\n }\n\n private abortOrphanedLoad(entry: Entry<Owner, Lane>): void {\n // Only a value-less in-flight load (a cache-miss \"pending\" entry) with no\n // committed subscriber and no preload retainer is safe to drop: it has no\n // value to lose, and any reader of such a key suspends rather than commits,\n // so it cannot be handed off to a sibling mid-commit. Value-bearing entries\n // are left alone — a \"refreshing\" entry still serves a usable value, and its\n // refresh settles into the normal inactive-retention path. Evicting those\n // would discard a live value or strand a sibling that read it without\n // suspending.\n if (this.entries.get(entry.canonicalKey) !== entry) return;\n if (\n isHeld(entry) ||\n entry.preloadTimer !== null ||\n entry.pending === null ||\n entryHasValue(entry)\n ) {\n return;\n }\n\n this.evictEntry(entry, \"evicted\");\n }\n\n dispose(): void {\n this.disposed = true;\n\n for (const entry of this.entries.values()) {\n this.clearInactiveTimer(entry);\n this.clearPreloadTimer(entry);\n this.abortEntryGenerations(entry, \"store-disposed\");\n this.notifyEntryChange(entry);\n }\n }\n\n hydrate(entries: readonly FigDataHydrationEntry[]): void {\n this.hydrateEntries(entries, true);\n }\n\n hydrateMissing(entries: readonly FigDataHydrationEntry[]): void {\n this.hydrateEntries(entries, false);\n }\n\n private hydrateEntries(\n entries: readonly FigDataHydrationEntry[],\n replaceValues: boolean,\n ): void {\n if (this.disposed) return;\n\n for (const hydrated of entries) {\n // Retiring an earlier entry can dispose the store through an abort listener.\n if (this.disposed) return;\n const normalized = normalizeKey(hydrated.key);\n const storeKey = normalized.canonical;\n const current = this.entries.get(storeKey);\n\n if (current !== undefined) {\n if (replaceValues || !entryHasValue(current)) {\n this.hydrateEntry(current, normalized.key, hydrated.value);\n }\n continue;\n }\n\n const entry = this.createEntry(\n normalized,\n null,\n null,\n \"fulfilled\",\n hydrated.value,\n );\n this.entries.set(storeKey, entry);\n this.notifyEntryChange(entry);\n }\n }\n\n snapshot(): FigDataHydrationEntry[] {\n return this.snapshotKeys(this.entries.keys());\n }\n\n snapshotKeys(canonicalKeys: Iterable<string>): FigDataHydrationEntry[] {\n const entries: FigDataHydrationEntry[] = [];\n\n for (const key of canonicalKeys) {\n const entry = this.entries.get(key);\n if (entry !== undefined && entryHasValue(entry))\n entries.push({ key: entry.key, value: entry.value });\n }\n\n return entries;\n }\n\n inspectDataEntries(): DataStoreEntrySnapshot[] {\n return Array.from(this.entries.values(), (entry) =>\n this.snapshotEntry(entry),\n );\n }\n\n inspectDataDependencyCanonicalKeys(owner: object): string[] {\n // Inspection surface only (devtools snapshots are dev-gated); returns\n // empty in prod even though ownerKeys is populated there.\n if (!__DEV__) return [];\n\n const keys = this.ownerKeys.get(owner);\n if (keys === undefined) return [];\n\n const dependencies: string[] = [];\n for (const key of keys) {\n const entry = this.entries.get(key);\n if (entry !== undefined) dependencies.push(entry.canonicalKey);\n }\n return dependencies;\n }\n\n invalidateData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n ...args: TArgs\n ): void {\n if (this.disposed) return;\n\n const entry = this.entryFor(resource, args, false);\n if (entry === null) return;\n\n this.invalidateEntry(entry, this.host.getLane());\n }\n\n invalidateDataError(error: unknown): boolean {\n if (this.disposed) return false;\n\n const keys = dataResourceKeysForError(error);\n if (keys === undefined || keys.length === 0) return false;\n\n const entries: Entry<Owner, Lane>[] = [];\n for (const key of keys) {\n const entry = this.entryForKey(key);\n if (entry !== null) entries.push(entry);\n }\n\n this.invalidateEntries(entries, error);\n return true;\n }\n\n invalidateDataKey(key: DataResourceKey): void {\n if (this.disposed) return;\n\n const entry = this.entryForKey(key);\n if (entry === null) return;\n\n this.invalidateEntry(entry, this.host.getLane());\n }\n\n invalidateDataPrefix(prefix: DataResourceKey): void {\n if (this.disposed) return;\n\n const prefixCanonical = normalizeKey(prefix).canonical;\n const entries: Entry<Owner, Lane>[] = [];\n for (const entry of this.entries.values()) {\n if (canonicalKeyStartsWith(entry.canonicalKey, prefixCanonical)) {\n entries.push(entry);\n }\n }\n\n this.invalidateEntries(entries);\n }\n\n ensureData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n ...args: TArgs\n ): Promise<TValue> {\n return this.ensureDataUntil(resource, args, undefined);\n }\n\n // `until` scopes one caller's wait: when it aborts, that caller stops\n // waiting and releases its retainer. The load or watch it waited on keeps\n // running for any other caller or reader.\n private async ensureDataUntil<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n until: AbortSignal | undefined,\n ): Promise<TValue> {\n for (;;) {\n if (until?.aborted === true) throw until.reason;\n if (this.disposed) {\n throw new Error(\n \"ensureData() requires a live data store; this store was disposed.\",\n );\n }\n\n const entry = this.entryFor(resource, args, true);\n this.clearInactiveTimer(entry);\n this.retainPreload(entry);\n\n if (entryHasValue(entry)) {\n this.revalidateIfStale(entry, resource, args);\n return entry.value as TValue;\n }\n\n if (entry.status === \"rejected\") throwDataResourceError(entry);\n\n const retainer = {};\n (entry.retainers ??= new Set()).add(retainer);\n try {\n this.recordWatchSource(entry, resource, args);\n let settled: Promise<unknown>;\n if (entry.pending !== null) {\n settled = entry.pending.promise;\n } else if (this.waitsOnWatch(resource)) {\n settled = this.beginWatchPending(entry).promise;\n } else {\n settled = this.startLoad(entry, resource, args, {\n lane: this.host.getLane(),\n refresh: false,\n });\n }\n await (until === undefined ? settled : untilAborted(settled, until));\n } finally {\n entry.retainers?.delete(retainer);\n // Hand retention back to the normal preload window so a reader\n // (the route component about to render) can still claim the entry.\n if (this.entries.get(entry.canonicalKey) === entry) {\n this.retainPreload(entry);\n this.scheduleWatchReconcile(entry);\n }\n }\n // Loop and re-inspect the entry rather than trusting this load's\n // result: a superseding load, a server hydration, or an eviction may\n // have changed the authoritative state while we awaited.\n }\n }\n\n preloadData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n ...args: TArgs\n ): void {\n if (this.disposed || resource.load === undefined) return;\n\n const entry = this.entryFor(resource, args, true);\n this.clearInactiveTimer(entry);\n this.retainPreload(entry);\n if (entry.pending !== null) return;\n if (entry.status === \"fulfilled\" && !entry.stale) return;\n\n void this.startLoad(entry, resource, args, {\n lane: this.host.getLane(),\n refresh: entry.status === \"fulfilled\",\n });\n }\n\n readData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n reads?: FigDataReads,\n ): TValue {\n const entry = this.entryFor(resource, args, true);\n this.clearInactiveTimer(entry);\n this.clearPreloadTimer(entry);\n // A render's read set holds the entry until its attempt commits, which\n // swaps the hold for a subscription, or is discarded, which releases the\n // hold and re-arms cleanup.\n if (reads !== undefined) (entry.retainers ??= new Set()).add(reads);\n // A read that throws still establishes a dependency, but has no snapshot.\n if (reads !== undefined && !reads.has(entry.canonicalKey))\n reads.set(entry.canonicalKey, undefined);\n this.recordWatchSource(entry, resource, args);\n this.revalidateIfStale(entry, resource, args);\n\n if (entry.status === \"pending\" && entry.pending === null) {\n if (this.waitsOnWatch(resource)) {\n this.beginWatchPending(entry);\n } else {\n void this.startLoad(entry, resource, args, {\n lane: this.host.getLane(),\n refresh: false,\n });\n }\n }\n\n const value = this.readCurrentValue<TValue>(entry);\n // Retain the first successful read, even if a later read changes or throws.\n if (reads !== undefined && reads.get(entry.canonicalKey) === undefined)\n reads.set(entry.canonicalKey, { value });\n return value;\n }\n\n refreshData<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n ...args: TArgs\n ): Promise<DataRefreshResult<TValue>> {\n if (this.disposed) {\n return Promise.resolve({\n reason: \"store-disposed\",\n staleValue: undefined,\n status: \"aborted\",\n });\n }\n\n if (resource.load === undefined) {\n const entry = this.entryFor(resource, args, false);\n if (entry === null) {\n return Promise.resolve(unsupportedRefreshResult<TValue>());\n }\n\n this.clearInactiveTimer(entry);\n return Promise.resolve(unsupportedRefreshResult<TValue>(entry));\n }\n\n const entry = this.entryFor(resource, args, true);\n this.clearInactiveTimer(entry);\n\n if (entry.pending !== null && entry.status !== \"refreshing\") {\n return entry.pending.promise as Promise<DataRefreshResult<TValue>>;\n }\n\n return this.startLoad(entry, resource, args, {\n lane: this.host.getLane(),\n refresh: entry.status === \"fulfilled\" || entry.status === \"refreshing\",\n });\n }\n\n run<T>(callback: () => T): T {\n const previousStore = setCurrentDataStore(this);\n try {\n return callback();\n } finally {\n setCurrentDataStore(previousStore);\n }\n }\n\n private entryFor<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n create: true,\n ): Entry<Owner, Lane>;\n private entryFor<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n create: false,\n ): Entry<Owner, Lane> | null;\n private entryFor<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n create: boolean,\n ): Entry<Owner, Lane> | null {\n const normalized = normalizeKey(resource.key(...args));\n // The fingerprint feeds only the dev drift diagnostics below, so\n // production never pays for encoding the args on every read.\n const fingerprint = __DEV__ ? fingerprintFor(resource, args) : null;\n const key = normalized.canonical;\n const current = this.entries.get(key);\n\n if (current !== undefined) {\n if (resource.inactiveRetentionMs !== undefined)\n current.inactiveRetentionMs = resource.inactiveRetentionMs;\n if (__DEV__) {\n diagnoseEntryDrift(\n current,\n resource,\n normalized.canonical,\n fingerprint,\n );\n }\n return current;\n }\n\n if (!create) return null;\n\n const entry = this.createEntry(\n normalized,\n resource as DataResource<unknown[], unknown>,\n fingerprint,\n \"pending\",\n undefined,\n );\n entry.inactiveRetentionMs = resource.inactiveRetentionMs;\n // A disposed store is terminal: hand back a transient entry but never\n // register it, so post-dispose reads cannot resurrect the cache.\n if (this.disposed) return entry;\n\n this.entries.set(key, entry);\n this.notifyEntryChange(entry);\n return entry;\n }\n\n private revalidateIfStale<TArgs extends unknown[], TValue>(\n entry: Entry<Owner, Lane>,\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n ): void {\n if (\n entry.status !== \"fulfilled\" ||\n !entry.stale ||\n entry.pending !== null ||\n entry.refreshFailed ||\n resource.load === undefined\n ) {\n return;\n }\n\n // Serve the stale value and revalidate in the background. A recorded\n // refreshError blocks retries until an explicit invalidate/refresh.\n void this.startLoad(entry, resource, args, {\n lane: this.host.getLane(),\n refresh: true,\n });\n }\n\n private entryForKey(key: DataResourceKey): Entry<Owner, Lane> | null {\n const normalized = normalizeKey(key);\n return this.entries.get(normalized.canonical) ?? null;\n }\n\n private createEntry(\n normalized: NormalizedKey,\n resource: DataResource<unknown[], unknown> | null,\n fingerprint: string | null,\n status: FigDataEntryStatus,\n value: unknown,\n ): Entry<Owner, Lane> {\n return {\n canonicalKey: normalized.canonical,\n retainers: null,\n error: undefined,\n fingerprint,\n invalidationVersion: 0,\n inactiveRetentionMs: undefined,\n inactiveTimer: null,\n key: normalized.key,\n lane: null,\n pending: null,\n preloadTimer: null,\n refreshError: undefined,\n refreshFailed: false,\n resource,\n stale: false,\n status,\n subscribers: new Set(),\n value,\n valueController: null,\n valueErrors: new WeakSet(),\n watchController: null,\n watchSource: null,\n };\n }\n\n private recordWatchSource<TArgs extends unknown[], TValue>(\n entry: Entry<Owner, Lane>,\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n ): void {\n if (resource.watch === undefined || entry.watchSource !== null) return;\n entry.watchSource = {\n args,\n resource: resource as DataResource<unknown[], unknown>,\n };\n }\n\n private waitsOnWatch<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n ): boolean {\n return (\n resource.load === undefined &&\n resource.watch !== undefined &&\n this.host.watchSources === true\n );\n }\n\n // A push-only read with no value suspends on a pending record that the\n // watch's first publish (or failure) settles. Whoever is waiting holds the\n // watch open: the read set of the render in progress, the Suspense boundary\n // that took that read over, or an ensureData caller. When none remain, the\n // watch stops and the value-less entry evicts.\n private beginWatchPending(entry: Entry<Owner, Lane>): PendingLoad<unknown> {\n if (entry.pending !== null) return entry.pending;\n const pending = createPendingLoad<unknown>(new AbortController());\n pending.watch = true;\n entry.pending = pending;\n entry.status = \"pending\";\n this.notifyEntryChange(entry);\n this.scheduleWatchReconcile(entry);\n return pending;\n }\n\n // The `data` handle given to a load or watch. Its ensureData retains the\n // ensured entry for as long as the calling generation lives, so a resource\n // derived from another (rows from an open database) keeps its source cached\n // while the derived value is visible or watched.\n private dependentHandle(signal: AbortSignal): FigDataStoreHandle {\n const retain = (entry: Entry<Owner, Lane>) => {\n if (signal.aborted || entry.retainers?.has(signal)) return;\n (entry.retainers ??= new Set()).add(signal);\n this.clearInactiveTimer(entry);\n signal.addEventListener(\n \"abort\",\n () => this.releaseRetainer(entry, signal),\n { once: true },\n );\n };\n return {\n ensureData: (resource, ...args) => {\n if (signal.aborted) return Promise.reject(signal.reason);\n if (!this.disposed) {\n const entry = this.entryFor(resource, args, true);\n // A cached or hydrated entry returns at once, so acquiring the\n // hold must itself restart a push-only watch the hold now wants.\n this.recordWatchSource(entry, resource, args);\n retain(entry);\n this.scheduleWatchReconcile(entry);\n }\n return this.ensureDataUntil(resource, args, signal);\n },\n hydrate: (entries) => this.hydrate(entries),\n invalidateData: (resource, ...args) =>\n this.invalidateData(resource, ...args),\n invalidateDataError: (error) => this.invalidateDataError(error),\n invalidateDataKey: (key) => this.invalidateDataKey(key),\n invalidateDataPrefix: (prefix) => this.invalidateDataPrefix(prefix),\n preloadData: (resource, ...args) => this.preloadData(resource, ...args),\n refreshData: (resource, ...args) => this.refreshData(resource, ...args),\n run: (callback) => this.run(callback),\n };\n }\n\n // A new value equal to the visible one keeps that value, its identity, and\n // the generation that produced it, so streamed work inside it continues and\n // readers render nothing. It still counts as a successful update: failure\n // and staleness clear.\n private keepEqualValue(entry: Entry<Owner, Lane>, stale: boolean): void {\n entry.error = undefined;\n entry.pending = null;\n entry.refreshError = undefined;\n entry.refreshFailed = false;\n entry.stale = stale;\n entry.status = \"fulfilled\";\n this.notifyEntryChange(entry);\n this.scheduleInactiveCleanup(entry);\n }\n\n // Watches start and stop from a microtask rather than inside commit or\n // cleanup: source code never runs mid-commit, and an unsubscribe followed by\n // a resubscribe in the same turn (owner churn) keeps the running watch.\n private scheduleWatchReconcile(entry: Entry<Owner, Lane>): void {\n if (entry.watchSource === null && entry.watchController === null) return;\n if (this.pendingWatchReconciles !== null) {\n this.pendingWatchReconciles.add(entry);\n return;\n }\n const entries = new Set([entry]);\n this.pendingWatchReconciles = entries;\n queueMicrotask(() => {\n this.pendingWatchReconciles = null;\n for (const pending of entries) this.reconcileWatch(pending);\n });\n }\n\n private wantsWatch(entry: Entry<Owner, Lane>): boolean {\n const source = entry.watchSource;\n if (\n source === null ||\n this.disposed ||\n this.host.watchSources !== true ||\n this.entries.get(entry.canonicalKey) !== entry\n ) {\n return false;\n }\n if (entry.subscribers.size > 0) return true;\n // A push-only entry's watch is also its read: anything holding the entry\n // (an uncommitted read, an awaiting caller, a dependent) holds it open.\n return source.resource.load === undefined && isHeld(entry);\n }\n\n private reconcileWatch(entry: Entry<Owner, Lane>): void {\n const wanted = this.wantsWatch(entry);\n if (wanted && entry.watchController === null) this.startWatch(entry);\n else if (!wanted && entry.watchController !== null)\n this.stopWatch(entry, \"released\");\n // Nobody is waiting for a value that only this watch could deliver.\n if (!wanted && entry.pending?.watch === true && !isHeld(entry)) {\n this.evictEntry(entry, \"evicted\");\n }\n }\n\n holdDataRead(reads: FigDataReads, canonicalKey: string): void {\n if (!reads.has(canonicalKey)) reads.set(canonicalKey, undefined);\n const entry = this.entries.get(canonicalKey);\n if (entry !== undefined) (entry.retainers ??= new Set()).add(reads);\n }\n\n releaseDataReads(reads: FigDataReads): void {\n // Discarding a render is not cancellation: a preserved transition may\n // still await its load. Only committed owner release cancels orphaned loads.\n for (const key of reads.keys()) {\n const entry = this.entries.get(key);\n if (entry !== undefined) this.releaseRetainer(entry, reads);\n }\n }\n\n private releaseRetainer(entry: Entry<Owner, Lane>, owner: object): void {\n if (\n !entry.retainers?.delete(owner) ||\n this.entries.get(entry.canonicalKey) !== entry\n )\n return;\n this.scheduleInactiveCleanup(entry);\n this.scheduleWatchReconcile(entry);\n }\n\n private startWatch(entry: Entry<Owner, Lane>): void {\n const source = entry.watchSource;\n const watch = source?.resource.watch;\n if (source === null || watch === undefined) return;\n\n const controller = new AbortController();\n entry.watchController = controller;\n this.notifyEntryChange(entry);\n const context = this.createWatchContext(entry, source, controller);\n try {\n watch(...source.args, context);\n } catch (error) {\n context.fail(error);\n }\n }\n\n private stopWatch(entry: Entry<Owner, Lane>, reason: WatchAbortReason): void {\n const controller = entry.watchController;\n if (controller === null) return;\n entry.watchController = null;\n // Nothing keeps the value current any more; the next read revalidates.\n if (reason === \"released\" && entryHasValue(entry)) entry.stale = true;\n this.notifyEntryChange(entry);\n controller.abort(reason);\n }\n\n private createWatchContext(\n entry: Entry<Owner, Lane>,\n source: WatchSource,\n controller: AbortController,\n ): DataResourceWatchContext<unknown> {\n const live = () =>\n !this.disposed &&\n !controller.signal.aborted &&\n this.entries.get(entry.canonicalKey) === entry;\n\n const data = this.dependentHandle(controller.signal);\n return {\n data,\n signal: controller.signal,\n publish: (value) => {\n if (!live()) return;\n const equals = source.resource.equals ?? Object.is;\n if (entryHasValue(entry) && equals(entry.value, value)) {\n // Like any publish, this supersedes an in-flight refresh, but the\n // visible generation stays authoritative.\n const pending = entry.pending;\n entry.invalidationVersion = 0;\n entry.lane = null;\n this.keepEqualValue(entry, false);\n pending?.resolve(abortedRefreshResult(entry, \"superseded\"));\n pending?.controller.abort(\"superseded\");\n return;\n }\n this.hydrateEntry(entry, entry.key, value);\n this.scheduleWatchReconcile(entry);\n },\n fail: (error) => {\n if (!live()) return;\n this.failWatchedEntry(entry, error);\n },\n refresh: () => {\n if (live()) return this.refreshData(source.resource, ...source.args);\n const reason: AbortReason | \"released\" = this.disposed\n ? \"store-disposed\"\n : controller.signal.reason === \"released\"\n ? \"released\"\n : \"evicted\";\n return Promise.resolve(abortedRefreshResult(entry, reason));\n },\n invalidate: () => {\n if (!live()) return;\n this.invalidateEntry(entry, this.host.getLane());\n },\n };\n }\n\n private failWatchedEntry(entry: Entry<Owner, Lane>, error: unknown): void {\n if (entryHasValue(entry)) {\n // Same as a failed refresh: the value stays visible and reads do not\n // retry on their own.\n entry.refreshError = error;\n entry.refreshFailed = true;\n entry.stale = true;\n this.publish(entry);\n return;\n }\n\n const pending = entry.pending;\n entry.pending = null;\n entry.error = error;\n entry.status = \"rejected\";\n markDataResourceError(error, entry.key);\n pending?.resolve({ error, status: \"rejected\" });\n this.publish(entry);\n pending?.controller.abort(error);\n }\n\n private hydrateEntry(\n entry: Entry<Owner, Lane>,\n key: DataResourceKey,\n value: unknown,\n ): void {\n this.clearInactiveTimer(entry);\n const valueController = entry.valueController;\n const pending = entry.pending;\n entry.valueController = null;\n entry.pending = null;\n entry.error = undefined;\n // The hydrated value replaces whatever attributed hole errors the old\n // value carried; a boundary still holding one must not retire it.\n entry.valueErrors = new WeakSet();\n entry.invalidationVersion = 0;\n entry.key = key;\n entry.lane = null;\n entry.refreshError = undefined;\n entry.refreshFailed = false;\n entry.stale = false;\n entry.status = \"fulfilled\";\n entry.value = value;\n pending?.resolve(abortedRefreshResult(entry, \"superseded\"));\n this.publish(entry);\n // Abort listeners may synchronously refresh this key. Publish the hydrated\n // generation first, and never overwrite a successor after calling them.\n pending?.controller.abort(\"superseded\");\n valueController?.abort(\"superseded\");\n }\n\n private startLoad<TArgs extends unknown[], TValue>(\n entry: Entry<Owner, Lane>,\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n options: LoadOptions<Lane>,\n ): Promise<DataRefreshResult<TValue>> {\n const hadValue = entryHasValue(entry);\n const load = resource.load;\n\n if (this.disposed) {\n return Promise.resolve(abortedRefreshResult(entry, \"store-disposed\"));\n }\n\n if (load === undefined) {\n const error = new Error(\n `Data resource \"${entry.canonicalKey}\" has no loader and no hydrated value.`,\n );\n entry.error = error;\n entry.status = \"rejected\";\n markDataResourceError(error, entry.key);\n this.notifyEntryChange(entry);\n return Promise.resolve(unsupportedRefreshResult<TValue>(entry));\n }\n\n const previousPending = entry.pending;\n const controller = new AbortController();\n // This generation's attributed hole errors. Allocated per load and\n // installed on the entry only at publish: attribution can fire before the\n // root value settles (a hole's error row can share a network chunk with\n // the root row), so the set must survive fulfillment, and a generation\n // that never publishes must never make the entry's live value\n // invalidatable through its own errors.\n const valueErrors = new WeakSet<object>();\n const invalidationVersion = entry.invalidationVersion;\n const pending = createPendingLoad<TValue>(controller);\n\n entry.lane = options.lane;\n entry.pending = pending as PendingLoad<unknown>;\n entry.status = options.refresh && hadValue ? \"refreshing\" : \"pending\";\n // Install the successor before retiring its predecessor: an abort listener\n // can start a newer refresh or dispose the store synchronously.\n previousPending?.resolve(abortedRefreshResult(entry, \"superseded\"));\n previousPending?.controller.abort(\"superseded\");\n this.notifyEntryChange(entry);\n if (controller.signal.aborted) return pending.promise;\n\n let loaded: TValue | PromiseLike<TValue>;\n try {\n loaded = load(\n ...args,\n this.createLoadContext(entry, controller, valueErrors),\n );\n } catch (error) {\n loaded = Promise.reject(error);\n }\n\n const settleAborted = (): DataRefreshResult<TValue> => {\n const result = abortedRefreshResult<TValue, Owner, Lane>(\n entry,\n \"superseded\",\n );\n pending.resolve(result);\n return result;\n };\n const fulfill = (value: TValue): DataRefreshResult<TValue> => {\n if (entry.pending !== pending || controller.signal.aborted) {\n return settleAborted();\n }\n\n const equals = resource.equals ?? Object.is;\n let equal: boolean;\n try {\n equal = entryHasValue(entry) && equals(entry.value as TValue, value);\n } catch (error) {\n return reject(error);\n }\n if (equal) {\n // An equal reload keeps the visible value, its identity, and the\n // generation that produced it; readers have nothing to re-render. The\n // new generation's value is discarded, so its background work stops.\n this.keepEqualValue(\n entry,\n entry.invalidationVersion !== invalidationVersion,\n );\n const result: DataRefreshResult<TValue> = {\n status: \"fulfilled\",\n value: entry.value as TValue,\n };\n pending.resolve(result);\n controller.abort(\"superseded\");\n return result;\n }\n\n const superseded = entry.valueController;\n // This generation is now the authoritative value; its controller stays\n // live for the background work still streaming into the value.\n entry.valueController = controller;\n entry.valueErrors = valueErrors;\n entry.error = undefined;\n entry.pending = null;\n entry.refreshError = undefined;\n entry.refreshFailed = false;\n entry.stale = entry.invalidationVersion !== invalidationVersion;\n entry.status = \"fulfilled\";\n entry.value = value;\n const result: DataRefreshResult<TValue> = { status: \"fulfilled\", value };\n pending.resolve(result);\n this.publish(entry);\n // The predecessor loses authority only now that the successor's value\n // has published: subscribers re-render top-down onto the new tree in\n // the same pass, so the old generation's retired holes unmount before\n // their abort rejections could reach a mounted reader.\n superseded?.abort(\"superseded\");\n return result;\n };\n const reject = (error: unknown): DataRefreshResult<TValue> => {\n if (entry.pending !== pending || controller.signal.aborted) {\n return settleAborted();\n }\n\n // A rejected load's generation never becomes authoritative; abort its\n // signal so background work it started stops. The previous\n // generation's valueController is deliberately untouched: a failed\n // refresh keeps the stale value fully alive, live holes included.\n entry.pending = null;\n\n if (hadValue && entryHasValue(entry)) {\n entry.refreshError = error;\n entry.refreshFailed = true;\n entry.stale = true;\n entry.status = \"fulfilled\";\n const result: DataRefreshResult<TValue> = {\n error,\n staleValue: entry.value as TValue,\n status: \"rejected\",\n };\n pending.resolve(result);\n this.publish(entry);\n controller.abort(error);\n return result;\n }\n\n entry.error = error;\n entry.status = \"rejected\";\n markDataResourceError(error, entry.key);\n const result: DataRefreshResult<TValue> = { error, status: \"rejected\" };\n pending.resolve(result);\n this.publish(entry);\n controller.abort(error);\n return result;\n };\n\n let thenable: boolean;\n try {\n thenable = isThenable(loaded);\n } catch (error) {\n // Accessing a thenable's `then` property can itself fail.\n reject(error);\n return pending.promise;\n }\n\n if (thenable) {\n void Promise.resolve(loaded).then(fulfill, reject);\n } else {\n fulfill(loaded as TValue);\n }\n return pending.promise;\n }\n\n private createLoadContext(\n entry: Entry<Owner, Lane>,\n controller: AbortController,\n valueErrors: WeakSet<object>,\n ): DataResourceLoadContext {\n const context: DataResourceLoadContext = {\n data: this.dependentHandle(controller.signal),\n signal: controller.signal,\n };\n defineLoadContextCapabilities(context, {\n key: entry.key,\n attributeError: (error) => {\n // A fulfilled payload value may reject one of its streamed holes later.\n // Attribute that error for as long as this generation's signal is live —\n // the signal's lifetime IS its authority, so a visible value keeps\n // attributing through a superseding refresh's window. Retired decodes\n // must not make their successor invalidatable by a stale error object;\n // the errors land in this generation's own set, which reaches the entry\n // only if this generation publishes.\n if (this.disposed || controller.signal.aborted) return;\n markDataResourceError(error, entry.key);\n if (isAttributableError(error)) valueErrors.add(error);\n },\n hydrate: (entries) => {\n // Server-pushed rows hydrate for as long as this generation's signal\n // is live — the same authority window as attributeError. A visible\n // value keeps hydrating through a superseding refresh's window;\n // retired, evicted, and disposed decodes cannot mutate the store\n // (every retirement path aborts the signal).\n if (this.disposed || controller.signal.aborted) return;\n\n // The loading entry's own value comes from the loader's return, never\n // from a data row: hydrating its key here would supersede — and abort —\n // the very load delivering it.\n const foreign = entries.filter(\n (hydrated) =>\n normalizeKey(hydrated.key).canonical !== entry.canonicalKey,\n );\n if (__DEV__ && foreign.length !== entries.length) {\n warn(\n `Data rows targeting the loading key ${entry.canonicalKey} were skipped: a loader cannot hydrate its own entry.`,\n );\n }\n for (const hydrated of foreign) {\n // Replacing an entry invokes its abort listeners synchronously. A\n // listener can retire this generation before the next row is applied.\n if (controller.signal.aborted) return;\n this.hydrate([hydrated]);\n }\n },\n });\n return context;\n }\n\n private publish(entry: Entry<Owner, Lane>): void {\n this.notifyEntryChange(entry);\n this.scheduleInactiveCleanup(entry);\n\n this.scheduleSubscribers(entry, entry.lane ?? this.host.getLane());\n }\n\n private scheduleSubscribers(entry: Entry<Owner, Lane>, lane: Lane): void {\n for (const subscriber of entry.subscribers) {\n this.host.schedule(subscriber, lane);\n }\n }\n\n // Terminal paths end every captured generation. Detach all of them before\n // invoking abort listeners so reentrant work cannot be cleared or aborted.\n private abortEntryGenerations(\n entry: Entry<Owner, Lane>,\n reason: AbortReason,\n ): void {\n const valueController = entry.valueController;\n const pending = entry.pending;\n entry.valueController = null;\n entry.pending = null;\n pending?.resolve(abortedRefreshResult(entry, reason));\n pending?.controller.abort(reason);\n valueController?.abort(reason);\n this.stopWatch(entry, reason);\n }\n\n private retainPreload(entry: Entry<Owner, Lane>): void {\n this.clearPreloadTimer(entry);\n if (this.disposed || !Number.isFinite(this.preloadRetentionMs)) return;\n\n entry.preloadTimer = scheduleStoreTimer(\n () => {\n entry.preloadTimer = null;\n if (!isHeld(entry) && entry.pending !== null && !entryHasValue(entry)) {\n this.evictEntry(entry, \"evicted\");\n return;\n }\n this.scheduleInactiveCleanup(entry);\n },\n Math.max(0, this.preloadRetentionMs),\n );\n }\n\n private scheduleInactiveCleanup(entry: Entry<Owner, Lane>): void {\n const retention = entry.inactiveRetentionMs ?? this.inactiveRetentionMs;\n if (\n this.disposed ||\n isHeld(entry) ||\n entry.pending !== null ||\n entry.preloadTimer !== null ||\n !Number.isFinite(retention)\n ) {\n return;\n }\n\n this.clearInactiveTimer(entry);\n entry.inactiveTimer = scheduleStoreTimer(\n () => {\n entry.inactiveTimer = null;\n if (\n isHeld(entry) ||\n entry.pending !== null ||\n entry.preloadTimer !== null\n ) {\n return;\n }\n this.evictEntry(entry, \"evicted\");\n },\n Math.max(0, retention),\n );\n }\n\n private evictEntry(entry: Entry<Owner, Lane>, reason: AbortReason): void {\n if (this.entries.get(entry.canonicalKey) !== entry) return;\n\n this.clearInactiveTimer(entry);\n this.clearPreloadTimer(entry);\n this.entries.delete(entry.canonicalKey);\n this.abortEntryGenerations(entry, reason);\n this.host.onEntryEvict?.(this.snapshotEntry(entry));\n }\n\n private clearInactiveTimer(entry: Entry<Owner, Lane>): void {\n if (entry.inactiveTimer === null) return;\n\n clearTimeout(entry.inactiveTimer);\n entry.inactiveTimer = null;\n }\n\n private clearPreloadTimer(entry: Entry<Owner, Lane>): void {\n if (entry.preloadTimer === null) return;\n\n clearTimeout(entry.preloadTimer);\n entry.preloadTimer = null;\n }\n\n private notifyEntryChange(entry: Entry<Owner, Lane>): void {\n this.host.onEntryChange?.(this.snapshotEntry(entry));\n }\n\n private snapshotEntry(entry: Entry<Owner, Lane>): DataStoreEntrySnapshot {\n const hasValue = entryHasValue(entry);\n return {\n canonicalKey: entry.canonicalKey,\n error: entry.status === \"rejected\" ? entry.error : undefined,\n hasValue,\n key: entry.key,\n pending: entry.pending !== null,\n refreshError: entry.refreshError,\n stale: entry.stale,\n status: entry.status,\n subscriberCount: entry.subscribers.size,\n value: hasValue ? entry.value : undefined,\n ...(entry.watchController === null ? {} : { watching: true }),\n };\n }\n\n private readCurrentValue<TValue>(entry: Entry<Owner, Lane>): TValue {\n if (entryHasValue(entry)) {\n return entry.value as TValue;\n }\n\n if (entry.status === \"rejected\") throwDataResourceError(entry);\n\n if (entry.pending === null) {\n throw new Error(\n `Data resource \"${entry.canonicalKey}\" has no pending load.`,\n );\n }\n\n throw entry.pending.promise;\n }\n\n private invalidateEntry(\n entry: Entry<Owner, Lane>,\n lane: Lane,\n attributedError?: unknown,\n ): void {\n entry.invalidationVersion += 1;\n entry.stale = true;\n // Clearing the prior refresh failure re-enables auto-refresh-on-read; an\n // explicit invalidation is a fresh \"this is stale, fetch again\" intent.\n entry.refreshError = undefined;\n entry.refreshFailed = false;\n let retiredController: AbortController | null = null;\n if (\n isAttributableError(attributedError) &&\n entry.valueErrors.has(attributedError)\n ) {\n retiredController = entry.valueController;\n entry.valueController = null;\n entry.valueErrors = new WeakSet();\n entry.value = undefined;\n entry.error = undefined;\n entry.status = \"pending\";\n } else if (entry.status === \"rejected\") {\n // The same intent applies to a cached rejection: without this, every\n // read rethrows the old error forever — remounting an ErrorBoundary\n // could never recover. Back to pending, so the next read loads afresh.\n entry.error = undefined;\n entry.status = \"pending\";\n }\n this.notifyEntryChange(entry);\n this.scheduleSubscribers(entry, lane);\n retiredController?.abort(attributedError);\n }\n\n private invalidateEntries(\n entries: readonly Entry<Owner, Lane>[],\n attributedError?: unknown,\n ): void {\n if (entries.length === 0) return;\n\n const lane = this.host.getLane();\n for (const entry of entries) {\n this.invalidateEntry(entry, lane, attributedError);\n }\n }\n}\n\nfunction normalizeKey(key: DataResourceKey): NormalizedKey {\n if (!Array.isArray(key) || typeof key[0] !== \"string\") {\n throw new Error(\n \"Data resource keys must be arrays starting with a string.\",\n );\n }\n\n return {\n canonical: encodeArray(key, createEncodePath(\"key\")),\n key,\n };\n}\n\nfunction canonicalKeyStartsWith(key: string, prefix: string): boolean {\n if (key === prefix) return true;\n\n const arrayPrefix = prefix.slice(0, -1);\n return key.startsWith(arrayPrefix) && key[arrayPrefix.length] === \",\";\n}\n\n// Every kind of ownership that keeps an entry from eviction: committed\n// readers, uncommitted reads (renders in progress and Suspense boundaries\n// waiting on them), and retainers (awaiting ensureData callers and dependent\n// generations). Every eviction path checks this, so a new kind of ownership\n// is added here once.\nfunction isHeld<Owner extends object, Lane>(\n entry: Entry<Owner, Lane>,\n): boolean {\n return entry.subscribers.size > 0 || (entry.retainers?.size ?? 0) > 0;\n}\n\nfunction entryHasValue<Owner extends object, Lane>(\n entry: Entry<Owner, Lane>,\n): boolean {\n return entry.status === \"fulfilled\" || entry.status === \"refreshing\";\n}\n\nfunction throwDataResourceError<Owner extends object, Lane>(\n entry: Entry<Owner, Lane>,\n): never {\n markDataResourceError(entry.error, entry.key);\n throw entry.error;\n}\n\nfunction abortedRefreshResult<T, Owner extends object, Lane>(\n entry: Entry<Owner, Lane>,\n reason: AbortReason | \"released\",\n): DataRefreshResult<T> {\n return {\n reason,\n staleValue: entryHasValue(entry) ? (entry.value as T) : undefined,\n status: \"aborted\",\n };\n}\n\nfunction unsupportedRefreshResult<\n T,\n Owner extends object = object,\n Lane = unknown,\n>(entry?: Entry<Owner, Lane>): DataRefreshResult<T> {\n const result: DataRefreshResult<T> = {\n reason: \"no-client-loader\",\n status: \"unsupported\",\n };\n\n if (entry !== undefined) {\n result.staleValue = entryHasValue(entry) ? (entry.value as T) : undefined;\n }\n\n return result;\n}\n\nfunction fingerprintFor<TArgs extends unknown[], TValue>(\n resource: DataResource<TArgs, TValue>,\n args: TArgs,\n): string | null {\n if (resource.debugArgs !== undefined) {\n return encodeValue(\n resource.debugArgs(...args),\n createEncodePath(\"debugArgs\"),\n );\n }\n\n try {\n return encodeArray(args, createEncodePath(\"args\"));\n } catch {\n return null;\n }\n}\n\nfunction diagnoseEntryDrift<\n Owner extends object,\n Lane,\n TArgs extends unknown[],\n TValue,\n>(\n entry: Entry<Owner, Lane>,\n resource: DataResource<TArgs, TValue>,\n key: string,\n fingerprint: string | null,\n): void {\n if (!__DEV__) return;\n\n if (entry.resource === null) {\n entry.resource = resource as DataResource<unknown[], unknown>;\n } else if (entry.resource !== resource) {\n warn(`Data resource key ${key} was read by multiple resource definitions.`);\n }\n\n if (\n entry.fingerprint !== null &&\n fingerprint !== null &&\n entry.fingerprint !== fingerprint\n ) {\n warn(\n `Data resource key ${key} was read with different argument fingerprints.`,\n );\n }\n}\n\nfunction warn(message: string): void {\n if (typeof console === \"undefined\") return;\n console.warn(message);\n}\n\nfunction createEncodePath(root: string): EncodePath {\n return { root, segments: [] };\n}\n\nfunction formatEncodePath(path: EncodePath): string {\n let text = path.root;\n for (const segment of path.segments) {\n text += typeof segment === \"number\" ? `[${segment}]` : `.${segment}`;\n }\n return text;\n}\n\nfunction encodeArray(values: readonly unknown[], path: EncodePath): string {\n const parts: string[] = [];\n for (let index = 0; index < values.length; index += 1) {\n path.segments.push(index);\n parts.push(encodeValue(values[index], path));\n path.segments.pop();\n }\n return `[${parts.join(\",\")}]`;\n}\n\nfunction encodeObject(value: object, path: EncodePath): string {\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n throw new Error(\n `Invalid data resource key value at ${formatEncodePath(path)}.`,\n );\n }\n\n const record = value as Record<string, unknown>;\n const keys = Object.keys(record).sort();\n const parts: string[] = [];\n\n for (const key of keys) {\n const child = record[key];\n if (child === undefined) {\n throw new Error(\n `Invalid undefined data resource key value at ${formatEncodePath(path)}.`,\n );\n }\n path.segments.push(key);\n parts.push(`${JSON.stringify(key)}:${encodeValue(child, path)}`);\n path.segments.pop();\n }\n\n return `{${parts.join(\",\")}}`;\n}\n\nfunction encodeValue(value: unknown, path: EncodePath): string {\n if (value === null) return \"null\";\n\n switch (typeof value) {\n case \"string\":\n return JSON.stringify(value);\n case \"boolean\":\n return value ? \"true\" : \"false\";\n case \"number\":\n if (!Number.isFinite(value)) {\n throw new Error(\n `Invalid number in data resource key at ${formatEncodePath(path)}.`,\n );\n }\n return Object.is(value, -0) ? \"0\" : JSON.stringify(value);\n case \"object\":\n if (Array.isArray(value)) return encodeArray(value, path);\n return encodeObject(value, path);\n default:\n throw new Error(\n `Invalid data resource key value at ${formatEncodePath(path)}.`,\n );\n }\n}\n\nfunction isThenable<T>(value: T | PromiseLike<T>): value is PromiseLike<T> {\n return (\n (typeof value === \"object\" || typeof value === \"function\") &&\n value !== null &&\n \"then\" in value &&\n typeof value.then === \"function\"\n );\n}\n\n// Settles with `promise`, or rejects with the signal's reason as soon as it\n// aborts. The underlying work is not cancelled; only this wait ends.\nfunction untilAborted<T>(promise: Promise<T>, signal: AbortSignal): Promise<T> {\n if (signal.aborted) return Promise.reject(signal.reason);\n return new Promise<T>((resolve, reject) => {\n const abort = () => reject(signal.reason);\n signal.addEventListener(\"abort\", abort, { once: true });\n promise.then(\n (value) => {\n signal.removeEventListener(\"abort\", abort);\n resolve(value);\n },\n (error: unknown) => {\n signal.removeEventListener(\"abort\", abort);\n reject(error);\n },\n );\n });\n}\n\nfunction createPendingLoad<T>(controller: AbortController): PendingLoad<T> {\n let resolve: (result: DataRefreshResult<T>) => void = () => undefined;\n const promise = new Promise<DataRefreshResult<T>>((settle) => {\n resolve = settle;\n });\n\n return {\n controller,\n promise,\n resolve,\n };\n}\n\nfunction scheduleStoreTimer(callback: () => void, delay: number): TimerHandle {\n const timer = setTimeout(callback, delay);\n const unref = (timer as { unref?: () => void }).unref;\n if (unref !== undefined) unref.call(timer);\n return timer;\n}\n\n/** Runs with data store. */\nexport function runWithDataStore<T>(store: FigDataStore, callback: () => T): T {\n return store.run(callback);\n}\n\n/** Current data store. */\nexport function currentDataStore(): FigDataStore {\n return resolveCurrentDataStore();\n}\n","import { getCurrentDataStore, setCurrentDataStore } from \"./data.ts\";\nimport { isThenable } from \"./thenables.ts\";\n\n/** Describes transition options. */\nexport interface TransitionOptions {\n types?: readonly string[];\n /**\n * Interrupts an active native View Transition before committing this\n * transition. The new commit still waits for the interrupted transition to\n * settle so host restoration cannot race its old-state snapshot.\n */\n viewTransition?: \"interrupt\";\n}\n\n/**\n * Runs synchronous work owned by a live transition. Promise and thenable results\n * are rejected; other return values are ignored. Calls after retirement are inert.\n */\nexport type TransitionUpdate = <Result>(\n callback: (() => Result) &\n (Extract<Result, PromiseLike<unknown>> extends never ? unknown : never),\n) => void;\n\n/** The signal and explicit update scope belong to this callback invocation. */\nexport type TransitionCallback<T = void | PromiseLike<void>> = (\n signal: AbortSignal,\n update: TransitionUpdate,\n) => T;\n\n/** Describes transition handler. */\nexport type TransitionHandler = <T>(\n callback: TransitionCallback<T>,\n options?: TransitionOptions,\n) => T;\n\nlet transitionHandler: TransitionHandler = (callback) =>\n runTransitionScope(callback, (run) => run());\n\n/**\n * Synchronous updates inherit transition priority. After awaiting, use the\n * callback's update function to schedule work in this same transition.\n */\nexport function transition<T>(\n callback: TransitionCallback<T>,\n options?: TransitionOptions,\n): T {\n return transitionHandler(callback, options);\n}\n\n/** Internal lifetime protocol shared by renderer and renderer-free scopes. */\nexport function runTransitionScope<T>(\n callback: TransitionCallback<T>,\n enter: <Result>(run: () => Result) => Result,\n controller: AbortController = new AbortController(),\n): T {\n const signal = controller.signal;\n const store = getCurrentDataStore();\n const runInScope = <Result>(run: () => Result): Result => {\n const previousStore = setCurrentDataStore(store);\n try {\n return enter(run);\n } finally {\n setCurrentDataStore(previousStore);\n }\n };\n const update: TransitionUpdate = (run) => {\n if (signal.aborted) return;\n const result: unknown = runInScope(run);\n if (isThenable(result)) {\n // Consume rejection from an invalid async callback before reporting the\n // contract violation. The asynchronous continuation is outside the scope.\n result.then(\n () => undefined,\n () => undefined,\n );\n throw new Error(\"Transition update callbacks must be synchronous.\");\n }\n };\n const finish = () => controller.abort();\n try {\n const result = runInScope(() => callback(signal, update));\n if (isThenable(result)) result.then(finish, finish);\n else finish();\n return result;\n } catch (error) {\n finish();\n throw error;\n }\n}\n\n/** Sets transition handler. */\nexport function setTransitionHandler(\n handler: TransitionHandler,\n): TransitionHandler {\n const previous = transitionHandler;\n transitionHandler = handler;\n return previous;\n}\n"],"mappings":";;;AAUA,MAAa,mBAAmB,OAAO,IAAI,aAAa;;AAGxD,SAAgB,cAAiB,cAAgC;CAC/D,OAAO,OAAO,QACX,UAA4C,MAAM,UACnD;EACE,UAAU;EACV;CACF,CACF;AACF;;AAGA,SAAgB,UAAU,OAA8C;CACtE,OACE,OAAO,UAAU,cACjB,cAAc,SACd,MAAM,aAAa;AAEvB;;;ACoNA,MAAM,gCAAgC,OAAO,IAAI,uBAAuB;;AAMxE,SAAgB,8BACd,SACA,cACM;CACN,OAAO,eAAe,SAAS,+BAA+B;EAC5D,cAAc;EACd,YAAY;EACZ,OAAO;CACT,CAAC;AACH;;AAGA,SAAgB,wBACd,SACqC;CACrC,OAAQ,QACN;AAEJ;AAEA,MAAM,mCAAmB,IAAI,QAAmC;AAEhE,IAAIA,qBAAwC;;AAG5C,SAAgB,sBAA2C;CACzD,OAAOA;AACT;;AAGA,SAAgB,wBACd,UAAU,gDACI;CACd,IAAIA,uBAAqB,MAAM,MAAM,IAAI,MAAM,OAAO;CACtD,OAAOA;AACT;;AAGA,SAAgB,oBACd,OACqB;CACrB,MAAM,gBAAgBA;CACtB,qBAAmB;CACnB,OAAO;AACT;;AAGA,SAAgB,sBACd,OACA,KACM;CAKN,IAAI,CAAC,oBAAoB,KAAK,GAAG;CAEj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