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/lucky-birds-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes an issue which caused some weird scrolling in rooms when using secondary sidepanel navigation.
2 changes: 1 addition & 1 deletion apps/meteor/client/views/room/body/RoomBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const RoomBody = (): ReactElement => {
targeDrop: [fileUploadTriggerProps, fileUploadOverlayProps],
} = useFileUpload();

const { innerRef: restoreScrollPositionInnerRef } = useRestoreScrollPosition(room._id);
const { innerRef: restoreScrollPositionInnerRef } = useRestoreScrollPosition();

const { messageListRef } = useMessageListNavigation();
const { innerRef: selectAndScrollRef, selectAllAndScrollToTop } = useSelectAllAndScrollToTop();
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/room/body/RoomBodyV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const RoomBody = (): ReactElement => {
targeDrop: [fileUploadTriggerProps, fileUploadOverlayProps],
} = useFileUpload();

const { innerRef: restoreScrollPositionInnerRef } = useRestoreScrollPosition(room._id);
const { innerRef: restoreScrollPositionInnerRef } = useRestoreScrollPosition();

const { messageListRef } = useMessageListNavigation();
const { innerRef: selectAndScrollRef, selectAllAndScrollToTop } = useSelectAllAndScrollToTop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jest.mock('../../../../lib/RoomManager', () => ({
RoomManager: {
getStore: jest.fn(),
},
useOpenedRoom: jest.fn(() => 'room-id'),
useSecondLevelOpenedRoom: jest.fn(() => 'room-id'),
}));

describe('useRestoreScrollPosition', () => {
Expand All @@ -21,7 +23,7 @@ describe('useRestoreScrollPosition', () => {

const useRefSpy = jest.spyOn(React, 'useRef').mockReturnValueOnce({ current: mockElement });

const { unmount } = renderHook(() => useRestoreScrollPosition('room-id'));
const { unmount } = renderHook(() => useRestoreScrollPosition());

expect(useRefSpy).toHaveBeenCalledWith(null);
expect(mockElement).toHaveProperty('scrollTop', 100);
Expand All @@ -42,7 +44,7 @@ describe('useRestoreScrollPosition', () => {

const useRefSpy = jest.spyOn(React, 'useRef').mockReturnValueOnce({ current: mockElement });

const { unmount } = renderHook(() => useRestoreScrollPosition('room-id'));
const { unmount } = renderHook(() => useRestoreScrollPosition());

expect(useRefSpy).toHaveBeenCalledWith(null);
expect(mockElement).toHaveProperty('scrollTop', 800);
Expand Down Expand Up @@ -71,7 +73,7 @@ describe('useRestoreScrollPosition', () => {

const useRefSpy = jest.spyOn(React, 'useRef').mockReturnValueOnce({ current: mockElement });

const { unmount } = renderHook(() => useRestoreScrollPosition('room-id'));
const { unmount } = renderHook(() => useRestoreScrollPosition());

expect(useRefSpy).toHaveBeenCalledWith(null);
expect(update).toHaveBeenCalledWith({ scroll: 500, atBottom: false });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { useCallback, useEffect, useRef } from 'react';

import { isAtBottom } from '../../../../../app/ui/client/views/app/lib/scrolling';
import { withThrottling } from '../../../../../lib/utils/highOrderFunctions';
import { RoomManager } from '../../../../lib/RoomManager';
import { RoomManager, useOpenedRoom, useSecondLevelOpenedRoom } from '../../../../lib/RoomManager';

export function useRestoreScrollPosition(roomId: IRoom['_id']) {
export function useRestoreScrollPosition() {
const ref = useRef<HTMLElement>(null);
const parentRoomId = useOpenedRoom();
const roomId = useSecondLevelOpenedRoom() ?? parentRoomId;

const handleRestoreScroll = useCallback(() => {
if (!ref.current) {
if (!ref.current || !roomId) {
return;
}

Expand All @@ -24,7 +25,7 @@ export function useRestoreScrollPosition(roomId: IRoom['_id']) {
}, [roomId]);

useEffect(() => {
if (!ref.current) {
if (!ref.current || !roomId) {
return;
}

Expand Down
Loading