fix(web): add random suffix to fallback assistant message IDs to prevent collisions
Some checks failed
ci/woodpecker/push/web Pipeline failed
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:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user