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
- 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
Copy file name to clipboardExpand all lines: src/blog/composite-components.md
+35-5Lines changed: 35 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -185,11 +185,45 @@ function PostPage() {
185
185
186
186
### With Query caching
187
187
188
+
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`
213
+
-`/posts/xyz` → cache miss on `['post', 'xyz']`, fetches post `xyz`
214
+
-`/posts/abc` → cache hit, instant render from cache (within staleTime)
215
+
216
+
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.
217
+
218
+
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.
219
+
220
+
For static content that rarely changes, you can cache aggressively:
@@ -303,10 +337,6 @@ No. RSCs are entirely opt-in. You can build fully client-side SPAs with TanStack
303
337
304
338
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
339
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
340
### Can I define my component outside of `createServerComponent`?
311
341
312
342
Yes. `createServerComponent` initiates the RSC stream generation, but your component can be defined separately and invoked inside:
0 commit comments