swup / swup

Versatile and extensible page transition library for server-rendered websites πŸŽ‰

Home Page:https://swup.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: Allow aborting running visits

daun opened this issue Β· comments

Describe the problem 🧐

  • Continuation of #844
  • In browsers, hitting the Esc button stops the page from loading
  • Swup currently doesn't have a way of specifically cancelling a running visit

Describe the propsed solution 😎

Extend the functionality of visit.abort():

  • Cancel the running fetch request
  • Revert the url bar change
  • Undo the out-animation to restore the content

There are two scenarios of aborting visits:

  • A β€” Abort a visit in favor of a new one: already supported, much simpler
  • B β€” Abort a visit and revert to previous state: new feature, a bit more complex

Questions:

  • Is "abort" the right terminology for both? Can both be supported with the same hook? One abort is "final" and stops everything, one abort is "intermediate" and merely transitions into the next visit
  • We could give the visit:abort hook an argument, { final: true } that indicates this. Feels a bit strange.
  • Example: hiding the progress bar on visit:abort only makes sense for scenario B, when the abort is "final".
  • Do other libraries support this? Turbo, Pjax, Livewire, etc.

Alternatives considered πŸ€”

  • Not implement the feature at all. It will probably add considerable complexity while not being a very common use case.
  • Extend existing or create new hooks to allow implementing this in userland
  • Just canceling the underlying fetch request is probably not enough as it won't fire end or abort hooks

How important is this feature to you? 🧭

Nice to have

Notes

  • I think we're getting into state machine territory here
  • From a cursory look over how the plugins determine the start and end of a visit, how the swup.navigating is set/unset, how thrown errors return early without 'finishing' a visit, this seems rather complex
  • Started a draft PR to explore the complexity and scope of this

Closing as not planned.