Skip to content

Conversation

MichaelWest22
Copy link
Collaborator

@MichaelWest22 MichaelWest22 commented Aug 4, 2025

Description

Currently the ajax api can not perform hx-push-url style history url updates easily as the only way to do it is by creating a dummy element with hx-push-url attribute and then using this as the source element of the ajax api request. Just adding a push option to the context you can pass in solves this by allowing this variable to be used to pass in the url to push or true. Also hx-location can make use of this same option to allow it pass an optional push value or 'false' if required and it default to 'true' which avoids manual history handling code in hx-location.

There is a minor bug that if you use a hx-location to redirect to a page the return hx-push-url the old way of manually updating history after hx-location finishes overwrites the hx-push-url request in the response leading to wierd history state. see #3115. By moving the push url option into hx-location but allowing it to be updated in the response resolves this issue

Also added a replace option As I found in #3114 that they wanted to also do replace sometimes and this is easy to add as well. Also found the determineHistoryUpdates function I had to update was confusing and repeated a lot of logic so re-wrote this function as well to make it simpler and easier to debug and understand.

Corresponding issue:
#3115
#2744
#2456
#2706

Testing

Added tests for the ajax api and hx-location to test out all the new options available.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@MichaelWest22 MichaelWest22 added the ready for review Issues that are ready to be considered for merging label Aug 8, 2025
@wooooodward
Copy link

@1cg just wondering if this can be merged - this will fix an issue I've had for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Issues that are ready to be considered for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants