balupton/history.js — Issue #131: State does not get pushed if only the URL changes to an empty string
Author: dobesv
Created: 2011-11-24 11:15:02+00:00
State: open

If you do, for example:

pushState({}, 'title', '?foo=bar');
pushState({}, 'title', '');

The second call to pushState is ignored because in History.normalizeState() it does this:

newState.url = History.getFullUrl(oldState.url?decodeURIComponent(oldState.url):(document.URL||document.location.href));

The assumption here seems to be that oldState.url being false-like means the caller didn't want to change URLs (?)

In any case, I think the test needs to be smarter somehow, perhaps (oldState.url || oldState.url === '') to allow an empty string to be considered a specified URL whereas other false-like values like null, undefined, and false would be treated as a missing value.

As a workaround, I've changed my call to pushState to pass "url || '/'" which also solves the problem for me. However, this was a hard-to-find bug for me so I'd recommend fixing it for the benefit of those who come after.