From c3c20de1b82133b1fef018c9ac4a90b1041288dc Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:10:02 +0100 Subject: [PATCH] Graph view: do initial refresh safely when autorefresh is off --- src/views/Graph.vue | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/views/Graph.vue b/src/views/Graph.vue index fa4b5050a0..79d92ebec8 100644 --- a/src/views/Graph.vue +++ b/src/views/Graph.vue @@ -283,16 +283,12 @@ export default { }, mounted () { - if (!this.autoRefresh) { - // load the graph if the autorefresh is off - this.refreshTimer = setInterval(this.refresh, 1000) - this.refreshTimer = null - } // compile & instantiate graphviz wasm /** @type {Promise} */ this.graphviz = Graphviz.load() // allow render to happen before we go configuring svgPanZoom this.$nextTick(() => { + this.refresh() this.updateTimer() }) this.mountSVGPanZoom() @@ -589,7 +585,10 @@ export default { this.updating = true // extract the graph (non reactive lists of nodes & edges) - const nodes = this.getGraphNodes() + const nodes = await this.waitFor(() => { + const nodes = this.getGraphNodes() + return nodes.length ? nodes : false + }) const edges = this.getGraphEdges() if (!nodes.length) { @@ -623,11 +622,9 @@ export default { // obtain the node dimensions to use in the layout // NOTE: need to wait for the nodes to all be rendered before we can // measure them - let nodeDimensions - await this.waitFor(() => { + const nodeDimensions = await this.waitFor(() => { try { - nodeDimensions = this.getNodeDimensions(nodes) - return true // all nodes rendered + return this.getNodeDimensions(nodes) // all nodes rendered } catch { return false // one or more nodes awaiting render } @@ -665,9 +662,8 @@ export default { // Will return when the callback returns something truthy. // OR after the configured number of retries for (let retry = 0; retry < retries; retry++) { - if (callback()) { - break - } + const ret = callback() + if (ret) return ret await new Promise(requestAnimationFrame) await this.$nextTick() }