Skip to content

Commit 7529b3c

Browse files
Dale-Blackclaude
andcommitted
Fix Plotly CDN race condition: shared loader with callback queue
Multiple Plotly islands on the same page each tried to load the CDN script independently, causing race conditions where some plots never rendered. Now uses a shared queue (window._plotlyQ): first island loads the CDN, subsequent islands push their draw callback to the queue. When the CDN loads, all queued draws execute. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d1af853 commit 7529b3c

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/compiler/packages_plotly.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ function _plotly_plot_compiler(ctx, kwargs, pos_args)
6565
el_expr = "(typeof island!=='undefined'?island.querySelector('div[id]'):document.getElementById('therapy-plot'))"
6666
end
6767

68-
return "(function() { var _el = $(el_expr); if (_el && typeof Plotly !== 'undefined') { Plotly.react(_el, $(traces_js), $(layout_js), {responsive: true, displayModeBar: false}); } else if (_el) { var _s = document.createElement('script'); _s.src = 'https://cdn.plot.ly/plotly-2.35.2.min.js'; _s.onload = function() { Plotly.newPlot(_el, $(traces_js), $(layout_js), {responsive: true, displayModeBar: false}); }; document.head.appendChild(_s); } }())"
68+
# Shared Plotly loader: first call loads CDN, subsequent calls queue until loaded
69+
return """(function(){var _el=$(el_expr);if(!_el)return;function _draw(){Plotly.react(_el,$(traces_js),$(layout_js),{responsive:true,displayModeBar:false});}if(typeof Plotly!=='undefined'){_draw();}else{window._plotlyQ=window._plotlyQ||[];window._plotlyQ.push(_draw);if(!window._plotlyLoading){window._plotlyLoading=true;var s=document.createElement('script');s.src='https://cdn.plot.ly/plotly-2.35.2.min.js';s.onload=function(){for(var i=0;i<window._plotlyQ.length;i++)window._plotlyQ[i]();window._plotlyQ=[];};document.head.appendChild(s);}}})()"""
6970
end
7071

7172
# ─── Registration function (called when a module that has these names is available) ───

0 commit comments

Comments
 (0)