Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResizeObserver loop limit exceeded #55

Closed
Grief opened this issue Apr 11, 2023 · 6 comments
Closed

ResizeObserver loop limit exceeded #55

Grief opened this issue Apr 11, 2023 · 6 comments

Comments

@Grief
Copy link

Grief commented Apr 11, 2023

After updating from 1.0.11 to 1.0.12 the following code
window.addEventListener("error", (e) => {...} started to receive the error ResizeObserver loop limit exceeded continuously.

That happens in chromium-based browsers only

@bvaughn
Copy link
Owner

bvaughn commented Apr 11, 2023

Share a repro and I'll take a look.

@Grief
Copy link
Author

Grief commented Apr 11, 2023

@bvaughn git clone https://github.com/Grief/bug.git && cd bug && npm install && npm start

@Grief Grief removed their assignment Apr 11, 2023
@bvaughn
Copy link
Owner

bvaughn commented Apr 11, 2023

I recorded a Replay of the repro you shared:
https://app.replay.io/recording/05679afd-311d-44cb-b68d-ea892a14b368

I don't understand why this is considered an error. It looks like ResizeObserver is only being instantiated twice (because of "strict effects" mode) and the first one is properly disconnected. Seems expected to me?

The resize handler does get called multiple times (4) which might be unexpected? The dimensions when it's called are:

  • 151 x 151
  • 151 x 151
  • 150 x 150
  • 151 x 151

@bvaughn
Copy link
Owner

bvaughn commented Apr 11, 2023

Doing a bit of research on this error and found this explanation:

I believe this error is the same as the one listed here as part of the ResizeObserver spec. Chromium based browsers seem to use a different error message than that exact one, but in Firefox the error message is the same.

This error is emitted if a resize event happens and the browser is unable to notify all the listeners within that frame. In our app this happens because we update some fairly global React state directly from the react-resize-detector callback, which triggered several React components to re-render at once. Because React re-renders synchronously, this delayed the browser’s paint until a frame or two later, causing this error.

I’m not sure if the browser eventually does notify all the listeners and this warning just means there was a dropped frame, or if some of them just get skipped for that event? If it’s the former then this is potentially an error that is safe to ignore, if it’s the latter than probably not.

That makes sense.

Seems like resolving it would be a matter of debouncing the setState call.

@bvaughn
Copy link
Owner

bvaughn commented Apr 11, 2023

Fixed in 12ddd48; tested with your repro and verified that the error alert is no longer shown.

Fix published in v1.0.14

Thanks for the repro!

@bvaughn bvaughn closed this as completed Apr 11, 2023
@Grief
Copy link
Author

Grief commented Apr 11, 2023

@bvaughn Thank you very much for such a quick fix! World will be much better if all the devs would react so fast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants