crdt
Loro CRDT state management with loro-mirror. Use when working on files in src/lib/crdt/.
When & Why to Use This Skill
This Claude skill provides comprehensive guidelines and specialized tools for managing state using Loro CRDT and loro-mirror. It optimizes the development of collaborative, offline-first applications by enforcing high-performance mutation patterns, defining robust data schemas, and providing specialized React hooks for seamless synchronization and conflict resolution.
Use Cases
- Real-Time Collaboration: Implementing multi-user state synchronization where concurrent edits are merged conflict-free using Loro CRDT.
- Offline-First State Management: Building resilient applications that track local changes via version vectors and sync reliably when connectivity is restored.
- React Performance Optimization: Utilizing draft-style mutations and specialized hooks like useVaultAction to ensure efficient change tracking and UI reactivity.
- Data Integrity & Auditing: Designing schemas with mandatory soft-delete patterns and UUID generation to maintain a reliable history of state transitions.
| name | crdt |
|---|---|
| description | Loro CRDT state management with loro-mirror. Use when working on files in src/lib/crdt/. |
CRDT Guidelines
Critical: Draft-Style Mutations Only
// CORRECT - mutate in place
setState((state) => {
state.transactions[id] = transaction;
});
// WRONG - returning new objects breaks change tracking
setState((state) => ({
...state,
transactions: { ...state.transactions, [id]: transaction },
}));
Rules
- Import types from
schema.ts, don't redeclare - Soft deletes: Set
deletedAttimestamp, never remove from document - Use
crypto.randomUUID()for IDs,Date.now()for timestamps
Schema Pattern
export const entitySchema = schema.LoroMap({
id: schema.String({ required: true }),
// ... fields
deletedAt: schema.Number(), // 0 = not deleted, >0 = timestamp
});
React Hooks
useActiveTransactions()- excludes soft-deleteduseTransactions()- includes soft-deleteduseVaultAction()- for mutations
Sync
- Updates encrypted before leaving client
- Loro handles versioning via version vectors
- Conflicts: last-write-wins per field