Add pushUrl option to ajax api and improve hx-location push url handling #3404
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded