-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useChat: Infinite re-renders when using messages as useEffect dependency #4741
Comments
@sebaFP did you encounter this issue as part of an ai sdk upgrade or independently? |
@lgrammel I just updated and ran into the issue after I updated the ai-sdk and vertex ai sdk. I re-installed my previous version (ai sdk: 4.1.16) and it started working again. The error seems to be happening after the final message is finished. It'll print out the whole long message I'm playing with, and then at the very end it throws that maximum depth error listed above |
@Godrules500 from which version did you update? |
@lgrammel I updated to the latest version which is 4.1.34 when it started breaking. So I went from 4.1.16 to 4.1.34 |
I have tried to reproduce this on the latest version of the AI SDK by adding: useEffect(() => {
// Any logic here
console.log('Messages', messages);
}, [messages]); // Adding messages as dependency to https://github.com/vercel/ai/blob/main/examples/next-openai/app/page.tsx The example works without problems. Are there other AI SDK packages that you have imported (e.g. |
Description
Bug Description
When using the messages array from useChat as a dependency in useEffect, it causes infinite re-renders and throws a "Maximum update depth exceeded" error.
Steps to Reproduce
Current Behavior
Expected Behavior
Environment
Additional Context
This seems to happen because messages reference might be changing on every render, causing the effect to run repeatedly.
Code example
No response
AI provider
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: