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
I am having trouble to run the tests locally.
when running npm run test I get an error:
Promise Rejection: Error: connect ECONNREFUSED ::1:65459
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 65459
}
Error: connect ECONNREFUSED ::1:65459
any suggestion on how to fix it?
I think I was getting that error when I was using Node 20 The test suite currently requires node 15.x because of the used packages and IE11 compatibility to run tests So make sure you have node 15.x installed!
Note this will be behind us when htmx 2 happens as the pipeline will use node 20.x
it worked with node 15. thanks @Telroshan
now the test is passing :)
Just pushed another fix to the tests. We should avoid real redirects to do not break the test suite.
@1cg hi, I know you have been really busy with the new release, but if you have sometime could you please help with a review here or refer me someone who could?
thanks!
hi @Telroshan @alexpetros , could you give me any feedbacks here?
Hey @nykolaslima, looking at the issue it seems like @1cg responded already: he said that we probably aren't able to merge this into 1.0, but to make an extension in the meantime and then we'll consider it for 2.0. I think the change is reasonable, but we're not doing any more 1.x releases.
I'm going to close PR for now since we're freezing the codebase until the release. If you want to take a look at the alpha version of 2.0 and see how this change might fit in there, you're more than welcome to.
thanks for the response @alexpetros
will adapt it to 2.0 and open another PR. thanks!
No, please don't open another PR right now. The branch is unstable and we're not going to consider feature requests for it until after it lands.