Repository navigation
Fix a crash when Stats details list the same entry twice - #26464
crazytonyli wants to merge 1 commit into
Conversation
When a Stats response listed the same entry twice, with the same name, count and link, the details table crashed on the equal rows. Each top-level row now also carries how many equal rows come before it, so both copies show, as they already do when their counts differ.
wpmobilebot
left a comment
There was a problem hiding this comment.
Verdict: request changes. Numbering the copies fixes the reported crash: the details list now loads and shows both copies, and the Sentry case is a single category with no children. But tapping a repeated entry that has two or more children still crashes with the same exception. Before this PR the same data crashed as soon as the list opened, so no user is worse off. The tap crash is only reachable with this PR, though, and a crash counts as a blocker. Details are inline.
Tested on an iPhone 18 Pro simulator, iOS 27.2, Jetpack Debug build of 3a268a5, New Stats off, signed in with the WP.com test account. Tag stats came from a review-only store patch: Garden ×2 (single category), "Travel, Food" ×2 (two tags), plus other rows. Steps: Stats > Insights > add the Tags and Categories card > View more. The list loads with both copies, and alignment, spacing, separators and bars look right (light mode):
Tests: the PR's SiteStatsDetailsDuplicateRowsTests (3) and SiteStatsInsightsDetailsViewModelTests (3) pass on the PR head, and all three new tests fail on the merge base. I added a review test showing that SiteStatsInsightsDetailsViewModel's copy of the change also works: a repeated category loads there, and it throws on the merge base.
Gaps: I didn't check dark mode, Dynamic Type or VoiceOver. The data was synthetic (no real affected site), and I didn't check the Clicks, Authors or Referrers screens in the app; they share the code path the unit tests cover.
| hideIndentedSeparator: hideIndentedSeparator, | ||
| hideFullSeparator: !isLastRow, | ||
| expanded: expanded) | ||
| row.copyIndex = earlierRowsByName[rowData.name, default: []].count { $0 == rowData } |
There was a problem hiding this comment.
Blocker: Expanding a repeated entry that has two or more children still crashes. rowExpanded looks up the row's name, so tapping either copy expands both. Each copy then appends the same DetailExpandableChildRows (and nested parentRow(rowData: childRowData…) rows), and those have no copyIndex. With two or more children the first ones match exactly, and the snapshot hits the same duplicate-identifier exception.
On trunk this data crashed when the list opened, so nobody is worse off. But the tap crash is only reachable with this PR, so the release note's "Fix a crash when opening … details that list the same entry twice" holds only until the user taps.
Evidence:
- App: in the build from the summary, tapping either "Travel, Food" row aborts with
NSInternalInconsistencyExceptionin-[__UIDiffableDataSourceSnapshot appendItemsWithIdentifiers:intoSectionWithIdentifier:], viaStatsTotalRow.didTapDisclosureButton→SiteStatsDetailTableViewController.toggleChildRowsForRow→SiteStatsDetailsViewModel.tableViewSnapshot. - Unit test: using the same table setup as
SiteStatsDetailsDuplicateRowsTests, a repeated two-tag group loads collapsed. AfterStatsDataHelper.expandedRowLabelsDetails[.insightsTagsAndCategories] = ["Travel, Food"],tableViewSnapshot()throwsNSInternalInconsistencyException(_UIDiffableDataSourceUpdate.m:81).
The same code is in SiteStatsInsightsDetailsViewModel at line 1196. A small fix that doesn't need #26462: pass the parent's copyIndex to the child and nested parent rows it appends, and add copyIndex to DetailExpandableChildRow's ==. Then the two expanded copies stay distinct, even though both still expand together.

Description
Fixes JETPACK-IOS-1KAX
To reproduce the issue: with New Stats turned off, open Insights > Tags and Categories > View more on a site whose stats list the same category twice, with the same name, views and link. The app crashes with "supplied item identifiers are not unique" as soon as the list loads. Clicks, Authors and Referrers details crash the same way when an entry is repeated. The Insights card shows both copies without crashing.
In the Sentry events the repeated entry is always a single category with a
?taxonomy=category&term=<slug>link on a custom domain. Reading the WordPress.com code, the endpoint builds Jetpack sites' term links from the slug only and drops the term ID, so two category terms with the same name and slug come out as identical groups. That part is a hypothesis; nobody checked an affected site's terms.Each top-level row now also compares how many equal rows come before it, so both copies show. That matches what the card already does, and what the details list does when the two copies' views differ. Dropping or merging the copy was ruled out: if the server explanation holds, they are two real terms. When one copy's count changes, only that row is replaced.
One case is still open: expanding a repeated entry that has two or more children expands both copies, and their children collide. The fix for that belongs in the child row identity that #26462 changes, so it can follow once that lands. The two PRs touch the same files but not the same lines, and they merge cleanly in either order.
What I ran
Claude Code ran these on an iOS 27.2 simulator:
WordPressTest/SiteStatsDetailsDuplicateRowsTestsandWordPressTest/SiteStatsDetailsPostStatsTests:Test run with 6 tests in 2 suites passed. The three new tests fail on trunk.WordPressTest/SiteStatsInsightsDetailsViewModelTests,WordPressTest/SiteStatsImmuTableRowsTestsandWordPressTest/StatsTotalRowDataTests:Executed 6 tests, with 0 failures.Testing instructions
Claude Code reproduced the crash and checked the fix in the Jetpack app with stats responses served from a local proxy. None of the test account's sites has tag stats, so this wasn't tested with real data.