Propagate turbo:submit-end events from data-turbo-method links#1406
Open
jeremy wants to merge 1 commit intohotwired:mainfrom
Open
Propagate turbo:submit-end events from data-turbo-method links#1406jeremy wants to merge 1 commit intohotwired:mainfrom
jeremy wants to merge 1 commit intohotwired:mainfrom
Conversation
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.
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 |
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.
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.