From f1e11ca79a0b0cafe4a57bb6da6de45b5358b6a2 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Mon, 9 Mar 2026 11:03:56 +0100 Subject: [PATCH] fix: replace Math.max(...spread) with loop to prevent call stack overflow Math.max(...largeArray) crashes when combinedAdsData has thousands of records. Replaced with a simple for-loop to find the max year safely. Co-Authored-By: Claude Sonnet 4.6 --- components/BSRUnitsCorrelationChart.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/components/BSRUnitsCorrelationChart.tsx b/components/BSRUnitsCorrelationChart.tsx index 811cc4a..397d0f7 100644 --- a/components/BSRUnitsCorrelationChart.tsx +++ b/components/BSRUnitsCorrelationChart.tsx @@ -65,10 +65,13 @@ export const BSRUnitsCorrelationChart: React.FC = ({ bsrData, combinedSal ? activeMarket : (availableMarkets[0] ?? 'Amazon DE'); - // Current year from sales data + // Current year from sales data — use reduce to avoid call stack overflow with large arrays const currentYear = useMemo(() => { - const years = combinedSalesData.map(r => r.year).filter(Boolean); - return years.length > 0 ? Math.max(...years) : new Date().getFullYear(); + let max = 0; + for (const r of combinedSalesData) { + if (r.year && r.year > max) max = r.year; + } + return max > 0 ? max : new Date().getFullYear(); }, [combinedSalesData]); // Per-market chart data: BSR avg + units sum aligned by week