dateRangeLength must be a positive integer dashboard error
Bug Description
There have been recent reports of the below error message, with one user stating this occurs when clicking on the Search console tab.
dateRangeLength must be a positive integer.
in LegacySearchConsoleDashboardWidgetSiteStats
in withData(LegacySearchConsoleDashboardWidgetSiteStats)
in Unknown
in WithSelect(withData(LegacySearchConsoleDashboardWidgetSiteStats))
in div
in Layout
in div
in div
in div
in div
in GoogleSitekitSearchConsoleDashboardWidget
in FilteredComponent
in WithFilters(ModuleApp)
in ModuleApp
in GoogleSitekitModule
in RestoreSnapshots
in ErrorHandler
in Root
- https://wordpress.org/support/topic/site-kit-encountered-an-error-36/ | Open | SH info provided
- https://wordpress.org/support/topic/error-search-google-in-site-kit/ | Open | SH info provided
- https://wordpress.org/support/topic/my-site-kit-has-occured-an-error/ | Open
- https://wordpress.org/support/topic/gsuite-shows-a-error-what-does-it-means | Resolved | SH info within topic | randomly started working as expected once more
- https://wordpress.org/support/topic/error-occur-to-site-kit/#post-14510879 | Open | SH info provided
- https://wordpress.org/support/topic/problem-with-search-console-in-google-site-kit/ | Open
- https://wordpress.org/support/topic/site-kit-encountered-an-error-38/#post-14516532 | Open
Troubleshooting ongoing, looking at the error message provided this looks similar to #3255
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
extractSearchConsoleDashboardDatashould be updated to acceptdateRangeLengthas a parameter rather than inferring this from the length of the data given as it does now- All (4) instances of components using
extractSearchConsoleDashboardDatashould be updated to retrieve the current date range length (e.g.getDateRangeNumberOfDays) to provide to this utility
Implementation Brief
- Merge #3478
Test Coverage
- Add and update tests for changes to
partitionReport
Visual Regression Changes
- Update reference images for Search Console chart due to change in date range (essentially undoes a change in #3348)
QA Brief
- Set up Site Kit using a property that has less-than-full data in Search Console (e.g. added in the last few weeks – @jamesozzie has such a property)
- Check Search Console dashboards (widget + non-widget based)
- Check all date ranges
- For date ranges that touch the maximum age of the property in Search Console (e.g. Last 28 days with the property added in Search Console 25 days ago) any larger date range should show same/similar metrics since larger date ranges include previous
Changelog entry
- Fix potential
dateRangeLength must be a positive integer.error for Search Console reports with missing dates.
Additional 2 reports added to issue description. No common plugins or obvious cause so far, all 3 sites do have a migration or demo content importer plugins active. Troubleshooting ongoing,
More reports of this from other users in an existing support topic. One of the users reported that since reporting the issue no longer occurs. The same user reported that from a Chrome browser incognito window the progress bar remained in a loading position.
Some findings from my investigation:
I first tried to generate a more meaningful stack trace:
- The error is thrown by the
partitionReportfunction in this file. - The
partitionReportfunction is used inside theextractSearchConsoleDashboardDatafunction here, - which in turn is used by the
LegacySearchConsoleDashboardWidgetSiteStatscomponent here.
I then managed to find one way to recreate the issue: it looks like if the report has only one row, the error is thrown.
extractSearchConsoleDashboardData tries to infer the range length from the number of rows:
export const extractSearchConsoleDashboardData = ( rows ) => {
// Infer range length from total number of rows.
const dateRangeLength = Math.floor( rows.length / 2 );
const { compareRange, currentRange } = partitionReport( rows, { dateRangeLength } );
// ...
And then partitionReport evaluates whether this is an integer greater than 1:
export const partitionReport = ( report, { dateRangeLength } ) => {
invariant( Array.isArray( report ), 'report must be an array to partition.' );
invariant( Number.isInteger( dateRangeLength ) && dateRangeLength > 0, 'dateRangeLength must be a positive integer.' );
This means that if the report only has one row, partitionReport is called with dateRangeLength of 0.5, which would then generate the error. LegacySearchConsoleDashboardWidgetSiteStats checks if the report is not undefined or empty, but a report with one row will be evaluated:
render() {
const { data, selectedStats } = this.props;
if ( ! data || ! data.length ) {
return null;
}
+ const subset = [ data[ 0 ] ];
const options = this.setOptions();
+ const processedData = extractSearchConsoleDashboardData( subset );
Based on this, a suggested fix might be to add a conditional to extractSearchConsoleDashboardData to account for cases where there is only one row of data.
This error also occurs if the number of rows in the report is 0 (zero) in extractSearchConsoleDashboardData. A conditional check in that function to see if the number of rows is less than 2 seems to solve the problem. If it is, setting dateRangeLength to 1 displays the widgets without error.
@Hazlitte Just a side note: LegacySearchConsoleDashboardWidgetSiteStats seems to check if the report is empty:
https://github.com/google/site-kit-wp/blob/045409d71d8f36315f97a0d47f49d39fcb9bdf0c/assets/js/modules/search-console/components/dashboard/LegacySearchConsoleDashboardWidgetSiteStats.js#L117-L119
Once the widgets.moduleScreens feature is turned on and we stop using the legacy widgets, we will still be calling extractSearchConsoleDashboardData:
https://github.com/google/site-kit-wp/blob/045409d71d8f36315f97a0d47f49d39fcb9bdf0c/assets/js/modules/search-console/components/module/ModuleOverviewWidget/Overview.js#L45-L47
In that scenario too, empty reports seem to be caught (via isZeroReport).
That was why I thought it might only be reports of length 1 that cause this issue. Thought it might be worth pointing out.
Either way, your > 2 fix suggestion would work, I think.
Thanks guys – let's see if we can get this fixed for the release.
Here is a possible solution in extractSearchConsoleDashboardData:
const dateRangeLength = rows.length > 1 ? Math.floor( rows.length / 2 ) : 1;
After looking into this a bit more, I've found this is due to other problems related to how the Search Console API works which I will open a new issue for. For now, this issue is just about avoiding the error by using the utility in the same way it is used everywhere else.
QA ✅
Ran through a series of tests on a site with has less-than-full data in Search Console.
Was unable to reproduce this error.


This is fixed on my end. Sending to approval.