Actions middleware#12373
Merged
Merged
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
e179f4f to
1e31f7a
Compare
matthewp
approved these changes
Nov 6, 2024
matthewp
left a comment
Contributor
There was a problem hiding this comment.
looks good! I like the compromise of adding getActionContext.
1 task
Contributor
Author
|
!preview astro-actions-middleware |
sarah11918
reviewed
Nov 8, 2024
sarah11918
left a comment
Member
There was a problem hiding this comment.
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]>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/middlewareandruntime/routeto dogfood this functioncontext.originPathnameproperty. 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