File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
lib/matplotlib/backends/web_backend/js Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,15 @@ mpl.figure.prototype._init_canvas = function () {
192192 }
193193
194194 this . resizeObserverInstance = new this . ResizeObserver ( function ( entries ) {
195+ // There's no need to resize if the WebSocket is not connected:
196+ // - If it is still connecting, then we will get an initial resize from
197+ // Python once it connects.
198+ // - If it has disconnected, then resizing will clear the canvas and
199+ // never get anything back to refill it, so better to not resize and
200+ // keep something visible.
201+ if ( fig . ws . readyState != 1 ) {
202+ return ;
203+ }
195204 var nentries = entries . length ;
196205 for ( var i = 0 ; i < nentries ; i ++ ) {
197206 var entry = entries [ i ] ;
@@ -239,7 +248,7 @@ mpl.figure.prototype._init_canvas = function () {
239248 // And update the size in Python. We ignore the initial 0/0 size
240249 // that occurs as the element is placed into the DOM, which should
241250 // otherwise not happen due to the minimum size styling.
242- if ( fig . ws . readyState == 1 && width != 0 && height != 0 ) {
251+ if ( width != 0 && height != 0 ) {
243252 fig . request_resize ( width , height ) ;
244253 }
245254 }
You can’t perform that action at this time.
0 commit comments