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

Canceling turbo:click does not stop a frame navigation. #610

Open
manuelpuyol opened this issue Jun 23, 2022 · 8 comments
Open

Canceling turbo:click does not stop a frame navigation. #610

manuelpuyol opened this issue Jun 23, 2022 · 8 comments

Comments

@manuelpuyol
Copy link
Contributor

Looking at the turbo:click docs:

Cancel this event to let the click fall through to the browser as normal navigation.

Though if your link triggers a frame navigation, running preventDefault() doesn't cancel it.


document.addEventListener('turbo:click', (e) => e.preventDefault()) on a Visit:

Screen.Recording.2022-06-23.at.4.25.54.PM.mov

document.addEventListener('turbo:click', (e) => e.preventDefault()) on a frame:

Screen.Recording.2022-06-23.at.4.26.51.PM.mov
@manuelpuyol
Copy link
Contributor Author

@dhh can we reopen this? #611 doesn't fix the canceling behavior

@dhh dhh reopened this Jul 18, 2022
@manuelpuyol
Copy link
Contributor Author

this was solved by #729

@manuelpuyol
Copy link
Contributor Author

This was reintroduced by #744

@seanpdoyle any reason why the test about this issue was removed? https://github.com/hotwired/turbo/pull/744/files#diff-ba1c7f863678da4856a147f82730481b725f848e033969fe679fc27f1e3263b4L459-L465

@seanpdoyle
Copy link
Contributor

@manuelpuyol that test was introduced between the last stable release, but complicated the process of rolling back the LinkClickObserver changes in #744.

With the rollback released, I'm in favor of re-introducing the test coverage and corresponding behavior, if we can!

@manuelpuyol
Copy link
Contributor Author

@seanpdoyle cool, I can try looking into it...

One question though, why do we always prevent turbo:click for frames?

event.preventDefault()

@seanpdoyle
Copy link
Contributor

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!

@manuelpuyol
Copy link
Contributor Author

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 #788, which adds a new turbo:frame-click event that controls frame clicks and can be canceled 🤷

@TAR5
Copy link

TAR5 commented Jan 17, 2024

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants