Environment
| Package |
Version |
| rc-resize-observer |
1.4.3 |
| React |
19 |
| Browsers |
Chrome/Edge 132+ (all Chromium-based) |
Description
SingleObserver defers its onResize callback via a microtask at src/SingleObserver/index.tsx#L84-L87:
// defer the callback but not defer to next frame
Promise.resolve().then(function () {
onResize(sizeInfo, target);
});
Microtasks execute within the same animation frame. When the deferred callback triggers a DOM layout change, the ResizeObserver fires again — creating a loop that exceeds the browser's depth limit. The browser then fires an ErrorEvent on window:
ResizeObserver loop completed with undelivered notifications.
Why this is now urgent — Chrome 132 change
This error has always occurred, but was previously invisible to error-tracking tools. Starting in Chrome 132, the ErrorEvent.error property changed from null to a string containing the error message (Chromium #391393420, chromium-dev thread).
|
Before Chrome 132 |
Chrome 132+ |
ErrorEvent.error |
null |
"ResizeObserver loop completed..." |
| Error trackers |
Silently discard |
Capture as unhandled error |
Applications using rc-resize-observer (via antd Table, Typography, etc.) now see a large spike in error reports. Other projects have been affected by the same Chrome change: Odoo PR #196740.
Reproduction
CodeSandbox: https://codesandbox.io/p/sandbox/reproduction-rc-resize-observer-loop-error-t4crpg
import React, { useRef } from "react";
import RcResizeObserver from "rc-resize-observer";
const LoopTrigger = ({ index }: { index: number }) => {
const ref = useRef<null | HTMLDivElement>(null);
return (
<RcResizeObserver
onResize={() => {
if (ref.current) {
const current = ref.current.offsetHeight;
ref.current.style.height = (current <= 20 ? 21 : 20) + "px";
}
}}
>
<div ref={ref}>Element {index}</div>
</RcResizeObserver>
);
};
export default function App() {
return (
<div>
{Array.from({ length: 10 }, (_, i) => (
<LoopTrigger key={i} index={i} />
))}
</div>
);
}
Each LoopTrigger wraps an element in <RcResizeObserver>. The onResize callback mutates the element's height, triggering another observation. Because rc-resize-observer delivers the callback via Promise.resolve().then(), the loop stays within the same frame. Open the codesandbox preview console — the error appears immediately on load.
Root cause
- Browser layout phase detects size change
- Singleton
ResizeObserver fires → observerUtil.js dispatches to listeners
SingleObserver.onInternalResize defers via Promise.resolve().then() — still same frame
- Microtask fires
onResize → layout change → browser detects new size change → loop
- Exceeds depth limit →
ErrorEvent with .error populated (Chrome 132+) → error trackers capture it
Suggested fix
Replace the microtask deferral with requestAnimationFrame to break the loop across frame boundaries:
// Let collection know what happened
onCollectionResize?.(sizeInfo, target, data);
if (onResize) {
- // defer the callback but not defer to next frame
- Promise.resolve().then(function () {
- onResize(sizeInfo, target);
- });
+ // defer the callback to the next frame to break the ResizeObserver loop
+ requestAnimationFrame(function () {
+ onResize(sizeInfo, target);
+ });
}
The comment in the existing code ("defer the callback but not defer to next frame") shows the microtask was intentional, but requestAnimationFrame would break the loop by deferring to the next frame — after the browser has finished processing all pending resize observations.
Related issues
Environment
Description
SingleObserverdefers itsonResizecallback via a microtask atsrc/SingleObserver/index.tsx#L84-L87:Microtasks execute within the same animation frame. When the deferred callback triggers a DOM layout change, the
ResizeObserverfires again — creating a loop that exceeds the browser's depth limit. The browser then fires anErrorEventonwindow:Why this is now urgent — Chrome 132 change
This error has always occurred, but was previously invisible to error-tracking tools. Starting in Chrome 132, the
ErrorEvent.errorproperty changed fromnullto a string containing the error message (Chromium #391393420, chromium-dev thread).ErrorEvent.errornull"ResizeObserver loop completed..."Applications using
rc-resize-observer(via antdTable,Typography, etc.) now see a large spike in error reports. Other projects have been affected by the same Chrome change: Odoo PR #196740.Reproduction
CodeSandbox: https://codesandbox.io/p/sandbox/reproduction-rc-resize-observer-loop-error-t4crpg
Each
LoopTriggerwraps an element in<RcResizeObserver>. TheonResizecallback mutates the element's height, triggering another observation. Becauserc-resize-observerdelivers the callback viaPromise.resolve().then(), the loop stays within the same frame. Open the codesandbox preview console — the error appears immediately on load.Root cause
ResizeObserverfires →observerUtil.jsdispatches to listenersSingleObserver.onInternalResizedefers viaPromise.resolve().then()— still same frameonResize→ layout change → browser detects new size change → loopErrorEventwith.errorpopulated (Chrome 132+) → error trackers capture itSuggested fix
Replace the microtask deferral with
requestAnimationFrameto break the loop across frame boundaries:// Let collection know what happened onCollectionResize?.(sizeInfo, target, data); if (onResize) { - // defer the callback but not defer to next frame - Promise.resolve().then(function () { - onResize(sizeInfo, target); - }); + // defer the callback to the next frame to break the ResizeObserver loop + requestAnimationFrame(function () { + onResize(sizeInfo, target); + }); }The comment in the existing code ("defer the callback but not defer to next frame") shows the microtask was intentional, but
requestAnimationFramewould break the loop by deferring to the next frame — after the browser has finished processing all pending resize observations.Related issues