React is Dead, Long live Reactive Rails
medium.com
medium.com
Since writing the blog post I found out that there's another competing framework that might realize the design goals I'm describing in succint, self-contained fashion:
I have no idea.
> Maybe I am doing something wrong?
You are doing nothing wrong.
Resume driven development is a real problem in our industry.
- Why should only anchors and forms be able to make HTTP requests?
- Why should only click and submit events trigger them?
- Why should only GETs and sometimes POSTs be available?
- Why should you have to replace the entire screen every time?
htmx tries to complete HTML as a hypertext, removing each of these limitations, so you can write advanced interfaces using plain ol' markup:
Can't help but wonder how much cooler it would be if only the attributes were not hx- namespaced. Is that not done for some technical reason?
I could make it pluggable so you could do away with the hx- if you wanted to. Most people want to go the other way and use data- prefixes (which is supported out of the box)
Half of the webapps I make are just digitalizing existing paper forms. There is barely any javascript but the javascript that is there is absolutely essential. If the noscript warriors actually thought about ways of making plain HTML good enough that a JS free site was possible then I'd have sympathy for them. As it is right now they are asking the impossible. They would even complain about htmx even though it is exactly what they want.
Examples like https://htmx.org/events/#htmx:validation:validate also seem weird. Basically it replaces JS with it's own scripting dialect that is written inline in a attribute and that dialect does not even have syntax highlighting on their own site.
Is it actually more simple than writing the equivalent html+js when you add on all the real-world requirements?
https://htmx.org/examples/inline-validation/
It's the normal web 1.0 thing: validate your data server side and render an error message/flagged input which is returned as html.
The latest dev version plugs into the HTML5 validation API so that client side validations are respected, but that doesn't require any scripting.
Htmx does fire a lot of events that you can hook into if you wish, and hyperscript is an experimental mechanism for doing so, but neither are the focus or a requirement for using htmx.
From experience, yes, it is much simpler than the javascript-framework based approach, at least for many use cases.
I usually try to avoid 500 and 400 errors in my applications, but for something like a network error, that obviously has to be handled client-side since, well, the server isn't available.
So you can write a three liner to handle it:
htmx.on("htmx:onLoadError", function(evt) {
htmx.find("#error-div").innerHTML = "A network error occured..."; // or whatever
}
This isn't code that would be hit regularly, unless your application or the network is in pretty bad shape.I got sucked into RJS, Turbolinks, Sprockets, and several other "cool" frontend technologies coming out of the Rails world that made my life miserable until I finally dropped them. Developer beware
It's also not mutually exclusive. You can totally leverage React components when Stimulus Reflex isn't enough.
Excited about the technology though, thanks for sharing!
> there is absolutely no technical need for Rails developers to use React anymore
The article is about React on top of Rails, not React in general. Leaving that out of the title makes this just clickbait.
For those truly complex UI logic cases, React components are still a tool you can use. The approaches aren't mutually exclusive.
I think of it this way, would you stream pre-rendered markup to a native iOS, Android, or Windows app? The thought of it is crazy, who would ever do that.
I think most people agree that the web is getting closer to native all the time. I think we're reaching the pivot where you're better off using React and co for any kind of interactivity. Page reloads are already used in media to portray slow/old websites. I don't see that getting better
How does it handle connectivity problems in the SPA? Not that react does this out of the box - just wondering if there is some advantage to how the Reflexes do it.
Also the names of ruby libs are hilarious. CableReady, ActionCable, TurboLinks, and StimulusReflex.
Not that "redux" or "thunk" much better.
One of the issues I find with Rails is that the 'old-way' of views, partials and a sprinkling of React is INSANELY productive. I've been trying hard to justify getting into Stimulus properly.
DHH is on a four-month sabbatical at the moment and my hope is that he's working on open-sourcing the framework behind hey.com, which Basecamp are calling 'new magic'[0]
There's something coming around object-oriented view components and client-size JS. I'm just not quite sure the perfect recipe has been found yet.
I suspect that the framework DHH comes up with will be very similar to Stimulus Reflex, or they may even roll that project into Rails/Stimulus.