registerSSR.
Data Preloading Overview
registerSSR
Per-route preload config Direct backend call
SSRQuery
Type-safe queries Model/method specification
Auto Injection
Auto inject to QueryClient Hydration handling
No HTTP
No network overhead Fast 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
cacheControl
Set Cache-Control header for SSR response.Internal Operation Principle
1. Server Rendering Process
2. Data Injection in entry-server
3. Client Hydration
Error Handling
Handling Preload Failures
Performance Optimization
1. Use Subsets
Load only needed fields to reduce transfer size.2. Parallel Loading
Execute multiple queries simultaneously (automatically parallelized).3. Conditional Loading
Selectively load only necessary data.Cautions
Next Steps
SSR Setup
SSR basic structure
Hydration Strategies
Hydration optimization
Cache Control
Caching strategies
Subset System
Data optimization