News for hackers. Stuff that matters.
Re:Common Beginner Mistakes with React by nine_k on Sunday March 12, 2023 @12:30AM (#35117000)
The usual problem is that people often pick an SPA tool for a job that a CGI script can handle. The fashion made "web UI" and "react" associated too strongly.

Much simpler tools can work if you allow for less fluid interfaces, and this may be a non-issues for a tool running on a LAN.

Re:Common Beginner Mistakes with React by otabdeveloper4 on Sunday March 12, 2023 @01:35AM (#35117406)
> less fluid

We're never replacing our old-style PHP internal tools, because according to business users it's "instantaneous", and any attempts to use a more SPA approach cause complaints about "sluggishness".

Re:Common Beginner Mistakes with React by eastbound on Sunday March 12, 2023 @03:58AM (#35117849)
Once the CGI page loads, all info is in there. React requires 1 request for the basic HTML, (1 request for the JS but it’s generally cached) and 1 request for the data from the REST API. It’s double the time to load a page.

React apps constantly have gray placeholders waiting for data to finish loading. Contrary to initial experiments, progressive rendering is recorded by the brain as a bad experience.

Re:Common Beginner Mistakes with React by zarzavat on Sunday March 12, 2023 @06:33AM (#35118536)
React is simply a library that renders your UI to the DOM. It doesn’t have any opinions on how your data is fetched, or how many roundtrips it takes. That’s an orthogonal concern. People have been using XMLHTTPRequest with CGI since the 00s, way before React was a twinkle in Zuck’s retinal sensors.

You can send your initial data for React with the HTML response if you want to eliminate the extra round trip on startup. Depending on the geographical distribution of your users it may or may not be worth it.

Re:Common Beginner Mistakes with React by robertoandred on Sunday March 12, 2023 @10:35PM (#35130199)
So just render the React page on the server and hydrate the markup after the page loads.
Re:Common Beginner Mistakes with React by terandle on Tuesday March 14, 2023 @03:16AM (#35148294)
React's new server components (only in next 13 at the moment, coming soon to other framework) addresses this problem. Of course react and node both have performance work they need to do also.
Re:Common Beginner Mistakes with React by pwdisswordfishc on Sunday March 12, 2023 @05:23AM (#35118243)
This but unironically.
Re:Common Beginner Mistakes with React by samwillis on Sunday March 12, 2023 @05:44AM (#35118320)
I have just spent the last year doing the literal opposite.

15 year old software product built on Perl CGI with a server rendered html+jQuery front end. Massively grown past the point where that is suitable, with plans to add interactive features that would be crazy to do with the old architecture. Have moved the whole thing to a VueJS frontend. We have kept the old Perl CGI server architecture, just refactored it to return JSON.

You are complete right, to many people chose a tool based on fashion. There are two main things to consider when picking a toolkit or architecture for a web app/site:

- what do my team and myself know well, what will be the most efficient?

- where is the state? Is it predominantly in a database on the server or client side in the browser?

The project I'm on when they first asked those questions, the answer was, Perl CGI and server side state in a database. That is no longer the case for the second question, the state is increasing moving to the client side, and that's why I joined the team.

If I was answering the second question as server side right now I would probably pick htmx+alpinejs.

However, sometimes the first question overrules the second.

(There is a third question, do you need an installable app too? In which case a SPA with a toolkit that supports PWAs or web view wrappers is a good option if you want to only have a single codebase)

Re:Common Beginner Mistakes with React by amelius on Sunday March 12, 2023 @09:08AM (#35119633)
So to go back to the driving/walking analogy, what you're saying is to work from home instead.