Add TanStack DB example with Rivet Actor SQLite integration#4427
Add TanStack DB example with Rivet Actor SQLite integration#4427
Conversation
Adds a new example that integrates TanStack DB with a RivetKit actor backed by SQLite. Demonstrates: - SQLite persistence via rivetkit/db with live migration - Real-time change events broadcast to all connected clients - Custom TanStack DB sync function seeded from actor's getTodos() action - Incremental delta updates via begin/write/commit for each broadcast event - Optimistic mutations (insert/toggle/delete) with automatic reconciliation - Reactive live queries with sub-millisecond differential dataflow updates - Filter tabs (All / Active / Completed) as live query examples https://claude.ai/code/session_01DJGfxUoy4Sy5B55bP8oXFj
|
🚅 Deployed to the rivet-pr-4427 environment in rivet-frontend
|
Code ReviewNice work on the TanStack DB integration. The concept is solid and the example demonstrates the pattern well. Here are the issues I found: Bugs / Correctness Race condition during initial seeding ( The Silent error swallowing in If
Add a guard:
This works for the current UI but is fragile. Any future code path that calls Missing Requirements (per CLAUDE.md) No Vercel example generated - CLAUDE.md states that when adding new examples the vercel equivalent must also be updated. The README missing required sections - The example template requires a Code Quality
Version numbers - Testing No tests are included for |
Introduces `@rivetkit/tanstack-db-collection` — a collection options creator for TanStack DB backed by Rivet Actors, modeled after `electricCollectionOptions` and `trailBaseCollectionOptions`. `rivetCollectionOptions()` encapsulates the full sync lifecycle: - Establishes the actor connection via a typed `getHandle` factory. - Seeds the TanStack DB collection from `getInitial` once connected. - Applies real-time deltas from the actor's broadcast event. - Routes optimistic mutations back to the actor via `onInsert`, `onUpdate`, and `onDelete` handlers that receive the live connection. The `examples/tanstack-db` example is updated to use the new package, removing all manual sync boilerplate (module-level globals, the `initCollection`/`applyChange` helpers, `useActor` hook wiring, and the manual `useEffect` for seeding). The `App.tsx` now only consumes the collection via `useLiveQuery` and `todoCollection.status`. https://claude.ai/code/session_01DJGfxUoy4Sy5B55bP8oXFj
Replaces inline React.CSSProperties style objects with Tailwind utility classes. Uses @tailwindcss/vite for zero-config Vite integration and defines custom theme tokens (--color-rivet, --color-surface, etc.) via @theme in index.css to match the project's dark color palette. https://claude.ai/code/session_01DJGfxUoy4Sy5B55bP8oXFj
Description
This PR adds a new example demonstrating how to integrate TanStack DB with Rivet Actors for real-time collaborative applications. The example showcases a todo list application with SQLite persistence in the actor, real-time broadcast to all connected clients, and reactive live queries in React.
Key Features
rivetkit/db, surviving server restarts and actor hibernationchangeevent, eliminating the need for pollingImplementation Details
Actor (
src/actors.ts)todoListactor with SQLite-backed state managementgetTodos,addTodo,toggleTodo,deleteTodoTodoChangedelta to all connected clientsTanStack DB Bridge (
frontend/collection.ts)todoCollectionwith custom sync callbacks wired to the actorinitCollection()fetches all existing todos and seeds the collection on connectapplyChange()applies incremental deltas from actor broadcast eventsonInsert,onUpdate,onDeletehandlers to sync local mutations back to the actorReact App (
frontend/App.tsx)useActorhook to connect to the actorType of change
How Has This Been Tested?
The example can be tested by:
pnpm install && pnpm devhttp://localhost:5173in a browserChecklist:
https://claude.ai/code/session_01DJGfxUoy4Sy5B55bP8oXFj