Skip to content

Commit a3b2576

Browse files
authored
Merge pull request matplotlib#27251 from QuLogic/webagg-resize
webagg: Don't resize canvas if WebSocket isn't connected
2 parents bff9593 + 93fa19b commit a3b2576

File tree

1 file changed

+10
-1
lines changed
  • lib/matplotlib/backends/web_backend/js

1 file changed

+10
-1
lines changed

lib/matplotlib/backends/web_backend/js/mpl.js

+10-1
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)