Hydration Overview
TanStack Query
dehydrate/hydrateAutomatic state restoration
Full Document Hydration
Document levelComplete SSR
Date Serialization
dateReviverAutomatic conversion
Selective Disable
disableHydrateCSR 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.