cleanup rive on unmount#366
Conversation
| ...riveParams, | ||
| canvas: canvasElem, | ||
| }); | ||
| if (riveRef.current != null) { |
There was a problem hiding this comment.
In this hook we are already doing:
return () => {
if (!isLoaded) {
r?.cleanup();
}
};
Could it be that we're not ever calling cleanup under the condition where it failed (or did not complete) to load before the hook was unmounted (isLoaded == false)?
The useRef seems like a better approach, but will we now be calling cleanup twice? And is that a problem?
There was a problem hiding this comment.
I. verified that calling cleanup twice is not an issue since we clean the file.
And yes, from all the debugging, this was happening in a scenario where the file is unmounted when it didn't finish loading and the on load event is not fired.
There was a problem hiding this comment.
So do we still need:
if (!isLoaded) {
r?.cleanup();
}
There was a problem hiding this comment.
I think we do in the (rare) scenario where it's not actually unmounted but we do trigger a new rive instance. The isLoaded should cleanup the previous one.
HayesGordon
left a comment
There was a problem hiding this comment.
LGTM, just the question about wether we should keep the !isLoaded conditional cleanup.
we need to keep a reference of the latest rive file instance in a ref hook to make sure we destroy it on unmount or else it can cause a memory leak