You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EquilibriumPlot crashes on empty/sparse data (Math.max(...[]), unguarded regression) #225
Combines two related findings from a codebase audit (B3, B8) — same code, same fix.
Problem
B3: In `src/components/plots/EquilibriumPlot.tsx` (lines 50–84, 135–136), when no equilibrium data has been recorded yet, `x = []`. `Math.max(...[])` returns `-Infinity` and `Math.min(...[])` returns `Infinity`, used as Y-axis positions for reference lines. The `bestFit` regression is also computed on empty data (`regression.logarithmic([])`) before the `x.length >= 3` guard exists, which can throw or return NaN/garbage.
B8: The `bestFit` `useMemo` (same lines) always runs `regression.logarithmic`/`regression.exponential` before checking `bestFitVisible = x.length >= 3` — the expensive/unsafe computation runs unconditionally on every render regardless of whether there's enough data to use it.
Severity: High (B3) / Medium (B8)
Fix
Guard all trace/line construction and the regression computation with `x.length >= 3` (the same threshold the component already uses to decide whether to display the result) before computing min/max and running regression. Return a safe empty/default result early if there isn't enough data.
Activity