Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/strange-stingrays-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes scroll issue when moving between channels or DMs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ describe('useRestoreScrollPosition', () => {
expect(screen.getByTestId('scrollable-element')).toHaveProperty('scrollTop', 123);
});

it('should jump to bottom if atBottom is true', () => {
const store = {
scroll: 123,
atBottom: true,
update: jest.fn(),
};
(RoomManager.getStore as jest.Mock).mockReturnValue(store);

const Test = () => {
const { innerRef } = useRestoreScrollPosition('GENERAL');
return (
<div ref={innerRef} style={{ height: '100px', overflowY: 'scroll' }} data-testid='scrollable-element'>
<div style={{ height: '800px' }}></div>
</div>
);
};

render(<Test />);

expect(screen.getByTestId('scrollable-element')).toBeInTheDocument();
expect(screen.getByTestId('scrollable-element')).toHaveStyle({ height: '100px', overflowY: 'scroll' });
expect(screen.getByTestId('scrollable-element')).toHaveProperty('scrollTop', 0);
});

it('should do nothing if no previous scroll position is stored', () => {
const store = {
scroll: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export function useRestoreScrollPosition(rid: string, wait = 100) {
return;
}
const store = RoomManager.getStore(rid);
if (store?.atBottom) {
node.scrollTop = node.scrollHeight;
node.scrollLeft = 30;
}
if (!jumpToRef.current && store?.scroll !== undefined && !store.atBottom) {
node.scrollTop = store.scroll;
node.scrollLeft = 30;
Expand Down
Loading