Skip to content

react strict mode and useChat #7891

@vv1n3k

Description

@vv1n3k

Description

React strict mode causes the useChat to initialize twice and when I try to start conversation in useEffect - eg. based on provided initial message from props, sendMessage calls API twice and apparently this cause very strange side effects like two opened streams. I tried to stop the first stream in useEffect when the component is unmounting but it's not working. Any idea how this should be handled? It's obviously only in development. I temporarily , switch off strict mode, but it's not the option in the long run

AI SDK Version

"@ai-sdk/openai": "2.0.0",
"@ai-sdk/provider": "^2.0.0",
"@ai-sdk/provider-utils": "^3.0.1",
"@ai-sdk/react": "^2.0.1",
"ai": "^5.0.0",
"react": "^19.0.0",
"next": "15.3.5",

Metadata

Metadata

Assignees

Labels

ai/uibugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions