Skip to content

Fix a crash when expanding two Stats detail rows that share a child - #26462

Merged
crazytonyli merged 2 commits into
trunkfrom
bugfix/26458-stats-shared-tag-child-rows
Nov 27, 2026
Merged

crazytonyli merged 2 commits into
trunkfrom
bugfix/26458-stats-shared-tag-child-rows

Conversation

@crazytonyli

Copy link
Copy Markdown
Contributor

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 changedCountReplacesOnlyThatMonth from #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.

SiteStatsInsightsDetailsViewModel has 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

  • I built this change and ran the affected tests locally

Claude Code ran these on an iOS 27.2 simulator:

  • WordPressTest/SiteStatsDetailsChildRowsTests and WordPressTest/SiteStatsDetailsPostStatsTests: Test run with 6 tests in 2 suites passed. The three new tests fail on trunk.
  • WordPressTest/SiteStatsInsightsDetailsViewModelTests, WordPressTest/SiteStatsImmuTableRowsTests and WordPressTest/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.

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.
@crazytonyli
crazytonyli marked this pull request as ready for review November 26, 2026 21:24
@crazytonyli crazytonyli added this to the 27.6 milestone Nov 26, 2026
@crazytonyli
crazytonyli requested a review from jkmassel November 26, 2026 21:25

@wpmobilebot wpmobilebot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread RELEASE-NOTES.txt Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The neighbouring entries end with a PR link. Consider adding [#26462].

@crazytonyli
crazytonyli added this pull request to the merge queue Nov 27, 2026
Merged via the queue into trunk with commit c0ded46 Nov 27, 2026
21 checks passed
@crazytonyli
crazytonyli deleted the bugfix/26458-stats-shared-tag-child-rows branch November 27, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stats: Tags and Categories details crashes when two expanded groups share a tag

2 participants