Skip to content

Conversation

MichaelWest22
Copy link
Collaborator

@MichaelWest22 MichaelWest22 commented Oct 1, 2025

Description

This PR fixes an issue with the history feature in htmx where currentPathForHistory could become stale after a full page navigation or browser refresh. The bug caused incorrect page content to be restored when navigating back in browser history, especially following sequences that mixed htmx requests and hard links. The fix initializes and stores the current path on htmx load to ensure the sessionStorage value always reflects the correct current URL, preventing mismatched or outdated content from being restored.

Seems like I caused this issue in #3330 when I added code to handle body based script tags causing history problems. The fix is to just make sure we sync the url location to session storage every load so that there is no situation where old url data can be used while retaining the fix.

Corresponding issue:
#3449

Testing

I tried adding automation and regression tests for this bug but the only way to reproduce it is with a hard reload which our testing framework does not support. Attempts to create manual tests that are useful and meaningful also failed because it is very hard to find the exact realistic steps to reproduce. It is easy to view the incorrect history data being saved to the cache but very hard to find a path to get it to use this bad cache data like the end user has managed to do somehow.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant