fix(react): Use full attributes instead of changed ones for agent#1307
fix(react): Use full attributes instead of changed ones for agent#1307chenghao-mou wants to merge 2 commits intomainfrom
Conversation
it can drop agent state and cause chat panel disappear in the playground. This fixes that.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
size-limit report 📦
|
1egoman
left a comment
There was a problem hiding this comment.
Left a quick note - if this is urgent / you need to get it out to fix a live issue, I think I'd be ok merging it in its current state. But I also don't want to let potential issues like this go uninvestigated.
| // 1. Listen for agent participant attribute changes | ||
| const [agentParticipantAttributes, setAgentParticipantAttributes] = React.useState< | ||
| Participant['attributes'] | ||
| >(agentParticipant?.attributes ?? {}); | ||
| React.useEffect(() => { | ||
| if (!agentParticipant) { | ||
| return; | ||
| } | ||
|
|
||
| const handleAttributesChanged = (attributes: UseAgentReturn['attributes']) => { | ||
| setAgentParticipantAttributes(attributes); | ||
| const handleAttributesChanged = () => { | ||
| setAgentParticipantAttributes({ ...agentParticipant.attributes }); | ||
| }; | ||
|
|
||
| agentParticipant.on(ParticipantEvent.AttributesChanged, handleAttributesChanged); | ||
| return () => { | ||
| agentParticipant.off(ParticipantEvent.AttributesChanged, handleAttributesChanged); | ||
| }; | ||
| }, [agentParticipant, emitter]); |
There was a problem hiding this comment.
FWIW, I think there might be a simpler way to make this change, swap the whole useEffect part for something like this:
const agentParticipantAttributes = agentParticipant.attributes;But also, I just want to make sure I understand the reason behind this change - can you outline a sequence where agentParticipant.attributes changes but the value passed as part of the ParticipantEvent.AttributesChanged event is out of date?
For context, the reason why I'm asking is agentParticipant comes from here, which is a filtered version of the return value of the useRemoteParticipants hook, which (via connectedParticipantsObserver) is emitting state updates when any of these events emit, not just ParticipantEvent.AttributesChanged.
So I'm a little worried this fix might be covering up an issue deeper in the stack where participant attributes are updated the ParticipantEvent.AttributesChanged isn't being emitted.
It can drop agent state and cause chat panel disappear in the playground. This fixes that by always using the latest participant attributes.