Skip to content

Commit 5804188

Browse files
authored
Copy width & height from the ResizeObserver callback (microsoft#201406)
Copy width & height from the ResizeObserver callback to avoid "ResizeObserver loop completed with undelivered notifications" error (fixes microsoft/monaco-editor#4311)
1 parent 30b7773 commit 5804188

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/vs/editor/browser/config/elementSizeObserver.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export class ElementSizeObserver extends Disposable {
4747
// Otherwise we will postpone to the next animation frame.
4848
// We'll use `observeContentRect` to store the content rect we received.
4949

50-
let observeContentRect: DOMRectReadOnly | null = null;
50+
let observedDimenstion: IDimension | null = null;
5151
const observeNow = () => {
52-
if (observeContentRect) {
53-
this.observe({ width: observeContentRect.width, height: observeContentRect.height });
52+
if (observedDimenstion) {
53+
this.observe({ width: observedDimenstion.width, height: observedDimenstion.height });
5454
} else {
5555
this.observe();
5656
}
@@ -75,7 +75,11 @@ export class ElementSizeObserver extends Disposable {
7575
};
7676

7777
this._resizeObserver = new ResizeObserver((entries) => {
78-
observeContentRect = (entries && entries[0] && entries[0].contentRect ? entries[0].contentRect : null);
78+
if (entries && entries[0] && entries[0].contentRect) {
79+
observedDimenstion = { width: entries[0].contentRect.width, height: entries[0].contentRect.height };
80+
} else {
81+
observedDimenstion = null;
82+
}
7983
shouldObserve = true;
8084
update();
8185
});

0 commit comments

Comments
 (0)