Repository navigation
Stop Stats cards reloading when the date range hasn't changed - #26410
Merged
Merged
Conversation
StatsViewModel passed its date range selection to every card whenever it was assigned, even when the value hadn't changed. The Today and top-list cards reload on every assignment, so an unchanged assignment cancelled any load still in flight and started it again, one request later. The chart triggered this itself: after each load it sets selectedBarDate (usually nil to nil), and the selection pipeline sends that on as a new subrange. It also happened after a range change with a bar selected, and on a Today card tap, which started the Today load twice. Only pass the selection on when it actually changes.
crazytonyli
approved these changes
Nov 17, 2026
crazytonyli
left a comment
Contributor
There was a problem hiding this comment.
AI found an edge case of using Stats at midnight. I don't think it's a big deal, and I'll leave it to you to decide whether to fix it or not.
The new guard can leave the Today card showing yesterday’s totals when its initial load crosses site midnight. Previously, the chart finishing first triggered Today to recompute its date and reload. The guard now drops that update because the selected range is unchanged, allowing Today’s old request to finish. A simulator test reproduces this on head and passes on base.
6 tasks
Contributor
Author
|
From Claude: Made a note to come back to this in #26412 |
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Nov 17, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Nov 17, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Nov 18, 2026
Contributor
|
Version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a race where the Stats Traffic screen cancels the Today card's and top-list cards' first load and starts it again, so they appear one request later than they should.
What happens
When the chart card finishes loading before the Today card, the Today card's request is cancelled and sent again. The Today card then appears a full request later than the chart. Top-list cards (Posts & Pages, Referrers, …) are hit the same way.
It depends on which request finishes first, so it doesn't happen every time.
Root Cause
StatsViewModelpasses its date range selection to every card each timedateRangeis assigned, even when the value hasn't changed.TodayCardViewModelandTopListViewModelreload on every assignment, and a reload cancels the load in flight.Three things assign an unchanged selection:
ChartCardViewModelsetsselectedBarDate(nil → nil). The$selectedBarDate.dropFirst().removeDuplicates()pipeline lets that first value through, becauseremoveDuplicates()has nothing earlier to compare it with.handleChartBarSelectionthen setssubrange = nil, which is already nil.selectedBarDate, so one tap starts the Today load twice.Traced on a simulator, with a temporary 2 s delay added to
StatsService.getSiteStatsto make the timing visible:StatsViewModelsends the unchanged selection to every card (subrange=nil)Fix
StatsViewModel.dateRange'sdidSetnow returns early when the new value equals the old one.Nothing depends on sending an unchanged selection again:
The Today card still reloads when you pick a bar, even though its data doesn't depend on the bar. That's pre-existing and unchanged here.
Test plan
StatsViewModelDateRangeTestswith a stub service that holds requests until the test releases them, covering all three triggers. They fail on trunk (Today: 2 requests cancelled, 4 made instead of 2; top list: 8 made instead of 2; the Today tap starts 2 loads) and pass with the fix: 150 of 150 runs.JetpackStatsTestssuite passes: 243 tests.