Removing React.js from the codebase and adapting Htmx for UI interactivity (2023)
Posted by Ralfp 7 hours ago
Comments
Comment by james2doyle 1 hour ago
The problem I had was that the entire experience became really slow when I had it all working together as one "response". Sending back all that HTML for an entire form with some large select lists as well as the response of results became noticeable laggy when there was more than a half dozen results.
I ended up switching to Alpine Ajax (https://alpine-ajax.js.org/) and pulled the form out of the response and just used a local x-data on it to track the state. This greatly reduced the HTML I needed to send back to just the list of results. I did make the form a bit more complicated but the experience felt a lot snappier. Both versions just synced the form state from the URL and kept the initial render as full HTML from the server.
I found that Alpine + Alpine Ajax was SMALLER than HTMX 4 even though (in my opinion) it offers a lot more features in a more approachable and intuitive way if you need to do interactivity and don’t want to trigger a request just to toggle some classes or attributes. Of course you can use both together (I started down that road) but you are mixing worlds and making the bundle size bigger at the same time.
I still like HTMX and will probably use it again. I just found that with an interactive experience like a product listing page, where the HTML response was quite large/expensive to fetch, it wasn’t the best choice for that.
Comment by dsego 34 minutes ago
https://github.com/dsego/ssr-playground/blob/main/src/server...
Comment by inigyou 1 hour ago
Comment by brabel 1 hour ago
Comment by tclancy 32 minutes ago
Comment by Capricorn2481 23 minutes ago
Comment by snorremd 4 hours ago
With HTMX you can do partial rendering and live updates via server-sent events. This gets you most of the way to the "client side" feel where things load dynamically based on user actions.
The only properly dynamic SPA-like feature in a forum I can think of is a WYSIWYG editor, but that you can build as a web component. Maybe a flexible highlight and quote system would be a bit difficult in pure HTMX (think of the comment functionality in Medium posts). So you'd want to build a few things in client side JS. But the main experience could very well be built with HTMX.
Comment by Pxtl 2 hours ago
I'd say that "Endless Scroll" is a good example of something that is... well maybe not interactive but still breaks the "just an HTML document" page metaphor that plays nice with such things.
Now, personally I find the UI compromises it takes to make endless scrolling happen are abhorrent (like not being able to ctrl-F or export the page content). But other people obviously like them.
Is that the kind of thing you'd be giving up as you move to a platform like HTMX?
Comment by geysersam 1 hour ago
Comment by jimberlage 1 hour ago
Maintaining a code path with a snippet for each possible viewing experience, back when REST was all the rage, was a bit obnoxious though.
Comment by toddmorey 2 hours ago
Comment by egeozcan 1 hour ago
If you want basic interactivity, HTMX is fine.
If you want something more (like sortable) I'd reach for lit instead of adding the Sortable.js dependency, something the HTMX docs suggest ( https://htmx.org/examples/sortable/ )
And yes there are also some scenarios that you want to control the whole routing and rendering stuff, then go for Solid, React, Angular, Vue, whatever.
There is no golden rule to all of this but finding out what makes sense is a fun exercise.
Comment by snorremd 1 hour ago
But interactivity in largely content-driven sites doesn't necessarily preclude HTMX. You can do a bunch of fancy interactive stuff with HTMX and some minimal JS. Drag and drop sort is a tiny drop-in JS snippet. Skeleton loaders and spinners are supported out of the box in HTMX as is infinite scroll as others pointed out.
I'm not saying Next.js, Solid Start, Remix, Nuxt or some other hybrid server and client rendered model doesn't work for forum software. Or that even client only rendering can be a valid approach if you accept the trade-offs (no curl-ability). People should use whatever they feel productive building with.
But if your backend is already a non-JavaScript server rendered framework like Django then HTMX makes a ton of sense to add some interactivity.
Comment by egeozcan 23 minutes ago
Otherwise, I'd recommend HMTX even if you have a super flexible JS backend.
That said, this is all baseless thinking without seeing any requirements and as I said before, trying to choose the right abstraction is the hard but fun part.
Comment by atoav 1 hour ago
I get lazy-loading for pages that contain a ton of media of which the user will likely only see a fraction. But some people seem to think infinite scroll is a good idea with text based content as well..
Comment by Pxtl 47 minutes ago
Comment by epolanski 3 hours ago
That's how interactivity has always worked.
Server-side render everything + ship interactivity via js on top of it.
I feel like most of the web developers forgot that React/Vue/etc solve a specific problem: single-page application.
This is a very narrow and specific problem: navigating from page to page not causing full page reloads.
But the web has changed since SPAs were needed in major ways:
1. the average device and connection is insanely faster than 10-15 years ago. Receiving and rendering content is not the problem it once was in the age of 2g connections and limited hardware mobile devices. Even the very low end phone from few years ago has nowadays 0 problems loading and parsing few hundred kbs of html and js.
2. Web technologies moved at all levels. Server technologies, cloud ones, browser ones. React and company are solving problems that barely belong to the modern web.
In short: today you can have an app-like, spa-like experience even out of fully server-side rendered applications. While also benefitting from shipping much less code to the client.
There's a very minimal amount of websites and applications out there that benefit, and aren't crippled by these rendering libraries: those that vastly leverage offline capabilities of the platform and want to keep working regardless of internet being available. I'm talking the notions and linears.
But bar from those, still working with this React slop is just not good for the user. Even multi billion companies hiring leetcode ninjas can't get acceptable user experience and performance out of those libraries, and it's not a coincidence: they keep forcing the wrong tool for the wrong problem.
They keep living in 2018 and at the end of the day the only excuse for those react/angular+tailwind slop is that there's an entire generation of developers that doesn't know anything else and has long lost any proper engineering skill (if there is any) in finding the right tool for the problem. This is a familiarity issue, not sound technical decisions. It's the "you can't go wrong with oracle/mysql/ibm", but actually you can, and it shows.
What's worse: it's incredibly cheap to experiment different solutions and approaches via LLMs in 2026, but people keep slopping the same monstrosities.
Comment by ko27 3 hours ago
Using the same reasoning, I’d come to the opposite conclusion. Devices are much faster than they were 10-15 years ago, but network latency is still roughly the same because physics limits how much it can improve. So reducing network round trips matters more than ever, which favors SPAs over MPAs.
Comment by bbg2401 2 hours ago
SPA’s tend to require more network round trips, sometimes significantly more based on the architecture.
Comment by Izkata 2 hours ago
Comment by ko27 2 hours ago
Comment by johsole 2 hours ago
Comment by shooly 3 hours ago
That's not true. They solve the problem of requiring separate code paths for interactive elements - one for initial render and another for updates.
Previously the server rendered the initial HTML and then client JS updated it after e.g. user clicks a button, but with React/Vue/etc., it's merged into one code path because HTML is derived from the current state.
> Even multi billion companies hiring leetcode ninjas can't get acceptable user experience
Modern UX is bad because many front-end programmers fundamentally just do not care about the UX, it's not about the specific tech they use.
Comment by recursive 1 hour ago
Comment by shooly 1 hour ago
Comment by epolanski 2 hours ago
That's the definition, I didn't made it up.
And those libraries solve that.
Your other definition, can be fully implemented server side, Elixir's Phoenix does that. But it's not the only one.
Comment by robertlagrant 2 hours ago
Your prior claim was that they only solve one problem, not about a definition. They solve several problems:
- less data can move over the wire compared to sending a full page every time (this is in your definition, and is definitely not always true, as sometimes REST APIs can return far more data than what's needed to render the screen)
- the same REST/data API can serve your website and other consumers, e.g. any native mobile apps or third party API consumers
- you can write tests for your frontend, e.g. you can unit test components' behaviour and style in isolation
- the frontend can also work, or at least respond usefully to the user, when the network or the backend are not working
Comment by shooly 2 hours ago
According to what you said, CSS also solves the problem of making an SPA because you could "switch pages" by changing CSS class names on `body`. But if someone asked what CSS is you're not gonna answer "you use CSS to make an SPA", even though _technically_ you can use it to make an SPA.
Comment by rubylimetea 15 minutes ago
Example: Render a scrollable list and you need to change contents of the li items mid scroll - it resets the scroll position to the top because of how it replaced the entire HTML on render. There are workarounds you can do, DOM hacks, but they aren’t ideal.
React is designed around that kind of thing. They do some funny magic under the hood to support seamless DOM reconciliation and things like prop drilling of entire components on the prop of another, and so-on. This gives them a more granular way to manipulate the DOM without total page re-rendering.
Next.js SSR works because it’s designed around React. So they’re giving you all the SSR stuff you want but you still get client-side React for rich interaction design and other SPA niceties.
So if someone releases an SSR-like thing like htmx it feels like something is missing.
Maybe htmx needs an opinionated framework that gets more into high performance rendering and state management.
Or maybe they hone in on the “basic web pages” market. Who knows, maybe those make a comeback somewhere. PDF gets replaced with standalone HTML or something, and people use HTMX, or maybe it’s used in a dev environment for HTML email design in some future where email can have events (who knows). Couple of ideas.
Right now it feel incomplete or has nowhere for me to plug it in. Love the concepts though, HTML/JS should have been like that.
Comment by christophilus 8 minutes ago
Comment by prologic 4 hours ago
Comment by wwweston 2 hours ago
Comment by bevr1337 51 minutes ago
After initial page load, a service worker could intercept all the HTMX app's AJAX requests, but it could only work with what's already cached. Using a lot of tooling like workbox the developer could pre-cache the entire app. (Would that mean no dynamic responses?)
Alternatively, implement the entire HTMX app in JS, build the app once for the NodeJS/Deno backend and once for the front-end. After page load, the frontend could take over.
Or something like that. It's a bit convoluted as PWA solutions often are.
Comment by johsole 3 hours ago
Have you found nice workarounds for that?
Comment by prologic 2 hours ago
If you'd like to find out how I build Mobile-first apps with Go, HTML and HTMX hit me up.
Comment by rahabash 1 hour ago
Comment by sgt 5 hours ago
Comment by asdfsa32 5 hours ago
Comment by dsego 25 minutes ago
Comment by sgt 5 hours ago
However for some really complex mini apps, that's another story. But for the rest of those CRUD pages, you can go simple server side rendered.
Comment by asdfsa32 4 hours ago
Comment by skydhash 4 hours ago
Comment by asdfsa32 4 hours ago
Again, the issue with htmx is that it pretends like it is not a framework, when in fact, it is just a second attempt at angular 1.0, with even more naive assumptions about web apps.
Comment by stymaar 3 hours ago
If it's a sub-function of a bigger ensemble that mostly dies something else then it's fine to call them “mini apps”.
For instance a bank app may contain a text editor for the internal messaging feature of the app, that would count as a min-app in that context.
Comment by sgt 1 hour ago
Comment by Exoristos 24 minutes ago
Comment by skeptic_ai 4 hours ago
Comment by dsego 18 minutes ago
Comment by prologic 4 hours ago
Comment by asdfsa32 3 hours ago
In fact, the complexity of Chat Messages and Notifications synchronisation is one of the prime reasons why React exists.
Comment by Zanfa 3 hours ago
Which makes it even more ironic that in the 10 years since React was announced in 2013 and when I quit Facebook, they never managed to fix the original state synchronization bug that they demonstrated in the original React announcement for more than a few months at a time at best.
I'm sure technically it wasn't a singular bug over the years and the causes were complex, but React did fuck all in relation to the unread message counter being correct.
Comment by infamia 2 hours ago
SSE is perfect for chat/notifications and is a lot simpler than syncing. The server pushes updates to the client doesn't require a sync. SSE is also more performant since it can keep the connection open. The example below is on a $10 vps last I heard.
Comment by greenchair 3 hours ago
Comment by Levitz 3 hours ago
Comment by ErroneousBosh 1 hour ago
It works quite well, and saves me an awful lot of tedious mucking about with other stuff.
Comment by sgt 1 hour ago
Comment by asdfsa32 4 hours ago
Comment by hazrmard 2 hours ago
Comment by scorxn 1 hour ago
Comment by n4pw01f 3 hours ago
Hono + WebComponents + HTMX + serverless is the backend for my apps now.
Comment by foxygen 2 hours ago
Comment by sjoedev 2 hours ago
Comment by skeptic_ai 34 minutes ago
I think this tells all about the level of competence of these devs. That’s literally unmaintainable. So instead of fixing the problem and have a nice api + interface + ssr, they patch it up with a yet worse approach in htmx.
> there's a lot of forum software out there that still does the old way of rendering as much as possible on the server and using some JavaScript on client to improve its interactivity here and there. And people are happy with that
Yeah, server returns class xxx and jquery needs to target that. Once is out of sync silent bugs will appear. And will be many, not a few. No way to check at compile time.
Comment by thrownaway561 3 hours ago
Comment by butz 3 hours ago
Comment by zuzululu 1 hour ago
although i wonder if LLM changes things
i am interested in moving away from React but its also what LLMs know infinitely more of than HTMX
Comment by Ralfp 5 hours ago
Comment by ErroneousBosh 1 hour ago
But Misago sure does look good.
Comment by fenestella 3 hours ago
Comment by Kuyawa 2 hours ago
Comment by leviyi 4 hours ago
Comment by wackget 1 hour ago
Comment by mmmmbbbhb 4 hours ago
Comment by asdfsa32 5 hours ago
But on serious note, htmx is basically a solution in the search of a problem. It is the new hype.
Or rather, a solution that overlooks 2 decades of learnings. Yes, for a small set of projects htmx is okay, but even then, where htmx is ideal, static is king, and once static is not good enough, htmx sooner or later starts to feel like the XAML and BPEL soap.
The fundamental problem is that it is pretending to be a declarative language while entirely imperative.
Comment by xutopia 4 hours ago
Comment by asdfsa32 4 hours ago
I have been writing frontends since early 2000. So I have seen it all, from activex being shinny to jquery, mootools, backbonejs, angular 1.0, php, Java Spring, Go. I looked into htmx and it is very much a second attempt at angular 1.0, which I did use for some good half decade as that was the best option at the time, but sooner or later, you get sick of stuffing "little codelets" inside attributes all over the place, which is exactly what htmx does.
If you want to understand what htmx is going to look like at scale, look at angular 1.0 projects.
Comment by xutopia 3 hours ago
Say you have a huge Google Ads budget burning up on those landing pages. Make one version with React and one with HTMX. Open Lighthouse and see performance difference. First page renders are much slower with React. Page load is slower and this makes a huge difference in mainland USA where people are still on 3G speeds on their budget phones.
"High traffic" might be the simplified view here and it took me a few page memos to explain it to my lead but the gist is that React is slower, takes longer to load and most of what it is used for is easily done with plain HTML and sprinkles of JS as needed. Unless you're streaming sound or video like you do on Facebook pages it's really not the right tool for the job in a majority of cases.
Comment by asdfsa32 3 hours ago
The gist of it continuously seems to be that people who think HTMX Great, know very little about good frontend engineering.
Comment by wild_egg 4 hours ago
The only thing the 2 have in common is the use of HTML attributes for functionality. Completely different on every other axis that matters.
Comment by asdfsa32 4 hours ago
Comment by wild_egg 2 hours ago
In another comment, you mentioned State Management. If this is on your mind then you are using htmx wrong. You should not be managing any client side state with htmx. State is on the server or in your database. Interactions on the client should immediately reflect the updated server state. If you have separate state on the client that needs to be managed, you are going to have a bad time regardless of framework.
Comment by officialchicken 4 hours ago
Comment by asdfsa32 4 hours ago
But I will answer your main questions since your comment seems to be in good faith.
Just like angular 1 choked on complex, high-frequency UIs, HTMX is going to follow the same faith. Github uses a similar approach to HTMX and you will find that even for such a simple system, their notification indicator elements on the same page are often out of sync.
The reasons for this is that State Management is hard, which is why the reconciliation loop of React-like frameworks and shadow-dom does away with pushing complex state management to user application and handles it systematically.
Of course, this doesn't mean htmx is useless, for a specific case of web apps, it is good enough, but the problem is that often times, you start with "specific cases" and your application grows overtime.
So when you consider that and the cost of doing htmx vs React or any react-like framework, picking htmx is only reasonable if it is the only option you're comfortable with and rarely on merit.
Comment by JSR_FDED 2 hours ago
Comment by ifwinterco 4 hours ago
If it's a traditional React SPA, you can use a versioned bundle with immutable caching and each user only has to download your bundle when you release an update or they use a new browser. You will need to think about how you handle spikes in traffic when you do a release, but even then users won't all load your page immediately after you bump the version.
Most of the time (existing user using the same browser, no update) there will be precisely zero traffic to your servers to load the React app except for the initial HTML skeleton.
For an app using SSR it's more complicated and I'll admit I don't know how that works at very high load
Comment by xutopia 3 hours ago
People weren't cancelling the page load and surfing back anymore. You cannot argue that React is extremely heavy and also adds a lot of time between first render. Test a normal HTMX page in Lighthouse and then convert it to React and you'll see how drastic things are.
People use React today out of habit rather than because it's the best tool for the job.
Comment by asdfsa32 3 hours ago
But while first render is of course important, now everything else is more expensive with htmx because you have to generate HTML on the server, on top of your usual fetch pipeline. Yes, for small traffic it makes little difference, but once you have >10k/s requests, things start to cost.
Comment by xutopia 3 hours ago
HTMX tools are simpler while providing straightforward thinking around html fragment caching, whole page caching. React just gives a runaround way of doing everything. I'll remind you React was built so that people could continue watching a streamed video while they navigated on a page. Most pages aren't streaming anything.
Comment by asdfsa32 3 hours ago
But for more details, see the sibling comment:
Comment by shooly 3 hours ago
What does React have to do with loading times of a page? React does not contribute to that at all other than having to download the JS runtime, which with Preact is 3KB.
> You cannot argue that React is extremely heavy and also adds a lot of time between first render
Yes you can! In no world would React itself add enough render time to make people navigate back, even if running on a computer from the 90s!
Comment by bcrosby95 4 hours ago
Comment by pelagicAustral 1 hour ago
steer clear.
Comment by dajonker 5 hours ago
Besides the memes, it is absolutely not hype-driven, but hypermedia driven. It asks the question: could HTML be even more powerful than it already is?
The creators of HTMX even want to standardize core ideas of HTMX into the official HTML specification: https://triptychproject.org/ Please read this and reply when you still think it's hype.
Comment by asdfsa32 4 hours ago
Hypermedia is what to web apps what XML is to programming languages. We have tried HTMX as a concept many times over, there is nothing new here, and like everything declarative, sooner or later it will fall short and you're going to reach for escape hatches and what not.
And the features specified in that project is nice to have, in the same way that it is nice that we have Date Pickers or other advanced input features, but it is never going to replace React-like frameworks.
Again, the reason we have finally stabilised on JSX is because you can't really "Declare" away HTML or sophisticated data and event management, Google really really tried that with Angular 1.0, and we know it doesn't scale.
Comment by monooso 4 hours ago
I have no idea what this means. The World Wide Web itself is quite literally hypermedia.
The fact that a lot of front-end frameworks appear hell bent on ignoring this fact doesn't make it any less true.
> Again, the reason we have finally stabilised on JSX is because you can't really "Declare" away HTML or sophisticated data and event management...
You may have stabilised on JSX, "we" have not. React is one way of building web applications. It's appropriate for a certain subset of highly interactive SPAs, and completely inappropriate for many other things.
Comment by jfengel 1 hour ago
I think he's saying that the Web is hypermedia plus Javascript, rather than just hypermedia. Which means, from the standpoint of the power of hierarchy, that it's Javascript, which also happens to use some hypermedia. Even if you use only a tiny bit of a Turing-complete language, Turing-completeness defines what your system actually can do.
This makes the Web fundamentally awkward, because most of the behavior is defined by the hypermedia part, and users have inconsistent expectations for what happens when you break the illusion.
HTMX works by extending the illusion. JSX works by breaking the illusion earlier rather than later.
Comment by asdfsa32 3 hours ago
Just about any reputable sources puts the combined market share of React, Vue, Angular 2+, and Solid well above 80%.
So I am not sure what "we" you are talking about.
Comment by monooso 1 hour ago
I have no idea if that's accurate, but let's assume for a moment that it is.
- Vue supports JSX, but it is not the default.
- Angular does not support JSX.
- Svelte, which you neglected to mention, does not support JSX.
- Solid does indeed use JSX, as of course does React.
So two out of the five main SPA frameworks don't even support JSX, and another doesn't typically use it.
As I said, you may have stabilised on JSX, "we" have not.
Comment by asdfsa32 3 hours ago
Comment by robertoandred 1 hour ago