I came up with a few ways to fix the problem (#110), but I think this one is the best because it takes care of two issues.
Unless I'm missing something, the purpose of the reflectRedirectedUrl function is to update the newly pushed (from reflectNewUrl) history state in the event the ajax request is redirected. However, right now it's doing it whether there was a redirect or not, which most of the time will be unnecessary. The lost anchors are a side effect of this, since it replaces the current state with the X-XHR-Current-Location value from the server (which omits anchors). As far as I can tell, my solution preserves the anchors while eliminating unnecessary replaceState calls.
You can swap conditions and remove brackets:
unless document.location.pathname + document.location.search is location = xhr.getResponseHeader 'X-XHR-Current-Location'
But in my opinion original location = xhr.getResponseHeader('X-XHR-Current-Location') is more much readable 😄.
location = xhr.getResponseHeader('X-XHR-Current-Location')
It's just personal preference. I like the way I did it, but I'd have no issue with changing it. I'll leave it up to @dhh to decide how he wants it before adding another commit.
I see. Also since Turbolinks is completly bracketless it's pointless to try add brackets to improve readability. I'm just point you to opportunity remove two more brackets 😸.