Skip to content

EquilibriumPlot crashes on empty/sparse data (Math.max(...[]), unguarded regression) #225

Description

@meganrm

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.

🤖 Filed via Claude Code from a codebase audit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions