-
Notifications
You must be signed in to change notification settings - Fork 474
Propagate turbo:submit-end events from data-turbo-method links #1406
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
Open
jeremy
wants to merge
1
commit into
hotwired:main
Choose a base branch
from
basecamp:fix-form-link-event-propagation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Clicking a `data-turbo-method` link submits an ephemeral form. The form is removed synchronously in a `turbo:submit-end` handler, blocking propagation to parent elements. This causes issues for ancestors that act on turbo:submit-end, like closing a dialog on redirect responses. To fix, defer form removal to allow the event to fully propagate.
seanpdoyle
reviewed
Nov 11, 2025
Comment on lines
+1260
to
+1276
| await page.evaluate(() => { | ||
| let eventPropagatedPastForm = false | ||
|
|
||
| // Listen on document to verify event propagates beyond the form element | ||
| document.addEventListener("turbo:submit-end", (event) => { | ||
| if (event.target.tagName === "FORM") { | ||
| eventPropagatedPastForm = true | ||
| } | ||
| }) | ||
|
|
||
| window.eventPropagatedPastForm = () => eventPropagatedPastForm | ||
| }) | ||
|
|
||
| await page.click("#turbo-method-post-to-targeted-frame") | ||
| await nextEventNamed(page, "turbo:submit-end") | ||
|
|
||
| assert.ok(await page.evaluate(() => window.eventPropagatedPastForm()), "turbo:submit-end propagated past the form element") |
Contributor
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.
Could this test be re-written to utilize Playwright's retrying assertions?:
Suggested change
| await page.evaluate(() => { | |
| let eventPropagatedPastForm = false | |
| // Listen on document to verify event propagates beyond the form element | |
| document.addEventListener("turbo:submit-end", (event) => { | |
| if (event.target.tagName === "FORM") { | |
| eventPropagatedPastForm = true | |
| } | |
| }) | |
| window.eventPropagatedPastForm = () => eventPropagatedPastForm | |
| }) | |
| await page.click("#turbo-method-post-to-targeted-frame") | |
| await nextEventNamed(page, "turbo:submit-end") | |
| assert.ok(await page.evaluate(() => window.eventPropagatedPastForm()), "turbo:submit-end propagated past the form element") | |
| const html = page.locator("html") | |
| await html.evaluate((documentElement) => { | |
| documentElement.addEventListener("turbo:submit-end", ({ target }) => { | |
| if (target instanceof HTMLFormElement) { | |
| documentElement.toggleAttribute("data-turbo-submit-end", true) | |
| } | |
| }) | |
| }) | |
| await page.click("#turbo-method-post-to-targeted-frame") | |
| await nextEventNamed(page, "turbo:submit-end") | |
| await expect(html, "turbo:submit-end propagated past the form element").toHaveAttribute("data-turbo-submit-end") |
Collaborator
|
This came up while debugging an error that was actually associated with another cause, and ultimately we agreed at that point to Stop fixing bugs around |
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.
Clicking a
data-turbo-methodlink submits an ephemeral form. The form is removed synchronously in aturbo:submit-endhandler, blocking propagation to parent elements.This causes issues for ancestors that act on turbo:submit-end, like closing a dialog on redirect responses.
To fix, defer form removal to allow the event to fully propagate.