## 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.
