Skip to content
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

docs(react-query): recommend against using server actions in queryFn #7970

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bartcheers
Copy link

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

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 TanStack#7934
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 28, 2024
@TkDodo
Copy link
Collaborator

TkDodo commented Sep 1, 2024

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

@bartcheers
Copy link
Author

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.

@TkDodo
Copy link
Collaborator

TkDodo commented Sep 2, 2024

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).

@TkDodo
Copy link
Collaborator

TkDodo commented Oct 11, 2024

@bartcheers it’s been a while. Do you plan on finishing this docs update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Next.js server action not getting executed
2 participants