From 5115001f7187414fefcedee53ba82ee9199aa6fb Mon Sep 17 00:00:00 2001
From: "metabase-bot[bot]"
 <109303359+metabase-bot[bot]@users.noreply.github.com>
Date: Mon, 1 Apr 2024 16:43:03 +0000
Subject: [PATCH] Fix x-ray dashboards run some queries twice on load (#40844)
 (#40853)

* Fix parameter values comparison in x-rays

* Skip rerun when `parameterValues` are not initialized

* Remove not used code

Co-authored-by: Anton Kulyk <kuliks.anton@gmail.com>
---
 .../src/metabase/dashboard/hoc/DashboardData.jsx | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/frontend/src/metabase/dashboard/hoc/DashboardData.jsx b/frontend/src/metabase/dashboard/hoc/DashboardData.jsx
index 61045a20bd4..6764e24ab7c 100644
--- a/frontend/src/metabase/dashboard/hoc/DashboardData.jsx
+++ b/frontend/src/metabase/dashboard/hoc/DashboardData.jsx
@@ -91,16 +91,24 @@ export const DashboardData = ComposedComponent =>
       UNSAFE_componentWillReceiveProps(nextProps) {
         if (nextProps.dashboardId !== this.props.dashboardId) {
           this.load(nextProps);
-        } else if (
+          return;
+        }
+
+        // First time componentWillReceiveProps is called,
+        // parameterValues are an empty object, and nextProps.parameterValues have all value set to null
+        // DashboardsData is only used for x-rays, and we should better switch them to the same logic as other dashboards
+        if (
+          !_.isEmpty(this.props.parameterValues) &&
           !_.isEqual(this.props.parameterValues, nextProps.parameterValues)
         ) {
           this.props.fetchDashboardCardData({
             reload: false,
             clearCache: true,
           });
-        } else if (
-          !_.isEqual(nextProps.selectedTabId, this.props.selectedTabId)
-        ) {
+          return;
+        }
+
+        if (!_.isEqual(nextProps.selectedTabId, this.props.selectedTabId)) {
           this.props.fetchDashboardCardData();
           this.props.fetchDashboardCardMetadata();
           return;
-- 
GitLab