Hydration Overview
TanStack Query
dehydrate/hydrate Automatic state restoration
Full Document Hydration
Document level Complete SSR
Date Serialization
dateReviver Automatic conversion
Selective Disable
disableHydrate CSR transition
Sonamu Hydration Process
1. Server: Dehydration
Serialize Query state on the server.2. Data Injection into HTML
3. Client: Hydration
Restore state and activate React on client.Date Serialization Handling
Problem: Date objects become strings with JSON.stringify
Solution: dateReviver
Sonamu automatically converts ISO date strings to Date objects.Preventing Hydration Mismatch
Problem: Error when server and client HTML differ
Solution 1: Use useEffect
Solution 2: suppressHydrationWarning
Use when server/client intentionally differ.disableHydrate Option
Disable Hydration and Switch to CSR
- When real-time data is important (dashboards, chat, etc.)
- When server/client rendering results intentionally differ
- When Hydration mismatch is hard to resolve
Full Document Hydration
Sonamu hydrates the entire document (not just div#root).- TanStack Router manages up to
<html>,<head>tags <HeadContent />,<Scripts />components modify head/body- Can dynamically change SEO meta tags
Suspense and Hydration
You can render Suspense fallback on server and load actual content on client.- All data is already loaded in SSR
- Fallback wonβt be visible
- Prevents Hydration mismatch
QueryClient Configuration
Server Configuration
Client Configuration
staleTime for server and client.
Router Context
Pass QueryClient via Router Context.Debugging
Verify Hydration
Check QueryClient State
Cautions
Next Steps
SSR Setup
SSR basic structure
Data Preloading
How to use registerSSR
Cache Control
TanStack Query caching
TanStack Query Docs
Query detailed guide