next.js: Server action called from client component is invoked but return data is always undefined (even though network response has data in it)

Link to the code that reproduces this issue

https://github.com/RahulBirCodes/server-action-bug

To Reproduce

  1. Start the application with yarn run dev
  2. Try navigating to demo.localhost:3000/test

Current vs. Expected behavior

Current behavior: The text on the page always says ‘Data from server is undefined’ and you get a small issue in the browser that says that you are accessing an undefined object.

Expected: Text on the page should say Data from server is test’ and there should be no errors that you are accessing an undefined object.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 22.2.0
  npm: 10.7.0
  Yarn: 1.22.21
  pnpm: 9.5.0
Relevant Packages:
  next: 14.2.5 // Latest available version is detected (14.2.5).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.4
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed)

Additional context

I am building a multi tenant site and this error only occurs when I add the middleware for multi tenancy. If I build a demo app without that middleware, everything works. Additionally, if I go into dev tools and look into network, I can see the data Im expecting from the server is there in the response, but no matter what I do I can’t access it from the client.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@ztanner Works on my project, thanks a lot!

Hello, Rahul.

Just tried to run your code and, apparently, the error does not occur on my machine (i dont know why)

image