PolymerLabs / uni-virtualizer

Monorepo for a "universal" (renderer-agnostic) virtual scroller and renderer-specific variants

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ResizeObserver loop limit exceeded error while scrolling

joekukish opened this issue · comments

Version

0.7.0-pre.2

Description

While migrating to the latest version of the virtualizer, I've noticed that an error with the ResizeObserver happens fairly often.

To reproduce:

  1. Go to https://polymerlabs.github.io/uni-virtualizer/scroll-to-index-lit-element/
  2. Open the console and type.
window.onerror = (e) => console.log(e);
  1. Scroll in the demo page.

Notice how the message ResizeObserver loop limit exceeded appears multiple times.

While doing the migration this error appears many times in the tests causing them to fail.

Sorry for the slow response here.

I haven't had time to dig deeply, but I am quite confident that the ResizeObserver loop limit exceeded error message is benign in this case and can be ignored.

Virtualizer's ResizeObserver callback is invoked not only when existing DOM children resize, but also whenever virtualizer adds new physical children. In the latter case, the layout may then explicitly set the size of one of those just-created children, which would theoretically cause the RO to need to fire again within the same animation frame. I think it's in this case that the browser's loop-detection being triggered, but it's not a situation in which a loop will actually occur. Long-term, there may be a way for us to avoid the error, but I don't believe it's indicative of a real behavior or performance problem.

Various reading in and around this area:

https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded
WICG/resize-observer#38
https://stackoverflow.com/questions/64238740/how-to-ignore-the-resizeobserver-loop-limit-exceeded-in-testcafe

Leaving the issue open for now, however, until we can take a deeper look.

I managed to get rid of the error by wrapping the _childrenSizeChanged body in a requestAnimationFrame method.

Screenshot 2022-05-13 at 14 50 06