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
487 stars 26 forks source link

Allow scroll to be restored multiple times #240

Closed jakearchibald closed 2 years ago

jakearchibald commented 2 years ago

Let's say I have a navigation that as-soon-as-possible loads a page skeleton, then loads the data afterwards.

Push/replace load

  1. Load skeleton content.
  2. Scroll to target element, or 0,0.
  3. Load real content.
  4. If there's a target element, and there wasn't one before: scroll to it.
  5. If there's a target element, and there was one before, but it's in a significantly different position to before: scroll to it.

Traversal

  1. Load skeleton content.
  2. Restore scroll.
  3. Load real content.
  4. If reapplying scroll restoration would result in a significantly different position: do it.

The reason you'd restore twice is if the intent was to restore to y=2000, but the page skeleton wasn't tall enough to accommodate that.

This is pretty hard to do in the current API.

Could this be achieved by allowing the developer to call scroll.restore() multiple times, and call it even when the scroll mode is "after-transition"?

Alternatively, there could be a scroll restoration mode of "throughout-transition", which attempts to do this automatically, reacting to DOM changes during the transition, as well as afterwards.

I'm not confident in my "significantly different position" heuristic. I'm thinking of what the browser does during a streaming page load.

jakearchibald commented 2 years ago

Doh, I just read that scroll restoration is already continual.