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

Actions: auto-redirect action response to avoid "confirm form resubmission" dialog #11603

Merged
merged 22 commits into from
Aug 9, 2024

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Aug 2, 2024

Changes

This change adds automatic redirects when an action is called. This follows Laravel's POST/redirect/GET pattern to avoid a "confirm form resubmission" dialog and remove the ?_astroAction param from the rendered result.

See the changeset for usage instructions.

  • Persist action data in a cookie. This cookie is not encrypted. We are investigating a general encryption strategy for Astro as part of Astro Islands: Encrypt server islands props #11535. If Astro adopts an encryption key as part of the runtime, we will revisit encryption of the action result cookie.
  • Redirect to referrer on error, and the url.pathname on success.
  • If an action cookie is present, populate getActionResult with the cookie JSON. Delete after the request has been fulfilled.

Testing

Update integration tests to follow an expected redirect.

Docs

Updated RFC docs with new guide: https://github.com/withastro/roadmap/blob/actions/proposals/0046-actions.md#call-actions-from-an-html-form

Copy link

changeset-bot bot commented Aug 2, 2024

🦋 Changeset detected

Latest commit: 699ec2b

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 2, 2024
@bholmesdev bholmesdev changed the base branch from main to feat/actions-edge-middleware August 2, 2024 17:51
@bholmesdev bholmesdev force-pushed the feat/actions-edge-middleware branch 2 times, most recently from 37b2823 to c4130c7 Compare August 5, 2024 11:59
Base automatically changed from feat/actions-edge-middleware to main August 5, 2024 12:22
@bholmesdev bholmesdev force-pushed the feat/redirect-on-html-response branch from 0496de4 to 7db24bb Compare August 7, 2024 19:43
@bholmesdev bholmesdev force-pushed the feat/redirect-on-html-response branch from 80ab841 to 7ee9b0c Compare August 8, 2024 13:08
@bholmesdev bholmesdev marked this pull request as ready for review August 8, 2024 13:21
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

The code looks good to me. I suppose we want to wait for the docs change before merging?

@ematipico
Copy link
Member

@bholmesdev is there a chapter in the RFC I can look at before reviewing the code?

@bholmesdev
Copy link
Contributor Author

@ematipico Thanks for flagging that! I just finished a new guide on the RFC docs: https://github.com/withastro/roadmap/blob/actions/proposals/0046-actions.md#call-actions-from-an-html-form

Writing out examples actually helped me find a design flaw. I decided the cookie should not be cleared on success. Otherwise, the action result data would disappear on a refresh.

@bholmesdev bholmesdev merged commit f31d466 into main Aug 9, 2024
13 checks passed
@bholmesdev bholmesdev deleted the feat/redirect-on-html-response branch August 9, 2024 21:17
@astrobot-houston astrobot-houston mentioned this pull request Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants