import { PrerenderDataValue, JsonSerializable } from '@webflow/data-types'; export { PrerenderDataValue } from '@webflow/data-types'; import { P as PrerenderDataKey } from './PrerenderDataProvider-CCyg3Z4U.js'; export { a as PrerenderDataMode, b as PrerenderDataProvider, c as PrerenderDataProviderProps } from './PrerenderDataProvider-CCyg3Z4U.js'; import 'react'; /** * Fetches data with Suspense and participates in prerender: during prerender the loader runs, * the result is recorded under `key`, and on the client that recorded value is returned * synchronously — so the component paints with real content on first render, with no refetch * and no loading flash. * * Use this when the component owns its own fetch (no React Query / SWR). For libraries that * own fetching, use {@link usePrerenderData} + {@link useHydrateData} instead. * * @example Fetch a profile and render it on first paint * ```tsx * function Profile({ id }: { id: string }) { * const { data } = useSuspenseData(["profile", id], () => fetchProfile(id)); * return

{data.name}

; * } * ``` * * @typeParam T - Author shape for the payload. The loader write is checked as * `T & JsonSerializable`; the returned `data` is `JsonSerializable` so non-JSON * fields cannot reappear through optional properties or unions after the wire round-trip. * Interfaces are OK; `Date`, `bigint`, `Map`, class instances, and top-level `undefined` * will type-error on the loader return. * @param key - A stable identifier for this piece of data. Either a plain string (used as-is — * handy for a URL + query string, e.g. `"/profiles/42"`) or an array of `string` / `number` / * `boolean` segments (e.g. `["profile", id]`) which are joined with `:`. If the same key is * written more than once, the first value wins. * @param loader - Returns a promise for the data. Keep it pure for a given key — it may run more * than once (e.g. under React Strict Mode). The resolved value must be JSON-serializable. * @returns `{ data }` — the resolved JSON-shaped value. The read type intentionally does not * intersect with `T`, because that would reintroduce non-JSON author types. * * @remarks * - The Webflow runtime already wraps every component in a Suspense boundary, so you don't need * your own `` for this to work; add one only if you want a custom loading UI. * - Set `ssr: 'prerender'` in your `declareComponent` options so the data resolves before first * paint. * - This is for first-paint/hydration parity, not a general-purpose cache: there is no built-in * refetch or invalidation. Use normal React state or a data library for updates after the * first paint. */ declare function useSuspenseData(key: PrerenderDataKey, loader: () => Promise>): { data: JsonSerializable; }; /** * Read-only bridge for components that fetch with their own Suspense-capable data library * (e.g. React Query's `useSuspenseQuery`, or SWR with `{ suspense: true }`). The library keeps * full ownership of fetching, caching, and refetching; this hook just returns the value * captured during prerender so you can seed the library (`initialData` / `fallbackData`) and * the client paints without refetching on first render. * * Returns the prerendered value as `data` (or `undefined` if nothing was captured yet). Pass * the **same `key`** and the library's resolved value to {@link useHydrateData} so it gets * recorded during prerender. * * For components that own their own fetch (no data library), use {@link useSuspenseData} * instead. * * @example React Query — define the key once and reuse it * ```tsx * function Cities({ offset }: { offset: number }) { * const key = ["cities", offset]; * const { data: initialData } = usePrerenderData(key); * const { data } = useSuspenseQuery({ * queryKey: key, * queryFn: () => fetchCitiesPage(offset), * initialData, * }); * useHydrateData(key, data); * return ; * } * ``` * * @example SWR * ```tsx * const key = ["cities", offset]; * const { data: fallbackData } = usePrerenderData(key); * const { data } = useSWR(key, () => fetchCitiesPage(offset), { suspense: true, fallbackData }); * useHydrateData(key, data); * ``` * * @typeParam T - The shape of the data (may be an `interface`). Provide it explicitly * (`usePrerenderData(key)`); it can't be inferred from the key alone. * The returned `data` is `JsonSerializable` (not `T & …`) so non-JSON fields (`Date`, * class instances, …) are not usable as their original types — intersecting with `T` would * reintroduce them (`Date & Brand` is still a `Date`). Pair with {@link useHydrateData} * (`T & JsonSerializable` on the write) using the same key / JSON-shaped `T`. * @param key - A stable identifier for this piece of data: a plain string (used as-is, handy for * a URL + query string) or an array of `string` / `number` / `boolean` segments (joined with * `:`). Reuse the same key for your data library's query key and {@link useHydrateData}. * @returns `{ data }` — the prerendered value, or `undefined` if nothing was captured yet. * * @remarks * - Pair this with {@link useHydrateData} to record your library's resolved value into the * snapshot. Pass it the same `key`. * - Never fetches or suspends on its own. */ declare function usePrerenderData(key: PrerenderDataKey): { data: JsonSerializable | undefined; }; /** * Records a value fetched by your own Suspense-capable data library into the prerender snapshot, * so the client can paint with it on first render instead of refetching. Pair it with * {@link usePrerenderData}, reusing the **same `key`** you passed there (and to your data * library). * * @example * ```tsx * const key = ["cities", offset]; * const { data: initialData } = usePrerenderData(key); * const { data } = useSuspenseQuery({ queryKey: key, queryFn, initialData }); * useHydrateData(key, data); * ``` * * @typeParam T - The shape of the data, inferred from `value`. Keep it the same type you seeded * with via {@link usePrerenderData}. Must be JSON-serializable * (`T & JsonSerializable`) — interfaces are OK; `Date` / `bigint` / class instances will * type-error. The read hook returns `JsonSerializable`; this write uses the intersection so * concrete values are checked as they enter the snapshot. * @param key - The same key you passed to {@link usePrerenderData}: a plain string or an array of * `string` / `number` / `boolean` segments. Define it once and reuse it so it can't drift. * @param value - The library's resolved value. `undefined` is accepted (and is a no-op), so you * don't need to assert non-null on library `data` types that stay `T | undefined` (e.g. SWR), * and a failed/empty fetch records nothing. * * @remarks * - This is a hook: call it at the top level **during render**, never inside `useEffect` — effects * don't run during prerender, so the value wouldn't be captured. (Hook rules enforce this.) * - Your library **must suspend during prerender** (`useSuspenseQuery`, or SWR `{ suspense: true }`). * `ssr: 'prerender'` only waits for Suspense, so a non-suspending fetch would record `undefined`. * - First-write-wins: if `key` already holds a value, this is a no-op. * - Errors are not transported: if the fetch fails during prerender the error surfaces to the host * error boundary; on the client your library handles its own errors and loading states. */ declare function useHydrateData(key: PrerenderDataKey, value: (T & JsonSerializable) | undefined): void; export { PrerenderDataKey, useHydrateData, usePrerenderData, useSuspenseData };