From 67c678121f7cc07cdf4a78ac9bf8c9c63adf265e Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Sat, 4 Jul 2026 19:33:22 +0200 Subject: [PATCH] fix: CanvasPreview crash - transform DBElement properties_json to CADElement properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backend returns DBElement with properties_json (string), not properties (object). CanvasPreview accessed el.properties.stroke directly → undefined → React crash → white screen. Fix: transform raw API response to CADElement format with JSON.parse(properties_json). --- frontend/src/pages/Dashboard.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/Dashboard.tsx b/frontend/src/pages/Dashboard.tsx index ff57e8c..1983879 100644 --- a/frontend/src/pages/Dashboard.tsx +++ b/frontend/src/pages/Dashboard.tsx @@ -33,8 +33,19 @@ function CanvasPreview({ project, token }: { project: Project; token: string }) try { const drawings = await getDrawings(token, project.id); if (drawings.length === 0) { if (!cancelled) setElements([]); return; } - const els = await getElements(token, drawings[0].id); - if (!cancelled) setElements(els); + const rawEls = await getElements(token, drawings[0].id); + // API may return DBElement with properties_json (string) instead of properties (object) + const transformed: CADElement[] = rawEls.map((el: any) => ({ + id: el.id, + type: el.type, + layerId: el.layer_id ?? el.layerId ?? '', + x: el.x ?? 0, + y: el.y ?? 0, + width: el.width ?? 0, + height: el.height ?? 0, + properties: typeof el.properties_json === 'string' ? JSON.parse(el.properties_json || '{}') : (el.properties ?? {}), + })); + if (!cancelled) setElements(transformed); } catch { if (!cancelled) setElements([]); } finally {