Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing unnecessary calls to mutateStreamData in useChat React hook #2951

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

tonyfarney
Copy link

This fixes #2950

@lgrammel
Copy link
Collaborator

Hey @tonyfarney meant to come back to this - the issue is legit, but I need to verify this fix actually works in different settings, e.g.. when something is already non-empty or when there are non-changes for non-empty data.

@tonyfarney
Copy link
Author

Hey @tonyfarney meant to come back to this - the issue is legit, but I need to verify this fix actually works in different settings, e.g.. when something is already non-empty or when there are non-changes for non-empty data.

Looking the code, the only situation data is not an empty array when passed to onUpdate is in process-data-protocol-response.ts:

update([...previousMessages, ...merged], [...data]); // make a copy of the data array

I think it's possible the situation of calling the update callback for the exact same data. But for avoiding to mutate stream data in such situation, would be necessary to compare the arrays or maybe just to check the array length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants