question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ResizeObserver loop limit exceeded

See original GitHub issue

👋 Hello. We have a component that’s using this hook with in it’s default form (no custom callback) and have been getting a lot of ResizeObserver loop limit exceeded errors thrown during usage.

From my brief search around the internet it seems as though this is harmless but it does add a lot of noise in common usage and that that noise could be avoided by wrapping the ResizeObserver callback in a requestAnimationFrame.

I could adjust our usage to do this using a custom callback, but that would mean reimplementing the core observer logic which seems rather pointless. Does it make sense as a core adjustment?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ZeeCodercommented, Apr 29, 2020

Yeah having a rAF call in there would mean that you no longer get notification of resize events as they happen, but rather with a 16ms delay or so. (Depending where you are in the current tick.)

If you need rAF, then it should be really easy to have a custom local hook, that does something like:

function useResizeObserverWithRAF(opts) {
const [size, setSize] = useState({width: undefined, height: undefined});
useResizeObserver({ ...opts, onResize: (size) => requestAnimationFrame(() => setSize(size)) });

return size;
}

In terms of such optimisations (like throttle and debounce) it’s not as easy to know exactly what people might need, and as you’d pile more feature on top, the harder it would be to maintain this lib, which is meant to be as low-level as it can. 🤷‍♂️

It is a good candidate for a readme entry or a codesandbox demo. (Like the ones I’ve made for throttle and debounce.)

1reaction
makenosoundcommented, Apr 29, 2020

Sorry, @ZeeCoder — I’m not that familiar with the ResizeObserver API or its usage in practice and so my reading of https://stackoverflow.com/a/50387233 was that that exception is usually caused not necessarily by an infinite loop, but by the observer triggering more events than can be handled in a frame.

What I was musing on as a solution was wrapping the observe callback in a requestAnimationFrame to ensure that it only passes events at a rate that’s actually usable in a consuming app. I imagine that could cause issues with an initial evaluation of their values though so it probably doesn’t make sense after all (and that suggestion was predicated on that SO comment being accurate anyway).

Read more comments on GitHub >

github_iconTop Results From Across the Web

ResizeObserver - loop limit exceeded - Stack Overflow
This error means that ResizeObserver was not able to deliver all observations within a single animation frame. It is benign (your site will...
Read more >
Error: ResizeObserver loop limit exceeded · Issue #5440
Resizing window triggers Error: ResizeObserver loop limit exceeded . The error is not logged in browser's console, but Sentry captures it.
Read more >
Uncaught exception: ResizeObserver loop limit exceeded
This is a legitimate problem, and the runtime error is in the console code. Regardless of what's in the CSV, the console should...
Read more >
ResizeObserver loop limit exceeded - Perspective - Ignition
I'm having a performance issue with perspective. The problem happens in a table component. I have two Arrays Object with 36 keys:values each ......
Read more >
Every time when I edit something in Tableau online, it ...
Every time when I edit something in Tableau online, it occurres an unexpected error. "ResizeObserver loop limit exceeded." Anyone knows how to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found