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)
This commit is contained in:
Alexandru Dima 2023-12-22 16:19:04 +01:00 committed by GitHub
parent 30b7773127
commit 58041888f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();
});