fix stale currentPathForHistory issue #3451
Open
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
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
master
for website changes,dev
forsource changes)
approved via an issue
npm run test
) and verified that it succeeded