fix: CanvasPreview crash - transform DBElement properties_json to CADElement properties
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).
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user