From 33335039f0c5f9fe490385be14372df176098e57 Mon Sep 17 00:00:00 2001 From: chinesepowered <22500229+chinesepowered@users.noreply.github.com> Date: Sun, 19 Jul 2026 21:47:48 -0700 Subject: [PATCH] fix(LineChart): guard against fewer than two points With an empty points array, coords is empty and `const [ex, ey] = coords[coords.length - 1]` destructures undefined and throws. With a single point, `i / (points.length - 1)` is 0/0 = NaN, producing NaN path geometry. Return an empty (but correctly sized) chart area when given fewer than two points, since a line needs at least two. --- src/components/Charts.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/Charts.tsx b/src/components/Charts.tsx index d7b597d..1456c05 100644 --- a/src/components/Charts.tsx +++ b/src/components/Charts.tsx @@ -70,6 +70,11 @@ export function LineChart({ const animate = !isStatic && !reduce; const w = 300, h = 120; + // A line needs at least two points. Bail before the geometry below, which + // would divide by zero (points.length - 1) for a single point and throw on + // the end-point destructure (coords[-1]) for an empty array. + if (points.length < 2) + return
; const max = Math.max(...points), min = Math.min(...points); const span = max - min || 1;