-
Notifications
You must be signed in to change notification settings - Fork 13.8k
fix: GIF/rich attachment collapse state resetting on message list scroll #41783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nazabucciarelli
wants to merge
10
commits into
develop
Choose a base branch
from
fix/giphy-collapse-state-scroll
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fea066b
fix: use RoomManager store instead of a context with attachments coll…
nazabucciarelli 667ef44
mock RoomManager in RommeMessage.spec.ts
nazabucciarelli f9b5900
add limit of 1000 attachments per room for toggledCollapsibles
nazabucciarelli 325b122
add tests for new hook + playwright ones for collapsible states
nazabucciarelli 3c39468
add warning to useKeepMounted hook
nazabucciarelli 8c3e2fe
remove unneeded useCallback wrapper
nazabucciarelli ea2ab49
add waiter to avoid test flakiness
nazabucciarelli 1938728
rollback file pushed by accident :)
nazabucciarelli e8e5e6b
fix typecheck err
nazabucciarelli d8b5d6b
second attempt of stabilizing the suite
nazabucciarelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@rocket.chat/meteor': patch | ||
| --- | ||
|
|
||
| Fixes an issue where message attachments lose their collapsed state when scrolled out of view. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
apps/meteor/client/components/message/hooks/useIsCollapsibleToggled.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { act, renderHook } from '@testing-library/react'; | ||
|
|
||
| import { useIsCollapsibleToggled } from './useIsCollapsibleToggled'; | ||
| import { RoomManager } from '../../../lib/RoomManager'; | ||
| import { MAX_TOGGLED_COLLAPSIBLES_PER_ROOM } from '../../../lib/constants'; | ||
|
|
||
| jest.mock('../../../../app/ui-utils/client/lib/RoomHistoryManager', () => ({ | ||
| RoomHistoryManager: {}, | ||
| })); | ||
|
|
||
| it('should not be toggled by default', () => { | ||
| RoomManager.open('room-a'); | ||
| const { result } = renderHook(() => useIsCollapsibleToggled('key-a')); | ||
| expect(result.current).toBe(false); | ||
| }); | ||
|
|
||
| it('should reflect an already-toggled key in the opened room store', () => { | ||
| RoomManager.open('room-b'); | ||
| RoomManager.getStore('room-b')?.toggleCollapsible('key-b'); | ||
|
|
||
| const { result } = renderHook(() => useIsCollapsibleToggled('key-b')); | ||
| expect(result.current).toBe(true); | ||
| }); | ||
|
|
||
| it('should re-render when the store toggles after mount', () => { | ||
| RoomManager.open('room-c'); | ||
| const { result } = renderHook(() => useIsCollapsibleToggled('key-c')); | ||
| expect(result.current).toBe(false); | ||
|
|
||
| act(() => { | ||
| RoomManager.getStore('room-c')?.toggleCollapsible('key-c'); | ||
| }); | ||
| expect(result.current).toBe(true); | ||
| }); | ||
|
|
||
| it('should not leak a toggle to a different key in the same room', () => { | ||
| RoomManager.open('room-d'); | ||
| RoomManager.getStore('room-d')?.toggleCollapsible('key-d1'); | ||
|
|
||
| const { result } = renderHook(() => useIsCollapsibleToggled('key-d2')); | ||
| expect(result.current).toBe(false); | ||
| }); | ||
|
|
||
| it('should be a no-op when there is no key', () => { | ||
| RoomManager.open('room-e'); | ||
| const { result } = renderHook(() => useIsCollapsibleToggled(undefined)); | ||
| expect(result.current).toBe(false); | ||
| }); | ||
|
|
||
| it('should be a no-op when there is no opened room', () => { | ||
| const currentlyOpened = RoomManager.opened; | ||
| if (currentlyOpened) { | ||
| RoomManager.back(currentlyOpened); | ||
| } | ||
|
|
||
| const { result } = renderHook(() => useIsCollapsibleToggled('key-f')); | ||
| expect(result.current).toBe(false); | ||
| }); | ||
|
|
||
| it('should evict the oldest toggle once a room store is full, keeping it bounded', () => { | ||
| RoomManager.open('room-bound'); | ||
| const store = RoomManager.getStore('room-bound'); | ||
| if (!store) { | ||
| throw new Error('store was not created'); | ||
| } | ||
|
|
||
| const total = MAX_TOGGLED_COLLAPSIBLES_PER_ROOM + 1; | ||
| for (let i = 0; i < total; i++) { | ||
| store.toggleCollapsible(`bulk-${i}`); | ||
| } | ||
|
|
||
| expect(store.isCollapsibleToggled('bulk-0')).toBe(false); | ||
| expect(store.isCollapsibleToggled('bulk-1')).toBe(true); | ||
| expect(store.isCollapsibleToggled(`bulk-${total - 1}`)).toBe(true); | ||
| }); |
25 changes: 25 additions & 0 deletions
25
apps/meteor/client/components/message/hooks/useIsCollapsibleToggled.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { useMemo, useSyncExternalStore } from 'react'; | ||
|
|
||
| import { RoomManager, getCollapsibleEventKey, useOpenedRoom } from '../../../lib/RoomManager'; | ||
|
|
||
| export const useIsCollapsibleToggled = (key: string | undefined): boolean => { | ||
| const rid = useOpenedRoom(); | ||
|
|
||
| const { subscribe, getSnapshot } = useMemo(() => { | ||
| const store = rid && key ? RoomManager.getStore(rid) : undefined; | ||
|
|
||
| if (!store || !key) { | ||
| return { | ||
| subscribe: () => () => undefined, | ||
| getSnapshot: () => false, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| subscribe: (cb: () => void) => store.on(getCollapsibleEventKey(key), cb), | ||
| getSnapshot: () => store.isCollapsibleToggled(key), | ||
| }; | ||
| }, [rid, key]); | ||
|
|
||
| return useSyncExternalStore(subscribe, getSnapshot); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.