Hi!
I am trying to use the master branch in one of our development. I find this library really good looking.
I noticed a few issues during my experiment. I am not sure if these are really bugs though, I am not seeing the code in its total depth yet. So, maybe, I misunderstand things. But, I like to write my observations here.
First of all, I started to write the demo application with the assumption that the statechange event is supposed to trigger on the initial page load as well. (By initial page load I mean what happens when an url representing a given state is force-reloaded in the browser, or such an url is visited as a link from another page, ie, when a page is loaded first, or reloaded completely.)
I think that this is true, the statechange should trigger on the initial page load, and this is a Good Thing. However, during my experimentation I had to realize that this does not happen so in all the browsers which is a pita. I tried to understand things better, and discovered a few issues.
1). On Safari, there is a problem (Safari 5 on MaxOSX). The event is not triggered on the page load. After research, it seems that this is not a problem of History.js, but rather a bug in Safari itself. (Have not tested yet if other WebKit browsers, such as Chrome, are also affected or not.)
I worked this around in our demo by triggering the missing statechange on the domload, on Safari. However, such a problem defies the real beauty of statechange. As an application developer, I would like to use statechange to set a given state in my widget, independently if this happens on the initial page load, or later during popping a given state in the history. I would not need or want to take care of the initial state, I'd rather just implement a single handler. In addition, it is very difficult for an application or widget to find out if the initial event has happened at all or not.
So, for this reason, I believe it would be nice to "fix" this problem of Safari with the initial popstate event from History.js. Then, statechange could work as expected on all HTML5 browsers, in the same way.
2). Without more explanation at this point, I need to mention that I also have problems with the page load on HTML4 browsers, I tested on IE8 only. It seems that in order to make history work correctly on IE, on the initial page load as well, I need to implement both the statechange and the anchorchange handlers. It would be nice not to need this. I still need further experimentation and a deeper understanding on this issue.
3). On HTML4 browsers, it seems that the current code does not create the hash fragments as shown in the documentation. They should be something like this:
www.mysite.com#?state=3/uid=3
- but the hash part gets url encoded (not sure if a problem really, but is this really necessary?) so you end up with this ugliness: ...#/this/path%3Fstate%3D3/uid%3D3
- and, the url path gets repeated after the hashmark. ie: you get
www.mysite.com/this/path#/this/path%3Fstate%3D3/uid%3D3
... notice how the /this/path is repeated after the #, again, is this really desired, and, needed?
So, I am not saying this is a problem for sure, just pointing out the inconsistency with what you write (imo, correctly) in the documentation page.
4). Finally, a definite bug: line 1121 in History.js is
History.Adapter.trigger('anchorchange');
where, it should be:
History.Adapter.trigger(window, 'anchorchange');
which results in this event not triggered at all.
To close it, thanks a lot in advance if you can take some time in enlightening me about what I think right or what I think wrong in my above observations. I am also willing to contribute to the code and/or tests as needed.
Best wishes,
Balazs Ree