From 58041888f48dc35ab6f4885765b7a45d1d67fe8e Mon Sep 17 00:00:00 2001 From: Alexandru Dima Date: Fri, 22 Dec 2023 16:19:04 +0100 Subject: [PATCH] Copy width & height from the ResizeObserver callback (#201406) Copy width & height from the ResizeObserver callback to avoid "ResizeObserver loop completed with undelivered notifications" error (fixes microsoft/monaco-editor#4311) --- src/vs/editor/browser/config/elementSizeObserver.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/vs/editor/browser/config/elementSizeObserver.ts b/src/vs/editor/browser/config/elementSizeObserver.ts index 9dd5af8e6d3..33eefc3aba8 100644 --- a/src/vs/editor/browser/config/elementSizeObserver.ts +++ b/src/vs/editor/browser/config/elementSizeObserver.ts @@ -47,10 +47,10 @@ export class ElementSizeObserver extends Disposable { // Otherwise we will postpone to the next animation frame. // We'll use `observeContentRect` to store the content rect we received. - let observeContentRect: DOMRectReadOnly | null = null; + let observedDimenstion: IDimension | null = null; const observeNow = () => { - if (observeContentRect) { - this.observe({ width: observeContentRect.width, height: observeContentRect.height }); + if (observedDimenstion) { + this.observe({ width: observedDimenstion.width, height: observedDimenstion.height }); } else { this.observe(); } @@ -75,7 +75,11 @@ export class ElementSizeObserver extends Disposable { }; this._resizeObserver = new ResizeObserver((entries) => { - observeContentRect = (entries && entries[0] && entries[0].contentRect ? entries[0].contentRect : null); + if (entries && entries[0] && entries[0].contentRect) { + observedDimenstion = { width: entries[0].contentRect.width, height: entries[0].contentRect.height }; + } else { + observedDimenstion = null; + } shouldObserve = true; update(); });