Bug 80697 - Broken behavior for back-button after history.pushState() + location.replace()
Summary: Broken behavior for back-button after history.pushState() + location.replace()
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Major
Assignee: Nobody
URL:
Keywords:
: 93506 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-03-09 04:37 PST by Sean Hogan
Modified: 2015-02-25 19:03 PST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sean Hogan 2012-03-09 04:37:02 PST
To reproduce:

1. Navigate to http://www.webkit.org/
2. Open the Javascript console and enter the following

    history.pushState({}, null, "/blog/");

The address-bar now says http://www.webkit.org/blog/, but the page hasn't changed (expected behavior).

3. Now enter the following

    location.replace("/blog/");

The address-bar now says http://www.webkit.org/blog/, and the page reflects this.

4. Press the back-button. The address-bar now says http://www.webkit.org/, but the page hasn't changed from the "/blog/" contents.

This behavior is also observed in up-to-date Chrome.
Comment 1 Sean Hogan 2012-03-10 02:38:25 PST
The same broken behavior is also exhibited if step 3 is:

    location.reload()
Comment 2 Sean Hogan 2012-04-20 23:04:09 PDT
A work-around for this issue is to replace step #3 with:

    history.replaceState({}, null, currentURL);
    location.replace(nextURL);

where 
    currentURL = "http://www.webkit.org/" or "/" 
    nextURL = "/blog/"

for the demo given above. 

This work-around can cause a flash of the currentURL in the address bar, and it seems bizarre that this should work while the straight-forward code path fails.
Comment 3 Sean Hogan 2012-04-22 05:26:09 PDT
An almost satisfactory work-around for this issue is to replace step #3 with:

    history.replaceState({}, null, "#");
    location.replace("");

I guess this indicates that identified bug is only an issue when `location.replace(url)` is the precise equivalent of `location.reload()` (and there has been a previous invocation of `history.pushState`.)
Comment 4 Adam Roben (:aroben) 2014-02-19 07:48:26 PST
*** Bug 93506 has been marked as a duplicate of this bug. ***
Comment 5 Adam Roben (:aroben) 2014-02-19 07:49:57 PST
See https://bugs.webkit.org/show_bug.cgi?id=93506 for a live test case.

AFAICT this behavior disagrees with the spec and with Firefox.