mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:25:22 +02:00
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
3e3975cd2b
commit
f1e11ca79a
@@ -65,10 +65,13 @@ export const BSRUnitsCorrelationChart: React.FC<Props> = ({ 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
|
||||
|
||||
Reference in New Issue
Block a user