News for hackers. Stuff that matters.
Re:React 19 by keb_ on Thursday December 05, 2024 @02:42PM (#42331848)
Yes. Something HTMX evangelists always forget to mention is that HTMX is not a replacement for React -- HTMX + a backend is. This introduces a whole new layer of complexity; it's a total tradeoff. That is to say there are probably React apps that would be better as HTMX apps.
Re:React 19 by exceptione on Thursday December 05, 2024 @03:14PM (#42332239)
Also, does that currently mean that the backend will be Javascript?

In the browser we have no choice, but I prefer to prevent that accident from spreading to my servers.

Re:React 19 by keb_ on Thursday December 05, 2024 @03:26PM (#42332362)
No. Backend can be anything.
Re:React 19 by thunky on Thursday December 05, 2024 @05:56PM (#42333789)
> HTMX is not a replacement for React -- HTMX + a backend is

Most React apps need a backend too.

Re:React 19 by lyu07282 on Thursday December 05, 2024 @06:46PM (#42334197)
Wouldn't the equivalent be more like server components in react? Or do people literally let their backend render presentational html (including tailwind css or whatever)? Like do htmlx people render html from database resultsets in their backends?
Re:React 19 by poncho_romero on Thursday December 05, 2024 @06:56PM (#42334279)
Why is it surprising that a backend returns HTML when it receives an HTTP request? That is the web
Re:React 19 by lyu07282 on Thursday December 05, 2024 @07:07PM (#42334354)
> Why is it surprising that a backend returns HTML when it receives an HTTP request? That is the web

We did that for a long time with Perl/PHP/ASP/JSP

I wonder why we stopped doing that? I'll just wait a few decades of your FE with this until you figure it out scnr

Re:React 19 by poncho_romero on Thursday December 05, 2024 @07:15PM (#42334421)
I don't understand what you are trying to say here. Serving HTML directly from the backend works wonderfully for almost all websites and web apps. The growing popularity of solutions like HTMX, Hotwire, and Phoenix LiveView is proof that React is not the panacea that was promised. Why prepare JSON on the backend, send it over the wire, and have the frontend transform that data into HTML when the backend could just send HTML in the first place?
Re:React 19 by least on Friday December 06, 2024 @12:40AM (#42336717)
> The growing popularity of solutions like HTMX, Hotwire, and Phoenix LiveView is proof that React is not the panacea that was promised.

Does it? To me, it seems more proof that software development trends are cyclical. It's also just not all that apparent that things like HTMX are all that popular. React is much more popular than any of them, and then JQuery remains even more popular than React, at least in terms of finding it on the web.

Working with XHR sending full HTML responses, it's pretty clear to me that there's some major tradeoffs to this approach. The payload sizes are larger and interactivity is dependent on round trips to the server. so you're increasing server load and are increasing payload sizes to save on client side processing.

If your views are data driven, then there's plenty of cases where you may want to have interactivity. filtering or sorting results, for example. So you click a column header, then you're sending another request to the server, asking for a new table with the newly sorted rows, it renders it, sends it back to the client, and then replaced the entirety of the table contents with the new contents. and then htmx does some magic to make it behave closer to native HTML (like enabling css transitions on replaced elements, for example).

Storing the state client side, you can perform a lot of these transformations without talking to the server again until you want to actually change data.

I'm all for sending plain html from the server. If your views are static and largely unchanging, then sure, by all means, send it over. You don't need a JSON response to render a blog post on the frontend. But as soon as you want any sort of interactivity in your forms or data views, then you probably don't want to make every interaction a round trip to the server and then you're back at having to think about state on the client, at which point objects in JS are just going to facilitate your needs better than html elements.

Re:React 19 by thunky on Friday December 06, 2024 @09:22AM (#42340062)
> If your views are data driven, then there's plenty of cases where you may want to have interactivity. filtering or sorting results

> Storing the state client side, you can perform a lot of these transformations without talking to the server again until you want to actually change data.

Only if you're only working with a tiny amount of data...

For example, say you have a dataset with 10k records. You're not going to want to send that all to the client so it can sort it locally. Much more efficient to send just the first 100 or whatever results. Then when the user clicks the sort button, ask the backend to re-sort it and give you the first 100 results again.

Bonus: those 100 results are already formatted as html table rows and htmx easily slots them right into the correct spot on the page.

Re:React 19 by least on Friday December 06, 2024 @10:55AM (#42340903)
It depends on the sort of data you're looking at, but definitely agree that you will need to hit the server sometimes, depending on the number of records you're looking at. Though even 10k row dataset can actually be handled quite easily with modest computers/phones. I'm not saying you should be doing that, but that would have more to do with usability than the client not being able to handle it.

But even with a modest 100 rows being retrieved, the payload size of fully rendered HTML is generally going to be substantially larger than JSON. These add up quickly when you're making round trip requests to the server for interactivity, especially if it's something like reordering tables.

This is a clear tradeoff and it's why we see trends like this oscillate between client-side and server-side.

I think React is seeing the downsides of being entirely client-side, which is why there's so much development into server side components. Conversely, things like HTMX are tackling problems of handling local state, client/server side caching, and well, payload sizes.

Re:React 19 by thunky on Friday December 06, 2024 @11:39AM (#42341322)
That's true but if you're concerned about payload sizes then 10k records is way too much to pre-send, and in general I think it's safer to depend on the server sending a known max size of html than it is to pre-send all the json every time.

Unless you're using tailwind or some other variation of inline styles, I don't think a typical formatted <tr> is going to be much bigger than a json record anyway. It might even be smaller if the json includes extra attributes that don't make it out to the html.

But I agree that if you know you have a tiny amount of data and you don't want to involve a server then it would be better to do the entire interaction client side. But nothing prevents you from plugging in a small client side lib (not react) and using server-side for everything you can.

Re:React 19 by yawaramin on Friday December 06, 2024 @06:19PM (#42345659)
> the payload size of fully rendered HTML is generally going to be substantially larger than JSON.

Substantially larger? No, I don't think so. Maybe slightly larger, but if you are compressing your responses (a best practice), there should not be a significant difference between them. And, while in a theoretical perfect world you send exactly the JSON needed for each response, in real-world conditions JSON APIs are quite often overfetching and making too many calls in the first place. Evidence: just look at any typical React-based webapp accessible to the public.

Meanwhile with htmx you can render and send the exact HTML you need for the response, and any overfetching is immediately obvious because it's all shown on the page.

Re:React 19 by least on Sunday December 08, 2024 @11:58AM (#42358215)
> No, I don't think so. Maybe slightly larger, but if you are compressing your responses (a best practice), there should not be a significant difference between them.

Are we talking about this in an absolute sense? because an html payload whether you compress it or not is generally going to be larger. It obviously depends on what your html looks like, but even if you only are using minimal class names and aria properties, it's still going to be larger than JSON in almost all cases. As in conservatively 50% larger but realistically even more than that, just based on admittedly rudimentary experiments. That's after minification/gzipping and tabulated data is best case scenario for HTML with the small element names (tr, td).

Does that actually matter? Maybe, maybe not. As you said, plenty of real world cases of JSON APIs that are sending excessive data or making calls to the server too much.

...but with things like HTMX, you're either hitting the server or you're using client-side processing of some sort (at which point we're back at why aren't we using something that effectively handles other frontend problems?). I also still think there's rather large downsides to having part of your frontend being handled by the responses from the backend, even if you're using only using full stack developers.

Re:React 19 by yawaramin on Sunday December 08, 2024 @01:30PM (#42359025)
Re:React 19 by keb_ on Sunday December 08, 2024 @07:19PM (#42361952)
False equivalence, and a disingenous one at that.

You can build single-page applications with React, you cannot with HTMX.

Re:React 19 by thunky on Monday December 09, 2024 @08:53AM (#42366286)
> You can build single-page applications with React, you cannot with HTMX.

Irrelevant to the conversation.

GP said:

HTMX is not a replacement for React -- HTMX + a backend is

So if you think that's not true because React can build SPAs and HTMX cannot, take it up with them (maybe you replied to the wrong comment?).

Re:React 19 by keb_ on Tuesday December 10, 2024 @12:36PM (#42379057)
GP was from me :)

You stated: "Most React apps need a backend too."

But in reality this is irrelevant to the conversation, because the top post was asking if comparing HTMX to React is like apples to oranges, which it is, because both tools accomplish different things with completely different feature-sets.

A good example of this is the implementation of TodoMVC. [1] React's implementation can live completely in the browser, and even be stateful. [2] An implementation with HTMX requires a server to handle templating/rendering. [3]

[1] https://todomvc.com/

[2] https://github.com/tastejs/todomvc/tree/master/examples/reac...

[3] https://github.com/rajasegar/todomvc-htmx

Re:React 19 by recursivedoubts on Tuesday December 10, 2024 @01:07PM (#42379432)
the vast majority of (non-native) react applications require a back-end, at the very least to deliver them to users

htmx-powered applications can be local-only via service workers[1]

i think there is a sense in which htmx vs. react is apples to apples, in that in the common case they are used to build web applications that talk in some manner to a back-end system. On the other hand, it is true that react does require additional support code in order to do that communication.

Regardless of that latter fact, and the fact that htmx does not require a server, there is a large overlap in practical applications that might be built with either, so it is good to know the strengths and weaknesses of both for comparison.

[1] - https://developer.mozilla.org/en-US/docs/Web/API/Service_Wor...

Re:React 19 by keb_ on Tuesday December 10, 2024 @01:26PM (#42379672)
> the vast majority of (non-native) react applications require a back-end, at the very least to deliver them to users

I mean, I guess if you consider me opening an index.html file in my browser requiring a backend in that my desktop operating system is the "backend server", then yes, but that's not what I was referring to. I don't think most folks would consider a CDN to serve static assets to mean "your React app requires a backend" in the traditional sense -- but that's a game of semantics.

> htmx-powered applications can be local-only via service workers

Do you have any examples of an HTMX app running completely client-side using service workers? Funny enough, the only example I found online ends up using Preact to render templates in the SW, but as a whole, this looks less ergonomic than simply using <insert JS library here> to build a SPA: https://joshi.monster/posts/serverless-htmx/

> there is a large overlap in practical applications that might be built with either, so it is good to know the strengths and weaknesses of both for comparison.

I could agree with this. I only care that people understand there are tradeoffs.