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

Prevent form links from submitting multiple requests #645

Merged
merged 1 commit into from
Jul 28, 2022

Conversation

seanpdoyle
Copy link
Contributor

The LinkInterceptor class contains some Frame-specific checks that
were at the root of <a data-turbo-method="..."> element clicks
submitting multiple HTTP requests.

To resolve the underlying issue, this commit changes the
FormLinkInterceptor class to rely on an instance of
LinkClickObserver instead of LinkInterceptor.

In order to make that possible, this commit also extends the
LinkClickObserver to accept a second argument to server as the
EventTarget for the click event listeners. As a consumer, the
FormLinkInterceptor instances attached to <turbo-frame> element
scope their listeners to the element, while the Session's
FormLinkInterceptor instance attaches a catch-all listener to the
window.

Since this commit changes the underlying event listening mechanism, it
also renames the FormLinkInterceptor and delegate to
FormLinkClickObserver to match the LinkClickObserver naming
patterns.

@seanpdoyle seanpdoyle force-pushed the form-link-click-observer branch 2 times, most recently from 8b6e2b8 to b1be7e9 Compare July 21, 2022 14:08
The `LinkInterceptor` class contains some Frame-specific checks that
were at the root of `<a data-turbo-method="...">` element clicks
submitting multiple HTTP requests.

To resolve the underlying issue, this commit changes the
`FormLinkInterceptor` class to rely on an instance of
`LinkClickObserver` instead of `LinkInterceptor`.

In order to make that possible, this commit also extends the
`LinkClickObserver` to accept a second argument to server as the
[EventTarget][] for the `click` event listeners. As a consumer, the
`FormLinkInterceptor` instances attached to `<turbo-frame>` element
scope their listeners to the element, while the `Session`'s
`FormLinkInterceptor` instance attaches a catch-all listener to the
`window`.

Since this commit changes the underlying event listening mechanism, it
also renames the `FormLinkInterceptor` and delegate to
`FormLinkClickObserver` to match the `LinkClickObserver` naming
patterns.

[EventTarget]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
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