@bgub/fig 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { a as createDataStore, b as createContext, c as dataResource, d as readDataStore, r as transition } from "./transition-CWjp9qRO.js";
1
+ import { S as createContext, a as createDataStore, c as dataResource, d as readDataStore, p as MissingCapabilityError, r as transition, v as requireCapability } from "./transition-BZTyeaMo.js";
2
2
  import { B as useBeforeLayout, E as lazy, F as readContext, G as useMemo, H as useCallback, I as readData, J as useState, K as useReactive, L as readPromise, U as useDeferredValue, V as useBeforePaint, W as useId, X as useTransition, Y as useSyncExternalStore, f as Fragment, g as createElement, h as clientReference, k as createMixin, m as ViewTransition, p as Suspense, q as useStableEvent, r as ErrorBoundary, t as Activity, w as isValidElement, z as useActionState } from "./element-DbzJUf5a.js";
3
3
  import { _ as stylesheet, d as meta, f as modulepreload, g as script, l as font, m as preload, p as preconnect, s as assets, v as title } from "./resource-BZOBllE_.js";
4
- export { Activity, ErrorBoundary, Fragment, Suspense, ViewTransition, assets, clientReference, createContext, createDataStore, createElement, createMixin, dataResource, font, isValidElement, lazy, meta, modulepreload, preconnect, preload, readContext, readData, readDataStore, readPromise, script, stylesheet, title, transition, useActionState, useBeforeLayout, useBeforePaint, useCallback, useDeferredValue, useId, useMemo, useReactive, useStableEvent, useState, useSyncExternalStore, useTransition };
4
+ export { Activity, ErrorBoundary, Fragment, MissingCapabilityError, Suspense, ViewTransition, assets, clientReference, createContext, createDataStore, createElement, createMixin, dataResource, font, isValidElement, lazy, meta, modulepreload, preconnect, preload, readContext, readData, readDataStore, readPromise, requireCapability, script, stylesheet, title, transition, useActionState, useBeforeLayout, useBeforePaint, useCallback, useDeferredValue, useId, useMemo, useReactive, useStableEvent, useState, useSyncExternalStore, useTransition };
@@ -1,4 +1,4 @@
1
- import { _ as resolveCurrentDataStore, a as createDataStore, f as runWithDataStore, g as markDataResourceError, h as loadContextCapabilities, i as attachDataStore, l as isDataStoreController, m as defineLoadContextCapabilities, n as setTransitionHandler, o as createRendererDataStore, p as dataResourceKeysForError, s as currentDataStore, t as runTransitionScope, u as normalizeDataResourceKey, v as setCurrentDataStore, x as isContext, y as FigContextSymbol } from "./transition-CWjp9qRO.js";
1
+ import { C as isContext, _ as markDataResourceError, a as createDataStore, b as setCurrentDataStore, f as runWithDataStore, g as loadContextCapabilities, h as defineLoadContextCapabilities, i as attachDataStore, l as isDataStoreController, m as dataResourceKeysForError, n as setTransitionHandler, o as createRendererDataStore, s as currentDataStore, t as runTransitionScope, u as normalizeDataResourceKey, x as FigContextSymbol, y as resolveCurrentDataStore } from "./transition-BZTyeaMo.js";
2
2
  import { A as markClientOnlyHostBehavior, C as isSuspense, D as FigMixinSymbol, M as mixinSlot, N as resolveHostMix, O as clientOnlyHostBehavior, P as readBrowser, R as setCurrentDispatcher, S as isPortal, T as isViewTransition, _ as createPortalNode, a as FigAssetsSymbol, b as isClientReference, c as FigErrorBoundarySymbol, d as FigViewTransitionSymbol, i as FigActivitySymbol, j as markClientOnlyHostProps, l as FigPortalSymbol, n as Assets, o as FigClientReferenceSymbol, s as FigElementSymbol, u as FigSuspenseSymbol, v as isActivity, w as isValidElement, x as isErrorBoundary, y as isAssets } from "./element-DbzJUf5a.js";
3
3
  import { a as assetResourceHostProps, b as readThenable, c as clientReferenceAssets, h as preventAssetResourceHoist, i as assetResourceFromHostValues, n as assetResourceFromHostAttributes, o as assetResourceKey, r as assetResourceFromHostProps, t as assetResourceDestination, u as isFigAssetResource, x as trackThenable, y as isThenable } from "./resource-BZOBllE_.js";
4
4
  import { _ as serializePayloadArray, b as serializePayloadSet, c as definePayloadGraphElement, d as encodePayloadValueWithGraph, g as rollbackPayloadGraph, h as jsonPayloadCodec, i as decodePayloadDataEntries, l as encodePayloadDataEntries, m as isPlainPayloadValue, n as checkpointPayloadGraph, o as decodePayloadValue, p as isPayloadSpecialModel, r as createPayloadGraphEncodeContext, t as assertPayloadCodecMatches, u as encodePayloadValue, v as serializePayloadMap, y as serializePayloadPlainObject } from "./payload-format-B9UbNtxo.js";
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","names":[],"sources":["../src/children.ts","../src/dom-nesting.ts","../src/suspense-protocol.ts"],"sourcesContent":["import {\n type AwaitedFigNode,\n type FigElement,\n type FigNode,\n type FigPortal,\n isPortal,\n isValidElement,\n} from \"./element.ts\";\nimport { isThenable } from \"./thenables.ts\";\n\n// What normalization leaves behind: arrays are flattened, null/undefined/\n// booleans are dropped, and numbers are stringified into (merged) text.\n/** Describes normalized child. */\nexport type NormalizedChild =\n | FigElement<any>\n | FigPortal<any>\n | PromiseLike<AwaitedFigNode>\n | string;\n\n// Child normalization shared by the reconciler and the server renderer.\n// Adjacent text merging here MUST match on both sides: the server emits\n// merged text nodes into HTML, and hydration matches them against the\n// client's fiber children — divergence is a hydration mismatch.\n/** Collect children. */\nexport function collectChildren(node: FigNode): NormalizedChild[] {\n if (Array.isArray(node)) return collectArrayChildren(node);\n\n const children: NormalizedChild[] = [];\n collectChild(node, children);\n return children;\n}\n\nfunction collectArrayChildren(children: FigNode[]): NormalizedChild[] {\n let previousWasText = false;\n for (let index = 0; index < children.length; index += 1) {\n const child = children[index];\n if (typeof child === \"string\") {\n if (child !== \"\" && !previousWasText) {\n previousWasText = true;\n continue;\n }\n } else {\n previousWasText = false;\n if (\n !Array.isArray(child) &&\n child !== null &&\n child !== undefined &&\n typeof child !== \"boolean\" &&\n typeof child !== \"number\"\n ) {\n if (isValidElement(child) || isPortal(child) || isThenable(child)) {\n continue;\n }\n throw invalidChildError(child);\n }\n }\n\n const normalized = children.slice(0, index) as NormalizedChild[];\n for (; index < children.length; index += 1) {\n collectChild(children[index], normalized);\n }\n return normalized;\n }\n return children as NormalizedChild[];\n}\n\nfunction collectChild(node: FigNode, children: NormalizedChild[]): void {\n if (Array.isArray(node)) {\n for (const child of node) collectChild(child, children);\n return;\n }\n\n if (node === null || node === undefined || typeof node === \"boolean\") return;\n\n if (typeof node === \"string\" || typeof node === \"number\") {\n appendTextChild(children, String(node));\n return;\n }\n\n if (isValidElement(node) || isPortal(node)) {\n children.push(node);\n return;\n }\n\n if (isThenable(node)) {\n children.push(node);\n return;\n }\n\n throw invalidChildError(node);\n}\n\nfunction appendTextChild(children: NormalizedChild[], text: string): void {\n if (text === \"\") return;\n\n const previous = children.at(-1);\n\n if (typeof previous === \"string\") {\n children[children.length - 1] = `${previous}${text}`;\n } else {\n children.push(text);\n }\n}\n\n/** Invalid child error. */\nexport function invalidChildError(value: unknown): Error {\n return new Error(\n `Invalid Fig child: ${describeInvalidChild(value)}. Render a string, number, element, promise, array, boolean, null, or undefined.`,\n );\n}\n\n/** Describes invalid child. */\nexport function describeInvalidChild(value: unknown): string {\n if (typeof value !== \"object\" || value === null) return typeof value;\n\n const keys = Object.keys(value);\n return keys.length === 0 ? \"object\" : `object with keys ${keys.join(\", \")}`;\n}\n","const phrasingContainers = \"|a|button|p|\";\n\n// HTML parser auto-close rules are scoped: these tags reset the \"is there an\n// open <a>/<button>/<p>?\" checks, so e.g. <a><table><td><a> and\n// <p><button><div> parse without re-parenting and must not be flagged.\n// <button> additionally terminates button scope (the <p> auto-close check).\nconst scopeTerminators =\n \"|applet|caption|desc|foreignobject|html|marquee|object|table|td|template|th|title|\";\n\nconst pAutoClosingTags =\n \"|address|article|aside|blockquote|center|details|dialog|dir|div|dl|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|main|menu|nav|ol|p|pre|section|table|ul|\";\n\nconst headChildren =\n \"|base|basefont|bgsound|link|meta|title|noscript|noframes|script|style|template|\";\n\nconst specialTags =\n \"|address|applet|area|article|aside|base|basefont|bgsound|blockquote|body|br|button|caption|center|col|colgroup|dd|details|dir|div|dl|dt|embed|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|iframe|img|input|keygen|li|link|listing|main|marquee|menu|meta|nav|noembed|noframes|noscript|object|ol|p|param|plaintext|pre|script|section|select|source|style|summary|table|tbody|td|template|textarea|tfoot|th|thead|title|tr|track|ul|wbr|xmp|mi|mo|mn|ms|mtext|annotation-xml|foreignobject|desc|\";\n\n/** Validates instance nesting. */\nexport function validateInstanceNesting(\n type: string,\n ancestors: readonly string[],\n): void {\n const child = normalizedTag(type);\n const parent =\n ancestors[0] === undefined ? null : normalizedTag(ancestors[0]);\n\n if (parent !== null && !validWithParent(child, parent)) {\n throw invalidNestingError(\n `<${child}> cannot be a child of <${parent}>.${hintFor(child, parent)}`,\n );\n }\n\n const invalidAncestor = invalidAncestorFor(child, ancestors);\n if (invalidAncestor !== null) {\n throw invalidNestingError(\n `<${child}> cannot appear inside <${invalidAncestor}>.`,\n );\n }\n}\n\n/** Validates text nesting. */\nexport function validateTextNesting(\n text: string,\n ancestors: readonly string[],\n): void {\n // Whitespace-only text is inserted in place even inside tables (\"in table\n // text\" mode only foster-parents non-whitespace), so it is harmless.\n if (!/[^ \\t\\n\\r\\f]/.test(text)) return;\n\n const parent =\n ancestors[0] === undefined ? null : normalizedTag(ancestors[0]);\n if (parent === null || validTextWithParent(parent)) return;\n\n throw invalidNestingError(`text cannot be a child of <${parent}>.`);\n}\n\nfunction validWithParent(child: string, parent: string): boolean {\n switch (parent) {\n case \"select\":\n return (\n child === \"hr\" ||\n child === \"option\" ||\n child === \"optgroup\" ||\n child === \"script\" ||\n child === \"template\"\n );\n case \"optgroup\":\n return child === \"option\";\n case \"option\":\n return false;\n case \"tr\":\n return child === \"th\" || child === \"td\" || scriptLike(child);\n case \"tbody\":\n case \"thead\":\n case \"tfoot\":\n return child === \"tr\" || scriptLike(child);\n case \"colgroup\":\n return child === \"col\" || child === \"template\";\n case \"table\":\n return (\n child === \"caption\" ||\n child === \"colgroup\" ||\n child === \"tbody\" ||\n child === \"tfoot\" ||\n child === \"thead\" ||\n scriptLike(child)\n );\n case \"head\":\n return tagIn(headChildren, child);\n case \"html\":\n return child === \"head\" || child === \"body\";\n case \"frameset\":\n return child === \"frame\";\n }\n\n switch (child) {\n case \"caption\":\n case \"col\":\n case \"colgroup\":\n case \"tbody\":\n case \"tfoot\":\n case \"thead\":\n case \"tr\":\n return parent === \"template\";\n case \"td\":\n case \"th\":\n return parent === \"tr\" || parent === \"template\";\n case \"option\":\n return parent === \"datalist\" || parent === \"template\";\n case \"optgroup\":\n return parent === \"template\";\n case \"head\":\n case \"body\":\n case \"frameset\":\n return parent === \"html\" || parent === \"template\";\n case \"frame\":\n return parent === \"template\";\n case \"html\":\n return false;\n }\n\n return true;\n}\n\nfunction validTextWithParent(parent: string): boolean {\n // <option>, <select>, and <optgroup> reject element children, but the\n // parser inserts character tokens into them in place, so text is legal.\n return (\n parent === \"option\" ||\n parent === \"select\" ||\n parent === \"optgroup\" ||\n validWithParent(\"#text\", parent)\n );\n}\n\nfunction invalidAncestorFor(\n child: string,\n ancestors: readonly string[],\n): string | null {\n let inScope = true;\n let inButtonScope = true;\n let inListScope = true;\n let inTemplate = false;\n\n for (const ancestorType of ancestors) {\n const ancestor = normalizedTag(ancestorType);\n\n if (child === ancestor && tagIn(phrasingContainers, child)) {\n if (child === \"p\" ? inButtonScope : inScope) return ancestor;\n }\n if (inButtonScope && ancestor === \"p\" && tagIn(pAutoClosingTags, child)) {\n return ancestor;\n }\n if (inListScope && listItemAncestor(child, ancestor)) return ancestor;\n // The parser's form element pointer ignores scope but resets in templates.\n if (!inTemplate && ancestor === \"form\" && child === \"form\") return ancestor;\n\n if (tagIn(scopeTerminators, ancestor)) {\n if (ancestor === \"template\") inTemplate = true;\n inScope = false;\n inButtonScope = false;\n } else if (ancestor === \"button\") {\n inButtonScope = false;\n }\n // li/dd/dt auto-closing sees through phrasing/formatting wrappers and\n // address/div/p; other special elements terminate the parser walk.\n if (\n tagIn(specialTags, ancestor) &&\n ancestor !== \"address\" &&\n ancestor !== \"div\" &&\n ancestor !== \"p\"\n ) {\n inListScope = false;\n }\n }\n\n return null;\n}\n\nfunction listItemAncestor(child: string, ancestor: string): boolean {\n if (child === \"li\") return ancestor === \"li\";\n if (child === \"dd\" || child === \"dt\") {\n return ancestor === \"dd\" || ancestor === \"dt\";\n }\n return false;\n}\n\nfunction normalizedTag(type: string): string {\n return type.toLowerCase();\n}\n\nfunction scriptLike(tag: string): boolean {\n return tag === \"script\" || tag === \"style\" || tag === \"template\";\n}\n\nfunction hintFor(child: string, parent: string): string {\n if (parent === \"table\" && child === \"tr\") {\n return \" Add a <tbody>, <thead>, or <tfoot>.\";\n }\n\n return \"\";\n}\n\nfunction invalidNestingError(message: string): Error {\n return new Error(`Invalid DOM nesting: ${message}`);\n}\n\nfunction tagIn(tags: string, tag: string): boolean {\n return tags.includes(`|${tag}|`);\n}\n","// The Suspense streaming wire format shared by the server renderer (which\n// emits these markers as HTML comments and interpolates them into the inline\n// reveal script) and fig-dom (which parses them into dehydrated boundaries).\n// Changing any value is a protocol change: server output and client parsing\n// must move together.\n\n/** The suspense marker prefix. */\nexport const SUSPENSE_MARKER_PREFIX = \"fig:suspense:\";\n/** The suspense completed marker. */\nexport const SUSPENSE_COMPLETED_MARKER = \"fig:suspense:completed\";\n/** The suspense browser-rendered marker. */\nexport const SUSPENSE_BROWSER_MARKER = \"fig:suspense:browser\";\n/** The suspense client marker. */\nexport const SUSPENSE_CLIENT_MARKER = \"fig:suspense:client\";\n/** The suspense pending prefix. */\nexport const SUSPENSE_PENDING_PREFIX = \"fig:suspense:pending:\";\n/** The suspense end marker. */\nexport const SUSPENSE_END_MARKER = \"/fig:suspense\";\n\n// The server emits a comment with exactly this data between adjacent text\n// writes that come from different normalized text children: the HTML parser\n// would otherwise merge them into one DOM text node while the client keeps\n// one text fiber each. fig-dom's hydration cursor skips only comments whose\n// data matches this value (fig:suspense markers use their own prefixes).\n/** The text separator data. */\nexport const TEXT_SEPARATOR_DATA = \",\";\n\n// Hidden Activity content streams inside an inert template carrying this\n// attribute; the client treats such templates as dehydrated boundaries.\n/** The activity template attribute. */\nexport const ACTIVITY_TEMPLATE_ATTRIBUTE = \"data-fig-activity\";\n\n/** The view transition name attribute. */\nexport const VIEW_TRANSITION_NAME_ATTRIBUTE = \"data-fig-vt-name\";\n/** The view transition class attribute. */\nexport const VIEW_TRANSITION_CLASS_ATTRIBUTE = \"data-fig-vt-class\";\n\n// Per-document mutex holding the currently running view transition. Client\n// commits and inline streaming reveals both wait on it before proceeding.\n/** The view transition pending property. */\nexport const VIEW_TRANSITION_PENDING_PROPERTY = \"__figViewTransition\";\n// React's maximum suspended-commit wait, shared with streaming reveals so a\n// non-settling transition cannot hold either path indefinitely.\n/** The view transition timeout ms. */\nexport const VIEW_TRANSITION_TIMEOUT_MS = 60_000;\n\n// Early-event capture: a tiny inline script at the top of a server-rendered\n// document queues replayable events that fire before the client bundle\n// executes. The first hydration root drains the queue, removes the capture\n// listeners, and replays claimed events through the standard replay path.\n// The event list must stay in sync with fig-dom's replayable set — a\n// discrete replay forces synchronous hydration of its target, which is what\n// makes pre-bundle clicks safe to honor.\n/** The hydration skip attribute. */\nexport const HYDRATION_SKIP_ATTRIBUTE = \"data-fig-hydration-skip\";\n/** The early event queue property. */\nexport const EARLY_EVENT_QUEUE_PROPERTY = \"__figEarlyEvents\";\n/** The early event handler property. */\nexport const EARLY_EVENT_HANDLER_PROPERTY = \"__figEarlyEventHandler\";\n// Streamed data rows: the `d` operation queues encoded rows on this document\n// property, keyed by the render's identifierPrefix, until the hydrating root\n// that owns the prefix drains it and replaces it with a live receiver.\n/** The streamed data property. */\nexport const STREAMED_DATA_PROPERTY = \"__figStreamedData\";\n/** The replayable event types. */\nexport const REPLAYABLE_EVENT_TYPES = [\n \"click\",\n \"keydown\",\n \"keyup\",\n \"pointerdown\",\n \"pointerup\",\n] as const;\n"],"mappings":";;;;;;AAwBA,SAAgB,gBAAgB,MAAkC;CAChE,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,qBAAqB,IAAI;CAEzD,MAAM,WAA8B,CAAC;CACrC,aAAa,MAAM,QAAQ;CAC3B,OAAO;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{"version":3,"file":"internal.js","names":[],"sources":["../src/children.ts","../src/dom-nesting.ts","../src/suspense-protocol.ts"],"sourcesContent":["import {\n type AwaitedFigNode,\n type FigElement,\n type FigNode,\n type FigPortal,\n isPortal,\n isValidElement,\n} from \"./element.ts\";\nimport { isThenable } from \"./thenables.ts\";\n\n// What normalization leaves behind: arrays are flattened, null/undefined/\n// booleans are dropped, and numbers are stringified into (merged) text.\n/** Describes normalized child. */\nexport type NormalizedChild =\n | FigElement<any>\n | FigPortal<any>\n | PromiseLike<AwaitedFigNode>\n | string;\n\n// Child normalization shared by the reconciler and the server renderer.\n// Adjacent text merging here MUST match on both sides: the server emits\n// merged text nodes into HTML, and hydration matches them against the\n// client's fiber children — divergence is a hydration mismatch.\n/** Collect children. */\nexport function collectChildren(node: FigNode): NormalizedChild[] {\n if (Array.isArray(node)) return collectArrayChildren(node);\n\n const children: NormalizedChild[] = [];\n collectChild(node, children);\n return children;\n}\n\nfunction collectArrayChildren(children: FigNode[]): NormalizedChild[] {\n let previousWasText = false;\n for (let index = 0; index < children.length; index += 1) {\n const child = children[index];\n if (typeof child === \"string\") {\n if (child !== \"\" && !previousWasText) {\n previousWasText = true;\n continue;\n }\n } else {\n previousWasText = false;\n if (\n !Array.isArray(child) &&\n child !== null &&\n child !== undefined &&\n typeof child !== \"boolean\" &&\n typeof child !== \"number\"\n ) {\n if (isValidElement(child) || isPortal(child) || isThenable(child)) {\n continue;\n }\n throw invalidChildError(child);\n }\n }\n\n const normalized = children.slice(0, index) as NormalizedChild[];\n for (; index < children.length; index += 1) {\n collectChild(children[index], normalized);\n }\n return normalized;\n }\n return children as NormalizedChild[];\n}\n\nfunction collectChild(node: FigNode, children: NormalizedChild[]): void {\n if (Array.isArray(node)) {\n for (const child of node) collectChild(child, children);\n return;\n }\n\n if (node === null || node === undefined || typeof node === \"boolean\") return;\n\n if (typeof node === \"string\" || typeof node === \"number\") {\n appendTextChild(children, String(node));\n return;\n }\n\n if (isValidElement(node) || isPortal(node)) {\n children.push(node);\n return;\n }\n\n if (isThenable(node)) {\n children.push(node);\n return;\n }\n\n throw invalidChildError(node);\n}\n\nfunction appendTextChild(children: NormalizedChild[], text: string): void {\n if (text === \"\") return;\n\n const previous = children.at(-1);\n\n if (typeof previous === \"string\") {\n children[children.length - 1] = `${previous}${text}`;\n } else {\n children.push(text);\n }\n}\n\n/** Invalid child error. */\nexport function invalidChildError(value: unknown): Error {\n return new Error(\n `Invalid Fig child: ${describeInvalidChild(value)}. Render a string, number, element, promise, array, boolean, null, or undefined.`,\n );\n}\n\n/** Describes invalid child. */\nexport function describeInvalidChild(value: unknown): string {\n if (typeof value !== \"object\" || value === null) return typeof value;\n\n const keys = Object.keys(value);\n return keys.length === 0 ? \"object\" : `object with keys ${keys.join(\", \")}`;\n}\n","const phrasingContainers = \"|a|button|p|\";\n\n// HTML parser auto-close rules are scoped: these tags reset the \"is there an\n// open <a>/<button>/<p>?\" checks, so e.g. <a><table><td><a> and\n// <p><button><div> parse without re-parenting and must not be flagged.\n// <button> additionally terminates button scope (the <p> auto-close check).\nconst scopeTerminators =\n \"|applet|caption|desc|foreignobject|html|marquee|object|table|td|template|th|title|\";\n\nconst pAutoClosingTags =\n \"|address|article|aside|blockquote|center|details|dialog|dir|div|dl|fieldset|figcaption|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|main|menu|nav|ol|p|pre|section|table|ul|\";\n\nconst headChildren =\n \"|base|basefont|bgsound|link|meta|title|noscript|noframes|script|style|template|\";\n\nconst specialTags =\n \"|address|applet|area|article|aside|base|basefont|bgsound|blockquote|body|br|button|caption|center|col|colgroup|dd|details|dir|div|dl|dt|embed|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hgroup|hr|html|iframe|img|input|keygen|li|link|listing|main|marquee|menu|meta|nav|noembed|noframes|noscript|object|ol|p|param|plaintext|pre|script|section|select|source|style|summary|table|tbody|td|template|textarea|tfoot|th|thead|title|tr|track|ul|wbr|xmp|mi|mo|mn|ms|mtext|annotation-xml|foreignobject|desc|\";\n\n/** Validates instance nesting. */\nexport function validateInstanceNesting(\n type: string,\n ancestors: readonly string[],\n): void {\n const child = normalizedTag(type);\n const parent =\n ancestors[0] === undefined ? null : normalizedTag(ancestors[0]);\n\n if (parent !== null && !validWithParent(child, parent)) {\n throw invalidNestingError(\n `<${child}> cannot be a child of <${parent}>.${hintFor(child, parent)}`,\n );\n }\n\n const invalidAncestor = invalidAncestorFor(child, ancestors);\n if (invalidAncestor !== null) {\n throw invalidNestingError(\n `<${child}> cannot appear inside <${invalidAncestor}>.`,\n );\n }\n}\n\n/** Validates text nesting. */\nexport function validateTextNesting(\n text: string,\n ancestors: readonly string[],\n): void {\n // Whitespace-only text is inserted in place even inside tables (\"in table\n // text\" mode only foster-parents non-whitespace), so it is harmless.\n if (!/[^ \\t\\n\\r\\f]/.test(text)) return;\n\n const parent =\n ancestors[0] === undefined ? null : normalizedTag(ancestors[0]);\n if (parent === null || validTextWithParent(parent)) return;\n\n throw invalidNestingError(`text cannot be a child of <${parent}>.`);\n}\n\nfunction validWithParent(child: string, parent: string): boolean {\n switch (parent) {\n case \"select\":\n return (\n child === \"hr\" ||\n child === \"option\" ||\n child === \"optgroup\" ||\n child === \"script\" ||\n child === \"template\"\n );\n case \"optgroup\":\n return child === \"option\";\n case \"option\":\n return false;\n case \"tr\":\n return child === \"th\" || child === \"td\" || scriptLike(child);\n case \"tbody\":\n case \"thead\":\n case \"tfoot\":\n return child === \"tr\" || scriptLike(child);\n case \"colgroup\":\n return child === \"col\" || child === \"template\";\n case \"table\":\n return (\n child === \"caption\" ||\n child === \"colgroup\" ||\n child === \"tbody\" ||\n child === \"tfoot\" ||\n child === \"thead\" ||\n scriptLike(child)\n );\n case \"head\":\n return tagIn(headChildren, child);\n case \"html\":\n return child === \"head\" || child === \"body\";\n case \"frameset\":\n return child === \"frame\";\n }\n\n switch (child) {\n case \"caption\":\n case \"col\":\n case \"colgroup\":\n case \"tbody\":\n case \"tfoot\":\n case \"thead\":\n case \"tr\":\n return parent === \"template\";\n case \"td\":\n case \"th\":\n return parent === \"tr\" || parent === \"template\";\n case \"option\":\n return parent === \"datalist\" || parent === \"template\";\n case \"optgroup\":\n return parent === \"template\";\n case \"head\":\n case \"body\":\n case \"frameset\":\n return parent === \"html\" || parent === \"template\";\n case \"frame\":\n return parent === \"template\";\n case \"html\":\n return false;\n }\n\n return true;\n}\n\nfunction validTextWithParent(parent: string): boolean {\n // <option>, <select>, and <optgroup> reject element children, but the\n // parser inserts character tokens into them in place, so text is legal.\n return (\n parent === \"option\" ||\n parent === \"select\" ||\n parent === \"optgroup\" ||\n validWithParent(\"#text\", parent)\n );\n}\n\nfunction invalidAncestorFor(\n child: string,\n ancestors: readonly string[],\n): string | null {\n let inScope = true;\n let inButtonScope = true;\n let inListScope = true;\n let inTemplate = false;\n\n for (const ancestorType of ancestors) {\n const ancestor = normalizedTag(ancestorType);\n\n if (child === ancestor && tagIn(phrasingContainers, child)) {\n if (child === \"p\" ? inButtonScope : inScope) return ancestor;\n }\n if (inButtonScope && ancestor === \"p\" && tagIn(pAutoClosingTags, child)) {\n return ancestor;\n }\n if (inListScope && listItemAncestor(child, ancestor)) return ancestor;\n // The parser's form element pointer ignores scope but resets in templates.\n if (!inTemplate && ancestor === \"form\" && child === \"form\") return ancestor;\n\n if (tagIn(scopeTerminators, ancestor)) {\n if (ancestor === \"template\") inTemplate = true;\n inScope = false;\n inButtonScope = false;\n } else if (ancestor === \"button\") {\n inButtonScope = false;\n }\n // li/dd/dt auto-closing sees through phrasing/formatting wrappers and\n // address/div/p; other special elements terminate the parser walk.\n if (\n tagIn(specialTags, ancestor) &&\n ancestor !== \"address\" &&\n ancestor !== \"div\" &&\n ancestor !== \"p\"\n ) {\n inListScope = false;\n }\n }\n\n return null;\n}\n\nfunction listItemAncestor(child: string, ancestor: string): boolean {\n if (child === \"li\") return ancestor === \"li\";\n if (child === \"dd\" || child === \"dt\") {\n return ancestor === \"dd\" || ancestor === \"dt\";\n }\n return false;\n}\n\nfunction normalizedTag(type: string): string {\n return type.toLowerCase();\n}\n\nfunction scriptLike(tag: string): boolean {\n return tag === \"script\" || tag === \"style\" || tag === \"template\";\n}\n\nfunction hintFor(child: string, parent: string): string {\n if (parent === \"table\" && child === \"tr\") {\n return \" Add a <tbody>, <thead>, or <tfoot>.\";\n }\n\n return \"\";\n}\n\nfunction invalidNestingError(message: string): Error {\n return new Error(`Invalid DOM nesting: ${message}`);\n}\n\nfunction tagIn(tags: string, tag: string): boolean {\n return tags.includes(`|${tag}|`);\n}\n","// The Suspense streaming wire format shared by the server renderer (which\n// emits these markers as HTML comments and interpolates them into the inline\n// reveal script) and fig-dom (which parses them into dehydrated boundaries).\n// Changing any value is a protocol change: server output and client parsing\n// must move together.\nimport type { DataResourceKey } from \"./data.ts\";\n\n/** The suspense marker prefix. */\nexport const SUSPENSE_MARKER_PREFIX = \"fig:suspense:\";\n/** The suspense completed marker. */\nexport const SUSPENSE_COMPLETED_MARKER = \"fig:suspense:completed\";\n/** The suspense browser-rendered marker. */\nexport const SUSPENSE_BROWSER_MARKER = \"fig:suspense:browser\";\n/** The suspense client marker. */\nexport const SUSPENSE_CLIENT_MARKER = \"fig:suspense:client\";\n/** The suspense pending prefix. */\nexport const SUSPENSE_PENDING_PREFIX = \"fig:suspense:pending:\";\n/** The suspense end marker. */\nexport const SUSPENSE_END_MARKER = \"/fig:suspense\";\n\n// The server emits a comment with exactly this data between adjacent text\n// writes that come from different normalized text children: the HTML parser\n// would otherwise merge them into one DOM text node while the client keeps\n// one text fiber each. fig-dom's hydration cursor skips only comments whose\n// data matches this value (fig:suspense markers use their own prefixes).\n/** The text separator data. */\nexport const TEXT_SEPARATOR_DATA = \",\";\n\n// Hidden Activity content streams inside an inert template carrying this\n// attribute; the client treats such templates as dehydrated boundaries.\n/** The activity template attribute. */\nexport const ACTIVITY_TEMPLATE_ATTRIBUTE = \"data-fig-activity\";\n\n/** The view transition name attribute. */\nexport const VIEW_TRANSITION_NAME_ATTRIBUTE = \"data-fig-vt-name\";\n/** The view transition class attribute. */\nexport const VIEW_TRANSITION_CLASS_ATTRIBUTE = \"data-fig-vt-class\";\n\n// Per-document mutex holding the currently running view transition. Client\n// commits and inline streaming reveals both wait on it before proceeding.\n/** The view transition pending property. */\nexport const VIEW_TRANSITION_PENDING_PROPERTY = \"__figViewTransition\";\n// React's maximum suspended-commit wait, shared with streaming reveals so a\n// non-settling transition cannot hold either path indefinitely.\n/** The view transition timeout ms. */\nexport const VIEW_TRANSITION_TIMEOUT_MS = 60_000;\n\n// Early-event capture: a tiny inline script at the top of a server-rendered\n// document queues replayable events that fire before the client bundle\n// executes. The first hydration root drains the queue, removes the capture\n// listeners, and replays claimed events through the standard replay path.\n// The event list must stay in sync with fig-dom's replayable set — a\n// discrete replay forces synchronous hydration of its target, which is what\n// makes pre-bundle clicks safe to honor.\n/** The hydration skip attribute. */\nexport const HYDRATION_SKIP_ATTRIBUTE = \"data-fig-hydration-skip\";\n/** The early event queue property. */\nexport const EARLY_EVENT_QUEUE_PROPERTY = \"__figEarlyEvents\";\n/** The early event handler property. */\nexport const EARLY_EVENT_HANDLER_PROPERTY = \"__figEarlyEventHandler\";\n// Streamed data rows: the `d` operation queues encoded rows on this document\n// property, keyed by the render's identifierPrefix, until the hydrating root\n// that owns the prefix drains it and replaces it with a live receiver.\n/** The streamed data property. */\nexport const STREAMED_DATA_PROPERTY = \"__figStreamedData\";\n// A `d` row with this shape carries no value: it promises that key's transfer\n// form in a later `d` operation, after the reveal. The browser holds that\n// key's load until the form arrives or the document finishes loading.\n/** Describes a streamed data marker. */\nexport interface StreamedDataMarker {\n key: DataResourceKey;\n pending: true;\n}\n/** The replayable event types. */\nexport const REPLAYABLE_EVENT_TYPES = [\n \"click\",\n \"keydown\",\n \"keyup\",\n \"pointerdown\",\n \"pointerup\",\n] as const;\n"],"mappings":";;;;;;AAwBA,SAAgB,gBAAgB,MAAkC;CAChE,IAAI,MAAM,QAAQ,IAAI,GA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AA+B;;AAK5C,MAAa,yBAAyB;;AAUtC,MAAa,yBAAyB;CACpC;CACA;CACA;CACA;CACA;AACF"}
@@ -1,3 +1,4 @@
1
+ import { P as readBrowser } from "./element-DbzJUf5a.js";
1
2
  import { y as isThenable$1 } from "./resource-BZOBllE_.js";
2
3
  //#region src/context.ts
3
4
  /** The Fig context symbol. */
@@ -68,6 +69,33 @@ function sameDataResourceKey(a, b) {
68
69
  function isAttributableError(value) {
69
70
  return (typeof value === "object" || typeof value === "function") && value !== null;
70
71
  }
72
+ const MissingCapabilityBrand = Symbol.for("fig.data-missing-capability");
73
+ /**
74
+ * Thrown by `requireCapability`: this load cannot run in the current
75
+ * environment. During server rendering, a read of the entry leaves the
76
+ * nearest Suspense fallback for the browser to render.
77
+ */
78
+ var MissingCapabilityError = class extends Error {
79
+ [MissingCapabilityBrand] = true;
80
+ reason;
81
+ constructor(reason) {
82
+ super("This data cannot be loaded here.");
83
+ this.name = "MissingCapabilityError";
84
+ this.reason = reason;
85
+ }
86
+ };
87
+ /**
88
+ * Asserts that a load's required capability is available. A false condition
89
+ * throws MissingCapabilityError; a true condition narrows it and lets the
90
+ * load continue in environments that provide the capability.
91
+ */
92
+ function requireCapability(condition, reason) {
93
+ if (!condition) throw new MissingCapabilityError(reason);
94
+ }
95
+ /** Checks whether a value is a missing-capability error. */
96
+ function isMissingCapability(value) {
97
+ return typeof value === "object" && value !== null && value[MissingCapabilityBrand] === true;
98
+ }
71
99
  //#endregion
72
100
  //#region src/data-store.ts
73
101
  const DataResourceSymbol = Symbol.for("fig.data-resource");
@@ -78,6 +106,7 @@ const DEFAULT_PRELOAD_RETENTION_MS = 3e4;
78
106
  const dataStoreFactory = createRendererDataStore;
79
107
  /** Data resource. */
80
108
  function dataResource(options) {
109
+ if (typeof options.transfer === "function" && options.load === void 0) throw new Error("A data resource with a transfer function requires a loader.");
81
110
  return {
82
111
  $$typeof: DataResourceSymbol,
83
112
  [DataStoreFactorySymbol]: dataStoreFactory,
@@ -86,6 +115,7 @@ function dataResource(options) {
86
115
  inactiveRetentionMs: options.inactiveRetentionMs,
87
116
  key: options.key,
88
117
  load: options.load,
118
+ transfer: options.transfer,
89
119
  watch: options.watch
90
120
  };
91
121
  }
@@ -131,6 +161,7 @@ function normalizeDataResourceKey(key) {
131
161
  var DefaultDataStore = class {
132
162
  host;
133
163
  entries = /* @__PURE__ */ new Map();
164
+ awaitedForms = /* @__PURE__ */ new Set();
134
165
  inactiveRetentionMs;
135
166
  ownerKeys = /* @__PURE__ */ new WeakMap();
136
167
  preloadRetentionMs;
@@ -218,12 +249,23 @@ var DefaultDataStore = class {
218
249
  }
219
250
  dispose() {
220
251
  this.disposed = true;
252
+ this.awaitedForms.clear();
253
+ let failure;
254
+ for (const entry of this.entries.values()) try {
255
+ const transferred = transferValue(entry);
256
+ if (transferred === void 0) continue;
257
+ entry.value = transferred.value;
258
+ entry.transferred = true;
259
+ } catch (error) {
260
+ failure ??= { error };
261
+ }
221
262
  for (const entry of this.entries.values()) {
222
263
  this.clearInactiveTimer(entry);
223
264
  this.clearPreloadTimer(entry);
224
265
  this.abortEntryGenerations(entry, "store-disposed");
225
266
  this.notifyEntryChange(entry);
226
267
  }
268
+ if (failure !== void 0) throw failure.error;
227
269
  }
228
270
  hydrate(entries) {
229
271
  this.hydrateEntries(entries, true);
@@ -238,27 +280,67 @@ var DefaultDataStore = class {
238
280
  const normalized = normalizeKey(hydrated.key);
239
281
  const storeKey = normalized.canonical;
240
282
  const current = this.entries.get(storeKey);
283
+ this.awaitedForms.delete(storeKey);
241
284
  if (current !== void 0) {
242
- if (replaceValues || !entryHasValue(current)) this.hydrateEntry(current, normalized.key, hydrated.value);
285
+ if (current.parkedLoad !== null) {
286
+ current.seed = { value: hydrated.value };
287
+ runParkedLoad(current);
288
+ continue;
289
+ }
290
+ if (replaceValues || !entryHasValue(current)) this.hydrateEntry(current, normalized.key, hydrated.value, true);
243
291
  continue;
244
292
  }
245
293
  const entry = this.createEntry(normalized, null, null, "fulfilled", hydrated.value);
294
+ entry.transferred = true;
246
295
  this.entries.set(storeKey, entry);
247
296
  this.notifyEntryChange(entry);
248
297
  }
249
298
  }
299
+ awaitTransferForms(keys) {
300
+ if (this.disposed) return;
301
+ for (const key of keys) {
302
+ const canonical = normalizeKey(key).canonical;
303
+ const entry = this.entries.get(canonical);
304
+ if (entry !== void 0 && (entryHasValue(entry) || entry.pending !== null)) continue;
305
+ this.awaitedForms.add(canonical);
306
+ }
307
+ }
308
+ releaseTransferForms() {
309
+ const keys = [...this.awaitedForms];
310
+ this.awaitedForms.clear();
311
+ for (const key of keys) {
312
+ const entry = this.entries.get(key);
313
+ if (entry !== void 0) runParkedLoad(entry);
314
+ }
315
+ }
250
316
  snapshot() {
251
317
  return this.snapshotKeys(this.entries.keys());
252
318
  }
253
- snapshotKeys(canonicalKeys) {
319
+ snapshotKeys(canonicalKeys, deferred) {
320
+ const sources = /* @__PURE__ */ new Map();
321
+ for (const entry of this.entries.values()) for (const retainer of entry.retainers ?? []) {
322
+ const retained = sources.get(retainer);
323
+ if (retained === void 0) sources.set(retainer, [entry]);
324
+ else retained.push(entry);
325
+ }
254
326
  const entries = [];
255
- for (const key of canonicalKeys) {
256
- const entry = this.entries.get(key);
257
- if (entry !== void 0 && entryHasValue(entry)) entries.push({
327
+ const visited = /* @__PURE__ */ new Set();
328
+ const requested = new Set(canonicalKeys);
329
+ const visit = (entry) => {
330
+ if (entry === void 0 || visited.has(entry)) return;
331
+ visited.add(entry);
332
+ const signal = entry.valueController?.signal;
333
+ if (signal !== void 0) sources.get(signal)?.forEach(visit);
334
+ const isRequested = requested.has(entry.canonicalKey);
335
+ if (!isRequested && typeof entry.resource?.transfer !== "function") return;
336
+ const transferred = transferValue(entry);
337
+ if (transferred === void 0) return;
338
+ (isRequested ? entries : deferred ?? entries).push({
258
339
  key: entry.key,
259
- value: entry.value
340
+ value: transferred.value
260
341
  });
261
- }
342
+ };
343
+ for (const key of requested) visit(this.entries.get(key));
262
344
  return entries;
263
345
  }
264
346
  inspectDataEntries() {
@@ -362,11 +444,13 @@ var DefaultDataStore = class {
362
444
  this.recordWatchSource(entry, resource, args);
363
445
  this.revalidateIfStale(entry, resource, args);
364
446
  if (entry.status === "pending" && entry.pending === null) {
447
+ const seeded = entry.seed !== null;
365
448
  if (this.waitsOnWatch(resource)) this.beginWatchPending(entry);
366
449
  else this.startLoad(entry, resource, args, {
367
450
  lane: this.host.getLane(),
368
451
  refresh: false
369
452
  });
453
+ if (seeded && loaderReturnedThenable(entry)) throw new Error(`Data resource "${entry.canonicalKey}" was read in render with a transferred value, but its load returned a promise for it. Return the value synchronously when \`transferred\` is set (a load declared \`async\` always returns a promise).`);
370
454
  }
371
455
  const value = this.readCurrentValue(entry);
372
456
  if (reads !== void 0 && reads.get(entry.canonicalKey) === void 0) reads.set(entry.canonicalKey, { value });
@@ -408,6 +492,7 @@ var DefaultDataStore = class {
408
492
  if (current !== void 0) {
409
493
  if (resource.inactiveRetentionMs !== void 0) current.inactiveRetentionMs = resource.inactiveRetentionMs;
410
494
  diagnoseEntryDrift(current, resource, normalized.canonical, fingerprint);
495
+ this.adoptResource(current, resource);
411
496
  return current;
412
497
  }
413
498
  if (!create) return null;
@@ -425,6 +510,14 @@ var DefaultDataStore = class {
425
510
  refresh: true
426
511
  });
427
512
  }
513
+ adoptResource(entry, resource) {
514
+ entry.resource ??= resource;
515
+ if (!entry.transferred || typeof resource.transfer !== "function" || resource.load === void 0 || !entryHasValue(entry)) return;
516
+ entry.transferred = false;
517
+ entry.seed = { value: entry.value };
518
+ entry.value = void 0;
519
+ entry.status = "pending";
520
+ }
428
521
  entryForKey(key) {
429
522
  const normalized = normalizeKey(key);
430
523
  return this.entries.get(normalized.canonical) ?? null;
@@ -438,6 +531,9 @@ var DefaultDataStore = class {
438
531
  invalidationVersion: 0,
439
532
  inactiveRetentionMs: void 0,
440
533
  inactiveTimer: null,
534
+ transferred: false,
535
+ seed: null,
536
+ parkedLoad: null,
441
537
  key: normalized.key,
442
538
  lane: null,
443
539
  pending: null,
@@ -584,7 +680,7 @@ var DefaultDataStore = class {
584
680
  publish: (value) => {
585
681
  if (!live()) return;
586
682
  const equals = source.resource.equals ?? Object.is;
587
- if (entryHasValue(entry) && equals(entry.value, value)) {
683
+ if (!(entry.transferred && typeof source.resource.transfer === "function") && entryHasValue(entry) && equals(entry.value, value)) {
588
684
  const pending = entry.pending;
589
685
  entry.invalidationVersion = 0;
590
686
  entry.lane = null;
@@ -593,7 +689,7 @@ var DefaultDataStore = class {
593
689
  pending?.controller.abort("superseded");
594
690
  return;
595
691
  }
596
- this.hydrateEntry(entry, entry.key, value);
692
+ this.hydrateEntry(entry, entry.key, value, false);
597
693
  this.scheduleWatchReconcile(entry);
598
694
  },
599
695
  fail: (error) => {
@@ -631,7 +727,7 @@ var DefaultDataStore = class {
631
727
  this.publish(entry);
632
728
  pending?.controller.abort(error);
633
729
  }
634
- hydrateEntry(entry, key, value) {
730
+ hydrateEntry(entry, key, value, transferred) {
635
731
  this.clearInactiveTimer(entry);
636
732
  const valueController = entry.valueController;
637
733
  const pending = entry.pending;
@@ -647,6 +743,8 @@ var DefaultDataStore = class {
647
743
  entry.stale = false;
648
744
  entry.status = "fulfilled";
649
745
  entry.value = value;
746
+ entry.transferred = transferred;
747
+ entry.seed = null;
650
748
  pending?.resolve(abortedRefreshResult(entry, "superseded"));
651
749
  this.publish(entry);
652
750
  pending?.controller.abort("superseded");
@@ -664,6 +762,7 @@ var DefaultDataStore = class {
664
762
  this.notifyEntryChange(entry);
665
763
  return Promise.resolve(unsupportedRefreshResult(entry));
666
764
  }
765
+ if (this.awaitedForms.has(entry.canonicalKey)) return this.parkLoad(entry, resource, args, options);
667
766
  const previousPending = entry.pending;
668
767
  const controller = new AbortController();
669
768
  const valueErrors = /* @__PURE__ */ new WeakSet();
@@ -677,10 +776,14 @@ var DefaultDataStore = class {
677
776
  this.notifyEntryChange(entry);
678
777
  if (controller.signal.aborted) return pending.promise;
679
778
  let loaded;
779
+ let missingCapability;
780
+ let threw = false;
680
781
  try {
681
782
  loaded = load(...args, this.createLoadContext(entry, controller, valueErrors));
682
783
  } catch (error) {
784
+ if (isMissingCapability(error)) missingCapability = error;
683
785
  loaded = Promise.reject(error);
786
+ threw = true;
684
787
  }
685
788
  const settleAborted = () => {
686
789
  const result = abortedRefreshResult(entry, "superseded");
@@ -716,6 +819,7 @@ var DefaultDataStore = class {
716
819
  entry.stale = entry.invalidationVersion !== invalidationVersion;
717
820
  entry.status = "fulfilled";
718
821
  entry.value = value;
822
+ entry.transferred = false;
719
823
  const result = {
720
824
  status: "fulfilled",
721
825
  value
@@ -755,6 +859,11 @@ var DefaultDataStore = class {
755
859
  controller.abort(error);
756
860
  return result;
757
861
  };
862
+ if (missingCapability !== void 0) {
863
+ loaded.catch(() => void 0);
864
+ reject(missingCapability);
865
+ return pending.promise;
866
+ }
758
867
  let thenable;
759
868
  try {
760
869
  thenable = isThenable(loaded);
@@ -762,15 +871,32 @@ var DefaultDataStore = class {
762
871
  reject(error);
763
872
  return pending.promise;
764
873
  }
765
- if (thenable) Promise.resolve(loaded).then(fulfill, reject);
766
- else fulfill(loaded);
874
+ if (thenable) {
875
+ if (!threw) pending.returnedThenable = true;
876
+ Promise.resolve(loaded).then(fulfill, reject);
877
+ } else fulfill(loaded);
767
878
  return pending.promise;
768
879
  }
880
+ parkLoad(entry, resource, args, options) {
881
+ if (entry.pending !== null) return entry.pending.promise;
882
+ const parked = createPendingLoad(new AbortController());
883
+ entry.pending = parked;
884
+ entry.status = "pending";
885
+ entry.parkedLoad = () => {
886
+ if (entry.pending !== parked) return;
887
+ entry.pending = null;
888
+ this.startLoad(entry, resource, args, options).then(parked.resolve);
889
+ };
890
+ this.notifyEntryChange(entry);
891
+ return parked.promise;
892
+ }
769
893
  createLoadContext(entry, controller, valueErrors) {
770
894
  const context = {
771
895
  data: this.dependentHandle(controller.signal),
772
- signal: controller.signal
896
+ signal: controller.signal,
897
+ transferred: entry.seed?.value
773
898
  };
899
+ entry.seed = null;
774
900
  defineLoadContextCapabilities(context, {
775
901
  key: entry.key,
776
902
  attributeError: (error) => {
@@ -869,7 +995,10 @@ var DefaultDataStore = class {
869
995
  }
870
996
  readCurrentValue(entry) {
871
997
  if (entryHasValue(entry)) return entry.value;
872
- if (entry.status === "rejected") throwDataResourceError(entry);
998
+ if (entry.status === "rejected") {
999
+ if (isMissingCapability(entry.error)) readBrowser(entry.error.reason);
1000
+ throwDataResourceError(entry);
1001
+ }
873
1002
  if (entry.pending === null) throw new Error(`Data resource "${entry.canonicalKey}" has no pending load.`);
874
1003
  throw entry.pending.promise;
875
1004
  }
@@ -884,6 +1013,7 @@ var DefaultDataStore = class {
884
1013
  entry.valueController = null;
885
1014
  entry.valueErrors = /* @__PURE__ */ new WeakSet();
886
1015
  entry.value = void 0;
1016
+ entry.transferred = false;
887
1017
  entry.error = void 0;
888
1018
  entry.status = "pending";
889
1019
  } else if (entry.status === "rejected") {
@@ -915,6 +1045,18 @@ function canonicalKeyStartsWith(key, prefix) {
915
1045
  function isHeld(entry) {
916
1046
  return entry.subscribers.size > 0 || (entry.retainers?.size ?? 0) > 0;
917
1047
  }
1048
+ function transferValue(entry) {
1049
+ const transfer = entry.resource?.transfer;
1050
+ if (!entryHasValue(entry) || transfer === false) return void 0;
1051
+ if (entry.transferred || transfer === void 0) return { value: entry.value };
1052
+ const value = transfer(entry.value);
1053
+ return value === void 0 ? void 0 : { value };
1054
+ }
1055
+ function runParkedLoad(entry) {
1056
+ const run = entry.parkedLoad;
1057
+ entry.parkedLoad = null;
1058
+ run?.();
1059
+ }
918
1060
  function entryHasValue(entry) {
919
1061
  return entry.status === "fulfilled" || entry.status === "refreshing";
920
1062
  }
@@ -946,8 +1088,7 @@ function fingerprintFor(resource, args) {
946
1088
  }
947
1089
  }
948
1090
  function diagnoseEntryDrift(entry, resource, key, fingerprint) {
949
- if (entry.resource === null) entry.resource = resource;
950
- else if (entry.resource !== resource) warn(`Data resource key ${key} was read by multiple resource definitions.`);
1091
+ if (entry.resource !== null && entry.resource !== resource) warn(`Data resource key ${key} was read by multiple resource definitions.`);
951
1092
  if (entry.fingerprint !== null && fingerprint !== null && entry.fingerprint !== fingerprint) warn(`Data resource key ${key} was read with different argument fingerprints.`);
952
1093
  }
953
1094
  function warn(message) {
@@ -1020,6 +1161,9 @@ function untilAborted(promise, signal) {
1020
1161
  });
1021
1162
  });
1022
1163
  }
1164
+ function loaderReturnedThenable(entry) {
1165
+ return entry.pending?.returnedThenable === true;
1166
+ }
1023
1167
  function createPendingLoad(controller) {
1024
1168
  let resolve = () => void 0;
1025
1169
  return {
@@ -1092,6 +1236,6 @@ function setTransitionHandler(handler) {
1092
1236
  return previous;
1093
1237
  }
1094
1238
  //#endregion
1095
- export { resolveCurrentDataStore as _, createDataStore as a, createContext as b, dataResource as c, readDataStore as d, runWithDataStore as f, markDataResourceError as g, loadContextCapabilities as h, attachDataStore as i, isDataStoreController as l, defineLoadContextCapabilities as m, setTransitionHandler as n, createRendererDataStore as o, dataResourceKeysForError as p, transition as r, currentDataStore as s, runTransitionScope as t, normalizeDataResourceKey as u, setCurrentDataStore as v, isContext as x, FigContextSymbol as y };
1239
+ export { isContext as C, createContext as S, markDataResourceError as _, createDataStore as a, setCurrentDataStore as b, dataResource as c, readDataStore as d, runWithDataStore as f, loadContextCapabilities as g, defineLoadContextCapabilities as h, attachDataStore as i, isDataStoreController as l, dataResourceKeysForError as m, setTransitionHandler as n, createRendererDataStore as o, MissingCapabilityError as p, transition as r, currentDataStore as s, runTransitionScope as t, normalizeDataResourceKey as u, requireCapability as v, FigContextSymbol as x, resolveCurrentDataStore as y };
1096
1240
 
1097
- //# sourceMappingURL=transition-CWjp9qRO.js.map
1241
+ //# sourceMappingURL=transition-BZTyeaMo.js.map