mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-31 12:47:58 +00:00
⚡️(frontend) memoize the ParticipantName component
Memoize the ParticipantName component so it does not re-render on unrelated parent updates when its props have not changed.
This commit is contained in:
committed by
aleb_the_flash
parent
bf6351e838
commit
e1457604ee
@@ -1,8 +1,6 @@
|
|||||||
import type { CSSProperties } from 'react'
|
import React, { CSSProperties } from 'react'
|
||||||
import { Text } from '@/primitives'
|
import { Text } from '@/primitives'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useParticipantInfo } from '@livekit/components-react'
|
|
||||||
import type { Participant } from 'livekit-client'
|
|
||||||
|
|
||||||
const participantNameStyles: CSSProperties = {
|
const participantNameStyles: CSSProperties = {
|
||||||
paddingBottom: '0.1rem',
|
paddingBottom: '0.1rem',
|
||||||
@@ -16,29 +14,29 @@ const participantNameScreenShareStyles: CSSProperties = {
|
|||||||
marginLeft: '0.4rem',
|
marginLeft: '0.4rem',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ParticipantName = ({
|
export const ParticipantName = React.memo(
|
||||||
participant,
|
({
|
||||||
isScreenShare = false,
|
displayedName,
|
||||||
}: {
|
isScreenShare = false,
|
||||||
participant: Participant
|
}: {
|
||||||
isScreenShare: boolean
|
displayedName?: string
|
||||||
}) => {
|
isScreenShare: boolean
|
||||||
const { t } = useTranslation('rooms', { keyPrefix: 'participantTile' })
|
}) => {
|
||||||
|
const { t } = useTranslation('rooms', { keyPrefix: 'participantTile' })
|
||||||
|
if (isScreenShare) {
|
||||||
|
return (
|
||||||
|
<Text variant="sm" style={participantNameScreenShareStyles}>
|
||||||
|
{t('screenShare', { name: displayedName })}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const { identity, name } = useParticipantInfo({ participant })
|
|
||||||
const displayedName = name != '' ? name : identity
|
|
||||||
|
|
||||||
if (isScreenShare) {
|
|
||||||
return (
|
return (
|
||||||
<Text variant="sm" style={participantNameScreenShareStyles}>
|
<Text variant="sm" style={participantNameStyles} aria-hidden="true">
|
||||||
{t('screenShare', { name: displayedName })}
|
{displayedName}
|
||||||
</Text>
|
</Text>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
ParticipantName.displayName = 'ParticipantName'
|
||||||
<Text variant="sm" style={participantNameStyles} aria-hidden="true">
|
|
||||||
{displayedName}
|
|
||||||
</Text>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
VideoTrack,
|
VideoTrack,
|
||||||
TrackRefContext,
|
TrackRefContext,
|
||||||
ParticipantContextIfNeeded,
|
ParticipantContextIfNeeded,
|
||||||
|
useParticipantInfo,
|
||||||
} from '@livekit/components-react'
|
} from '@livekit/components-react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {
|
import {
|
||||||
@@ -74,9 +75,12 @@ export const ParticipantTile: (
|
|||||||
ref
|
ref
|
||||||
) {
|
) {
|
||||||
const { pinnedTrackRef } = useSnapshot(layoutStore)
|
const { pinnedTrackRef } = useSnapshot(layoutStore)
|
||||||
|
|
||||||
const trackReference = useEnsureTrackRef(trackRef)
|
const trackReference = useEnsureTrackRef(trackRef)
|
||||||
|
|
||||||
|
const { identity, name } = useParticipantInfo({
|
||||||
|
participant: trackReference.participant,
|
||||||
|
})
|
||||||
|
|
||||||
const { elementProps } = useParticipantTile<HTMLDivElement>({
|
const { elementProps } = useParticipantTile<HTMLDivElement>({
|
||||||
htmlProps,
|
htmlProps,
|
||||||
disableSpeakingIndicator,
|
disableSpeakingIndicator,
|
||||||
@@ -222,8 +226,8 @@ export const ParticipantTile: (
|
|||||||
)}
|
)}
|
||||||
<div className="lk-participant-name-wrapper">
|
<div className="lk-participant-name-wrapper">
|
||||||
<ParticipantName
|
<ParticipantName
|
||||||
|
displayedName={name != '' ? name : identity}
|
||||||
isScreenShare={isScreenShare}
|
isScreenShare={isScreenShare}
|
||||||
participant={trackReference.participant}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user