From 0b6c5722a5c2bd979e46d451080bbc032d567d76 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Mon, 22 May 2023 14:57:56 +0100 Subject: [PATCH] Graph: Fix bug with showing/hiding the legend (#68774) * don't unmount the root when hiding the legend * update comment --- public/app/plugins/panel/graph/graph.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index 819fa92e37d..eccc354ac75 100644 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -136,9 +136,14 @@ class GraphElement { if (!this.panel.legend.show) { if (this.legendElem.hasChildNodes()) { - this.legendElemRoot.unmount(); + this.legendElemRoot.render(null); } - this.renderPanel(); + // we need to wait for react to finish rendering the legend before we can render the graph + // this is a slightly worse version of the `renderCallback` logic we use below + // the problem here is there's nothing to pass a `renderCallback` to since we don't want to render the legend at all. + setTimeout(() => { + this.renderPanel(); + }); return; }