From 23ed0467a26ea25eedca0fe5406d88b0d2d52842 Mon Sep 17 00:00:00 2001
From: Yury Molodov <yurymolodov@gmail.com>
Date: Fri, 21 Apr 2023 10:59:09 +0200
Subject: [PATCH] vmui: fix freeze when query regular with heatmap query
 (#4093)

* fix: fix freeze when query regular with heatmap query

* vmui/docs: fix freeze when query regular with heatmap query
---
 .../packages/vmui/src/pages/CustomPanel/index.tsx     | 11 +++++++++--
 app/vmui/packages/vmui/src/utils/uplot/heatmap.ts     |  2 +-
 docs/CHANGELOG.md                                     |  1 +
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/app/vmui/packages/vmui/src/pages/CustomPanel/index.tsx b/app/vmui/packages/vmui/src/pages/CustomPanel/index.tsx
index 8d760ff57..2194056d2 100644
--- a/app/vmui/packages/vmui/src/pages/CustomPanel/index.tsx
+++ b/app/vmui/packages/vmui/src/pages/CustomPanel/index.tsx
@@ -44,7 +44,14 @@ const CustomPanel: FC = () => {
 
   const { queryOptions } = useFetchQueryOptions();
   const {
-    isLoading, liveData, graphData, error, queryErrors, warning, traces, isHistogram
+    isLoading,
+    liveData,
+    graphData,
+    error,
+    queryErrors,
+    warning,
+    traces,
+    isHistogram
   } = useFetchQuery({
     visible: true,
     customStep,
@@ -97,7 +104,7 @@ const CustomPanel: FC = () => {
 
   useEffect(() => {
     graphDispatch({ type: "SET_IS_HISTOGRAM", payload: isHistogram });
-  }, [isHistogram]);
+  }, [graphData]);
 
   return (
     <div
diff --git a/app/vmui/packages/vmui/src/utils/uplot/heatmap.ts b/app/vmui/packages/vmui/src/utils/uplot/heatmap.ts
index 0f03a11c5..0f57a3ce2 100644
--- a/app/vmui/packages/vmui/src/utils/uplot/heatmap.ts
+++ b/app/vmui/packages/vmui/src/utils/uplot/heatmap.ts
@@ -137,7 +137,7 @@ export const convertPrometheusToVictoriaMetrics = (buckets: MetricResult[]): Met
 };
 
 const getUpperBound = (bucket: MetricResult) => {
-  const values = (bucket.metric.vmrange || bucket.metric.le).split("...");
+  const values = (bucket.metric.vmrange || bucket.metric.le || "").split("...");
   return promValueToNumber(values[values.length - 1]);
 };
 
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index dbb53cff6..2aaab8d16 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -29,6 +29,7 @@ The following tip changes can be tested by building VictoriaMetrics components f
 * BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): fix a panic when the duration in the query contains uppercase `M` suffix. Such a suffix isn't allowed to use in durations, since it clashes with `a million` suffix, e.g. it isn't clear whether `rate(metric[5M])` means rate over 5 minutes, 5 months or 5 million seconds. See [this](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3589) and [this](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4120) issues.
 * BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert.html): retry failed read request on the closed connection one more time. This improves rules execution reliability when connection between vmalert and datasource closes unexpectedly.
 * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix the display of the tenant selector. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4160).
+* BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): fix issue where vmui would freeze when adding a query that returned regular rows alongside a heatmap query.
 * BUGFIX: [VictoriaMetrics cluster](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html): prevent from possible panic when the number of vmstorage nodes increases when [automatic vmstorage discovery](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#automatic-vmstorage-discovery) is enabled.
 
 ## [v1.90.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.90.0)