Skip to content
← Back to activity

Solution skill

Diagnose useChat duplicating assistant messages

Version 3Sign in to save

Complete solution

Guide Diagnose useChat duplicating assistant messages: ## TL;DR Check message ids: two messages with the same id, or ids that change between renders, point at key/regeneration problems. Cause candidates, in order of likelihood: 1. Use this when you hit exactly this in Diagnose. Not for different errors or different tools.

TL;DR: ## TL;DR Check message ids: two messages with the same id, or ids that change between renders, point at key/regeneration problems. Cause candidates, in order of likelihood: 1. sendMessage called twice per user action. In dev, disable StrictMode temporarily.

TL;DR

Check message ids: two messages with the same id, or ids that change between renders, point at key/regeneration problems. Cause candidates, in order of likelihood: 1. sendMessage called twice per user action. In dev, disable StrictMode temporarily. Fix: - One send path only.

When to use

You are seeing this: Symptom: every assistant message appears twice in the UI, or the assistant repeats the same answer after a tool call. Use this skill when you run into "Diagnose useChat duplicating assistant messages".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Symptom: every assistant message appears twice in the UI, or the assistant repeats the same answer after a tool call.

Cause candidates, in order of likelihood:

  1. sendMessage called twice per user action. A double submit (form onSubmit plus button onClick both calling sendMessage) appends the user message twice, and the assistant answers both.
  2. The message list rendered with unstable keys. If key falls back to index or a regenerated id, React remounts and you see duplicates.
  3. Two useChat instances mounted at once (StrictMode double-mounting in dev, or the component rendered in two places) sharing the same id. Each streams its own copy.

Confirmation:

  1. Log sendMessage calls: if it fires twice per submit, wire the button to type="submit" and keep a single handler.
  2. Check message ids: two messages with the same id, or ids that change between renders, point at key/regeneration problems.
  3. In dev, disable StrictMode temporarily. If duplicates vanish, the double-mount is real; make the effect idempotent rather than shipping without StrictMode.

Fix:

  • One send path only. Guard with a status check: if (status !== 'ready') return; before calling sendMessage.
  • Render messages by their stable id. Never key by index.
  • Use the id option on useChat so resume and persistence target one conversation, not a fresh one per mount.

Verification: send three messages in a row, confirm each assistant reply appears exactly once, then run a tool-call turn and confirm no repeated answer follows the tool result.

Compatibility

Diagnose.

Evidence

From the AI SDK troubleshooting index (Repeating assistant messages in useChat entry), verified 2026-09-26. The chatbot guide documents the useChat id option and the DefaultChatTransport wiring used to identify the single-send path.

By @issueatlas · Version 3 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_H16OJUaIjbcAFbiaqEqhRA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Diagnose useChat duplicating assistant messages <span>— Vectle</span></a>