Pitfalls
Common mistakes that cause data corruption, sync issues, or unexpected behavior—and how to avoid them.
Overview
CRDT-based applications can fail in subtle ways that are hard to debug. Many issues only appear when multiple users edit simultaneously, making them difficult to reproduce in development. This section documents the most common pitfalls organized by what you’re doing when you encounter them.
Topics
- Data Modeling - Schema and structure decisions that cause problems
- API Usage - Mistakes when calling Yjs methods
- Events & Sync - Handling the distributed nature of CRDTs
The Cost of CRDT Bugs
CRDT bugs are particularly problematic because:
- Data corruption spreads - Once corrupted data syncs to other clients, it’s everywhere
- Hard to reproduce - Issues may only occur with specific timing of concurrent edits
- Silent failures - Changes may be lost without any error messages
- Difficult to fix - Corrupted documents may need manual repair or data loss
Quick Reference
| What You’re Doing | Common Issues |
|---|---|
| Designing schema | Complex objects in arrays, index references, binary data in CRDT |
| Calling Yjs methods | Mutating after set, wrong getMap/new confusion, missing transactions |
| Handling events | Not checking local flag, flooding awareness, assuming sync order |
Quick Checklist
Before deploying a collaborative feature, verify:
- Complex content in Y.Map with IDs, order in Y.Array
- All references use IDs, not indices
- Never mutating objects after
set() - Using
yDoc.getMap()notnew Y.Map() - Changes batched in transactions
- Undo uses
trackedOriginsto isolate users - Observers check
transaction.localwhen needed - Awareness updates are debounced
- Large binary data uses blob storage, not CRDT
Most Common Issues
| Symptom | Likely Cause | See |
|---|---|---|
| Data disappears after reorder | Objects in array | Data Modeling |
| Changes don’t sync | Mutating after insertion | API Usage |
| Undo affects other users | Missing trackedOrigins | API Usage |
| Slow sync, high memory | Large data in CRDT | Data Modeling |
| Duplicate events | Not checking local flag | Events & Sync |