bigskysoftware / bigskysoftware/htmx

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

Open
#4,071 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start at the async #restoreHistory(state, path) entry point mentioned in the issue and reproduce the four-step hx-post/hx-get, replaceState, and back-navigation sequence. Determine whether the observed behavior is intended; done means either documenting the required history state or making browser back navigation restore the page correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.