# Problem
Almost all browsers restore scroll position when a user traverses history.
This behavior works well for document style web sites but it is often not
appropriate for single-page web applications where the page content may be
reconstructed (often asynchronously) upon navigation and where the
wants to control the details of visual transition between UI states.

Currently it is not possible to disable the scroll behavior so web
have resorted to various hacks [1]. Here are the two most popular:
- Avoid document scrolling altogether by fixing body size and putting
  in an inner scrollable div. This breaks browser features that depend on
  document scrolling such as top controls hiding, or overscroll visuals and
  some cases disables fast scroll optimizations for document scrolling.
- Use a secondary scroll after browser's initial attempts to restore scroll.
  This leads to two visible jumps and bad UX.

Few documented cases of web developers struggling with this problem may be
found in [2, 3, 4].

# Proposal
Allow web applications to explicitly disable user agents default scroll
restoration behavior via History API. This is achieved by adding a fourth
optional parameter 'options' to both history.pushState,
Obviously the default values will be backward compatible. We should also
provide a new attribute (history.options)  that exposes the current
value of this new property and use it to provide a simple feature detection.

Below is the IDL for the proposed changes:

partial interface History {
  void pushState(in any data, in DOMString title, in optional DOMString
url, in optional StateOptions options);
  void replaceState(in any data, in DOMString title, in optional DOMString
url, in optional StateOptions options);
  readonly attribute StateOptions options;

dictionary StateOptions {
Boolean restoreScroll = true,

Here is a more complete version of this proposal with details around
background, current proposal design, and considered alternative designs:

We like to implement this or something similar in blink and would be
interested to hear from other vendors. All feedback on proposed design is
welcome. :)

Majid Valipour

[2] https://bugzilla.mozilla.org/show_bug.cgi?id=679458
[3] https://github.com/rackt/react-router/issues/707
[4] http://andrz.me/blog/scrollx-scroll-why-history

Reply via email to