Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/kind-peas-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Reduces web client memory comsumption due to memory leaks
2 changes: 1 addition & 1 deletion apps/meteor/app/analytics/client/loadScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useAnalytics = (): void => {
window._paq = window._paq || [];
window._paq.push(['setUserId', uid]);
}
});
}, [uid]);

useEffect(() => {
if (!googleId) {
Expand Down
54 changes: 30 additions & 24 deletions apps/meteor/client/views/room/body/hooks/useListIsAtBottom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCallback, useRef } from 'react';

import { isAtBottom as isAtBottomLib } from '../../../../../app/ui/client/views/app/lib/scrolling';
import { withThrottling } from '../../../../../lib/utils/highOrderFunctions';
import { useSafeRefCallback } from '../../../../hooks/useSafeRefCallback';

export const useListIsAtBottom = () => {
const atBottomRef = useRef(true);
Expand All @@ -27,37 +28,42 @@ export const useListIsAtBottom = () => {
return isAtBottomLib(innerBoxRef.current, threshold);
}, []);

const ref = useCallback(
(node: HTMLElement | null) => {
if (!node) {
return;
}

const messageList = node.querySelector('ul');
const ref = useSafeRefCallback(
useCallback(
(node: HTMLElement | null) => {
if (!node) {
return;
}

if (!messageList) {
return;
}
const messageList = node.querySelector('ul');

const observer = new ResizeObserver(() => {
if (atBottomRef.current === true) {
node.scrollTo({ left: 30, top: node.scrollHeight });
if (!messageList) {
return;
}
});

observer.observe(messageList);
const observer = new ResizeObserver(() => {
if (atBottomRef.current === true) {
node.scrollTo({ left: 30, top: node.scrollHeight });
}
});

observer.observe(messageList);

node.addEventListener(
'scroll',
withThrottling({ wait: 100 })(() => {
const handleScroll = withThrottling({ wait: 100 })(() => {
atBottomRef.current = isAtBottom(100);
}),
{
});

node.addEventListener('scroll', handleScroll, {
passive: true,
},
);
},
[isAtBottom],
});

return () => {
observer.disconnect();
node.removeEventListener('scroll', handleScroll);
};
},
[isAtBottom],
),
);

return {
Expand Down
33 changes: 21 additions & 12 deletions apps/meteor/client/views/room/hooks/useIsVisible.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { useDebouncedState, useSafely } from '@rocket.chat/fuselage-hooks';
import { useCallback } from 'react';

import { useSafeRefCallback } from '../../../hooks/useSafeRefCallback';

export const useIsVisible = () => {
const [menuVisibility, setMenuVisibility] = useSafely(useDebouncedState(!!window.DISABLE_ANIMATION, 100));

const callbackRef = useCallback(
(node: HTMLElement | null) => {
if (!node) {
return;
}
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
setMenuVisibility(entry.isIntersecting);
const callbackRef = useSafeRefCallback(
useCallback(
(node: HTMLElement | null) => {
if (!node) {
return;
}

const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
setMenuVisibility(entry.isIntersecting);
});
});
});

observer.observe(node);
},
[setMenuVisibility],
observer.observe(node);

return () => {
observer.disconnect();
};
},
[setMenuVisibility],
),
);

return [callbackRef, menuVisibility] as const;
Expand Down
Loading