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