mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-31 12:47:58 +00:00
⚡️(frontend) narrow chat event subscriptions to reduce re-renders
Reduce the set of events the chat subscribes to, keeping only those that actually affect its rendering. This avoids frequent re-renders triggered by unrelated events on the room or participants.
This commit is contained in:
committed by
aleb_the_flash
parent
94abdfc0f9
commit
4598aafa23
@@ -3,7 +3,7 @@ import React from 'react'
|
|||||||
import {
|
import {
|
||||||
formatChatMessageLinks,
|
formatChatMessageLinks,
|
||||||
useChat,
|
useChat,
|
||||||
useParticipants,
|
useRemoteParticipants,
|
||||||
useRoomContext,
|
useRoomContext,
|
||||||
} from '@livekit/components-react'
|
} from '@livekit/components-react'
|
||||||
import {
|
import {
|
||||||
@@ -75,13 +75,9 @@ export function Chat({ ...props }: ChatProps) {
|
|||||||
shouldRestoreOnClose: () => !isSidePanelOpen,
|
shouldRestoreOnClose: () => !isSidePanelOpen,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Use useParticipants hook to trigger a re-render when the participant list changes.
|
// Use to trigger a re-render when the participant list changes.
|
||||||
const participants = useParticipants({
|
const remoteParticipants = useRemoteParticipants({
|
||||||
updateOnlyOn: [
|
updateOnlyOn: [RoomEvent.ParticipantNameChanged],
|
||||||
RoomEvent.ParticipantAttributesChanged,
|
|
||||||
RoomEvent.ParticipantNameChanged,
|
|
||||||
RoomEvent.ParticipantMetadataChanged,
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const lastReadMsgAt = React.useRef<ChatMessage['timestamp']>(0)
|
const lastReadMsgAt = React.useRef<ChatMessage['timestamp']>(0)
|
||||||
@@ -150,10 +146,10 @@ export function Chat({ ...props }: ChatProps) {
|
|||||||
msg.timestamp - allMsg[idx - 1].timestamp < 60_000 &&
|
msg.timestamp - allMsg[idx - 1].timestamp < 60_000 &&
|
||||||
allMsg[idx - 1].from === msg.from,
|
allMsg[idx - 1].from === msg.from,
|
||||||
}))
|
}))
|
||||||
// `participants` is included so rows re-render when participant
|
// `remoteParticipants` is included so rows re-render when participant
|
||||||
// information (name, metadata) changes.
|
// information (name) changes.
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [chatMessages, participants])
|
}, [chatMessages, remoteParticipants])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Div
|
<Div
|
||||||
|
|||||||
Reference in New Issue
Block a user