perf(room): memoize timeline/composer handlers and emoji-pack room lookups

- RoomTimeline: wrap jump-to-latest/unread + mark-as-read handlers in useCallback
  (the handlers passed to memoized message children were already memoized).
- RoomInput: wrap file/upload/emoji/sticker/location callbacks in useCallback so
  the editor and toolbar don't re-render needlessly.
- EmojiBoard: hoist repeated mx.getRoom() pack-label lookups into a useMemo'd map
  in the emoji and sticker sidebars (previously called per-render in map loops).

Behavior unchanged. (RoomTimeline/RoomInput already have ErrorBoundary wrappers
in RoomView, so no boundary added.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-24 08:22:00 -04:00
co-authored by Claude Opus 4.8
parent c0f9867218
commit b7e1f89c1d
3 changed files with 119 additions and 89 deletions
+6 -6
View File
@@ -906,25 +906,25 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
}
}, [scrollToElement, editId]);
const handleJumpToLatest = () => {
const handleJumpToLatest = useCallback(() => {
if (eventId) {
navigateRoom(room.roomId, undefined, { replace: true });
}
setTimeline(getInitialTimeline(room));
scrollToBottomRef.current.count += 1;
scrollToBottomRef.current.smooth = false;
};
}, [eventId, navigateRoom, room]);
const handleJumpToUnread = () => {
const handleJumpToUnread = useCallback(() => {
if (unreadInfo?.readUptoEventId) {
setTimeline(getEmptyTimeline());
loadEventTimeline(unreadInfo.readUptoEventId);
}
};
}, [unreadInfo, loadEventTimeline]);
const handleMarkAsRead = () => {
const handleMarkAsRead = useCallback(() => {
markAsRead(mx, room.roomId, hideActivity);
};
}, [mx, room, hideActivity]);
const handleOpenReply: MouseEventHandler = useCallback(
async (evt) => {