Skip to content

Commit e6a4b88

Browse files
committed
transport/vercel: match history by message ID instead of reference
Reference-based matching is brittle — if useChat ever clones messages during state updates the Set.has() check would silently miss them.
1 parent 7cf750e commit e6a4b88

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/vercel/transport/chat-transport.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ export const createChatTransport = (
212212
} else {
213213
// Build history nodes from the transport's conversation tree.
214214
// The local `history` is a subset of messages (excludes the last message
215-
// being sent). Match by reference to extract the full nodes.
215+
// being sent). Match by message ID for robustness against cloned objects.
216216
const allNodes = transport.getNodes();
217-
const historySet = new Set(history);
218-
const historyNodes = allNodes.filter((n) => historySet.has(n.message));
217+
const historyIds = new Set(history.map((m) => m.id));
218+
const historyNodes = allNodes.filter((n) => historyIds.has(n.message.id));
219219
sendBody = {
220220
history: historyNodes,
221221
id: opts.chatId,

0 commit comments

Comments
 (0)