File tree 1 file changed +10
-1
lines changed
lib/matplotlib/backends/web_backend/js
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 () {
192
192
}
193
193
194
194
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
+ }
195
204
var nentries = entries . length ;
196
205
for ( var i = 0 ; i < nentries ; i ++ ) {
197
206
var entry = entries [ i ] ;
@@ -239,7 +248,7 @@ mpl.figure.prototype._init_canvas = function () {
239
248
// And update the size in Python. We ignore the initial 0/0 size
240
249
// that occurs as the element is placed into the DOM, which should
241
250
// 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 ) {
243
252
fig . request_resize ( width , height ) ;
244
253
}
245
254
}
You can’t perform that action at this time.
0 commit comments