Proposal for customizing scroll restoration

6 views
Skip to first unread message

Majid Valipour

unread,
Mar 18, 2015, 12:13:04 PM3/18/15
to input-dev, aero...@chromium.org, Nate Chapin, Ryoji Watanabe, Dima Voytenko, Rick Byers
The ability to opt out of the default scroll restoration behavior has been a requested features from external web developers and internal teams (G+ Tau, and GWS UI ) developers.

I have put together a proposal to achieve this through an backward compatible addition to History API. This was informed by an initial naive implementationI like to get your feedback on this before starting the discussion on whatwg mailing list for its potential adoption into the spec.

Ryoji, Dima: Please let me know if this is enough to address your particular requirements.


Thanks
Majid

Dima Voytenko

unread,
Mar 18, 2015, 12:49:16 PM3/18/15
to Majid Valipour, input-dev, aero...@chromium.org, Nate Chapin, Ryoji Watanabe, Rick Byers
Majid,

The idea of disabling scroll restoration makes sense to me if manual control of transition desired. This is the case for us so, I'd definitely like to see something like this soon. I can start by switching G+ to natural BODY scroll under experiment and we can use it as a guide of what we need to anticipate for this use case.

-d

Majid Valipour

unread,
Mar 20, 2015, 11:02:52 AM3/20/15
to Dima Voytenko, Majid Valipour, input-dev, aero...@chromium.org, Nate Chapin, Ryoji Watanabe, Rick Byers
Dima,

Thanks for your feedbacks. I will let you know as soon as we have an implementation that you can experiment with. Once I get feedback from whatwg it shouldn't take too long to implement.

Majid

Dima Voytenko

unread,
Mar 20, 2015, 11:06:30 AM3/20/15
to Majid Valipour, Ryoji Watanabe, aero...@chromium.org, input-dev, Majid Valipour, Rick Byers, Nate Chapin, Malte Ubl

+Malte FYI

Thanks Majid! Looking forward!

Majid Valipour

unread,
May 19, 2015, 3:25:18 PM5/19/15
to Dima Voytenko, Ryoji Watanabe, aero...@chromium.org, input-dev, Majid Valipour, Rick Byers, Nate Chapin, Malte Ubl
Dima,

This is now in M44 as an experimental feature behind this flag:  #enable-experimental-web-platform-features

Here is a simple example of how it can be used: 
// disable scroll restoration for current page state
if ('options' in history) {
var options = {scrollRestoration: 'manual'}; // default is 'auto' 
history.replaceState(history.state, '', location.toString(), options); // works on pushState too.
}

It is also fairly easy to create a global flag that controls scroll restoration using this API. 


Majid

Dima Voytenko

unread,
May 19, 2015, 4:57:33 PM5/19/15
to Majid Valipour, Ryoji Watanabe, aero...@chromium.org, input-dev, Majid Valipour, Rick Byers, Nate Chapin, Malte Ubl
Great! To confirm. I will just set window.history.scrollRestoration to 'manual' and we are all good. Right?

Majid Valipour

unread,
May 19, 2015, 5:21:05 PM5/19/15
to Dima Voytenko, Ryoji Watanabe, aero...@chromium.org, input-dev, Majid Valipour, Rick Byers, Nate Chapin, Malte Ubl
The API requires you to pass {scrollRestoration: 'manual'} to either history.pushState or history.replaceState as their fourth optional parameter. The scroll restoration option is tied to individual history entries as opposed to being a global flag.

If you want to use a simple global flag then you can perhaps use this script which poly-fills the global control flag using the per-entry API.

The API is not set into stones yet. In fact there is some discussion on the standards group in having a global flag instead of a per-entry control. Your feedback as a web-developer will be very valuable here. (I have argued for per-entry API as it better reflect the underlying behaviour and it is easier to reason about when one wants a different restoration behaviour for different UI states.)


Majid

Dima Voytenko

unread,
May 19, 2015, 5:55:12 PM5/19/15
to Majid Valipour, Ryoji Watanabe, aero...@chromium.org, input-dev, Majid Valipour, Rick Byers, Nate Chapin, Malte Ubl
Got it. THanks!
Reply all
Reply to author
Forward
0 new messages