registerSSR.
Data Preloading Overview
registerSSR
Per-route preload configDirect backend call
SSRQuery
Type-safe queriesModel/method specification
Auto Injection
Auto inject to QueryClientHydration handling
No HTTP
No network overheadFast response
How to Use registerSSR
Basic Structure
- Server receives request for
/users/123 pathmatching:/users/:id→params = { id: "123" }- Execute
preloadfunction → returnsSSRQuery[] - Direct backend call to
UserModel.getUser("C", 123)(no HTTP!) - Inject result with
QueryClient.setQueryData(["User", "getUser", "C", 123], result) - Send HTML + dehydratedState to client
- Client hydrates and immediately uses data
SSRQuery Type
params follows the backend method’s parameter order (excluding Context).
Practical Examples
Single Data Loading
Preload user information on user detail page.Multiple Data Simultaneous Loading
Preload both post and comments on post detail page.Parameter Processing
You can process URL parameters before use.Conditional Preloading
Load different data based on conditions.Query Key Matching
For preloaded data to match the client’s useQuery, queryKey must match exactly.Correct Matching
Incorrect Matching
SSRRoute Options
disableHydrate
Disable Hydration and render new on client.- When server/client rendering results may differ
- When real-time data is important
- Resolving Hydration mismatch