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 1 year ago • 3 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 28 '24 22:01 nykolaslima

@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

nykolaslima avatar Jan 28 '24 22:01 nykolaslima

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).

mrinc avatar Feb 01 '24 16:02 mrinc

@Telroshan @alexpetros any feedback on this?

nykolaslima avatar Feb 10 '24 12:02 nykolaslima

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!

Telroshan avatar Feb 25 '24 20:02 Telroshan

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)

alexpetros avatar Feb 25 '24 22:02 alexpetros