Skip to content

Commit

Permalink
trigger onPageReady only when data changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kpatticha committed Feb 25, 2025
1 parent 466045c commit c9be509
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import { useTrackPageview, FeatureFeedbackButton } from '@kbn/observability-shared-plugin/public';
import { usePerformanceContext } from '@kbn/ebt-tools';
import { OnboardingFlow } from '../../../components/shared/templates/no_data_config';
Expand Down Expand Up @@ -65,7 +65,7 @@ const MetricsExplorerContent = () => {
const { currentView } = useMetricsExplorerViews();

const { kibanaVersion, isCloudEnv, isServerlessEnv } = useKibanaEnvironmentContext();

const prevDataRef = useRef(data);
const { onPageReady } = usePerformanceContext();

useTrackPageview({ app: 'infra_metrics', path: 'metrics_explorer' });
Expand Down Expand Up @@ -97,13 +97,15 @@ const MetricsExplorerContent = () => {
};

useEffect(() => {
if (!isLoading && data) {
if (!isLoading && data && prevDataRef.current !== data) {
onPageReady({
meta: {
rangeFrom: timeRange.from,
rangeTo: timeRange.to,
},
});

prevDataRef.current = data;
}
}, [isLoading, data, timeRange.from, timeRange.to, onPageReady]);

Expand Down

0 comments on commit c9be509

Please sign in to comment.