You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove serialization FAQ and add detailed caching example (#622)
* Remove serialization FAQ and add detailed caching example
- Removed the FAQ about serialization support (unnecessary discussion)
- Expanded the caching section with a detailed example showing how
query keys with route params trigger automatic cache invalidation
- Added clear navigation flow example demonstrating cache hits/misses
* Add detailed Router caching example with loaderDeps
- Explain how Router automatically caches loader data by route + params
- Add loaderDeps example showing search param dependencies in cache key
- Show navigation flow and cache hit/miss behavior
* ci: apply automated fixes
---------
Co-authored-by: Claude <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Navigate from `/posts/abc` to `/posts/xyz` and the loader runs again because `$postId` changed. Navigate back to `/posts/abc` and Router serves the cached server component instantly (within the default `gcTime`).
189
+
190
+
For dependencies beyond route params, use `loaderDeps` to include search params or other reactive values in the cache key:
Now the cache key includes both the route param and search params. Change `?tab=comments` to `?tab=related` and the server component refetches. Change back and you get a cache hit.
212
+
213
+
**Router handles this automatically.** No manual cache keys, no query configuration. The server component is fetched when dependencies change and cached when they don't.
214
+
186
215
### With Query caching
187
216
217
+
Because server components are just data, they integrate naturally with TanStack Query's caching model. The query key determines cache identity—include route params and the cache automatically invalidates when they change:
-`/posts/abc` → fetches and caches the server component for post `abc`
242
+
-`/posts/xyz` → cache miss on `['post', 'xyz']`, fetches post `xyz`
243
+
-`/posts/abc` → cache hit, instant render from cache (within staleTime)
244
+
245
+
The server component for post `abc` is still in the cache. Navigate back and it renders immediately—no network request, no loading state. The entire rendered UI tree is preserved.
246
+
247
+
This works because **the RSC payload is the cache value**. Query doesn't know or care that it's caching a server component. It's just bytes that happen to decode into a React element tree.
248
+
249
+
For static content that rarely changes, you can cache aggressively:
@@ -303,10 +366,6 @@ No. RSCs are entirely opt-in. You can build fully client-side SPAs with TanStack
303
366
304
367
TanStack Start's RSC implementation builds on React's Flight protocol and works with React 19. Server Actions are a separate primitive. `createServerFn` serves a similar purpose but integrates with TanStack's middleware, validation, and caching model. We're watching the Server Actions API and will align where it makes sense.
305
368
306
-
### When will TanStack Start's full serialization work inside RSCs?
307
-
308
-
It's on the roadmap. The current release uses React's Flight serializer directly, which handles the core use cases. Unifying with TanStack Start's serializer for custom types, extended serialization, and tighter TanStack DB integration is planned for a future release.
309
-
310
369
### Can I define my component outside of `createServerComponent`?
311
370
312
371
Yes. `createServerComponent` initiates the RSC stream generation, but your component can be defined separately and invoked inside:
0 commit comments