docs(react-query): recommend against using server actions in queryFn
Update the useQuery documentation to clarify that server actions should not be used in queryFn. Server actions are meant for mutations, run serially, and cannot execute in parallel, potentially leading to unexpected behavior. Recommend using API routes instead for data fetching.
Closes #7934
This shouldn't go to the api reference, but to the advanced ssr guide. Also, please link to this paragraph from the react docs: https://react.dev/reference/rsc/use-server#caveats
This shouldn't go to the api reference, but to the advanced ssr guide. Also, please link to this paragraph from the react docs:
https://react.dev/reference/rsc/use-server#caveats
Happy to update. However, to my understanding calling server actions from the server does not turn them into post requests, and does not make them blocking.
When people run into this issue they are making the fetch call from the client using the queryfn. I figured this would be the place they'd look first when running into issues.
However, to my understanding calling server actions from the server does not turn them into post requests, and does not make them blocking.
That's right, and this isn't what I am proposing. The SSR guide has tons of usQuery usages in client components because that's what you need to do after the "handoff" from the server. Have you read it? We already have a NOTE about server actions on that page, I would probably merge the two. "Server actions only work when queryFn isn't a reference" is another reason to not recommend them for fetching data.
I figured this would be the place they'd look first when running into issues.
It will be more confusing for all other people who don't use next-js and read the useQuery API docs. They might not even know what "server actions" are. Recommendations like that are not for api references (they tell you what's possible), but for guides (they tell you what you should do or avoid).
@bartcheers it’s been a while. Do you plan on finishing this docs update?