Fix several potential memory leaks (#5586)

This commit is contained in:
zubiden 2025-02-13 14:28:05 +01:00 committed by Alexander Zinchuk
parent 3405d62523
commit 37617b4b8e
4 changed files with 18 additions and 4 deletions

View File

@ -144,6 +144,8 @@ export function animateOpening(isArchived?: boolean) {
}
toggleAvatar?.classList.remove('animating');
peer.classList.remove('animating');
callbacks.delete(cb);
});
}, ANIMATION_DURATION + ANIMATION_END_DELAY);
@ -283,6 +285,8 @@ export function animateClosing(isArchived?: boolean) {
peer.classList.remove('animating');
toggleAvatar!.classList.remove('animating');
});
callbacks.delete(cb);
}, ANIMATION_DURATION + ANIMATION_END_DELAY);
callbacks.add(cb);

View File

@ -163,6 +163,7 @@ export function useIntersectionObserver({
function destroy() {
callbacks.clear();
observer.disconnect();
entriesAccumulator.clear();
}
controllerRef.current = {

View File

@ -722,6 +722,8 @@ function useEffectBase(
};
}
if (effectConfig) effectConfig.schedule = undefined; // Help GC
byCursor[cursor] = {
...effectConfig,
dependencies,

View File

@ -57,8 +57,17 @@ export default function animateHorizontalScroll(container: HTMLElement, left: nu
const startAt = Date.now();
function cleanup() {
container.style.scrollSnapType = '';
delete container.dataset.scrollId;
stopById.delete(id);
}
animate(() => {
if (isStopped) return false;
if (isStopped) {
cleanup();
return false;
}
const t = Math.min((Date.now() - startAt) / duration, 1);
@ -66,9 +75,7 @@ export default function animateHorizontalScroll(container: HTMLElement, left: nu
container.scrollLeft = Math.round(target - currentPath);
if (t >= 1) {
container.style.scrollSnapType = '';
delete container.dataset.scrollId;
stopById.delete(id);
cleanup();
resolve();
}