From 12ddd48d7b347753f174244181e2af39923155fe Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Tue, 11 Apr 2023 17:02:09 -0400 Subject: [PATCH] Fix potential "ResizeObserver loop limit exceeded" error --- src/AutoSizer.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AutoSizer.ts b/src/AutoSizer.ts index bccd01d..1bb5c1f 100644 --- a/src/AutoSizer.ts +++ b/src/AutoSizer.ts @@ -84,7 +84,12 @@ export class AutoSizer extends Component { // See issue #41 if (this._parentNode != null) { if (typeof ResizeObserver !== "undefined") { - this._resizeObserver = new ResizeObserver(this._onResize); + this._resizeObserver = new ResizeObserver(() => { + // Guard against "ResizeObserver loop limit exceeded" error; + // could be triggered if the state update causes the ResizeObserver handler to run long. + // See https://github.com/bvaughn/react-virtualized-auto-sizer/issues/55 + setTimeout(this._onResize, 0); + }); this._resizeObserver.observe(this._parentNode); } else { this._detectElementResize = createDetectElementResize(