WICG / navigation-api

The new navigation API provides a new interface for navigations and session history, with a focus on single-page application navigations.
https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigation-api
484 stars 30 forks source link

Revamp intercepted-navigation scroll handling #239

Closed domenic closed 2 years ago

domenic commented 2 years ago

This changes the default behavior of intercepted navigations with respect to scrolling in the following ways:

This change requires some updated API surface: the scrollRestoration option to intercept() has become scroll, and the navigateEvent.restoreScroll() method has become navigateEvent.scroll(). The latter method now has more capabilities, working to give browser-default-like behavior for "push", "replace", and "reload" in addition to "traverse".

Similar to before, all of this can be opted out of by using scroll: "manual".

Closes #237 by giving an easy default behavior for SPA navigations with hashes.

Closes #231 by making "push", "replace", and "reload" behave by default in an MPA-like manner with respect to scroll position, just like "traverse" does.


Preview | Diff

domenic commented 2 years ago

could I interest you in a { scroll: 'auto' } default, that acts like after-transition, unless navigateEvent.scroll() is called before the intercept promise settles?

Hmm, I wonder if we should just make that the behavior of "after-transition"...

jakearchibald commented 2 years ago

Yeah, that makes sense