tanstack/db/offline
Claude Code and agent skill by tanstack/db
- community
Checking that the SKILL.md file is still in the repository.
Offline transaction support for TanStack DB. OfflineExecutor orchestrates persistent outbox (IndexedDB/localStorage), leader election (WebLocks/ BroadcastChannel), retry with backoff, and connectivity detection. createOfflineTransaction/createOfflineAction wrap TanStack DB primitives with offline persistence. Idempotency keys for at-least-once delivery. Graceful degradation to online-only mode when storage unavailable. React Native support via separate entry point.
Install
npx vskill@latest install tanstack/db/offlineSKILL.md
The same SKILL.md was published earlier as tanstack/db/offline.
This skill builds on db-core and mutations-optimistic. Read those first.
TanStack DB — Offline Transactions
Setup
Core API
createOfflineTransaction
If the executor is not the leader tab, falls back to createTransaction directly (no offline persistence).
createOfflineAction
If the executor is not the leader tab, falls back to createOptimisticAction directly.
Architecture
Components
| Component | Purpose | Default | |
|---|---|---|---|
| Storage | Persist transactions to survive page reload | IndexedDB → localStorage fallback | |
| OutboxManager | FIFO queue of pending transactions | Automatic | |
| KeyScheduler | Serialize transactions touching same keys | Automatic | |
| TransactionExecutor | Execute with retry + backoff | Automatic | |
| LeaderElection | Only one tab processes the outbox | WebLocks → BroadcastChannel | |
| OnlineDetector | Pause/resume on connectivity changes | navigator.onLine + events |
Transaction lifecycle
- Mutation applied optimistically to collection (instant UI update)
- Transaction serialized and persisted to storage (outbox)
- Leader tab picks up transaction and executes
mutationFn - On success: removed from outbox, optimistic state resolved
- On failure: retried with exponential backoff
- On page reload: outbox replayed, optimistic state restored
Leader election
Only one tab processes the outbox to prevent duplicate execution. Non-leader tabs use regular createTransaction/createOptimisticAction (online-only, no persistence).
Storage degradation
The executor probes storage availability on startup:
When storage is unavailable (private browsing, quota exceeded), the executor operates in online-only mode — mutations work normally but aren't persisted across page reloads.
Configuration
Custom storage adapter
Error Handling
NonRetriableError
Throwing NonRetriableError stops retry and removes the transaction from the outbox. Use it for failures known to be permanent under the server contract, such as validation errors or a 409 that means an unrecoverable duplicate. A recoverable 401 can instead reach shouldRetry.
Retry decisions
Set shouldRetry to override the default decision for a named mutation function error. The hook receives the named mutation function's Error and retry count (0 on the first failure). The same Error instance is passed through; a non-Error rejection is converted to an Error and may lose custom fields. Return true to retry, false to stop, or undefined to use the default decision. For example, return true for a recoverable 401 and undefined otherwise. NonRetriableError always stops without calling the hook. The default backoff and configured jitter still determine retry timing. The hook is synchronous and shared by all named mutation functions. An async hook returns a Promise, which fails its outbox row. Put function-specific context on the thrown error when retry rules differ between functions. If the hook throws or returns another value, the executor records a terminal rejection for that row, removes it from the outbox, and rejects its waiting promises with the hook failure. Other queued rows continue after the failed row's deletion is acknowledged. New commits may join the queue during cleanup, but cannot run ahead of that deletion. A fresh executor does not replay the failed row. The named mutation function error is logged; the hook failure is the caller-facing and stored error. Stored errors retain name, message, and stack, but a restart does not restore an arbitrary error subclass or its custom fields. If marker storage or deletion fails, the caller still receives the hook error while the executor stops with the storage error and retains queued work. A saved terminal marker skips the named mutation function after restart; an unmarked row can replay. To decide from an HTTP status, throw an error carrying response.status in the named mutation function and inspect its numeric status in shouldRetry.
Call throwOnHttpFailure(response) in the named mutation function and pass shouldRetry: retryOnRecoverable401 in the executor config.
Idempotency keys
Every offline transaction includes an idempotencyKey. Pass it to your API to prevent duplicate execution on retry:
React Native
Outbox Management
Common Mistakes
CRITICAL Not passing idempotencyKey to the API
Wrong:
Correct:
Offline transactions retry on failure. Without idempotency keys, retries can create duplicate records on the server.
HIGH Not waiting for initialization
Wrong:
Correct:
startOfflineExecutor initializes asynchronously (probes storage, requests leadership, replays outbox). Creating transactions before initialization completes may miss the leader election result and use the wrong code path.
HIGH Missing collection in collections map
Wrong:
Correct:
The collections map is used to restore optimistic state from the outbox on page reload. Without it, previously pending mutations won't show their optimistic state while being replayed.
MEDIUM Not handling NonRetriableError for permanent failures
Wrong:
Correct:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpackages/offline-transactions/skills/offline/SKILL.md
Popularity
- Repository stars
- 3,969
- Repository forks
- 277
- 7-day trend score
- 41
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/tanstack/db/offline)