hotwired / turbo

The speed of a single-page web application without having to write any JavaScript
https://turbo.hotwired.dev
MIT License
6.7k stars 425 forks source link

Cancel navigation when user presses ESC #619

Open fregante opened 2 years ago

fregante commented 2 years ago

Regular navigation in the browser can be stopped by clicking the browser’s "Stop loading" button or by hitting the ESC key. Turbo does not handle this and requests cannot be cancelled after fetch is made.

I looked into the code and I have not found a way to implement this myself outside Turbo:

I wish Turbo would either:

Prior art

dhh commented 2 years ago

I like the idea of matching the browser here. Making in-flight requests cancelable with esc. Please do explore.

fregante commented 1 year ago

I'd love to see this eventually in Turbo. I tried looking into it and there doesn't seem to be any way to cancel these events completely.

Turbo allows "cancellation" of turbo:click and turbo:before-render but both of them cause Turbo to set location.href and trigger a full-page reload. "Cancellation" refers to the AJAX loading, not just to the loading.