Skip to content

Commit

Permalink
fix: dispatch draw command to avoid render race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Oct 31, 2023
1 parent b045153 commit 0145e44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/static/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function drawGraph(opts, content) {

// check that a valid graph was rendered
if (buildGraphElement === null || buildGraphElement.node() === null) {
console.log('unable to continue drawing graph, root element is invalid');
return;
}

Expand Down
12 changes: 9 additions & 3 deletions src/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,19 @@ var opts = {
app.ports.renderBuildGraph.subscribe(function (graphData) {
const graphviz = Graphviz.load().then(res => {
var content = res.layout(graphData.dot, 'svg', 'dot');

// construct graph building options
opts.isRefreshDraw = opts.currentBuild === graphData.build_id;
opts.centerOnDraw = graphData.center_on_draw;
opts.currentBuild = graphData.build_id;
opts.contentFilter = graphData.filter;

// track the currently drawn build
opts.currentBuild = graphData.build_id;

opts.onGraphInteraction = app.ports.onGraphInteraction;
Graph.drawGraph(opts, content);

// dispatch the draw command to avoid elm/js rendering order issues
setTimeout(() => {
Graph.drawGraph(opts, content);
}, 0);
});
});

0 comments on commit 0145e44

Please sign in to comment.