Skip to content

Strange behavior when navigating back to a previous page (both pages are with htmx) since 2.0.5 #3449

@nikomiranda

Description

@nikomiranda

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

  1. In page A click the button to load with htmx
  2. Go to page b using HREF
  3. In page B click the button to load with htmx
  4. Perform a browser refresh
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions