Skip to content

Commit 69ab0bd

Browse files
authored
Boost: Fix empty performance history on initial page load (#35211)
* Load performance history data on-mount but keep it for longer * Refresh performance history on score update * changelog * Add a clarification comment
1 parent 8c90070 commit 69ab0bd

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

projects/plugins/boost/app/assets/src/js/features/performance-history/lib/hooks.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ export const usePerformanceHistoryQuery = () => {
2727
const [ query ] = useDataSync(
2828
'jetpack_boost_ds',
2929
'performance_history',
30-
performanceHistoryDataSchema
30+
performanceHistoryDataSchema,
31+
{
32+
query: {
33+
staleTime: 12 * 60 * 60 * 1000, // 12 hours
34+
},
35+
}
3136
);
3237

3338
return query;

projects/plugins/boost/app/assets/src/js/features/performance-history/performance-history.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Button } from '@automattic/jetpack-components';
1212
import { useNavigate } from 'react-router-dom';
1313
import { useSingleModuleState } from '$features/module/lib/stores';
1414
import styles from './performance-history.module.scss';
15+
import { useEffect } from 'react';
1516

1617
const PerformanceHistoryBody = () => {
1718
const [ performanceHistoryState ] = useSingleModuleState( 'performance_history' );
@@ -23,6 +24,13 @@ const PerformanceHistoryBody = () => {
2324
);
2425
const navigate = useNavigate();
2526

27+
/*
28+
* Fetch new data on initial page-load. This is a lazy data-sync and initially empty.
29+
*/
30+
useEffect( () => {
31+
refetch();
32+
}, [ refetch ] );
33+
2634
if ( isError && ! isFetching ) {
2735
return (
2836
<ErrorNotice
@@ -44,7 +52,7 @@ const PerformanceHistoryBody = () => {
4452
needsUpgrade={ needsUpgrade }
4553
handleUpgrade={ () => navigate( '/upgrade' ) }
4654
handleDismissFreshStart={ dismissFreshStart }
47-
isLoading={ isFetching }
55+
isLoading={ isFetching && ( ! data || data.periods.length === 0 ) }
4856
/>
4957
);
5058
};

projects/plugins/boost/app/assets/src/js/features/speed-score/speed-score.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import styles from './speed-score.module.scss';
1818
import { useModulesState } from '$features/module/lib/stores';
1919
import { useCriticalCssState } from '$features/critical-css/lib/stores/critical-css-state';
2020
import { useLocalCriticalCssGeneratorStatus } from '$features/critical-css/local-generator/local-generator-provider';
21+
import { queryClient } from '@automattic/jetpack-react-data-sync-client';
2122

2223
const SpeedScore = () => {
2324
const { site } = Jetpack_Boost;
@@ -50,6 +51,13 @@ const SpeedScore = () => {
5051
}
5152
}, [ loadScore, site.online ] );
5253

54+
// Mark performance history data as stale when speed scores are loaded.
55+
useEffect( () => {
56+
if ( site.online && status === 'loaded' ) {
57+
queryClient.invalidateQueries( { queryKey: [ 'performance_history' ] } );
58+
}
59+
}, [ site.online, status ] );
60+
5361
useDebouncedRefreshScore(
5462
{ moduleStates, criticalCssCreated: cssState.created || 0, criticalCssIsGenerating },
5563
async () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: fixed
3+
Comment: Fixed empty performance history on initial page load. Introduced during react migration
4+
5+

0 commit comments

Comments
 (0)