fix(chat): stabilize message identities
This commit is contained in:
@@ -7,20 +7,7 @@ export type ChatRenderItem =
|
||||
| { type: "msg"; message: UiMessage; key: string };
|
||||
|
||||
export function createChatMessageKeyResolver(): ChatMessageKeyResolver {
|
||||
const localMessageKeys = new WeakMap<UiMessage, string>();
|
||||
let nextLocalMessageKey = 0;
|
||||
|
||||
return (message) => {
|
||||
if (message.id && message.id.length > 0) return `msg-${message.id}`;
|
||||
|
||||
const existing = localMessageKeys.get(message);
|
||||
if (existing) return existing;
|
||||
|
||||
nextLocalMessageKey += 1;
|
||||
const next = `local-msg-${nextLocalMessageKey}`;
|
||||
localMessageKeys.set(message, next);
|
||||
return next;
|
||||
};
|
||||
return (message) => `msg-${message.displayId}`;
|
||||
}
|
||||
|
||||
export function buildChatRenderItems(
|
||||
|
||||
Reference in New Issue
Block a user