[4.0.0-beta6] hx-preload fails to reuse cached GET when hx-get uses relative URLs
Bug report
Using htmx 4.0.0-beta6 with the hx-preload extension.
When preloading a link with a relative hx-get URL, the preload request is made successfully, but the cached response is not reused on click.
Example:
<a
hx-get="https://domain.com/some/url"
hx-preload="mouseover timeout:10s">
Some link
</a>
Steps to reproduce: Hover the link. Wait for the preload request to complete. Click the link.
Expected: The click should reuse the preloaded response.
Actual: A second GET request is sent.
Debugging showed:
cached action : https://domain.com/some/url
current action: /some/url
The comparison in hx-preload.js:
elt._htmx.preload.action === ctx.request.action
This fails because the URLs are semantically identical but different strings.
A possible fix (tested locally):
elt._htmx.preload.action === new URL(ctx.request.action, location.href).href
This normalizes the URL before comparison.
Environment:
htmx: 4.0.0-beta6 hx-preload: 4.0.0-beta6 Browser: Chrome/Firefox
Thanks for finding this. I've pushed up a fix that reuses the core htmx logic to calculate the action url to compare with which seems to be a more reliable fix from my testing. Would be good if you can test yourself with the four-dev branch src/htmx.js version to confirm it fixes your issue.