fix: element creation fails with empty layer_id (FOREIGN KEY constraint)

Three fixes:
1. interaction/index.ts: Add layerId to created element in confirmDraw()
2. CanvasArea.tsx: Sync layers to LayerManager via layerManagerRef
3. App.tsx: Fallback to activeLayerId in handleElementCreated if layerId missing

Root cause: LayerManager.activeLayerId was empty because layers were never
synced from React state to the interaction layer LayerManager. New elements
got layer_id="" which failed SQLite FOREIGN KEY constraint.

Also includes Yjs sync race condition fix from previous commit.
This commit is contained in:
2026-06-26 20:31:50 +02:00
parent bd8bedcfed
commit 7ad0e11873
3 changed files with 33 additions and 9 deletions
+1 -1
View File
@@ -961,7 +961,7 @@ export class InteractionEngine {
} else if (this.state.activeTool === 'revcloud' && this.state.points.length >= 2) {
el = dimService.createRevCloud(this.state.points, layerId);
} else {
el = { ...this.state.previewElement, id: this.generateId() };
el = { ...this.state.previewElement, id: this.generateId(), layerId: layerId };
}
this.onElementCreated?.(el);