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

Prevent the 'Message' components from unexpectedly re-rendering while receiving tokens #1051

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions libs/react-client/src/utils/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ const updateMessageContentById = (
isInput: boolean
): IStep[] => {
const nextMessages = [...messages];
for (let index = 0; index < nextMessages.length; index++) {
let changed = false;
for (let index = nextMessages.length - 1; index >=0; index--) {
const msg = nextMessages[index];

if (isEqual(msg.id, messageId)) {
Expand Down Expand Up @@ -197,19 +198,25 @@ const updateMessageContentById = (
}

nextMessages[index] = { ...msg };
} else if (msg.steps) {
msg.steps = updateMessageContentById(
changed = true;
break;
} else if (msg.steps && msg.steps.length > 0) {
const newSteps = updateMessageContentById(
msg.steps,
messageId,
updatedContent,
isSequence,
isInput
);
nextMessages[index] = { ...msg };
if (newSteps !== msg.steps) {
nextMessages[index] = { ...msg };
changed = true;
break;
}
}
}

return nextMessages;
return changed?nextMessages:messages;
};

export {
Expand Down
Loading