-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
I am having an strange behavior when going back to a previous page (using hx-history and hx-push-url)
Given two different pages
<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.min.js"></script>
<meta name="htmx-config" content='{"refreshOnHistoryMiss":"true"}'>
</head>
<body>
<h1>Page A</h1>
<div>
<button
hx-push-url="page_a_frag"
hx-post="fragment1"
hx-target="#container"
>
Click me before going to page B
</button>
</div>
<br/><br/>
<div id="container">
</div>
<br/><br/>
<a href="page_b">Go to page B</a>
</body>
</html>
<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.min.js"></script>
<meta name="htmx-config" content='{"refreshOnHistoryMiss":"true"}'>
</head>
<body>
<h1>Page B</h1>
<div>
<button
hx-push-url="page_b_frag"
hx-post="fragment2"
hx-target="#container"
>
Click me to load fragment
</button>
</div>
<div id="container">
</div>
</body>
</html>
Steps to reproduce
- In page A click the button to load with htmx
- Go to page b using HREF
- In page B click the button to load with htmx
- Perform a browser refresh
- Use Back button in browser
At this point the page B should be shown, but without having any htmx request the content is replaced by something of the page a.
I think that something is not working well in the sessionStorage.
With 2.0.4 version was working good, but the behavior is different after 2.0.5 (I think with the modification of using sessionStorage instead of localStorage)
I tried to make an example in git hub pages
https://nikomiranda.github.io/htmx-2.0.5-history/page_a
Since I cannot use POST there I replaced with GET requests, the result is not exactly the same as this description but It's not working good as well.
(When going back after the refresh, the URL changes but not the content or not refresh is performed)
Thank you and sorry if my explanation is not very clear.