Repository navigation
Fix a crash when expanding two Stats detail rows that share a child - #26462
Conversation
A tag in two expanded tag groups, a link in two Clicks groups, or a post under two authors made two equal child rows, and the diffable table crashed on the duplicates. Child rows now also compare the names of the rows they sit under.
wpmobilebot
left a comment
There was a problem hiding this comment.
Approve. I checked this on an iPhone 18 Pro simulator running iOS 27.2, using the Jetpack app with old Stats. A review-only patch replaced the Tags and Categories response with two groups that share a tag (news, tech and news, sport) plus six single categories. I opened Insights > Tags and Categories > View more, expanded both groups, then collapsed and re-expanded them. There was no crash, each news row stayed under its own group, and the layout, separators and spacing looked right:
Tests: the three new SiteStatsDetailsChildRowsTests pass, as do SiteStatsDetailsPostStatsTests (including changedCountReplacesOnlyThatMonth) and the existing XCTest stats suites. With the three source files reverted to trunk, all three new tests crash with NSInternalInconsistencyException, so they cover the bug. A local probe confirmed that a parent's count change leaves its child rows equal, so the children aren't reloaded. CI is green.
The grandchild path ([rowData.name, childRowData.name]) can only be reached for Referrers. Referrer rows don't expand on this screen (StatsTotalRow skips .periodReferrers), so I didn't check it. I also didn't check the Clicks and Authors screens in the app. The unit tests cover them.
| // If this child has no children, add it as a child row. | ||
| guard !grandChildRowsData.isEmpty else { | ||
| detailDataRows.append(childRow(rowData: childRowData, | ||
| parentNames: [rowData.name], |
There was a problem hiding this comment.
Pre-existing: As the description says, parents are told apart by name only, so two parents with the same name and an equal child still crash. I confirmed this with a local test: two authors both named "Alex" sharing a post, both expanded, makes tableViewSnapshot() throw NSInternalInconsistencyException. It throws on trunk too, so this PR doesn't make it worse. Optional follow-up: use the parent's position instead of its name (for example parentPath: [idx] / [idx, childIdx]). It's unique even when names repeat, and a count change still leaves unchanged children equal. A reorder would only reload rows.
| 27.6 | ||
| ----- | ||
| * [*] Stats: Fix a crash when expanding two years with the same month and views in a post's Months and Years or Avg. Views Per Day details [#26415] | ||
| * [*] Stats: Fix a crash when expanding two Tags and Categories groups that share a tag, two Clicks groups with the same link, or two Authors with the same post |
There was a problem hiding this comment.
Nit: The neighbouring entries end with a PR link. Consider adding [#26462].

Description
Fixes #26458
To reproduce the issue: with New Stats turned off, open Insights > Tags and Categories > View more on a site whose top tags include two groups that share a tag (for example "news, tech" and "news, sport"). Expand both groups. The app crashes with "supplied item identifiers are not unique". Clicks (the same link in two groups) and Authors (a co-authored post under two authors) crash the same way. Referrers can't, because tapping a referrer group opens a separate screen.
The two "news" child rows were equal, so the diffable table rejected them. Child rows now also compare the names of the rows they sit under. This is the same crash #26415 fixed for Post Stats months, with the parent as the identity instead of a per-section key, so it covers every expandable section at once.
The identity uses parent names rather than whole parent rows. Comparing whole rows also fixes the crash, but a parent's new count would then replace all of its unchanged children, which breaks
changedCountReplacesOnlyThatMonthfrom #26415. The trade-off: two parents with the same name and an equal child, such as two authors with the same display name sharing a post, would still collide.SiteStatsInsightsDetailsViewModelhas a copy of the row builder. Its Tags, Clicks and Authors paths aren't reachable today, but it gets the same change so the two copies stay identical.None of the Sentry reports still kept come from these screens. JETPACK-IOS-1KAX is also on Tags and Categories but has a different cause (the same top-level row twice in one response), so this PR doesn't fix it.
What I ran
Claude Code ran these on an iOS 27.2 simulator:
WordPressTest/SiteStatsDetailsChildRowsTestsandWordPressTest/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. This run was before a test-fixture-only change.Testing instructions
Claude Code reproduced the crash and checked the fix in the Jetpack app with stats responses served from a local proxy, not real site data.