Clarifying the correct usage and reliability of server functions from client components #77469
Unanswered
reh2ur
asked this question in
App Router
Replies: 2 comments 1 reply
-
did you manage to get to the underlying issue? I'm having the same problems after a Stripe redirect; only by printing the error message I get "An unexpected response was received from the server." which makes no sense since the action was executed successfully. |
Beta Was this translation helpful? Give feedback.
1 reply
-
@reh2ur, I ran into the same issues and questions. In my case, the problem was caused by the middlewares — specifically the i18n and Supabase Auth middlewares. You may want to check if your middleware is affecting the response as well. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey folks,
I'm confused about using server functions from the client side in Next.js and could use some help clarifying things.
Since the beginning, we've relied heavily on server functions declared with
'use server'
for API communication. Recently, we've noticed increased occurrences of the error:Failed to find Server Action "..."
. Investigating further, these errors appear when calling server functions withinuseEffect
or Tanstack Query'suseQuery
, often after redirects from our third-party payment provider. Sometimes these functions then unexpectedly returnundefined
or throwAn unexpected response was received from the server
, despite normally being reliable.Here's how we're currently calling server functions:
Using
useQuery
:Using
useEffect
:I initially thought server functions would translate to simple fetch calls (like calling API routes). But given these issues, could someone clarify:
Why might server functions be unreliable in
useEffect
s and/or after certain redirects?Is there any documented recommendation or best practice for using server functions from the client?
Should we instead rely on explicit route handlers or something like TRPC for these scenarios?
Thanks for any insights!
Beta Was this translation helpful? Give feedback.
All reactions