Repository navigation
frontend: burn down four diagram/server TypeScript issues - #730
Conversation
Three latent frontend issues surfaced during the React component audit: - adjustFlows (Flow.tsx) threw via defined(otherEnd) on a degenerate self-loop flow whose endpoints both attach to the same stock -- a shape that can't be drawn in the editor but arrives via imported models or programmatic patches, crashing the canvas. It now returns the flow unchanged when there is no other endpoint to anchor the valve against. - Menu (components/Menu.tsx) anchored Radix to a position:fixed proxy holding a getBoundingClientRect snapshot memoized on anchorEl identity, so the menu detached from its trigger if the anchor moved while open. A new useAnchorRect hook re-measures on capture-phase scroll, resize, and ResizeObserver, bailing out when the rect is unchanged so a stationary anchor does not force a re-render per scroll tick. - The (currently dead) Snapshotter error-append handlers in Editor.tsx used a non-functional setState read-then-write; converted both to the functional updater form matching the other concurrent-safe append sites so they cannot clobber a concurrent append if the Snapshotter is re-enabled. Fixes #720 Fixes #710 Fixes #728
After the body-parser 1->2 upgrade (with Express 4->5), req.body is
undefined -- not {} -- for empty-body or wrong-Content-Type requests. The
POST /api/projects and PATCH /api/user handlers dereferenced req.body
without guarding, so a malformed request threw a TypeError that Express 5
surfaced as a generic 500 instead of the intended 400, logging a stack
that masks real 500s in monitoring.
Extract the body validation into pure, dependency-free validators
(api-validation.ts) that treat a missing/undefined body as a bad request,
wire them into the two handlers, and unit-test them in isolation. Keeping
them out of api.ts means the validator tests do not pull the DB/protobuf/
engine-WASM surface into their module graph.
Fixes #691
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #730 +/- ##
=======================================
Coverage 90.61% 90.61%
=======================================
Files 224 224
Lines 135889 135889
=======================================
+ Hits 123132 123133 +1
+ Misses 12757 12756 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ReviewReviewed all four fixes. No blocking issues found. Notes (not blocking)
What I verified
Overall correctness verdictCorrect. The patch fixes the four targeted issues with appropriate test coverage and does not introduce regressions in the paths I traced. |
Fixes #720, fixes #710, fixes #728, fixes #691
Closes a batch of frontend/TypeScript issues surfaced during the recent React component audit and the deploy-risk audit. Each fix is test-driven; the changes were run through an adversarial sub-agent review and iterated until no material findings remained.
Fixes
#720 —
adjustFlowscrashes on a degenerate self-loop flowadjustFlows(src/diagram/drawing/Flow.tsx) calleddefined(otherEnd)and threw when handed a flow whose first and last points are both attached to the same stock. Such a flow can't be drawn in the editor but can arrive via imported models (XMILE/Vensim) or programmatic patches (MCP/API), crashing the canvas render/interaction path. It now early-returns the flow unchanged when there is no "other end" to anchor the valve fraction against (defense at the render boundary).flow-routing.test.ts— "degenerate self-loop flow" (reproduces the crash, verifies graceful no-op).#710 — Menu anchors Radix to a stale
getBoundingClientRectsnapshotMenu.tsxpositioned the dropdown via aposition:fixedproxy span placed at a rect memoized onanchorElidentity, so it never re-measured when the anchor moved (scroll/resize/reflow) and the menu detached from its trigger. A newuseAnchorRect(anchorEl, open)hook re-measures (viauseLayoutEffect) on capture-phasescroll,resize, andResizeObserverwhile open, and bails out (returns the prior reference) when the rect is unchanged so a stationary anchor doesn't force a re-render on every scroll tick.menu.test.tsx— initial measure, scroll-follow, resize-follow, listener-detach-on-close + reopen re-measure.#728 — Snapshotter
modelErrorsappends use non-functionalsetStateThe two snapshot-image error handlers in
Editor.tsxappended tomodelErrorswith a read-then-writesetState({ ... latest.current.state.modelErrors ... }), which is clobber-prone under concurrent appends. Converted both to the functional updater form, matching the file's other concurrent-safe append sites. (The Snapshotter UI is currently commented out, so this is dead code today; the fix prevents it being re-enabled in a broken state — no test is reachable.)#691 — Empty-body requests return 500 instead of 400
After the body-parser 1→2 / Express 4→5 upgrades,
req.bodyisundefined(not{}) for empty-body or wrong-Content-Typerequests.POST /api/projectsandPATCH /api/userdereferencedreq.bodywithout guarding, so malformed/probe traffic threw aTypeErrorthat Express 5 surfaced as a generic 500 (with stack noise that masks real 500s) instead of the intended 400. The body validation is extracted into pure, dependency-free validators (src/server/api-validation.ts) wired into both handlers.api-body-validation.test.ts— undefined/null/empty/wrong-type/falsy/extra-key cases for both validators (kept out ofapi.tsso the unit tests don't pull the DB/protobuf/engine-WASM graph).Verification
Deliberately deferred (not in this PR)
These related frontend/TS issues were evaluated and intentionally left for focused follow-ups:
canonicalizeimplementations): the issue's suggested approach (promote into@simlin/core, have@simlin/engineconsume it) is backwards relative to the actual dependency direction (@simlin/core→@simlin/engine; engine has no@simlindeps by design). True unification requires a core→engine runtime import plus a new cross-package subpath that must resolve consistently across four jest configs and the rsbuild production bundle — an architecture/bundler change too risky to bundle with hygiene fixes.ProjectController; needs dedicated design.exhaustive-depswould surface a large backlog against the freshly-migratedlatest-ref / empty-deps-effect code; a deliberate enable-and-triage effort of its own.