Skip to content

Standardize history restore functions to use proper htmx swap functions - #3306

Merged
1cg merged 20 commits into
bigskysoftware:devfrom
MichaelWest22:history-improvments3
Jun 16, 2025
Merged

Standardize history restore functions to use proper htmx swap functions #3306
1cg merged 20 commits into
bigskysoftware:devfrom
MichaelWest22:history-improvments3

Conversation

@MichaelWest22

@MichaelWest22 MichaelWest22 commented May 8, 2025

Copy link
Copy Markdown
Collaborator

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:historyCacheHit event 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

  • 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 force-pushed the history-improvments3 branch from 7aa258a to cbb1e97 Compare June 2, 2025 07:55
@1cg
1cg merged commit 508e332 into bigskysoftware:dev Jun 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants