Skip to content

Commit 5cffe97

Browse files
Do initial refresh safely when autorefresh is off
1 parent 9abf4dc commit 5cffe97

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/views/Graph.vue

+9-13
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,12 @@ export default {
282282
},
283283

284284
mounted () {
285-
if (!this.autoRefresh) {
286-
// load the graph if the autorefresh is off
287-
this.refreshTimer = setInterval(this.refresh, 1000)
288-
this.refreshTimer = null
289-
}
290285
// compile & instantiate graphviz wasm
291286
/** @type {Promise<Graphviz>} */
292287
this.graphviz = Graphviz.load()
293288
// allow render to happen before we go configuring svgPanZoom
294289
this.$nextTick(() => {
290+
this.refresh()
295291
this.updateTimer()
296292
})
297293
this.mountSVGPanZoom()
@@ -588,7 +584,10 @@ export default {
588584
this.updating = true
589585

590586
// extract the graph (non reactive lists of nodes & edges)
591-
const nodes = this.getGraphNodes()
587+
const nodes = await this.waitFor(() => {
588+
const nodes = this.getGraphNodes()
589+
return nodes.length ? nodes : false
590+
})
592591
const edges = this.getGraphEdges()
593592

594593
if (!nodes.length) {
@@ -622,11 +621,9 @@ export default {
622621
// obtain the node dimensions to use in the layout
623622
// NOTE: need to wait for the nodes to all be rendered before we can
624623
// measure them
625-
let nodeDimensions
626-
await this.waitFor(() => {
624+
const nodeDimensions = await this.waitFor(() => {
627625
try {
628-
nodeDimensions = this.getNodeDimensions(nodes)
629-
return true // all nodes rendered
626+
return this.getNodeDimensions(nodes) // all nodes rendered
630627
} catch {
631628
return false // one or more nodes awaiting render
632629
}
@@ -664,9 +661,8 @@ export default {
664661
// Will return when the callback returns something truthy.
665662
// OR after the configured number of retries
666663
for (let retry = 0; retry < retries; retry++) {
667-
if (callback()) {
668-
break
669-
}
664+
const ret = callback()
665+
if (ret) return ret
670666
await new Promise(requestAnimationFrame)
671667
await this.$nextTick()
672668
}

0 commit comments

Comments
 (0)