Open manuelpuyol opened 2 years ago
@dhh can we reopen this? #611 doesn't fix the canceling behavior
this was solved by https://github.com/hotwired/turbo/pull/729
This was reintroduced by https://github.com/hotwired/turbo/pull/744
@seanpdoyle any reason why the test about this issue was removed? https://github.com/hotwired/turbo/pull/744/files#diff-ba1c7f863678da4856a147f82730481b725f848e033969fe679fc27f1e3263b4L459-L465
@manuelpuyol that test was introduced between the last stable release, but complicated the process of rolling back the LinkClickObserver
changes in https://github.com/hotwired/turbo/pull/744.
With the rollback released, I'm in favor of re-introducing the test coverage and corresponding behavior, if we can!
@seanpdoyle cool, I can try looking into it...
One question though, why do we always prevent turbo:click
for frames?
One question though, why do we always prevent turbo:click for frames?
That is a decision that pre-dates my involvement in the project: https://github.com/hotwired/turbo/blame/v7.0.0-beta.1/src/core/frames/link_interceptor.ts#L39-L40
I'm in favor of experimenting with a different implementation, and support some trial and error with the hopes that the test suite will guide us!
I'm not sure it's possible to cancel frames only looking at turbo:click
with the current architecture 🤔
What was the reason #412 was reverted?
As a possible workaround, we can do something like https://github.com/hotwired/turbo/pull/788, which adds a new turbo:frame-click
event that controls frame clicks and can be canceled 🤷
before-visit events, that are caused by promoted frame links, are also not cancellable.
<a href="/myframepage" data-turbo-frame="myframe" data-turbo-action="advance">Frame link promoted to visit</a>
<script>
document.addEventListener("turbo:before-visit", function(event) {
alert('visit!');
event.preventDefault(); // prevents regular visit but does not prevent promoted frame load
});
</script>
Looking at the
turbo:click
docs:Though if your link triggers a frame navigation, running
preventDefault()
doesn't cancel it.document.addEventListener('turbo:click', (e) => e.preventDefault())
on a Visit:https://user-images.githubusercontent.com/11280312/175405211-c6b112ea-1fd7-4afe-93b8-04cde5e910fa.mov
document.addEventListener('turbo:click', (e) => e.preventDefault())
on a frame:https://user-images.githubusercontent.com/11280312/175405308-19dcfbe7-de8f-4d88-8d08-72d3af4b943c.mov