fix: use repo.create() instead of invalid document ID format
Change from repo.find('automerge:patricia') to repo.create() because
Automerge requires proper UUID-based document IDs, not arbitrary strings.
Each client creates a local document, loads initial data from server,
and syncs via WebSocket. The server syncs documents by room ID, not
by Automerge document ID.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
776526c65e
commit
48dac00f59
|
|
@ -116,16 +116,14 @@ export function useAutomergeSync(config: AutomergeSyncConfig): TLStoreWithStatus
|
||||||
console.log("🔌 Initializing Automerge Repo with NetworkAdapter for room:", roomId)
|
console.log("🔌 Initializing Automerge Repo with NetworkAdapter for room:", roomId)
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
// CRITICAL: Use repo.find() with a consistent document ID based on roomId
|
// CRITICAL: Create or find the document for this room
|
||||||
// This ensures all windows/tabs share the same Automerge document and can sync properly
|
// We use repo.create() which generates a proper Automerge document ID
|
||||||
// Format: automerge:${roomId} matches what the server expects (see AutomergeDurableObject.ts line 327)
|
// The document will be shared across clients via the WebSocket sync protocol
|
||||||
const documentId = `automerge:${roomId}` as any
|
console.log(`🔌 Creating Automerge document for room: ${roomId}`)
|
||||||
console.log(`🔌 Finding or creating Automerge document with ID: ${documentId}`)
|
|
||||||
|
|
||||||
// Use repo.find() to get or create the document with this ID
|
// Create a new document - Automerge will generate a proper document ID
|
||||||
// This ensures all windows share the same document instance
|
// All clients connecting to the same room will sync via the WebSocket
|
||||||
// Note: repo.find() returns a Promise, so we await it
|
const handle = repo.create<TLStoreSnapshot>()
|
||||||
const handle = await repo.find(documentId)
|
|
||||||
|
|
||||||
console.log("Found/Created Automerge handle via Repo:", {
|
console.log("Found/Created Automerge handle via Repo:", {
|
||||||
handleId: handle.documentId,
|
handleId: handle.documentId,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue