From cdbaf017f941ea4800db448a0f16ba5049a42a90 Mon Sep 17 00:00:00 2001 From: Ewan Croft Date: Thu, 13 Aug 2026 14:44:40 +0100 Subject: [PATCH] fix(tourmaline): correct mostPopularYear/Month fallback on empty data The fallback for zero-scrobble data (e.g. a date-range filter with no matches) was an object literal ({year: "N/A", count: 0}), but the code that consumes it indexes with [0]/[1] as if it were the [key, count] tuple sortedYears/monthlyCounts entries actually are. On that fallback path it silently produced {year: undefined, count: undefined} instead of the intended placeholder. --- packages/tourmaline/src/lib/analysis/aggregator.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/tourmaline/src/lib/analysis/aggregator.ts b/packages/tourmaline/src/lib/analysis/aggregator.ts index 3d1801e..1b1073e 100644 --- a/packages/tourmaline/src/lib/analysis/aggregator.ts +++ b/packages/tourmaline/src/lib/analysis/aggregator.ts @@ -337,10 +337,13 @@ export class Aggregator { yearCounts.set(year, (yearCounts.get(year) ?? 0) + count); } const sortedYears = [...yearCounts.entries()].sort((a, b) => b[1] - a[1]); - const mostPopularYear = sortedYears[0] ?? { year: "N/A", count: 0 }; + // Fallback must match the [key, count] tuple shape below — an object + // literal here would silently index to `undefined` via [0]/[1] on + // empty data (e.g. a date-range filter with zero matching scrobbles). + const mostPopularYear = sortedYears[0] ?? ["N/A", 0]; const mostPopularMonth = [...this.monthlyCounts.entries()].sort( (a, b) => b[1] - a[1], - )[0] ?? { month: "N/A", count: 0 }; + )[0] ?? ["N/A", 0]; const scrobbleStreaks = calcScrobbleStreaks(this.dailyCounts); const longestScrobbleStreak = scrobbleStreaks[0] ?? null; -- 2.51.2