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

add api example #743

Merged
merged 2 commits into from
Jun 9, 2024
Merged

add api example #743

merged 2 commits into from
Jun 9, 2024

Conversation

dai-shi
Copy link
Owner

@dai-shi dai-shi commented Jun 6, 2024

While we wait for #329 (which takes time to design and implement, and we believe most cases are covered by server actions), we can use the low-level middleware api.

Copy link

vercel bot commented Jun 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
waku ⬜️ Ignored (Inspect) Visit Preview Jun 6, 2024 6:08am

Copy link

codesandbox-ci bot commented Jun 6, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

codesandbox-ci bot commented Jun 6, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Contributor

@himself65 himself65 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most cases are covered by server actions

I noticed something recently that React only allows one server action running at the backend at the same time. So now I think this causes server action is not suitable for some cases if there're many users doing some operation in the same time.

https://react.dev/reference/rsc/use-server
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.

BTW, this is not same as the normal restful API, that processes multiple POST queries
simultaneously.

Some similar issue: vercel/next.js#64396

@dai-shi
Copy link
Owner Author

dai-shi commented Jun 6, 2024

I wonder if it's a framework choice or a React rule.

Anyway, I believe #329 is unavoidable for us. I'll work on it, but it will take time. There are some other tasks with priority (not because of the use case, but the internal architecture.)

@himself65
Copy link
Contributor

I wonder if it's a framework choice or a React rule.

I believe this is React behavior, which will prohibit race conditions in the React backend at all

@dai-shi
Copy link
Owner Author

dai-shi commented Jun 6, 2024

By the way, for data fetching, we should use server components and rsc is capable of sending promises, so technically we can wrap the api with rsc.

@dai-shi dai-shi marked this pull request as ready for review June 9, 2024 11:21
@dai-shi dai-shi merged commit 81a7bc3 into main Jun 9, 2024
27 of 28 checks passed
@dai-shi dai-shi deleted the api-example branch June 9, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants