Skip to content

Commit 0c94b1b

Browse files
authored
Fix: Avoid re-renders due to query being re-created on each render (#103224)
1 parent 19432e4 commit 0c94b1b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

client/my-sites/stats/site.jsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import InlineSupportLink from 'calypso/components/inline-support-link';
2727
import JetpackColophon from 'calypso/components/jetpack-colophon';
2828
import NavigationHeader from 'calypso/components/navigation-header';
2929
import StickyPanel from 'calypso/components/sticky-panel';
30-
import memoizeLast from 'calypso/lib/memoize-last';
3130
import version_compare from 'calypso/lib/version-compare';
3231
import Main from 'calypso/my-sites/stats/components/stats-main';
3332
import {
@@ -95,14 +94,6 @@ const HIDDABLE_MODULES = AVAILABLE_PAGE_MODULES.traffic.map( ( module ) => {
9594
return module.key;
9695
} );
9796

98-
const chartRangeToQuery = memoizeLast( ( chartRange ) => ( {
99-
period: 'day',
100-
start_date: chartRange.chartStart,
101-
date: chartRange.chartEnd,
102-
summarize: 1,
103-
max: 10,
104-
} ) );
105-
10697
const CHART_VIEWS = {
10798
attr: 'views',
10899
legendOptions: [ 'visitors' ],
@@ -504,7 +495,16 @@ function StatsBody( { siteId, chartTab = 'views', date, context, isInternal, ...
504495
setActiveLegend( period !== 'hour' ? newActiveTab.legendOptions || [] : [] );
505496
}, [ chartTab, period, activeTabState, context.query ] );
506497

507-
const query = chartRangeToQuery( customChartRange );
498+
const query = useMemo(
499+
() => ( {
500+
period: 'day',
501+
start_date: customChartRange.chartStart,
502+
date: customChartRange.chartEnd,
503+
summarize: 1,
504+
max: 10,
505+
} ),
506+
[ customChartRange.chartStart, customChartRange.chartEnd ]
507+
);
508508

509509
// For period option links
510510
const traffic = {

0 commit comments

Comments
 (0)