Repository navigation
Fix a crash when expanding two years in a post's Months and Years stats - #26415
Conversation
Month rows in Months and Years and Avg. Views Per Day showed only the month name and views, so the same month with the same views in two expanded years produced equal rows. The diffable detail table rejected them as duplicate items and the app crashed. Month rows now carry their year and month, and row equality compares it.
|
Version |
jkmassel
left a comment
There was a problem hiding this comment.
From Claude:
Not blocking: the fix is correct and stops the crash. Nothing it breaks turned up.
What we checked
- Sentry JETPACK-IOS-1ASW: all 11 reports Sentry still keeps are the month-row case, on releases up to 27.4.
- The new tests pass on this branch (4 cases) and all 4 fail with trunk's
StatsDataHelper.swiftandStatsTotalRow.swift. - iOS 27.2 simulator, Jetpack Debug, New Stats off, post stats served through a local proxy with April at 12 views in both 2026 and 2025. In Months and Years details, the trunk build crashes on the second expand with the same "identifiers are not unique" error as Sentry. This branch keeps both years open, and collapsing and reopening 2026 also works.
- swift-format and SwiftLint are clean on the changed lines.
A similar crash this PR doesn't cover
Tags and Categories details crashes the same way when two expanded groups share a tag, for example "news, tech" and "news, sport". We reproduced it on a build of this branch. It's older than this PR, so it shouldn't hold this one up; filed as #26458. Making each child row include its parent's identity would cover months, tags and other expandable sections in one place.
Three nits inline.
| /// | ||
| /// Without it, the same month with the same views in two years gives equal rows, and the | ||
| /// diffable Stats detail table crashes on the duplicate items when both years are expanded. | ||
| var month: DateComponents? |
There was a problem hiding this comment.
Finding from Claude:
Nit: month holds the year as well as the month, and the year is what keeps rows from different years apart. A name like yearMonth would make it harder for someone to fill it with DateComponents(month: 4) later and bring the crash back.
| /// Without it, the same month with the same views in two years gives equal rows, and the | ||
| /// diffable Stats detail table crashes on the duplicate items when both years are expanded. |
There was a problem hiding this comment.
Finding from Claude:
Nit: this paragraph describes the crash the change fixes, which fits the commit message better. One line is enough here, for example:
| /// Without it, the same month with the same views in two years gives equal rows, and the | |
| /// diffable Stats detail table crashes on the duplicate items when both years are expanded. | |
| /// Keeps the same month from different years distinct, since `name` shows only the month. |
| StatsDataHelper.expandedRowLabelsDetails[section] = years | ||
| } | ||
|
|
||
| /// Seven years with positive totals, as in the reproduction. 2026 and 2025 both |
There was a problem hiding this comment.
Finding from Claude:
Nit: "as in the reproduction" points at something a later reader can't open. Dropping that phrase keeps the comment true.
🤖 Build Failure AnalysisThis build has failures. Claude has analyzed them - check the build annotations for details. |
Trunk is on 27.6 since the 27.5 code freeze.
Fixes JETPACK-IOS-1ASW: https://a8c.sentry.io/issues/5297452992/
In classic Post Stats, Months and Years and Avg. Views Per Day crash with
NSInternalInconsistencyException("identifiers are not unique") when two expanded years have the same month with the same views. Month rows held only the month name and the count, so April 2026 and April 2025 with 12 views were equal rows, and the diffable table rejected them as duplicates.Month rows now carry their year and month, and row equality compares it.
Testing:
SiteStatsDetailsPostStatsTestschecks the view model's table snapshot. Its four cases fail on trunk and pass with this change.To test by hand: open a post with the same month and views in two years, then expand both years in Months and Years.