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

Change default action for form submissions that redirect to the current location #1072

Merged
merged 2 commits into from
Nov 20, 2023

Conversation

afcapel
Copy link
Collaborator

@afcapel afcapel commented Nov 20, 2023

This changes the default action for form submission that redirect to the current location from "advance" to "replace". This makes more sense since we're re-rendering the current page, there should be no new entry in the history.

We are also changing the morphing behaviour to only kick in when the visit action is "replace". This is to avoid morphing the page when, for example, we are following a link, unless we opt in to morphing by setting the data-turbo-action attribute to replace.

The main use case for morphing remains the same: you submit a form that changes some state and redirect to the same location. Turbo handles the redirect and morphs the page to reflect the new state.

…nt location

This changes the default action for form submission that redirect to the
current location from "advance" to "replace". This makes more sense since
we're re-rendering the current page, there should be no new entry in the
history.

We are also changing the morphing behaviour to only kick in when the
visit action is "replace". This is to avoid morphing the page when, for example,
we are follwing a link, unless we opt in to morphing by setting the
data-turbo-action attribute to replace.

The main use case for morphing remains the same: you submit a form that
changes some state and refirect to the same location. Turbo handles the
redirect and morphs the page to reflect the new state.
Copy link
Member

@jorgemanrubia jorgemanrubia left a comment

Choose a reason for hiding this comment

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

👍 👍

@afcapel afcapel merged commit c471974 into main Nov 20, 2023
2 checks passed
@afcapel afcapel deleted the replace-form-submission branch November 20, 2023 17:22
@@ -307,6 +307,18 @@ test("clicking the forward button", async ({ page }) => {
assert.equal(await visitAction(page), "restore")
})

test("form submissions that redirect to a different location have a default advance action", async ({ page }) => {
Copy link
Member

Choose a reason for hiding this comment

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

I would add a page refresh test to validate that morphing doesn't trigger if you click on a link pointing to the current page.

domchristie pushed a commit to domchristie/turbo that referenced this pull request Jul 20, 2024
…nt location (hotwired#1072)

* Change default action for form submissions that redirect to the current location

This changes the default action for form submission that redirect to the
current location from "advance" to "replace". This makes more sense since
we're re-rendering the current page, there should be no new entry in the
history.

We are also changing the morphing behaviour to only kick in when the
visit action is "replace". This is to avoid morphing the page when, for example,
we are follwing a link, unless we opt in to morphing by setting the
data-turbo-action attribute to replace.

The main use case for morphing remains the same: you submit a form that
changes some state and refirect to the same location. Turbo handles the
redirect and morphs the page to reflect the new state.

* Add parentheses to clarify conditional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants