Repository navigation
Description
Problem
A view containing a link or flow that references a deleted/dangling element UID makes the whole model uneditable. The Editor degrades to the ErrorBoundary "Something went wrong" box, and reloading re-throws (the bad state is persisted), so the model is permanently stuck.
Root cause
src/diagram/drawing/Canvas.tsx resolves referenced elements via getElementByUid (Canvas.tsx:601-611), which returns defined(element). defined() (src/core/common.ts:14-19) throws Error('expected non-undefined object') when its argument is undefined.
For links and flows this resolution is UNGUARDED:
- Link endpoints (Canvas.tsx ~2159-2160):
const from = r.derived.selectionUpdates.get(element.fromUid) || getElementByUid(element.fromUid); let to = r.derived.selectionUpdates.get(element.toUid) || getElementByUid(element.toUid);
- Flow endpoints (Canvas.tsx ~2228, ~2238):
const source = getElementByUid(sourceId); ... const sink = getElementByUid(sinkId);
If fromUid/toUid (link) or an endpoint's attachedToUid (flow) points at a UID no longer present in the view, getElementByUid throws during render, which the ErrorBoundary catches and converts to the permanent "Something went wrong" state.
By contrast, alias and cloud rendering ARE guarded: the alias path (Canvas.tsx ~2022-2040) uses r.elements.get(element.aliasOfUid) as NamedViewElement | undefined followed by an if (aliasOf) check, so a dangling alias target degrades gracefully instead of throwing.
The engine does not prune dangling link/flow references on load: src/simlin-engine/src/serde.rs (~1656-1657) copies from_uid/to_uid verbatim. So a stored model -- an old one, or one imported from another tool -- with a dangling link/flow reference renders the editor permanently uneditable for that model.
Why it matters
- Robustness / availability: a single dangling UID bricks the entire editor for a model, and the failure is sticky across reloads because the bad data is persisted. There is no in-app recovery path.
- Inconsistency: aliases and clouds already tolerate dangling refs; links and flows should match that behavior.
- This was found during a pre-deploy audit of the diagram editor and is NOT fixed by PR Pre-deploy hardening: fix silent data-loss + undo regression, pin pnpm, add canary deploy #810.
Components affected
src/diagram/drawing/Canvas.tsx(link rendering ~2159-2160; flow rendering ~2228, ~2238)src/core/common.ts:14-19(defined()throws)src/simlin-engine/src/serde.rs(~1656-1657; no dangling-ref pruning on load)
Possible approaches
- Add per-element guards for links and flow endpoints that mirror the existing alias/cloud pattern: when a referenced UID does not resolve, skip rendering that element (or repair it) instead of throwing. This keeps the rest of the model editable.
- Optionally, harden the engine load path (
serde.rs) to prune or repair dangling link/flow references so bad data cannot be stored/round-tripped in the first place. The diagram-side guard is the minimum fix; the engine-side prune is defense-in-depth.
Discovery
Identified during a pre-deploy robustness audit of the Simlin diagram editor (not addressed by PR #810).
Activity
diagram: harden the editor against dangling refs, undo races, and NaN…
bpowers commentedon Jun 29, 2026
Fixed in a2ee852 (on main). flow()/connector() (and the drag-time isValidTarget/deriveDraggedLinkArc lookups) now resolve endpoints with the non-throwing tryGetElementByUid and skip a broken element instead of throwing out of render into the ErrorBoundary, so a persisted dangling flow/link UID reference no longer makes the model permanently uneditable.