diff --git a/frontend/src/services/EmbedBridge.ts b/frontend/src/services/EmbedBridge.ts index 13ed86a5..501e90e1 100644 --- a/frontend/src/services/EmbedBridge.ts +++ b/frontend/src/services/EmbedBridge.ts @@ -92,9 +92,26 @@ class EmbedBridge { // Set wires if provided if (data.wires && Array.isArray(data.wires)) { - // Filter out null/undefined wires to prevent runtime errors - const validWires = data.wires.filter((w) => w && w.start && w.end && w.id) as never[]; - store.setWires(validWires); + // Saved circuits (e.g. Elemes `velxio_circuit`) often ship wires + // as bare { start, end } pairs WITHOUT an `id`, `color`, or + // `waypoints`. The previous filter required `w.id` and silently + // dropped EVERY wire, so lessons with wires appeared empty. + // Relax the guard to require only a valid start+end endpoint, and + // fill in the fields the store/wire renderer expect. + const validWires = data.wires + .filter((w) => w && w.start && w.end) as Array>; + const normalized = validWires.map((w, i) => ({ + id: w.id || `wire-${Date.now()}-${i}`, + start: w.start, + end: w.end, + color: w.color || '#e74c3c', + waypoints: w.waypoints || [], + })); + store.setWires(normalized as never[]); + // Wire endpoints store x/y; recompute them against component/board + // pins so the wires actually render (loadExample.ts does the same + // after setWires — without this, wires sit at 0,0 and are invisible). + useSimulatorStore.getState().recalculateAllWirePositions(); } break; }