-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use raw attribute href on hx-boost #1742
Conversation
This resolves a bug when file system URLs are used on Windows. It reverts part of a previous change where URLs were normalized prior to the request in order to reduce key collisions in the history cache. Because htmx's history cache is based entirely on response URLs, not request URLs, I am reasonably confident that reverting this line doesn't affect that optimization at all, but in any case it causes a bug which is more important.
Oh okay, I know what's going on here, it's about the mocks. We normalize the URL before the mock server gets to it. They do in fact normalize the same way. Got it, got it. I updated the description.
🤷 The tests should be runnable from a file! I take your point that we should probably also set up some tests that test from a server, but it's a good thing that the tests should work in as many environments as possible. If anything it's a bug with the tests themselves, but if you look at this commit in isolation: that line of code introduces unnecessary surface area for inconsistencies; I know why this fence was erected and would like to tear it down. |
I'm ok with the change, I mean as long as it works, I'm totally fine with it I agree with your argument that if the browser already handles it, we shouldn't add a useless instruction Now, considering all is good and tests work, conceptually I would still advocate for running the tests in a http served environment rather than a file environment But again, that's just a side conceptual debate here ; I'm not saying this PR should not be merged, I'm all ok with it. Again, as long as it works, it's perfectly fine for me |
For sure, I'm actually going to look into multi-platform tests after this. |
If we don't retrieve the fully resolved url of a relative href then it's possible to cache two pages that share the same url slug with the same key, which can lead to the wrong page being retrieved from the cache on history restore. For example:
That was the reasoning behind that part of my original PR. |
Right—do you have any evidence that needs to be done in the the request? Because that's the only part of your chance that this reverts. I fully understand why we're normalizing the URL before manually saving to the history API, but all of that logic happens in the response. I don't think this line in the request does anything useful. (it might be nice to have a test case for this, the history API logic is not straightforward) |
I tested my scenario with your change (on modern browsers) and I can't reproduce the key collision, so I think this is good to go.
Just to be clear, the history cache in localStorage is saved in a subsequent request + response cycle, when the user navigates away from the current page, NOT as part of the response to the click on the original boosted link. |
Thank you very much @croxton! If you're able to share your testing steps I'd be curious to see them.
I'm talking about this part, which happens in Lines 3294 to 3307 in 05d53f4
|
Just some simple manual tests - I created some html pages as per my scenario and used boosted links with hrefs containing relative links, browsed around a bit, then examined the cache entries that get created in the localStorage history cache.
I've been testing for key collisions in the localStorage cache. |
Description
This resolves a bug with file system URLs on Windows. It reverts part of a previous change (#1338) where URLs were normalized prior to the request in order to reduce key collisions in the history cache.
The gist is that on Windows,
elt.href
normalizes relative URLs like this:Why does
elt.href
normalize relative URLs on Windows file systems differently from how anchor elements normalize URLs? It doesn't. It normalizes the URL into something that is wrong (on Windows) before themockServer()
function can get to it. It turns this:into this:
Which, while usually the same thing, is still an additional normalization that we perform with JavaScript which deviates from the browser's request normalization, and I can't see any justification for keeping it. Because htmx's history cache is based entirely on response URLs, not request URLs, I am reasonably confident that reverting this line doesn't affect the optimization from #1338 at all.
And, conceptually, it makes a lot more sense that we would just pass the raw attribute value to the browser's request engine and let it do whatever normalizing it does there—which is less likely to deviate from regular
<a href="">
behavior. Doing it twice introduces the possibility of error without any clear benefit.@Telroshan and I discovered this bug as part of #1732.
He doesn't totally agree with me that this change is necessary so if you want a competing view go read that thread.See below for some of that discussion, but we agree now.Testing
Passes locally and on the CI. I also ran a Windows Server GitHub runner and while that was not very reliable at running our tests, it didn't have the same issue anymore at least.
This change should make it possible for Windows users to run our headless test suite with no errors using
npm t
.@Telroshan tested on windows and this fixes the tests so he can proceed with #1687