Skip to content

Commit

Permalink
Fix product card tracks loading issue (#36790)
Browse files Browse the repository at this point in the history
* Use useLayoutEffect instead of useEffect

* changelog

* Add comment explaining reasoning for hook
  • Loading branch information
CodeyGuyDylan authored Apr 9, 2024
1 parent b969a79 commit b4cd9a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { useConnectionErrorNotice, ConnectionError } from '@automattic/jetpack-connection';
import { __ } from '@wordpress/i18n';
import classnames from 'classnames';
import { useContext, useEffect, useState } from 'react';
import { useContext, useLayoutEffect, useState } from 'react';
/*
* Internal dependencies
*/
Expand Down Expand Up @@ -98,7 +98,9 @@ export default function MyJetpackScreen() {
const { recordEvent } = useAnalytics();
const [ reloading, setReloading ] = useState( false );

useEffect( () => {
// useLayoutEffect gets called before useEffect.
// We are using it here to ensure the `page_view` event gets triggered first.
useLayoutEffect( () => {
recordEvent( 'jetpack_myjetpack_page_view', {
red_bubble_alerts: Object.keys( redBubbleAlerts ).join( ',' ),
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure page_view gets loaded before product_card_loaded

0 comments on commit b4cd9a2

Please sign in to comment.