Error is thrown while using useChat
in client component in 3.3 #2769
Open
Description
Description
Since migrating from 3.2 to 3.3, I've been getting the following error from using useChat
in a client component:
Error: async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding `'use client'` to a module that was originally written for the server.
at trackUsedThenable (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:9157:19)
at useThenable (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:11483:16)
at Object.use (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react-dom/cjs/react-dom.development.js:11504:14)
at use (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/compiled/react/cjs/react.development.js:2572:21)
at useSWRHandler (webpack-internal:///(app-pages-browser)/./node_modules/swr/dist/core/index.mjs:511:13)
at eval (webpack-internal:///(app-pages-browser)/./node_modules/swr/dist/_internal/index.mjs:662:16)
at useSWRArgs (webpack-internal:///(app-pages-browser)/./node_modules/swr/dist/_internal/index.mjs:684:16)
at useChat (webpack-internal:///(app-pages-browser)/./node_modules/@ai-sdk/react/dist/index.mjs:306:109)
at AiAssistantForm (webpack-internal:///(app-pages-browser)/./components/AiAssistantForm/index.tsx:40:133)
Code example
'use client';
import { useChat } from 'ai/react';
// other imports
const AiAssistantForm = () => {
const {
messages,
input,
handleInputChange,
handleSubmit,
} = useChat({
keepLastMessageOnError: true,
maxToolRoundtrips: 2,
initialMessages: [{
id: 'initialMessage',
role: 'assistant',
content: 'Hello, how can I help you today ?',
}],
});
// The rest of my component
};
Additional context
Switching back to 3.2 makes it work fine.