Standardize history restore functions to use proper htmx swap functions - #3306
Merged
Conversation
MichaelWest22
force-pushed
the
history-improvments3
branch
from
June 2, 2025 07:55
7aa258a to
cbb1e97
Compare
…22/htmx into history-improvments3
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 loadHistoryFromServer and restoreHistory functions are coded to manually perform the history restoration process as manual code that does not reuse any of the existing htmx swapping code used by normal ajax and boost requests. This means it does not respect all the normal htmx conventions and does not fire core htmx events during the swap. Also The existing history events do not give any easy ability to control how htmx restores history because of the order they are fired.
I tested replacing the loadHistoryfromServer with a full htmx ajax request to get it to perform the same action just like a boost and while this works well it does mean that history loads now respond to all htmx headers and fire all the normal events and we may want this history restore to be more like a full page reload without htmx most of the time. So instead I just implemented the swap function and extended the swap function to perform the needed scroll to number and title update options that it was missing.
This change has no real semantic change to the way the history restores really it is just more extensible now with various options to override the default behavior during the events and i've added a new
htmx:historyCacheHitevent to allow overriding cache hit events if required. All the data sent to the events can be modified if required as these event details are reused by the swap api's after the events.Also during the swaps it does now emit the afterSwap and afterSettle events that were missing before but these events are unlikely to cause issues If these are now emitted.
Corresponding issue:
#3031
Testing
Added new tests to test and show off the new events preventing and updating the history restore actions.
Checklist
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded