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

Fix(virtual-core): Wrap ResizeObserver callbacks in window.requestAnimationFrame to avoid error #842

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

samstronghammer
Copy link

This PR wraps the two ResizeObserver callbacks with a window.requestAnimationFrame so that the "ResizeObserver loop completed with undelivered notifications" error doesn't happen.

Problem: ResizeObserver callbacks throw errors if they aren't able to resolve fully when they are invoked. This can happen if the callbacks are called at an inopportune time for the main thread, resulting in callbacks being dropped and the "ResizeObserver loop completed with undelivered notifications" error. This varies depending on how and when the resizes happened, and what browser you're on. I've found that Firefox is particularly picky about this.

Solution: There are several suggested here. In my personal experience, window.requestAnimationFrame solves the problem pretty well. Wrapping the two callbacks in the ResizeObservers here resulted in the errors completely stopping for my use case.

After some resize events, the "ResizeObserver loop completed with undelivered notifications" error occurred without this fix.
@piecyk
Copy link
Collaborator

piecyk commented Sep 26, 2024

@samstronghammer most cases this error has no real effect, other than log in console what is annoying. Wrapping it with requestAnimationFrame would creates it's own issues.

@samstronghammer
Copy link
Author

samstronghammer commented Sep 26, 2024

@piecyk How the error shows depends on your development environment, and is difficult to block otherwise. As seen here for folks doing react development with webpack, the page is completely covered with an error dialog every time this happens, making it difficult to use. This issue is critical to resolve for my workflow and I'm happy to put the time in to solve the issues you think requestAnimationFrame will cause. I haven't noticed any through regular use, do you have any ideas how to make a problematic behavior happen? Given that the callback is invoked when the screen is updating, I don't see how this could have a noticeable effect on the UX.
image

@piecyk
Copy link
Collaborator

piecyk commented Oct 11, 2024

Thanks for sharing more details, and I totally understand the impact this has on your workflow. I’ll try to debug the issue further and see if I can provide a workaround to minimize the problem, or use requestAnimationFrame, let see. I’ll keep you updated once I have more insights or a better approach.

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

Successfully merging this pull request may close these issues.

2 participants