Skip to content

Commit

Permalink
refactor: improve jumpToMessage code
Browse files Browse the repository at this point in the history
i.e. ensure that `__internal_check_jump_to_message`
was set by this component instance prior to resetting it.

This doesn't appear to fix any current bugs,
but hopefully will save us later.
  • Loading branch information
WofWca committed Feb 11, 2025
1 parent a0e1c2a commit 1f536ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/frontend/src/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,27 @@ export default function MessageList({ accountId, chat, refComposer }: Props) {
}
maybeJumpToMessageHack()
window.__internal_check_jump_to_message = maybeJumpToMessageHack
const thisMessageListIntanceSymbol = useRef(Symbol())
window.__internal_current_message_list_instance_id =
thisMessageListIntanceSymbol.current
useEffect(() => {
// Unset this when unmounting, so that it's the next component instance
// Unset `__internal_check_jump_to_message` when unmounting,
// so that it's the next component instance
// that handles the `__internal_jump_to_message_asap` value.
// This is important e.g. for "Show in Chat" in the gallery.
// The gallery is displayed when the MessageList component
// is not displayed.
//
// TODO we probably need to ensure that the next component instance
// didn't already set it itself.
return () => {
if (
window.__internal_current_message_list_instance_id !==
// eslint-disable-next-line react-hooks/exhaustive-deps
thisMessageListIntanceSymbol.current
) {
// This means that another component has already set
// `__internal_check_jump_to_message`.
// No need to clean it up.
return
}
window.__internal_check_jump_to_message = undefined
}
}, [])
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ declare global {
* it gets assigned when the component gets rendered.
*/
__internal_check_jump_to_message?: () => void
/**
* This is used by MessageList to see if another, newer instance
* of a MessageList exists.
*/
__internal_current_message_list_instance_id?: symbol
__updateAccountListSidebar: (() => void) | undefined
}
}

0 comments on commit 1f536ff

Please sign in to comment.