From 8109adee274c336579b8f6bfd17814768c96c0a7 Mon Sep 17 00:00:00 2001 From: Peter Petrov Date: Sat, 21 Dec 2024 00:10:54 +0200 Subject: [PATCH] Boost: Fix sending multiple tracks when speed score changes (#40700) * Fix sending multiple tracks when speed score changes * Fix sending speed score changed tracks when popup was dismissed * add changelog --------- Co-authored-by: Adnan Haque --- .../js/features/speed-score/pop-out/pop-out.tsx | 14 ++++++++------ .../boost/changelog/fix-speed-score-changed-tracks | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 projects/plugins/boost/changelog/fix-speed-score-changed-tracks diff --git a/projects/plugins/boost/app/assets/src/js/features/speed-score/pop-out/pop-out.tsx b/projects/plugins/boost/app/assets/src/js/features/speed-score/pop-out/pop-out.tsx index 7b2338d27e4e5..715b2d3e17318 100644 --- a/projects/plugins/boost/app/assets/src/js/features/speed-score/pop-out/pop-out.tsx +++ b/projects/plugins/boost/app/assets/src/js/features/speed-score/pop-out/pop-out.tsx @@ -2,7 +2,7 @@ import { animated, useSpring } from '@react-spring/web'; import CloseButton from '$features/ui/close-button/close-button'; import styles from './pop-out.module.scss'; import { __ } from '@wordpress/i18n'; -import { ReactNode, useState } from 'react'; +import { ReactNode, useState, useEffect } from 'react'; import { Button } from '@wordpress/components'; import { useDismissibleAlertState } from '$features/performance-history/lib/hooks'; import { getRedirectUrl } from '@automattic/jetpack-components'; @@ -77,11 +77,13 @@ function PopOut( { scoreChange }: Props ) { const hideAlert = () => setClose( true ); - if ( hasScoreChanged ) { - recordBoostEvent( 'speed_score_alert_shown', { - score_direction: scoreChange > 0 ? 'up' : 'down', - } ); - } + useEffect( () => { + if ( hasScoreChanged && ! isDismissed && ! isClosed ) { + recordBoostEvent( 'speed_score_alert_shown', { + score_direction: scoreChange > 0 ? 'up' : 'down', + } ); + } + }, [ hasScoreChanged, scoreChange, isDismissed, isClosed ] ); const animationStyles = useSpring( { from: { diff --git a/projects/plugins/boost/changelog/fix-speed-score-changed-tracks b/projects/plugins/boost/changelog/fix-speed-score-changed-tracks new file mode 100644 index 0000000000000..5d4a87253a8ea --- /dev/null +++ b/projects/plugins/boost/changelog/fix-speed-score-changed-tracks @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: Fix for an unreleased change. + +