Hydration
Learn about SoulCache's hydration for server-side rendering
Hydration
Hydration transfers server-fetched data to the client cache for instant rendering.
Functions
dehydrate(cache, options?)
Serialize cache entries for transport.
hydrate(cache, state, options?)
Restore dehydrated state into a cache.
serialize(state)
Serialize dehydrated state to JSON string.
deserialize(json)
Deserialize JSON string back to dehydrated state.
Types
DehydratedState
DehydratedQuery
DehydrationOptions
HydrationOptions
mergeStrategy controls how hydration treats queries that already exist in the cache:
'overwrite'(default): the dehydrated entry replaces the existing entry'skip': existing entries are left untouched; only missing queries are added'merge': existing entries with data are preserved; entries without data are hydrated
Usage
Server Side
Client Side
Features
Automatic Serialization
Data is automatically serialized and deserialized for transport
Type-Safe Hydration
Full TypeScript support for dehydrated state
Selective Hydration
Only hydrate the queries that are needed on the client
Merge Strategies
Choose between skip, overwrite, or merge hydration strategies
Best Practices
Hydration Guidelines
- Fetch on server — Pre-populate cache before rendering
- Hydrate early — Do it before first render for optimal performance
- Match queries — Ensure server and client query keys match
- Handle mismatches — Gracefully handle server/client differences