Discovery of the day: Edge always fires a popstate event when the URL hash is updated, even though it is updated to the same string as before. Chrome, on the other hand, only fires popstate if the updated hash is different the second time.

So for example, if I click on a link with href=#foo twice, Edge will fire two popstate events, where Chrome will fire only one. In the examples below , I used location.hash, but I have verified that the link clicking works the same way.

Popstate behavior on Edge 14. popstate fired twice.: Popstate behavior on Edge 14

Popstate behavior on Chrome 56 popstate fired once: Popstate behavior on Chrome v56

Then there’s Edge 13 that doesn’t fire popstate at all (ohgodwhy): Popstate behavior on Edge 13 This is a known bug and claimed to have been fixed, I assume in later versions of Edge.

This is particularly frustrating when you are using popstate events as a trigger for things like showing and hiding modals. Or if you’re using them to trigger a load of sorts.

I am not sure what the specs of this are, but if we consider each state that a homepage can be in tied to a unique URL, it makes sense to not have to fire a state change when the hash value remains the same. Then again, apparently browsers are known to handle the popstate event differently.

Popstate specs for the curious who might be up to the task of finding out the correct behavior: link.

This was giving me a pretty nasty bug that took awhile to figure out. So hopefully this helps someone out there.