-
Notifications
You must be signed in to change notification settings - Fork 0
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
Move data fetching into FlightCard
#1
base: main
Are you sure you want to change the base?
Conversation
aiState.done([ | ||
...aiState.get(), | ||
{ | ||
role: "function", | ||
name: "get_flight_info", | ||
content: JSON.stringify(flightInfo), | ||
content: "TODO", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware that this is not trivial to solve (one approach here), so there's a chance that this may be an anti-pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But giving up colocation of data fetching in server components, when using them in an AI app (as shown in https://sdk.vercel.ai/docs/concepts/ai-rsc#nested-ui-streaming), would also be unfortunate.
c1a0fc5
to
4229a53
Compare
Wait, shouldn't it be |
Indeed, if I manually patch the response, the bug is fixed. After having looked into https://github.com/vercel/ai/blob/main/packages/core/rsc/streamable.tsx and https://github.com/vercel/ai/blob/main/packages/core/rsc/utils.tsx, I'm not sure this can be fixed in It might instead be a bug in |
Ok, I think I've figured it out. The bug was introduced by facebook/react#28283. If I revert this change locally, the bug is fixed. Reading the PR description and the added code comments, there doesn't appear to be a simple fix, as it would be required to track which rows have been emitted already to decide whether to use |
Alternative to #28620. Instead of emitting lazy references to not-yet-emitted models in the Flight Server, this fixes the observed issue in unstubbable/ai-rsc-test#1 by adjusting the lazy model resolution in the Flight Client to update stale blocked root models, before assigning them as chunk values. In addition, the element props are not outlined anymore in the Flight Server to avoid having to also handle their staleness in blocked elements. fixes #28595
Alternative to #28620. Instead of emitting lazy references to not-yet-emitted models in the Flight Server, this fixes the observed issue in unstubbable/ai-rsc-test#1 by adjusting the lazy model resolution in the Flight Client to update stale blocked root models, before assigning them as chunk values. In addition, the element props are not outlined anymore in the Flight Server to avoid having to also handle their staleness in blocked elements. fixes #28595 DiffTrain build for [93f9179](93f9179)
…ok#28669) Alternative to facebook#28620. Instead of emitting lazy references to not-yet-emitted models in the Flight Server, this fixes the observed issue in unstubbable/ai-rsc-test#1 by adjusting the lazy model resolution in the Flight Client to update stale blocked root models, before assigning them as chunk values. In addition, the element props are not outlined anymore in the Flight Server to avoid having to also handle their staleness in blocked elements. fixes facebook#28595
How we got here (commits on
main
)Reproducing the issue (this PR)
When moving the data fetching from
render
into theFlightCard
component, a race condition is triggered where, under certain circumstances, e.g. when starting the server with a production build, or when delaying the data fetching, the rendered element is unmounted again.Here's how it should behave:
dev.mov
And here it's failing:
prod.mov
This is the RSC response for the successful run:
And this is the RSC response for the failed run:
Note that the last two RSC rows are switched here. When I add a breakpoint to
setMessages
, or delay the setter with a timeout, this response is also handled correctly, though.