fix(web): add random suffix to fallback assistant message IDs to prevent collisions
Some checks failed
ci/woodpecker/push/web Pipeline failed

Message IDs generated in the fallback path used only Date.now() which caused
ID collisions in rapid-send scenarios (multiple sends within the same millisecond).
Adding the same Math.random() suffix used by userMessage IDs ensures uniqueness.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 20:41:43 -06:00
parent 7de0e734b0
commit 5ba77d8952

View File

@@ -294,7 +294,7 @@ export function useChat(options: UseChatOptions = {}): UseChatReturn {
const response = await sendChatMessage(request);
const assistantMessage: Message = {
id: `assistant-${Date.now().toString()}`,
id: `assistant-${Date.now().toString()}-${Math.random().toString(36).slice(2, 8)}`,
role: "assistant",
content: response.message.content,
createdAt: new Date().toISOString(),
@@ -328,7 +328,7 @@ export function useChat(options: UseChatOptions = {}): UseChatReturn {
});
const errorMessage: Message = {
id: `error-${String(Date.now())}`,
id: `error-${String(Date.now())}-${Math.random().toString(36).slice(2, 8)}`,
role: "assistant",
content: "Something went wrong. Please try again.",
createdAt: new Date().toISOString(),