-
-
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
HX-Request and HX-Current-URL headers are missing in the request to restore from history #2013
HX-Request and HX-Current-URL headers are missing in the request to restore from history #2013
Conversation
…estore from history
e6c4240
to
b76c981
Compare
Looks great, thanks @xhaggi |
@xhaggi what do you think the value of |
The same as for normal htmx requests |
Adding It is now necessary to check The effect of this change is erratic behavior when local storage history is deleted or |
The documentation also does not say that it will not be present for history restore requests, so that was always a questionable basis for building that behavior. We're happy to work with django-htmx to help them update the package though.
To be clear, is the effect of the broken django-htmx integration, or something about htmx itself? |
Django-htmx is practically just a super thin middleware that makes accessing htmx related headers a bit easier. So the issue he explains is that it's not enough to check for HX-Request, you also need to check for HX-History-Restore-Request on every request. I've personally tried to replicate the issue in multiple ways without any success. Feel free to skim through the issue, it's not really django-htmx specific. |
Why are you relying on this header to detect a partial or full page load? IMO the header indicates that it is just a request from htmx, nothing else. |
Yes I agree, but there should be a canonical way how backend should distinguish full/partial page request on the same URL.
I have only seen examples of backend integrations that use |
I take advantage of pushing URLs to history (mainly |
I've reviewed the sample project provided by @brablc It's related to attributes that push history, like hx-boost, hx-push-url in combination with hx-history false Take this simple code as an example: <div id="gl"></div>
<button
hx-get="{{ request.path }}" hx-target="#gl" hx-push-url="true" hx-history="false">test</button> If you load your page and press this button and try to go back, it will issue a htmx request, so checking for hx-request header will simply not be enough. |
Can someone explain why the history restore request also needs the |
Description
The request to restore a page from history is missing the
HX-Request
andHX-Current-URL
request headers. The request headers documentation for HX-Request states that theHX-Request
header is always present and has the value "true". Some third-party libraries such as htmx-spring-boot actually rely on this.Testing
Added unit tests.
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded