From 579e96cf5d1ec0fc5c420c4dc05b0a521a21b115 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Mon, 16 Mar 2026 15:12:10 +0100 Subject: [PATCH] fix: add null safety checks for years in TopMovers - Add || null to years array access to prevent undefined values - Add !currentYear || !previousYear to insufficient data check - This prevents errors when filtered data has less than 2 years Co-authored-by: Qwen-Coder --- components/TopMovers.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/TopMovers.tsx b/components/TopMovers.tsx index f004bba..4fa3e93 100644 --- a/components/TopMovers.tsx +++ b/components/TopMovers.tsx @@ -190,8 +190,8 @@ const TopMovers: React.FC = ({ data, stockMap, vendorStockMap, b const { currentYear, previousYear, availableYears } = useMemo(() => { const years = Array.from(new Set(data.map(d => d.year))).sort((a: number, b: number) => b - a); return { - currentYear: years[0], - previousYear: years[1], + currentYear: years[0] || null, + previousYear: years[1] || null, availableYears: years }; }, [data]); @@ -263,7 +263,7 @@ const TopMovers: React.FC = ({ data, stockMap, vendorStockMap, b }, [data, metric, currentYear, previousYear]); - if (availableYears.length < 2) { + if (availableYears.length < 2 || !currentYear || !previousYear) { return (

Insufficient Data for Comparison