-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Actions middleware #12373
Actions middleware #12373
Conversation
🦋 Changeset detectedLatest commit: cba1e11 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
b266772
to
e179f4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
e179f4f
to
1e31f7a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! I like the compromise of adding getActionContext
.
!preview astro-actions-middleware |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job Ben!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this will make people super happy @bholmesdev ! Just doing my docs diligence (will be getting through the guide material later today) and dropping some thoughts re: the changeset.
Also noting that I don't see any new error messages here, so confirming no new ones were added that I should be looking at! 🙌
Co-authored-by: Sarah Rainsberger <[email protected]>
Change Action cookie redirects to an opt-in feature users can implement using middleware. This means Actions submitted from an HTML form action will no longer redirect to the destination as a GET request. Instead, the page will be rendered as a POST result.
This is meant to address the 4 KB size limit users have encountered when calling actions from an HTML form action. It can be difficult to predict the size of an action result for large validation errors or longer return values, like AI chatbot results.
So, we've introduced a new
getActionContext()
utility to let you decide how action results are handled from middleware. You may choose to implement the existing cookie redirect from Astro v4, or implement forwarding with your own session storage.Here is an example of how our built-in POST middleware works. This calls the appropriate action handler and sets the result to be accessible from
Astro.getActionResult()
:See the changeset for a sample implementation of cookie forwarding from Astro v4.
Changes
getActionContext()
utility that exposes utilities to get an action request and set the resultruntime/middleware
andruntime/route
to dogfood this functioncontext.originPathname
property. This is used to retrieve the original pathname through any rewrites. Needed for users to DIY cookie forwarding, and should be useful for middleware authors in general.Testing
Docs
withastro/docs#9943