Live data from Hacker News

Htmx Is Composable?

timkellogg.me

51–60 of 69 posts

Re: Htmx Is Composable?

#51

One thing I see lacking with HTMX is that, eventually, someone will want to package and distribute a third party component. You say "but it's meant for small things not requiring much scripting" and I say "I don't believe you - once it's in it will grow indefinitely". This is definitely possible, but unless you are using WASM or something you would have component libraries specifically built for a backend language or…

Yeah, thats been my experience with it also. It works great for small things and getting going, but eventually the project starts to grow and you want to embed something that would be straightforward if you used a JS framework and then the spaghetti code starts as you bolt on a JS component inside of HTMX. After the 10th time you do this the project gets pretty messy and you want to just start from scratch with a conventional framework.

Re: Htmx Is Composable?

#52
post #49

Something about this feels really at odds with all the "locality of behavior" virtue the creator/maintainer often promotes.

Yep, and as soon as you need non-local updates, the whole concept of HTML-over-the-wire starts breaking down. I really like this HN comment on this topic: https://news.ycombinator.com/item?id=38081174

As mentioned in that comment, there is hx-swap-oob, but there is also the official htmx multi-swap extension that makes this pretty trivial.

https://htmx.org/extensions/multi-swap/

In that example, you'd just send partials for the card and cart elements and they'll both be swapped out.

Re: Htmx Is Composable?

#53
post #14

I am confused about htmx because if it is about AJAX, they don't replace the window URL as user clicks about and around unless you explicitly tell HTMX to do so. And if you step into that realm of keeping the window URL in sync with where exactly the user is in the app, then you're almost already into realm of SPAs but without having the full set of tools that go with SPA. Any open source project done in HTMX that ha…

If you want the URL to be updated, just go and do a full request.

Re: Htmx Is Composable?

#54
post #32
post #14

I am confused about htmx because if it is about AJAX, they don't replace the window URL as user clicks about and around unless you explicitly tell HTMX to do so. And if you step into that realm of keeping the window URL in sync with where exactly the user is in the app, then you're almost already into realm of SPAs but without having the full set of tools that go with SPA. Any open source project done in HTMX that ha…

Keeping the url in sync can be done by tracking whether the request has the `HX-Request` header in it and then returning either a partial template or the full the template, example of the helper - https://github.com/Austionian/bl0g/blob/46182cf762e9acefc35e... The great part of this, too, is caching these responses is still simple with the a `Vary: HX-Request`

And, of course, with a 'Cache-Control: ...' header.

Re: Htmx Is Composable?

#55
post #14

I am confused about htmx because if it is about AJAX, they don't replace the window URL as user clicks about and around unless you explicitly tell HTMX to do so. And if you step into that realm of keeping the window URL in sync with where exactly the user is in the app, then you're almost already into realm of SPAs but without having the full set of tools that go with SPA. Any open source project done in HTMX that ha…

> I am confused about htmx because if it is about AJAX, they don't replace the window URL as user clicks about and around unless you explicitly tell HTMX to do so.

When you use `hx-boost` (one of the most common uses), it does an ajax request, updates all the child elements, and updates the URL in the browser automatically.

Re: Htmx Is Composable?

#56
post #21

Earlier quoted context omitted.

>not everything needs the window url to be updated. The user needs it to be. It is the single most important handle of information for a layman. Of copying and pasting URL to someone else so that's kinda should be non negotiable for any pro user developer/engineer. I find React to be too convoluted through its evolution multiple times over (plus the virtual DOM and horrendous ergonomics of hooks) but at the time, I'm…

The thing is... not everything needs the window url to be updated. Either because the URL is the same, or because you're pulling content that shouldn't/can't/won't be accessible with a direct URL. For example: - Blog: You add a comment to a blog post. The comment appears without reloading, and you don't need a new URL (because it's the same blog post) - Menu navigation: You load menu items and/or children via htmx. T…

For all your examples I can think of a reason to update the url in some or most scenarios. It depends.

New blog comment can be part of the url target with the comment id. Makes it easy to share and puts the scroll bar at the right position.

Menu navigation can be quite complex with nested modals, you might want to be able to deeplink for documentation/training purposes and highlight a selection.

With a cart you might want to add a ‘cart state/session’ id so you can share it with your spouse to quickly get to an agreement about stuff to order.

Re: Htmx Is Composable?

#57
post #14

I am confused about htmx because if it is about AJAX, they don't replace the window URL as user clicks about and around unless you explicitly tell HTMX to do so. And if you step into that realm of keeping the window URL in sync with where exactly the user is in the app, then you're almost already into realm of SPAs but without having the full set of tools that go with SPA. Any open source project done in HTMX that ha…

If you want the URL to be updated, just go and do a full request.

That doesn’t make sense because there’s millions of reasons to update the url even when navigating sub sections of the page or to reflect some sort of state that needs to be persistent when refreshed/shared.

Re: Htmx Is Composable?

#58
post #4

This reminded me that one thing I miss from WPF is the "free" render-time polymorphism. If you had an interface, say ICard, and a few xaml data templates for how to render the concrete types, all you had to do was bind to a collection of ICards and it would automatically do what I guess we'd now call pattern matching on the concrete type of each element to render it without needing to mix the presentation with the pl…

Why did WPF go out of style? (or did it? idk) It seems like a good pattern, but it's always good to look at historical cases for the gotchas

Microsoft's desktop strategy has been a disaster.

If I had to guess? A bad decision and then sunk cost. If for their cross platform story they'd gone the avalonia route and developed cross platform wpf they would have been miles ahead of wherever they are now with their three or four competing underfunded ideas. Then wasm as a target might eventually have even fallen into their laps.

They have good execution in general but their strategy in this space is closer to a "12 startups in 12 months" style approach.

Re: Htmx Is Composable?

#59
post #49

Earlier quoted context omitted.

Yep, and as soon as you need non-local updates, the whole concept of HTML-over-the-wire starts breaking down. I really like this HN comment on this topic: https://news.ycombinator.com/item?id=38081174

As mentioned in that comment, there is hx-swap-oob, but there is also the official htmx multi-swap extension that makes this pretty trivial. https://htmx.org/extensions/multi-swap/ In that example, you'd just send partials for the card and cart elements and they'll both be swapped out.

If we continue the cart example, what should HTTP endpoint return in that case?

Re: Htmx Is Composable?

#60
post #9

The author of the article needs to read this https://youryoure.com/?its

Sometimes people are just in a rush or just a bit careless, much like you were here: https://news.ycombinator.com/item?id=38879565 . It really isn't the end of the world. Glass houses, and all that.

I agree with the spirit of your comment, but I do think the bar for proof-reading published material (like a blog post) should be much higher than the bar for informal communication (like a forum comment).
Post reply on HN