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

Form Link Submissions: Don't remove <form> until submission is complete #678

Merged
merged 2 commits into from Aug 11, 2022

Conversation

seanpdoyle
Copy link
Contributor

@seanpdoyle seanpdoyle commented Aug 10, 2022

When an <a> element annotated with [data-turbo-method] is clicked,
Turbo Drive creates, appends, submits, and removes a <form> element
behind the scenes.

Unfortunately, prior to this commit, the <form> element is submitted
then removed synchronously and immediately. This means that by the time
the submit events (and resulting turbo:before-fetch-request and
turbo:submit-start events) bubble up through the document, the
<form> element is already disconnected.

In its absence, the document.documentElement serves as the event's
target.

This commit changes that process to defer the elements removal until
after it dispatches a turbo:submit-end event.

The result is that the element is present throughout all the events, and
is accessible through event.target.

@seanpdoyle seanpdoyle force-pushed the defer-form-link-removal branch 6 times, most recently from 6888c83 to 24672bf Compare August 10, 2022 22:14
Instead of timing frame navigations by beat, use `nextEventOnTarget`,
target the frame, then assert about its header text content.
…lete

When an `<a>` element annotated with `[data-turbo-method]` is clicked,
Turbo Drive creates, appends, submits, and removes a `<form>` element
behind the scenes.

Unfortunately, prior to this commit, the `<form>` element is submitted
then removed synchronously and immediately. This means that by the time
the `submit` events (and resulting `turbo:before-fetch-request` and
`turbo:submit-start` events) bubble up through the document, the
`<form>` element is already disconnected.

In its absence, the `document.documentElement` serves as the event's
target.

This commit changes that process to defer the elements removal until
_after_ it dispatches a `turbo:submit-end` event.

The result is that the element is present throughout all the events, and
is accessible through `event.target`.
@dhh dhh merged commit 28a5dc4 into hotwired:main Aug 11, 2022
@seanpdoyle seanpdoyle deleted the defer-form-link-removal branch August 11, 2022 13:12
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.

None yet

2 participants