From bbe19c520634ebdb93f0ab2a3588dbd26eb939c3 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Tue, 3 Mar 2026 11:13:54 -0800 Subject: [PATCH] fix: deep-clone shape data to prevent Automerge proxy re-assignment error Break Automerge proxy chain in #shapeToData() and #updateShapeInDoc() to fix "Cannot create a reference to an existing document object" on canvas load and WS sync. Co-Authored-By: Claude Opus 4.6 --- lib/community-sync.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/community-sync.ts b/lib/community-sync.ts index 25f6d88..31460af 100644 --- a/lib/community-sync.ts +++ b/lib/community-sync.ts @@ -492,7 +492,7 @@ export class CommunitySync extends EventTarget { this.#doc = Automerge.change(this.#doc, `Update shape ${shape.id}`, (doc) => { if (!doc.shapes) doc.shapes = {}; - doc.shapes[shape.id] = shapeData; + doc.shapes[shape.id] = JSON.parse(JSON.stringify(shapeData)); }); this.#scheduleSave(); @@ -518,7 +518,9 @@ export class CommunitySync extends EventTarget { // Merge all extra properties from toJSON for (const [key, value] of Object.entries(json)) { if (!(key in data)) { - data[key] = value; + data[key] = typeof value === 'object' && value !== null + ? JSON.parse(JSON.stringify(value)) + : value; } }