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 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-03-03 11:13:54 -08:00
parent e2e12afc96
commit 023a88352f
1 changed files with 4 additions and 2 deletions

View File

@ -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;
}
}