#4071·htmx

[htmx4] Back navigation stop workings when calling history.replaceState

Author: nikomirandaCreated Sep 13, 2026Updated Sep 14, 2026

Hello.

When testing the migration to htmx4 I found some case that I had to debug/check the htmx code to understand the behavior.

  1. First page do an hx-post/hx-get to second page.
  2. Second page calls custom history.replaceState for example to add a hash to keep track of some UI selection.
  3. Browser back page is press.
  4. Browser URL changes but nothing happens (no reload or ajax replace)

When debugging the problem is that async #restoreHistory(state, path) needs to have an object htmx: true in the state in order to work.

I think that if this is the intended behavior it should be well documented somewhere. As a workaround adding that object when calling replaceState will solve it. But somehow is a little tricky.