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

bug: rive animations can get "stuck" in a stopped rendering state due to IntersectionObserver #257

Open
aroman opened this issue May 23, 2024 · 4 comments

Comments

@aroman
Copy link

aroman commented May 23, 2024

We've tracked a nasty race condition down in our product that ultimately we determined was caused by rive-react's usage of the IntersectionObserver to pause rendering while canvases are occluded.

In certain circumstances, this effect can cause the canvas to get "stuck" in a stopped-rendering state. Simply running startRendering() on a canvas in this state fixes the issue.

Our temporary workaround is to call startRendering() periodically every 100ms to ensure these get un-stuck. However, obviously, this should be fixed...

@aroman aroman changed the title bug: rive animations can get "stuck" in a stopped rendering state due to IntersectionObserver bug: rive animations can get "stuck" in a stopped rendering state due to IntersectionObserver May 23, 2024
@bodymovin
Copy link
Contributor

Hey! Can you share some basic steps to reproduce it?
Do you happen to know if it's while scrolling, on load, or when components are reordered in the DOM?

@MrRoboman
Copy link

Linking our thread in the community:
https://rive.app/community/forums/support/fsnLLkXUaA62/react-rive-animations-getting-stuck/ftTlrwM2cxuq

As mentioned there, we've noticed it when reordering DOM elements, resizing the window, leaving and coming back to the tab... sometimes it seems to happen without any apparent explanation.

@MrRoboman
Copy link

The code we think is causing the problem:

useEffect(() => {
const observer = new IntersectionObserver(([entry]) => {
entry.isIntersecting
? rive && rive.startRendering()
: rive && rive.stopRendering();
});
if (canvasElem) {
observer.observe(canvasElem);
}
return () => {
observer.disconnect();
};
}, [rive, canvasElem]);

@DCDRins
Copy link

DCDRins commented Jun 19, 2024

Have the same problem
"startRendering" never happens, animation is stuck

Rive animation should be anywhere, but out of viewport for the first render.

UPD: if it's not enough to understand the prob, let me know and I will share a real life example of this bug

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

4 participants