Server actions to accompany formActions #7305
xpertekShaun
started this conversation in
Ideas
Replies: 2 comments 5 replies
-
A form uses
How should the data get merged? |
Beta Was this translation helpful? Give feedback.
4 replies
-
i like this idea, currently facing the same issue on sending JSON to form action. It would be just feel unnatural to stringified JSON into FormData. |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
Form Actions are superb. It would be great if we could improve the ability to submit client side fetch's and have a similar DX to form actions.
Currently, form Actions fail unless they get a non-null FormData object. I thought I would float the ideas for hopefully some positive DX
fetch('?/formation', {method: 'POST', body: JSON.stringify(data)})
was submitted to the formaction, instead of failing, it would behave asif{Content-Type: 'application/json'}
was set and process the request..then().catch()
wrangling. And just update the route page with the new data.Benefits:
+server.ts
+server.ts
api's cleanerDownsides:
The biggest downside obviously is that client side fetches are not Form actions. Renaming Form actions will lead to a breaking change which we dont want.
Perhaps this functionality can be included instead in +server.ts files?
The page url reload issue we had with form actions wont be an issue here, so we could theoretically keep POST, PUT, GET, PATCH, DELETE (powerful when needed) in +server.ts, but perhaps we could also export an actions object from +server.ts, and name it "Server Actions"?
Beta Was this translation helpful? Give feedback.
All reactions