Skip to content

fix(react): treat id: undefined the same as omitting id in useChat - #16228

Closed
Aayush-engineer wants to merge 1 commit into
vercel:mainfrom
Aayush-engineer:fix/use-chat-undefined-id-recreates-instance
Closed

fix(react): treat id: undefined the same as omitting id in useChat#16228
Aayush-engineer wants to merge 1 commit into
vercel:mainfrom
Aayush-engineer:fix/use-chat-undefined-id-recreates-instance

Conversation

@Aayush-engineer

Copy link
Copy Markdown
Contributor

Background

Passing id: undefined to useChat causes the internal Chat instance
to be recreated on every render, wiping all messages and in-flight streams.
This is a common pattern: id={conversationId ?? undefined}.

Fixes #16226

Summary

Added a nullish check (options.id != null) to the shouldRecreateChat
condition so that id: undefined is treated the same as omitting id.

Checklist

  • All commits are signed
  • Tests passing (62/62)
  • Changeset added
  • Self-reviewed

@Aayush-engineer
Aayush-engineer force-pushed the fix/use-chat-undefined-id-recreates-instance branch from 2f0c8d9 to bee563f Compare June 18, 2026 05:34
@gr2m gr2m closed this in 550e413 Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useChat({ id: undefined }) recreates the Chat instance on every render, wiping messages

1 participant