Hacker News new | ask | show | jobs
by rasso 1258 days ago
Actually, HTMX has a fundamental flaw if it comes to history restoration: In some scenarios it takes snapshots of the DOM for history navigation, just before navigating away from a page. If the DOM was previously modified by other JS libraries like Alpine, jQuery or any other tool, these changes end up in the history snapshot, leading to unexpected results [1]. I've had a much smoother experience with Alpine + swup [2]. Disclaimer: I became a maintainer of swup this year.

[1] https://github.com/bigskysoftware/htmx/issues/1015

[2] https://github.com/swup/swup

2 comments

To illustrate:

Say you have a collapsible menu (Burger etc.) which you just implement with a simple CSS based toggle. You open the menu and then navigate to a different page (via htmx). All good. But now your back button will break because it will send you to the previous page but with the menu open.

In this particular case it's _kind of fine_ depending on your navigation concept and design. It might even be a feature! But this behavior just proliferates little workarounds and caveats and can lead to surprising UI bugs, especially if you need some state management in-memory etc.

So htmx is great the less JS you use on top of it, except you are very aware of how it operates and how you interact properly with it's events. It's a very well designed and small library overall - with caveats.

Fair, I was going based on hearsay/docs. It looks like LiveView has been trying to accommodate the issue with some work arounds such as: https://github.com/phoenixframework/phoenix_live_view/issues...