by tored · 5y ago · 0 comments
I do understand the need for React when building truly complex applications, like a spreadsheet or word processor app, but I wouldn't be surprised if the majority of projects using React could be solved with a simple template rendered in the backend.
For one of my clients projects it started out in what seemed like a simple crud app and so I did the few reactive changes in pure java script. The thing is: requirements changed and now after a while I couldn't get around adding VueJS simply because the reactive changes kept piling up.
Even though the HN sentiment seems to be that all "modern" frameworks are just huge piles of code that you add to your project without understanding how any of this works, my personal opinion is that using something like nextjs with server side rendering is not all that different from using a server side php framework like laravel. You still generate the same html unless you need reactive changes and when you do, you are happy to have chosen that. And to play a bit the devil's advocate: Unless you write your own webserver and template rendering engine you are already using a bunch of code you don't really understand.
By putting 20% the effort we put nowadays with these big frameworks into well organized "sprinkles" it is a very viable alternatives. Tools such as Stimulus, unpoly, htmx,etc make this very approachable and maintainable.
To me, SPAs only make sense in two scenarios: 1) You have the requirement for the app to work offline, or on really bad network connections (subway, etc) or 2) You already have a team which only wants to do SPAs and everything else is uncool to them.
Just fetch the pre-rendered HTML fragment and put into the page. Done.
And the good thing is that you can render a server side component either as part of a full page load or separately for a dynamic update.
But if you have decided to do frontend rendered templates, then I agree, pick one of the popular frameworks from the start of the project.
Vue is IMHO a better pick than React, Vue has better ergonomics and is just better how everything is tied together. Vue is a well designed framework.
I am not sure about that. Look at Google. For their truly complex applications like a spreadsheet or word processor (Google docs) they seem to have given up on the DOM altogether and are reimplementing the whole UI in HTML5 canvas.
> I wouldn't be surprised if the majority of projects using React could be solved with a simple template rendered in the backend
Yes, Google and the rest of the folks who are pushing for web components believe they can be.
> solved with a simple template rendered in the backend
Or a simple template rendered in the frontend, see this demo, where no huge libs are used. Instead a 200-line lib is used to get the equivalent of stateless React components: https://github.com/wisercoder/eureka
But here I am at work, doing CRUD forms with rxjs, epics, redux, websockets and a shitton of home made packages for doing validation, lazy translations, mixing microfrontends, etc, etc.
Server Side Events (SSE) is better option to websockets IMHO, it is a much simpler protocol so you can implement in any backend of choice with a few lines because it just a HTTP request that is kept open for a longer period of time.
Websockets are bidirectional whereas SSE are unidirectional, but you rarely need the client to push huge data sets to the server.
And if you already have endpoints for fetching HTML fragments for rendering a components, SSE fits well as enhancement into that architecture to get a more live experience.
e.g.
model update in backend -> notify frontend with SSE that model changed -> component that renders model fetches new HTML fragment over HTTP.
This makes the messages over SSE tiny, only need to say that a model changed, not the entire model data. This means that you can turn off SSE and the applications still works, just without live updates thru push, e.g switch to timer based solution instead.
What is also nice by fetching HTML fragments over HTTP is that you use cache headers, if you already have the latest fragment that is just a 304 Not modified.
I think that SSR with dynamic updates of HTML fragments closer respects how the web was intended.
Also, it make task splitting between frontend and backend engineer that much more easier.
The need to separate the team into frontend & backend engineers is a direct consequence of the over complicated frontend frameworks.
That is another tragedy of this heavy frontend trend. We are undermining the team’s performance and makes it harder to finish deadlines.
Usually what happens is that the frontend & backend engineers get out of sync and starts working on other things until they can sync again.
When this happens too often there is push to put the backend and the frontend in different teams.
After the split the teams start evolving separate cultures and mindset how to solve things and soon enough both teams has their own build and deploy pipes.
Eventually the teams no longer feel that they share a mutual idea of common ownership and the project stagnates.
If we keep things nice & simple we can work as fullstack engineers together as a team.