API Usage
Mistakes when calling Yjs methods.
Mutating Objects After Insertion
Yjs snapshots on set(). Later mutations don’t propagate.
Fix: Create new objects, or use nested Y.Map for granular updates:
Moving Shared Types Between Parents
Shared types can only have one parent.
Fix: Copy data to new shared type, delete old.
Creating New Instances Instead of Accessing
new Y.Map() is unattached. Use yDoc.getMap().
Not Using Transactions
Fix: Wrap in transact():
Forgetting trackedOrigins
Without trackedOrigins, undo captures collaborators’ changes.
Fix:
Checklist
- Never mutate after
set() - Don’t move shared types between parents
- Use
yDoc.getMap(), notnew Y.Map() - Wrap related changes in
transact() - Configure UndoManager with
trackedOrigins