From ca65ee133c2fce09f22c37da201e0b370dd68749 Mon Sep 17 00:00:00 2001 From: Julien Wajsberg Date: Thu, 31 Mar 2022 11:09:52 +0200 Subject: [PATCH] Support the case where some visual metrics properties are missing Fixes #3966 --- src/profile-logic/tracks.js | 14 +++++++++++--- src/selectors/profile.js | 15 ++++++++------- src/types/profile.js | 17 +++++++++-------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/profile-logic/tracks.js b/src/profile-logic/tracks.js index c6d16011efd..d6e15bd5a62 100644 --- a/src/profile-logic/tracks.js +++ b/src/profile-logic/tracks.js @@ -387,9 +387,17 @@ export function computeGlobalTracks(profile: Profile): GlobalTrack[] { // Add the visual progress tracks if we have visualMetrics data. if (profile.meta && profile.meta.visualMetrics) { - globalTracks.push({ type: 'visual-progress' }); - globalTracks.push({ type: 'perceptual-visual-progress' }); - globalTracks.push({ type: 'contentful-visual-progress' }); + const metrics = profile.meta.visualMetrics; + // Some metrics might be missing depending on the options specified to browsertime. + if (metrics.VisualProgress) { + globalTracks.push({ type: 'visual-progress' }); + } + if (metrics.PerceptualSpeedIndexProgress) { + globalTracks.push({ type: 'perceptual-visual-progress' }); + } + if (metrics.ContentfulSpeedIndexProgress) { + globalTracks.push({ type: 'contentful-visual-progress' }); + } } // When adding a new track type, this sort ensures that the newer tracks are added diff --git a/src/selectors/profile.js b/src/selectors/profile.js index d12485a6752..949b67db031 100644 --- a/src/selectors/profile.js +++ b/src/selectors/profile.js @@ -170,14 +170,15 @@ export const getVisualMetrics: Selector = (state) => getVisualMetricsOrNull(state), 'Tried to access the visual metrics when it does not exist.' ); -export const getVisualProgress: Selector = (state) => - getVisualMetrics(state).VisualProgress; -export const getPerceptualSpeedIndexProgress: Selector = ( +export const getVisualProgress: Selector = ( state -) => getVisualMetrics(state).PerceptualSpeedIndexProgress; -export const getContentfulSpeedIndexProgress: Selector = ( - state -) => getVisualMetrics(state).ContentfulSpeedIndexProgress; +) => getVisualMetrics(state).VisualProgress; +export const getPerceptualSpeedIndexProgress: Selector< + ProgressGraphData[] | null +> = (state) => getVisualMetrics(state).PerceptualSpeedIndexProgress ?? null; +export const getContentfulSpeedIndexProgress: Selector< + ProgressGraphData[] | null +> = (state) => getVisualMetrics(state).ContentfulSpeedIndexProgress ?? null; export const getProfilerConfiguration: Selector = ( state ) => getMeta(state).configuration; diff --git a/src/types/profile.js b/src/types/profile.js index f6cc9d49020..57a8883dbcc 100644 --- a/src/types/profile.js +++ b/src/types/profile.js @@ -688,14 +688,6 @@ export type ProgressGraphData = {| * into the geckoprofile. More information about browsertime can be found through https://github.com/mozilla/browsertime. */ export type VisualMetrics = {| - // ContentfulSpeedIndex and ContentfulSpeedIndexProgress generated here - // https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1330 - ContentfulSpeedIndex: number, - ContentfulSpeedIndexProgress: ProgressGraphData[], - // PerceptualSpeedIndex and PerceptualSpeedIndexProgress generated here - // https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1319 - PerceptualSpeedIndex: number, - PerceptualSpeedIndexProgress: ProgressGraphData[], // FirstVisualChange, LastVisualChange, SpeedIndex generated here // https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1310 FirstVisualChange: number, @@ -712,6 +704,15 @@ export type VisualMetrics = {| VisualComplete85: number, VisualComplete95: number, VisualComplete99: number, + // Contentful and Perceptual values may all be missing + // ContentfulSpeedIndex and ContentfulSpeedIndexProgress generated here + // https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1330 + ContentfulSpeedIndex?: number, + ContentfulSpeedIndexProgress?: ProgressGraphData[], + // PerceptualSpeedIndex and PerceptualSpeedIndexProgress generated here + // https://github.com/mozilla/browsertime/blob/f453e93152003c7befb9a062feab86e25a4e9550/vendor/visualmetrics.py#L1319 + PerceptualSpeedIndex?: number, + PerceptualSpeedIndexProgress?: ProgressGraphData[], |}; // Units of ThreadCPUDelta values for different platforms.