import { serverCache } from 'rntwsc/cache' import type { HydrationData, UseHydrationData } from 'rntwsc/hydration/config' import { sck } from 'rntwsc/hydration/config' import { DehydrateTemplate } from 'rntwsc/hydration/dehydrate-template' import { isServer, isWeb } from 'rntwsc/platform' // to not dehydrate a key twice const browserDehydrated = new Set() export const dehydrated = () => isServer ? serverCache(sck.dehydrated, () => new Set()) : browserDehydrated // to not dehydrate on browser if this key has no server counterpart // will be used on browser rehydrate to mark export const rehydrated = new Set() export type DehydrateProps = { k: string v?: HydrationData } const Dehydrate = ({ k, v }: DehydrateProps) => { if (!v) { return null } // render with effects return } export const dehydrate = ( k: string, v: HydrationData | undefined, ): UseHydrationData => ({ ...v, loading: false, refetch, dehydrateJsx: isWeb ? : null, }) // default noop on the server side // will be replaced in transpiled variants const refetch = () => Promise.resolve()