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

Parallel server action calls #69265

Open
yehonatanyosefi opened this issue Aug 24, 2024 · 4 comments
Open

Parallel server action calls #69265

yehonatanyosefi opened this issue Aug 24, 2024 · 4 comments
Labels
bug Issue was opened via the bug report template. create-next-app Related to our CLI tool for quickly starting a new Next.js application. Parallel & Intercepting Routes Related to Parallel and/or Intercepting routes. Performance Anything with regards to Next.js performance.

Comments

@yehonatanyosefi
Copy link

yehonatanyosefi commented Aug 24, 2024

Link to the code that reproduces this issue

https://github.com/yehonatanyosefi/parallel-routes-example

To Reproduce

  1. start the application
  2. click start button
  3. see console logs come out as ABAB on the server side with two post requests, and on the client side it taking 2 seconds instead of one even though using promise.all

Current vs. Expected behavior

Current behavior of nextjs server actions are they are executed in sequential fashion, however there is no flag or option or a config to let them be executed in parallel. Causing them to block some ux. For example for ai image generation, you'd have to wait for the last call to finish before making your next one, causing you to need to wait over 15 seconds before you can even generate more images instead of the Expected behavior of being able to send them in parallel and stream in finished generations by awaiting them.

In the example I sent you can see even though I used Promise.all on 2 promises that each take a second that should be expected take only 1 second together but because of the sequential nature the current behavior is it takes 2.

Provide environment information

when hosted on vercel it happens, locally it happens too:
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32393
  Available CPU cores: 20
Binaries:
  Node: 20.10.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.0.0-canary.128 // Latest available version is detected (15.0.0-canary.128).
  eslint-config-next: N/A
  react: 19.0.0-rc-eb3ad065-20240822
  react-dom: 19.0.0-rc-eb3ad065-20240822
  typescript: 5.3.3
Next.js Config:
  output: N/A

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

create-next-app, Parallel & Intercepting Routes, Performance

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

next dev (local), Vercel (Deployed)

Additional context

Edit: https://x.com/cramforce/status/1733240566954230063
Above's link to a reply by Vercel's CTO agreeing it should have control if we want it parallel

@yehonatanyosefi yehonatanyosefi added the bug Issue was opened via the bug report template. label Aug 24, 2024
@github-actions github-actions bot added create-next-app Related to our CLI tool for quickly starting a new Next.js application. Parallel & Intercepting Routes Related to Parallel and/or Intercepting routes. Performance Anything with regards to Next.js performance. labels Aug 24, 2024
@simonri
Copy link
Contributor

simonri commented Aug 25, 2024

Server Actions are designed for mutations that update server-side state; they are not recommended for data fetching. Accordingly, frameworks implementing Server Actions typically process one action at a time and do not have a way to cache the return value.

https://react.dev/reference/rsc/use-server#caveats

@yehonatanyosefi
Copy link
Author

Server Actions are designed for mutations that update server-side state; they are not recommended for data fetching. Accordingly, frameworks implementing Server Actions typically process one action at a time and do not have a way to cache the return value.

https://react.dev/reference/rsc/use-server#caveats

https://x.com/cramforce/status/1733240566954230063
Your CTO agrees with me

@simonri
Copy link
Contributor

simonri commented Aug 25, 2024

The docs mention that only sequential server action calls are supported, so running them in parallel shouldn't be expected.

@musjj
Copy link

musjj commented Aug 27, 2024

I would also agree that it would be very cool to use server actions as an RPC system.

There's this other thread: #69265 that mentions:

I can confirm this is by design.

Why? To prevent things such as inconsistent states from navigation aborting, client fetching, etc.

But I'm not exactly sure what this means. If a server action is pure (only queries for data), there shouldn't be a problem right? If so, it would be nice if there is a way to mark a server action as a "query" and allow it to run parallel to other queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. create-next-app Related to our CLI tool for quickly starting a new Next.js application. Parallel & Intercepting Routes Related to Parallel and/or Intercepting routes. Performance Anything with regards to Next.js performance.
Projects
None yet
Development

No branches or pull requests

3 participants