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

Bug: promises passed to server actions block on promise parameters #28510

Open
AaronFriel opened this issue Mar 7, 2024 · 0 comments
Open

Bug: promises passed to server actions block on promise parameters #28510

AaronFriel opened this issue Mar 7, 2024 · 0 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@AaronFriel
Copy link

React version: 18.2.0

Steps To Reproduce

  1. Create a server action that takes a promise parameter p:
    "use server";
    
    export async function serverAction(p: Promise<void>) {
      console.log(p);
      const t1 = new Date();
    
      await p;
    
      const t2 = new Date();
    
      console.log("elapsed", t2.valueOf() - t1.valueOf());
      return {
        t1,
        t2,
      };
    }
  2. Pass new Promise((r) => setTimeout(r, 10_000)) to that server action.
  3. Expect that the action begins running immediately, then blocks on the promise, and reports an elapsed time of approximately 10 seconds.

Link to code example:

https://codesandbox.io/p/devbox/next-14-0-3-forked-7q86s7?file=%2Fapp%2Factions.ts%3A4%2C18&workspaceId=958ee911-ec8f-4ca3-9ce1-668005ecaeb8

The current behavior

Serialization of promises is synchronous and blocking.

The expected behavior

That a promise could be passed to a server action and resolved asynchronously, e.g., as a cancellation token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

1 participant