ai
ai copied to clipboard
Streaming or yield not working on Vercel
Description
I set up an app just like in the examples. When I run it locally, it streams and yields from function* generators in the render functions perfectly. When I upload to Vercel and run it through there, there is no streaming. Responses still come in, but I don't see any of my spinners or loading messages when sent with yield.
I've made sure to update the ai, openai, and next packages to latest.
Code example
No response
Additional context
No response
I solved this by adding
export const runtime = "edge"
in my page.tsx
Maybe the documentation should reflect that.
@stephenkalnoske-sans which docs page were you looking at?
https://sdk.vercel.ai/docs/concepts/ai-rsc
https://sdk.vercel.ai/docs/api-reference/generative-ui/render
@lgrammel
I have the same issue. I created a minimum project with the example code in the docs and verified it. https://github.com/miurla/my-ai-app/blob/68fcd6540db4a4652093c0ae621a87367471fdcb/app/page.tsx#L7-L8
Is it correct to set export const runtime = "edge"
?
In Vercel's ChatBot, it doesn't seem to be set to edge, but it works.
Are there any necessary settings in Vercel?
@miurla can you try export const dynamic = 'force-dynamic'
? (edge might not be needed)
CC @shuding re RSC
@lgrammel Thank you for your quick response! I tried it, but it's not working.
https://github.com/miurla/my-ai-app/blob/main/app/page.tsx#L8
Additional information
By removing use client
from page.tsx and setting export const dynamic = 'force-dynamic'
, streaming started working.
However, a client-side exception occurs.
https://github.com/miurla/morphic/blob/test-stream/app/page.tsx#L3
There was a bug up until 14.2.2 with streaming + server actions + Node.js that has since been resolved. https://github.com/miurla/morphic/pull/5#issuecomment-2100788459
This issue seems to have been caused by a combination of factors. It has been resolved in 14.2.3. I think we can close this issue.