Keep the loading state when the response is a HX-Redirect
Description
When we do a HX request and the response is a redirect the loading state should be kept - if it doesn't the application will "flick" before loading the new page.
Corresponding issue: #2146
Testing
Have a simple form that submits to an endpoint that responds with a HX-Redirect header - the loading state should be kept until the redirect is successfully done:
<form hx-post="/test">
<button type="submit" data-loading-disable>
Submit!
</button>
</form>
Checklist
- [X] I have read the contribution guidelines
- [X] I have targeted this PR against the correct branch (
masterfor website changes,devfor source changes) - [X] This is either a bugfix, a documentation update, or a new feature that has been explicitly approved via an issue
- [X] I ran the test suite locally (
npm run test) and verified that it succeeded
@alexpetros thanks for the help in the other PR. I have adapted it to htmx v2 branch. please let me know if there is anything I could improve
Just a heads up - I haven't looked further into it however did see this popup while using this change locally with v1.9.10: Refused to get unsafe header "HX-Redirect"
Maybe just add as a note to test/check (ref #173).
@Telroshan @alexpetros any feedback on this?
I personally did the same thing on my fork as I prefer the visual experience of keeping the loading state active, to avoid that very flick you mentioned. I can only speak for myself here though! @alexpetros @1cg thoughts on this ? Also with the latest changes, you'd have to resolve conflicts!
Only the feedback I offered on the last PR which was that we like the idea, but please don't PR against this branch right now because the branch is unstable. I'm going to close this PR on account of that, but please feel free to ping me and I'll reopen it when htmx 2 launches (probably < 2 months)