Skip to content

fix(react): Use full attributes instead of changed ones for agent#1307

Open
chenghao-mou wants to merge 2 commits intomainfrom
chenghao/fix/agent-attribute-update
Open

fix(react): Use full attributes instead of changed ones for agent#1307
chenghao-mou wants to merge 2 commits intomainfrom
chenghao/fix/agent-attribute-update

Conversation

@chenghao-mou
Copy link
Member

@chenghao-mou chenghao-mou commented Mar 10, 2026

It can drop agent state and cause chat panel disappear in the playground. This fixes that by always using the latest participant attributes.

it can drop agent state and cause chat panel disappear in the playground. This fixes that.
@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2026

⚠️ No Changeset found

Latest commit: a531826

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
components-js-storybook-5kld Ready Ready Preview, Comment Mar 10, 2026 8:29pm

Request Review

@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2026

size-limit report 📦

Path Size
LiveKitRoom only 6 KB (0%)
LiveKitRoom with VideoConference 32.2 KB (0%)
All exports 43.08 KB (-0.03% 🔽)

@chenghao-mou chenghao-mou requested a review from 1egoman March 11, 2026 09:42
Copy link
Contributor

@1egoman 1egoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 550 to 567
// 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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants