This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28553 - Allow disabling of default scroll restoration behavior on history navigation
Summary: Allow disabling of default scroll restoration behavior on history navigation
Status: RESOLVED MOVED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P2 normal
Target Milestone: Needs Impl Interest
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-23 21:45 UTC by Majid Valipour
Modified: 2015-11-16 11:29 UTC (History)
3 users (show)

See Also:


Attachments

Description Majid Valipour 2015-04-23 21:45:33 UTC
Problem:
All major 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
application wants to control the details of visual transition between UI states.
Currently it is not possible to disable the scroll behavior so web
developers have resorted to various hacks.

Full discussion on mailing list: https://lists.w3.org/Archives/Public/public-whatwg-archive/2015Mar/0070.html


Proposed solution:
We should allow web applications to explicitly disable user agents default scroll restoration behavior via History API.  Here are the proposed changes to achieve this:

- Add a fourth optional parameter 'options' to both history.pushState, and history.replaceState. Options default values is backward compatible.
- Add a new attribute history.options that exposes the current
effective value of this new property. This is also used to provide a simple feature detection mechanism to check that the user-agent supports this new optional property.


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 willRestoreScroll = false
}
Comment 1 Majid Valipour 2015-04-23 21:53:46 UTC
Here is Blink intent-to-implement: https://groups.google.com/a/chromium.org/d/msg/blink-dev/U1e2lmGs4tM/9_70ojL8TiIJ

Here is Chromium bug that tracks the implementation of this for chromium:
https://code.google.com/p/chromium/issues/detail?id=477353

Note that Chromium bug describes a slightly different API which has been proposed on WhatWG mailing list. This is not an issue and we will implement the API that is accepted by specification.
Comment 2 Rick Byers 2015-04-24 00:22:08 UTC
Mozilla bug for addressing this issue somehow: https://bugzilla.mozilla.org/show_bug.cgi?id=679458
Comment 3 Majid Valipour 2015-08-04 15:30:48 UTC
After several rounds of feedback from WHATWG we have update the API to use a single attribute on history object. This API is supported by Mozilla.

Here is the unofficial spec which list changes to the HTML spec:
http://majido.github.io/scroll-restoration-proposal/history-based-api.html

Here is a set of web platform tests that verify this new attribute:
http://majido.github.io/scroll-restoration-proposal/tests/

Web IDL for the new API:

enum ScrollRestoration {
    "auto",
    "manual"
};

partial interface History {
    attribute ScrollRestoration scrollRestoration;
};
Comment 4 Majid Valipour 2015-10-22 18:13:32 UTC
This API is shipping in latest chrome stable.
https://www.chromestatus.com/features/5657284784947200
Comment 5 Simon Pieters 2015-11-16 11:29:52 UTC
https://github.com/whatwg/html/pull/278