Home > Articles > Details

Error: ResizeObserver loop limit exceeded


Question: How do you solve for an error that says "ResizeObserver loop limit exceeded" in JavaScript when the window resizes?

Login to See the Rest of the Answer

Answer:
This error is thrown when there is a Video Control on the Web page or when the elements on the Web page gets resized. If you are catching errors logged into the Web Browser's console then this error will appear. In order to solve for this error, implement in your code the following function.

1.

const resizeObserver = new ResizeObserver(entries => {
            // We wrap it in requestAnimationFrame to avoid this error - ResizeObserver loop limit exceeded
            window.requestAnimationFrame(() => {
                if (!Array.isArray(entries) || !entries.length) {
                    return;
                }
                // your code
            });
        });

If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.


© 2022 - ErnesTech - Privacy