fix(chat): stop the just-sent user message from flickering
The server echo of an optimistic user message carries different part ids, so the reducer dropped the optimistic part and appended the server one at the end, and MessageBody keyed user parts by part id. The key change remounted the text subtree (blank frame, markdown re-parse, truncation state reset) and the append reordered text against file parts. Replace the optimistic part in place and key user parts positionally.
This commit is contained in:
@@ -726,10 +726,13 @@ const UserMessageBody = React.memo(({ messageId, parts, messageCreatedAt, isMobi
|
||||
)}
|
||||
style={useStickyScrollableUserContent ? { maxHeight: 'calc(var(--chat-scroll-height, 100dvh) * 0.4)' } : undefined}
|
||||
>
|
||||
{/* Positional keys, not part ids: the server echo of a just-sent
|
||||
message swaps the optimistic part id, and id-based keys would
|
||||
remount the text subtree (blank frame + height jump). */}
|
||||
{userContentParts.map((part, index) => {
|
||||
if (isSubtaskPart(part)) {
|
||||
return (
|
||||
<React.Fragment key={part.id ?? `user-subtask-${index}`}>
|
||||
<React.Fragment key={`user-subtask-${index}`}>
|
||||
<UserSubtaskPart part={part} />
|
||||
</React.Fragment>
|
||||
);
|
||||
@@ -737,7 +740,7 @@ const UserMessageBody = React.memo(({ messageId, parts, messageCreatedAt, isMobi
|
||||
|
||||
if (isShellActionPart(part)) {
|
||||
return (
|
||||
<React.Fragment key={part.id ?? `user-shell-${index}`}>
|
||||
<React.Fragment key={`user-shell-${index}`}>
|
||||
<UserShellActionPart part={part} />
|
||||
</React.Fragment>
|
||||
);
|
||||
@@ -752,7 +755,7 @@ const UserMessageBody = React.memo(({ messageId, parts, messageCreatedAt, isMobi
|
||||
}
|
||||
}
|
||||
return (
|
||||
<React.Fragment key={part.id ?? `user-text-${index}`}>
|
||||
<React.Fragment key={`user-text-${index}`}>
|
||||
<UserTextPart
|
||||
part={part}
|
||||
messageId={messageId}
|
||||
|
||||
Reference in New Issue
Block a user