htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Keep the loading state when the response is a HX-Redirect

Open nykolaslima opened this issue 2 years ago • 5 comments

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 (master for website changes, dev for 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

nykolaslima avatar Jan 07 '24 15:01 nykolaslima

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?

nykolaslima avatar Jan 07 '24 17:01 nykolaslima

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

Telroshan avatar Jan 07 '24 19:01 Telroshan

it worked with node 15. thanks @Telroshan

now the test is passing :)

nykolaslima avatar Jan 08 '24 02:01 nykolaslima

Just pushed another fix to the tests. We should avoid real redirects to do not break the test suite.

nykolaslima avatar Jan 09 '24 00:01 nykolaslima

@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!

nykolaslima avatar Jan 19 '24 02:01 nykolaslima

hi @Telroshan @alexpetros , could you give me any feedbacks here?

nykolaslima avatar Jan 27 '24 16:01 nykolaslima

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.

alexpetros avatar Jan 27 '24 20:01 alexpetros

thanks for the response @alexpetros

will adapt it to 2.0 and open another PR. thanks!

nykolaslima avatar Jan 28 '24 22:01 nykolaslima

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.

alexpetros avatar Jan 29 '24 00:01 alexpetros