257 points · by alexzeitler · 2y ago · 179 comments
It still feels wrong. I don’t know if I mean wrong as in “incorrect” or wrong as in “cheating/too easy.”
It gracefully makes sites work like it’s 2025 or 1999, but I have to design my markup like it’s 1999. I can never decide if this is good or bad.
My projects all depend on an API for automation. So by buying into this doctrine, and rejecting even content negotiation, I am at least doubling my endpoints.
It’s like being 12 years old, and falling in love with a “bad girl” who doesn’t go to church—and never shows up to class—but makes you remember a lot of basic truths.
Being less poetic. Installing python-multipart to do anything interactive with forms seems like a codesmell, but I don’t know what it is ;)
EDIT: my final comment was not a diss on htmx obviously. But the idea of using browser-consumable response data after the success of computer-readable encodings for web apps
(I guess I just mean hashmaps/dicts/json/object)
I was late to React (like 2020 late!) but have worked on three large (code base and requests) projects in React since then. Development was not fun, iteration was slow, but deployments were fast, yay for DevOps.
I am now building an in house platform in HTMX and it’s wonderful. I get the fun and speed of the early days with the CI/CD we have now.
The project I’ve built would already be a pain to deal with in React, instead it’s fast to load, has snappy interactions, has less code and is easy to extend.
It feels like cheating, but only because React projects get so hard to work on.
Because of primeagen I've been bit buy the curiosity bug, so I wanna try it, but till I try it I am trying to figure out why the day-to-day experience is better. Because for me the biggest win is the idea of having thinner client logic. But I think I would use a React Server Component today to ease that issue.
But yea, genuinely curious. Thanks!
1. Horrible project structure because it’s so unopinionated. Angular has its problems but it’s so much easier to navigate around (one of the reasons I like NestJS is it uses a similar structure). I once worked on a React project where every component was a folder with an index.tsx file in it and default export so tracing issues was hell since the folder name was the best clue you had but people renamed components on import. Not soley a React issue, but made worse by its lack of opinions. 2. State management in React becomes a nightmare for: a: keeping server and client state in sync, thunk/the other one b: everyone eventually puts it all in a global store so you’ve got the faff of dispatching, reducing, whatevering each and every update, adding a single toggle can involve updating half a dozen files.
On the performance side I have a table in my htmx app showing a few thousand bits of data. In React this would need to be paginated, with HTMX I just send the fully hydrated table to the browser and it loads it in a fraction of a second. Then when it updates I just rerun the SQL query, rerender the table on the server, send it back to the browser and HTMX swaps it in.
For me SPA + API always felt like building an application twice. With htmx I build it once.
Hope that helps.
But yes, the generalized and popular React ecosystem is a mess.
React makes it easy to create a big mess.
Because I only spent 3 years in SPA land I feel quite comfortable with only shipping what the browser needs to display what the user wants. Getting JS to render everything always felt a bit odd to me.
> making everything a reducer
just curiosity from someone whos not very experienced in react, but what are the problems with that?Just don’t make me develop a production site with a dev environment that falls over due to CORS for my first semester at my fancy new job ;)
(And why do you call state management in stateless design “hooks?” And, and!)
Web components are great, let’s build a framework around them! /sarcasm probably referencing an XKCD
I don’t mean to exaggerate, but your code will tend to mirror your organization structure. I have worked at companies where I thought our product was great because the API rocked.
Then in my last 3 months I got to meet the frontend (definitely a jobsmell: not seeing the frontend every day.)
Definitely misjudged the quality of our product, because apparently we wrote two different products (shrug) ;)
Pretty strong argument for htmx, actually. But again, in a weird way where we fire the frontend and become actual full-stack engineers for everrrrything.
I exaggerate here because graphql does not solve the datalake problem. And it doesn’t do graphs (you can). The curb appeal looked super promising, but then it was just rpc with a bespoke ORM syntax.
yep, and that's a good thing:
If you can query that client-side, you don't need an hypermedia client, you need an RPC client.
I've run into some problems with the Custom Element lifecycle, though. Not sure how to solve them, because `connectedCallback` is the wrong place for my custom code. The odds are I am doing it wrong (or have a fundamental misunderstanding!)
Basically, lets say I have two custom elements: A and B.
All Bs are a descendant (even if not direct) of an A.
Each A grabs all B children and copies the data out of a specified child of the B, then uses it.[1]
When the connectedCallback for A is executed, the Bs are not yet connected and thus don't show up in a call to querySelector.
I've (sort of) worked around this by having each B, when connected, find the closest A ancestor, and add itself to an array field of that ancestor. A's connectedCallback performs a setInterval with ever-increasing delays until some specific maximum (I use 10ms). The setInterval just redisplays with whatever labels are in the array.
Now, this is probably a stupid way of doing this, and I believe a better way is to use MutationObserver, which I will probably switch to at some point.
However, my point is still: the life-cycle did not offer me some way to hook into A only when all the children are attached to the DOM.
[1] A practical example of this would be tabbed-containers. The <tab-container> shouldn't hold the labels for each <tab-item>, it should get the labels from the <tab-item> itself.
https://developer.mozilla.org/en-US/docs/Web/API/CustomEleme...
It's not been well covered in the standard Custom components blogs.
In "regular" frameworks, this problem would be expressed as state that is owned by A, that B's contribute to. Maybe by calling a function passed down to them, or by updating a shared store. It's a big shortcoming that composition of web components is limited to string attributes unless you use some sort of framework to mediate things.
Something tells me that the backlash will be enormous.
The "State of JavaScript" survey is illuminating for these kinds of technologies. They often follow a trajectory towards "more liked", while remaining consistently and firmly in the "not used" quadrant. Everyone thinks they look amazing and refreshing, and maybe some people have even actually written some small apps in them, but (almost) nobody is using them at scale.
It's not a bad thing really, but the hype can be annoying
Every org I've worked at since the last Rails project I worked on around 2014 has built JavaScript heavy thick clients on top of API's. That's not really where Rails shines, and I've not seen it around at all for newer projects since roughly that time.
It's anecdotal, but it's my experience that the industry has largely settled on the SPA + API's architecture, and the technologies every org I've worked at use to build those SPA's are either React, Angular, Vue, or very occasionally for niche cases their own JavaScript framework.
I understand that some people on Hacker News still dislike the complexity of modern front ends, and I get it, I really do. But I haven't seen any real alternatives that have been seriously used in anger to build an actual commercial application since React, Angular (and Vue) took over.
However I have not seen anything really substantial either that confirms that HTMX works in large projects just as well as in smaller ones. I plan to use HTMX in another larger, upcoming project though as I want to gain some insights on the side too.
That being said I am aware that it might turn out to be a mess. But I would be content with the fact that HTMX is generally very useful for smaller projects and just put it in my respective imaginary toolbox to keep in mind for those kinds of projects.
Every time this is brought up (use in larger projects), people usually only mention this article/video and nothing else, so I'm not sure if that's a good or bad thing.
To be honest I am looking forward to the day when we can put all the HTMX/React whatever debates to rest and it will just be another great tool amongst other tools.
That isn't a very large codebase for frontend, I'd expect one person to be able to do that in less than one month if they're actually trying.
Define large? By size of project or volume of users.
HTMX is more targeted for the latter, not the former.
THere is a continuum. Static pages, SSG's on one side, and SPAs/react all the way at the opposite end. They both do VERY different things. HTMX is some where in the middle, think content heavy PAGES that need lightweight public facing interaction (email/contact, validation loops, a form or two, maybe some dynamic conversions, a carrousel)
Static home page for cache performance, html for sales contact cycle, react for the app you sell ... all three can and should be coexisting!
> Majority of apps are small
I'd like to see some data on it, but intuitively that resonates. The lighthouses of UI frameworks - notably React & Angular - emerged from the needs of big apps, with 100s of people, and structures that delineate front-end and back-end teams. The organisations behind the frameworks - Google, Meta - are very influential in setting industry direction. So those frameworks become "the way to do UI". That doctrine spreads through the community, and the context of origin and use is occluded.
If htmx or similar drives a re-think then that's healthy to me. My own experience is with lots of comparatively small apps. Plain old server-side rendering hits the 80/20 for most, and something like htmx might move that indicatively to ~90/10. Which is attractive because it means 1 tech stack and comparatively less requirement for hard delineation of skills in dev teams.
It's not saying "throw away React/Angular/..., you never need them". There are clearly situations where they're a good fit. Where fit means both organisational and technical. But they're not a good fit in every case.
Why does it seem that way? There are plenty of talks on youtube of commercial projects that switched from React to htmx and found considerable benefits.
Is this inline CSS reimagined?
B) There are many ways to "reinvent inline styles", this one is good, actually. I used to work with a fairly mature codebase. We enforced BEM-style names, but otherwise the CSS was extremely ad hoc (which, it is my impression, is quite normal). I ran some queries on our existing code, and found that most of our CSS classes were only used once, and most elements had only one style. They quite often had generic names, though, and when working with them you were always afraid to change a class because you didn't know if it'd been recruited elsewhere. And you certainly didn't delete anything. The growth in the size of the CSS was also quite extreme - it doubled over a year as far as I can remember. Probably because nobody ever deleted a class, even when they stopped using it, because then you would've had to check for sure that it was now unused and.. meh.
I starting referring to all this as "might as well be inline"-styles, because really, all we did was move the inline information to a different file, which... has no benefits when you think about it[0]. A thoughtful application of atomic CSS would have been a massive ergonomic improvement IMO, and I've since used Tailwind on a big project and found it much, much easier to work with over time than the other system.
[0] Yes, I know about the CSS Zen Garden. I don't think the principles apply to web applications - and, if anything, the approach to colors and font sizes in Tailwind makes theming much easier than in a messy codebase like what I used to work with.
Also, it's like building your new and shiny app with i18n in mind. Do you really need translations when you are the only user? Probably not, but development is also about trying to predict what will happen next. classes helps you to grow.
HTMX is just another tool to be deployed. If your app requires a SPA experience or large amounts of javascript for the UI, its not the right tool for the job. Where I have had great experience with it is for applications that have discrete javascript implementations or none. Lot's of applications that are quite valuable to the end user, are really just a bunch of CRUD like operations and don't really need a full blown FE framework.
On the upside, by that point I knew the CRA codebase well enough to predict what it would do even in edge cases, and CRACO's implementation was immediately comprehensible, and none of my colleagues had to try and understand my half-arsed NIH version.
(avoiding being in any of this situation in the first place would likely have been preferable, but given where things were when I landed on the project in question that would've required a TARDIS)
You can still use react , vue, solid or whatever for the dynamic parts that make sense to do clientside
I can see how that might be useful for simple things but for anything with any level of sophistication aren't you going to have to jump right into JavaScript?
I just don't really get the big picture of HTMx. Is it making easy things easy and leaving hard things to React or Vue or whatever?
Can someone please sell me on it - why should I be excited given that to get anything hard done I have to jump straight into JavaScript.
Some applications benefit from being in the style of a SPA, others do not. For the scenarios that do not benefit from a SPA (or other full JS framework) htmx is really nice to work with, I still use javascript along with htmx but I delineate its usefulness to projects that don't benefit from massive amounts of global state that the FE needs to know about. Over the years I have found that the majority of applications I have built in a commercial setting, global state was not all that useful.
My mental historical model kind of went like this. We got backbone.js and started to make these magical like interfaces for the web. We then started to build everything as a SPA. We optimized for state management and how to efficiently update the dom. Because SPA were uncrawlable we would manage a static site and the SPA, then we got frameworks that could handle requests to specific views within the applications. After playing around with htmx I started to think that perhaps all that management the FE app was doing was not really necessary for a lot of the applications I had built. I can couple html with discrete javascript applications where necessary. For me thats the sweet spot but again, htmx is not a one tool fits all. There are many apps out there that benefit from using vue/svelte/other frameworks.
People today write static blogs with TS/React/Next/whatever because that's what they know. It's not because it's the best tool for the job (or even close to that).
It has become standard to use React/Next/GraphQL for any new project, regardless if you're building a new Google Docs (which definitely benefits from JS) or yet another CRUD application that has lists, details and the occasional interactive page like a graph or something similar.
That's the crux of the issue: we seem to have lost the ability to think critically and choose what we require, in favor of copy pasting choices from everyone else and calling it a day.
Once you're heavily invested in all the JS-only technology, your incentive is to stay in that lane. To consider better alternatives is simply too costly for many.
That's why we turn everything in sight into JS. Someone I can't recall said once: everything that can will be rewritten in JS. We even have people building email templates with React now because all they know is JavaScript.
“Any application that can be written in JavaScript, will eventually be written in JavaScript.”
One problem I did face is trying to put together a large json to a POST request. I did experiment if I could do this all in the 'htmx way' of using input=hidden but was not working. With this, it was best to store this as a JS variable, or call a JS function to return json, which was all specified in htmx (in html)
Point is there are some exceptions that I have to do some javascript but the amount is much less when using other popular frameworks.
Overall, I am doing most work using htmx and odd exceptions with simple javascript functions to returns text or json.. or javascript to compliment my css.
update: formatted the json better
Thank you for expressing interest and, potentially, an approach to suggest ideas.
On my original attempt, I just couldn't get the POST request to work. I cannot remember the details but, due to time constraints, had to resort to something.
I will admit that this is an area I would like to revisit, but the current approach does work well... for now.
My json is larger than below, but provides examples of the inputs they represent on screen:-
{
"catA": {
"capacity": 90, // value from slider control
"memberType": 4, // value from single drop down
"members": [1, 2, 10, 100], // values from multi select drop down
},
"catB": {
"dateRange": { // both individual text fields
"from": "2024-01-03 10:00:00",
"to": "2024-01-04 10:00:00"
}
}
}(I swear I've read the htmx docs but either I missed this part or I've forgotten it since)
I migrated my personal site from pure Vue 2 to Vue 4 + Nuxt recently. The migration guide was a garden path, but when I started a new project and just moved my components over into the conventional nuxt locations, everything went quite smoothly.
My use case is quite narrow. It's basically a blog but with some embedded applications (mostly simulations), heavy use of a particular custom component. I like the hot swapping from the vue framework and I appreciate the static compilation of the result from Nuxt.
I thought about doing something like HTMX + web components, but I would still need to figure out how to bundle what javascript into each page. Plus, web components have absolutely no server side rendering without another layer of complexity. Setting all that up seemed to me to be effort better spent on the occasional migration. Plus, when the going gets rough, Vue always had my back. My next step will be embedding wasm though... so that might change things, I'll see.
Is this a thing?
Though I'd admit it doesn't have the beautiful simplicity as concating some strings.
I end up with a `.astro` file that server renders the HTML and adds a script to define the custom element. In the browser its more pike cheap hydration - the custom element doesn't re-render anything up front, it will just grab references to the server rendered DOM nodes and setup event handlers.
I know Lit has an SSR helper, though I haven't used it myself I think its supposed to make server rendering you lit web components much easier.
I'll admit that I'm not a frontend guru so my bias for writing apps like I did 20 years ago likely shows here.
Still, when I consider all the different abstractions and details around using something like Next.js + Typescript, and where the division between server and client becomes mixed, reducing complexity feels advantageous.
Tailwind is another good example where the explicit nature of attaching styles makes sense if you are writing React components. You've encapsulated all that noise behind a simple JSX tag. Using Tailwind with something that returns HTML then requires a similar way to encapsulate the noise. Again, I found using Templ with Go made that feasible, but I still have avoided Tailwind just b/c I don't want to introduce the noise too soon if possible.
It all makes me wonder if we lost the idea of a fullstack engineer, not because the problems became so challenging that we needed the extra complexity, but rather because we organized our applications into frontend and backend organizationally when we should have been more diligent in maintaining teams that could do everything.
The real tl;dr is that Templ for Go is pretty handy for writing components :)
I understand there are some security challenges, as in "local" mode it can only communicate over HTTP with local app, or probably without CORS, etc. XSS might be a real issue here.
I can't imagine doing XHR requests that return partial HTML snippets to be "good" for a crawler that expects one page to link to another (assuming they are running JS to begin with).
It's like the coding version of https://en.wikipedia.org/wiki/Dancing_mania
Then, I encountered the raving fans. That's when I knew the shark had been jumped.
How you want to write CSS is a tradeoff.
Traditional CSS without tools like Tailwind, styled-components or other "hacks" is especially bad at collaboration and evolving from prototypes to large sites or apps, in my experience.
They're attributing a cult like / social influence phenomenon to the popularity of it. That others use it because others use it; not on any perceived by them actual merit of tailwinds design.
Traditional CSS? I’d update a style in a few specific spots and everything benefits.
I wish I liked tailwind it's all the rage but I just don't
The reason why it is big is efficiency. Once people know those class names by heart, they get a "nice" (arguably) default style very quickly without jumping between multiple files. This matters more than one might think..
Tailwind sacrificed that for dev ux. The next generation will have a harder time learning about web primitives.
And htmx is not something I need for these days thankfully. I use phoenix liveview and get away with writing very little pretty dumb code. It's wonderful.
I also avoids the giant size of Tailwind classes that requires that elaborate build/reduction process. You can just include Bootstrap from a CDN or whatever.
A future project of mine is to build a mini-browser of sorts, and I'm going to use tailwind as the minimal basis for getting the CSS to work. so... I'm enjoying it... like a lot.
You just move HTML from anywhere and it would just look exactly the same (subject to your overrides/customisations of course) so I don't think Tailwind is going away anywhere.
Rather, it now can be thought of as a mini language or notation built on top of CSS.
So far UnoCSS works very well for me. It's like light-weight and customizable Tailwind. Also for more complicated "components" I use css modules and refer to my theme values via directives (I think this is doable in Tailwind too?).
I'm thinking something similar using a web component library could be good. Maybe material or fluent based.
I wish people move away from describing things they dislike as bad, horrible, dumpster fire. Describing the problem in a discussion site is always better
But notice how you're then left with a bunch of repetitive HTML on which you apply those classes. If you bundle up the repetitive HTML into a reusable abstraction (like a component), then you're no longer repeating the CSS and so you don't need to bundle the CSS into classes anymore, thus reducing work. A type of inline styles, without the limitations, then gives you more direct control over styling on the bundled HTML itself. That's how you should use Atomic CSS/Tailwind.
As for Htmx, it's nothing new. I don't dislike it, but comparing it to web frameworks like React is missing the point. A lot of what it gives you (or doesn't) can already be achieved with a bit of vanilla js and, if you're feeling fancy, jQuery. Advocating for it as a replacement for something like React is sort of like recommending a bicycle to someone who drives. Yeah, it has its place, but it doesn't replace the utility of the car. Insisting it does indicate you don't know much about cars - or maybe bikes.
Anyway htmx uncomfortably reminds me of the MVC servers we use to write 15 years ago where the frontend always ended up being an unreadable unmaintainable mess after a few years because the frontend was treated as a random collection of assets for views to use.
api server + react/vue/angular work good. They are just js(templates compiled to js). They are for building webapps.
Anyway, html is not turing complete.