Bug 93506 - History state is incorrect attached to new document when loaded via location.assign or location.replace
Summary: History state is incorrect attached to new document when loaded via location....
Status: RESOLVED DUPLICATE of bug 80697
Alias: None
Product: WebKit
Classification: Unclassified
Component: History (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-08 12:38 PDT by Joshua Peek
Modified: 2014-02-19 07:48 PST (History)
5 users (show)

See Also:


Attachments
Layout test cases (2.66 KB, patch)
2012-08-08 12:38 PDT, Joshua Peek
no flags Details | Formatted Diff | Diff
empty-document-goes-back.html (125 bytes, text/html)
2012-08-22 11:13 PDT, Adam Roben (:aroben)
no flags Details
assign-after-pushstate.html (710 bytes, text/html)
2012-08-22 11:14 PDT, Adam Roben (:aroben)
no flags Details
test.html (561 bytes, text/html)
2012-08-22 11:20 PDT, Adam Roben (:aroben)
no flags Details
cute puppy image (61 bytes, text/plain)
2012-08-22 11:22 PDT, Adam Roben (:aroben)
no flags Details
cute puppy image (23.78 KB, image/jpeg)
2012-08-22 11:23 PDT, Adam Roben (:aroben)
no flags Details
test.html (571 bytes, text/html)
2012-08-22 11:24 PDT, Adam Roben (:aroben)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joshua Peek 2012-08-08 12:38:12 PDT
Created attachment 157271 [details]
Layout test cases

To reproduce, load an initial document, then call history.pushState({foo:true}, "", url) to set a new url. Calling location.assign or location.replace with the new current url will correctly reload a new document. But the history state associated with the document is incorrect. `event.state` will be `{foo:true}` instead of `null` and pushing the back button will cause a pop state event instead of loading the previous document.

    # URL: /
    history.pushState({foo:true}, "", "/other.html")
    location.assign("/other.html")

    # URL: /other.html
    event.state # => {foo:true} should be null
    history.back() # => causes popstate instead of loading "/"
Comment 1 Balaji N.V. 2012-08-16 23:09:57 PDT
Are you accessing the event.state in the popstate event handler? I am trying to access event.state from postate event handler, and the problem is not reproducible. Is it possible to attach another test case which can be used as it is.

Thanks
Comment 2 Joshua Peek 2012-08-17 08:20:34 PDT
There shouldn't be a popstate event on the second page. It should be a hard load back to the previous page. Thats the bug. Can you view the automated case I posted? It passes in Firefox.

(In reply to comment #1)
> Are you accessing the event.state in the popstate event handler? I am trying to access event.state from postate event handler, and the problem is not reproducible. Is it possible to attach another test case which can be used as it is.
> 
> Thanks
Comment 3 Brady Eidson 2012-08-17 09:30:30 PDT
(In reply to comment #2)
> There shouldn't be a popstate event on the second page. It should be a hard load back to the previous page. 

This is inaccurate and is expected behavior.

There is always a popstate event.

Checkout "5.9.3 Activating state object entries" of HTML5.  Or for much more colloquial conversation about it check out the mozilla dev network's explanation - https://developer.mozilla.org/en-US/docs/DOM/window.onpopstate

How does your test case behave in Firefox?
Comment 4 Brady Eidson 2012-08-17 09:31:08 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > There shouldn't be a popstate event on the second page. It should be a hard load back to the previous page. 
> 
> This is inaccurate and is expected behavior.
> 
> There is always a popstate event.

To clarify - there is always a popstate event *when traversing the session history*.  There should not be one on new page loads.
Comment 5 Joshua Peek 2012-08-17 09:47:14 PDT
Sorry, its really not about the popstate event itself then.

Whats the technical language for when the Back button actually loads a new document vs only firing a popstate event?

The bug is anytime you do history.pushState({}, "", "/newurl"), then attempt to renavigate to the same url again. The back button gets into a strange state.

I guess, my exception is that anytime you reload a document, it should have its own session history.
Comment 6 Brady Eidson 2012-08-17 09:54:00 PDT
(In reply to comment #5)
> Sorry, its really not about the popstate event itself then.
> 
> Whats the technical language for when the Back button actually loads a new document vs only firing a popstate event?

Pressing the back button is "traversing the session history."

And whether or not that means moving to the previous fragment scroll for the current document, *only* popping a previously pushed state, or navigating to a completely different document... there is always a popstate event.

> I guess, my exception is that anytime you reload a document, it should have its own session history.

This is false.  Reloading the current document replaces the current item in the session history, but doesn't affect anything else.

I ask again - What happens in other browsers?
Comment 7 Brady Eidson 2012-08-17 10:06:35 PDT
I'm sorry, I just noticed that you already commented it passes in Firefox.  It was at the end of a long line that scrolled off my screen  :)
Comment 8 Joshua Peek 2012-08-20 12:55:15 PDT
Sorry, I still think I'm not getting the terminology quite right. I made a quick video to help demonstrate. And it actually doesn't seem to be limited to `location.assign` or `location.replace`. It happens anytime you navigate to the url, even with a click.

Video: http://cl.ly/3P0V2o3W2g0t
Source: https://gist.github.com/3407127
Comment 9 Adam Roben (:aroben) 2012-08-22 11:13:01 PDT
Created attachment 159969 [details]
empty-document-goes-back.html
Comment 10 Adam Roben (:aroben) 2012-08-22 11:14:06 PDT
Created attachment 159970 [details]
assign-after-pushstate.html
Comment 11 Adam Roben (:aroben) 2012-08-22 11:20:39 PDT
Created attachment 159971 [details]
test.html
Comment 12 Adam Roben (:aroben) 2012-08-22 11:22:25 PDT
Created attachment 159973 [details]
cute puppy image
Comment 13 Adam Roben (:aroben) 2012-08-22 11:23:47 PDT
Created attachment 159975 [details]
cute puppy image
Comment 14 Adam Roben (:aroben) 2012-08-22 11:24:33 PDT
Created attachment 159976 [details]
test.html
Comment 15 Adam Roben (:aroben) 2012-08-22 11:25:32 PDT
Comment on attachment 159976 [details]
test.html

I think this live test can be used to reproduce the behavior seen in Josh's video.
Comment 16 Adam Roben (:aroben) 2012-08-22 12:10:30 PDT
Here's the bug as I see it based on test.html:

1. Click "Run JS"
2. Click either of the two links on the page
3. Click Back

The URL changes back to the test page, but instead of showing the test page again you just continue to see the puppy picture.

If you perform the same steps in Firefox, you end up back on the test page.

Brady, which behavior seems correct to you? Firefox's makes more sense to me, but I'm no expert in this pushState stuff.
Comment 17 Sean Hogan 2012-08-29 21:03:36 PDT
FYI this is a duplicate of Bug 80697.

    https://bugs.webkit.org/show_bug.cgi?id=80697
Comment 18 Adam Roben (:aroben) 2014-02-19 07:48:26 PST
Agreed.

*** This bug has been marked as a duplicate of bug 80697 ***