The index validation was incorrectly rejecting valid tldraw fractional indices like "b1", "c10", etc. tldraw's fractional indexing uses: - First letter (a-z) indicates integer part length (a=1 digit, b=2 digits) - Followed by alphanumeric characters for value and jitter This was causing ValidationError on production for Embed shapes with index "b1". Fixed regex in all validation functions to accept any lowercase letter prefix, not just 'a'. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| AutomergeToTLStore.ts | ||
| CloudflareAdapter.ts | ||
| MinimalSanitization.ts | ||
| README.md | ||
| TLStoreToAutomerge.ts | ||
| default_store.ts | ||
| documentIdMapping.ts | ||
| index.ts | ||
| useAutomergeStoreV2.ts | ||
| useAutomergeSync.ts | ||
| useAutomergeSyncRepo.ts | ||
README.md
Automerge Integration for TLdraw
This directory contains the Automerge-based sync implementation that replaces the TLdraw sync system.
Files
AutomergeToTLStore.ts- Converts Automerge patches to TLdraw store updatesTLStoreToAutomerge.ts- Converts TLdraw store changes to Automerge document updatesuseAutomergeStoreV2.ts- Core React hook for managing Automerge document state with TLdrawuseAutomergeSync.ts- Main sync hook that replacesuseSyncfrom TLdraw (uses V2 internally)CloudflareAdapter.ts- Adapter for Cloudflare Durable Objects and R2 storagedefault_store.ts- Default TLdraw store structure for new documentsindex.ts- Main exports
Benefits over TLdraw Sync
- Better Conflict Resolution: Automerge's CRDT nature handles concurrent edits more elegantly
- Offline-First: Works seamlessly offline and syncs when reconnected
- Smaller Sync Payloads: Only sends changes (patches) rather than full state
- Cross-Session Persistence: Better handling of data across different devices/sessions
- Automatic Merging: No manual conflict resolution needed
Usage
Replace the TLdraw sync import:
// Old
import { useSync } from "@tldraw/sync"
// New
import { useAutomergeSync } from "@/automerge/useAutomergeSync"
The API is identical, so no other changes are needed in your components.
Cloudflare Integration
The system uses:
- Durable Objects: For real-time WebSocket connections and document state management
- R2 Storage: For persistent document storage
- Automerge Network Adapter: Custom adapter for Cloudflare's infrastructure
Migration
To switch from TLdraw sync to Automerge sync:
- Update the Board component to use
useAutomergeSync - Deploy the new worker with Automerge Durable Object
- The CloudflareAdapter will automatically connect to
/connect/{roomId}via WebSocket
The migration is backward compatible - the system will handle both legacy and new document formats.