by nemothekid · 5y ago · 0 comments
React is great for SPAs. Most large companies are working on honest-to-god SPAs. By extension most engineers are working on SPAs. So most tooling is created for SPAs. Now if you aren't building an SPA you look around and find almost every resource is around building an SPA. Even if you know you don't need an SPA, it's easier to hire, iterate, and even use other open source solutions if you are building an SPA, so you try to hamfist your project into an SPA.
It's a bit like having a bike commute in America. A bike might be the best thing for you to do - cheaper than a car, keeps you healthy and you don't need a garage. But you quickly find that everything is built for cars and it's easier to deal with the disadvantages of a car than try to commute with a bike.
I remember thinking the same thing about Hadoop 5-6 years ago. If you had "small data" you could get what you wanted with SQL and fast disks. But everything else assumed you were on Hadoop. Newgrads were trained in hadoop. New tools were Hadoop first. New research was all hadoop. If you hit a small issue with your DB, almost every solution would be "this is how it's solved in Hadoop". It was hard to even know if what you were trying to do what even possible without Hadoop.
The only optimism I have is that maybe in 5 years we will all collectively wake up and stop trying to shove React everywhere just like we stopped with Hadoop.
Most devs don't work at large companies, at least not tech oriented large companies. I'm almost certain most projects don't come out from such companies either, statistically.
In fact, most projects are not SPA, nor using any kind of AI, Big Data, or another buzzword.
So I don't think that's it.
I think that large companies are just the loudest, also creating/promoting popular FOSS projects, and they have great engineers that are on many social networkd, including HN, or write famous blogs.
And so people have the impression that you need an SPA into a docker mix among other microservices each horizontally scaled in the cloud, monitored using an observability framework, using a big data pipeline for processing things they will store in their NoSQL sharded DB accessible through a GraphQL Api.
Because Jack working at GAFAM for $500k has the time, env and will to sing about it, but Juan working in a Madrid bank is just spending his company time fixing the Tomcat server quietly.
that would be very surprising. Companies like IBM, Microsoft, ATOS, CapGemini ... employ literally hundreds of thousands of devs each
On the other side, the long tail of devs working in medium and small companies are probably working on both a frontend and a backend. This is especially true when there are one or two developers in all the company, when the company business is selling some service or physical product and software is a cost and not the source of income. And a medium company in the USA is a large one in many countries, a small one a medium one.
So the sum of devs in the long tail can be much larger than the sum of the devs in the top companies.
Seriously, what is there? Microsoft doesn't even have a clear direction for desktop apps - their most recent stuff like VS Code and Teams are built on Electron.
We recently rewrote our tutorials from scratch [2], and offer an opinionated set of guidelines on how to write Redux code effectively [3], such as "put all Redux logic for one feature in a single file", "use feature folders", and "prefer putting logic in reducers".
We also now recommend some TypeScript usage patterns [4] that simplify the amount of types you have to write.
Finally, we are about to release a new "RTK Query" data fetching layer that will be in the upcoming RTK 1.6 release [5]. It's in beta now [6], and we're just polishing the docs before it goes live.
Hopefully this will help you and anyone else who's using Redux!
[0] https://redux.js.org/tutorials/essentials/part-2-app-structu...
[1] https://react-redux.js.org/api/hooks
[2] https://redux.js.org/tutorials/index
[3] https://redux.js.org/style-guide/style-guide
[4] https://redux.js.org/recipes/usage-with-typescript
[5] https://deploy-preview-1016--redux-starter-kit-docs.netlify....
[6] https://github.com/reduxjs/redux-toolkit/releases/tag/v1.6.0...
Yeah, one of the reasons we recommend the hooks API as the default _is_ because it's so much easier to use with TS. It's _possible_ to use `connect` with TS, but the typing overloads are a complete pain to work with. Fortunately, `useSelector` is just a simple function call, and `useDispatch` just gives you the `dispatch` method itself. Less abstraction, easier to type correctly, and easier to use.
For the parts it doesn't match, truly global stuff or tonnes of mutation, MobX is nicer out of the box than Redux. Redux can be just as nice and in some ways more powerful, but thats only after installing and configuring X amount of middlewares, with all the type confusion that can add :(
It's also worth noting that there are some significant difference between `useReducer+useContext` and Redux. Not saying those are bad and that you should avoid them : ) just that it's important to understand the intended use cases and technical behavior differences [2].
[0] https://redux.js.org/tutorials/fundamentals/part-8-modern-re...
[1] https://redux.js.org/recipes/usage-with-typescript
[2] https://blog.isquaredsoftware.com/2021/01/context-redux-diff...
I’m glad to hear the Typescript inference issues I ran into a year, year and a half ago are solved. That wasn’t Redux’s fault per se, but composing middleware in such a way that the types flowed through correctly was such a hassle previously. Nice to hear it’s better now
WPF (and whatever they've taken to calling the UWP version of it now) is a little more modern, and it's what I was initially leaning towards, but also doesn't seem to be moving much and it feels like the future is very unclear, while even MS themselves have started putting out Electron apps. It really doesn't breed confidence.
WinUI is the future, but they’ve admitted it will be years before it reaches the maturity of UWP, which is embarrassingly bad even 5 years on.
WPF, in my opinion, is the best choice for “native” windows apps. The actual best choice is Electron, as most teams doing new work at MS have noticed.
WPF, for native, hits the sweet spot of supporting newer technology (high DPI), having decent performance, and being well implemented; it has been solid for at least 10 years now. Also easy to style and theme, similar in concept to web, but just more annoying.
The future could be MAUI though; and it is around the corner
Myself, I'd just build some command line script that hit up a database and pipe data to build a GNUPlot script and just generate a PDF report. That seems to be the best way to hook into a well maintained GUI project. It isn't sexy, but it's dead simple, should last forever, and be very simple to port to a different OS or language in a single afternoon.
WinForms is alive. And will be for some time.
Take a look at Sciter [1]. You build your UI using HTML/CSS/JavaScript, and your application logic in any language with a C FFI [2], and it supports Windows, Linux, Mac OS, and Android. The distribution size is tiny: only a single dynamic library of around 10 MiB. It's not open source, though.
[2] Available bindings, apart from C and C++: https://sciter.com/developers/sciter-sdk-bindings/
The focus and revenue is from cloud now, since MS has comparatively little hardware or advertising profits.
Develop desktop apps in something focused on it, such as QT. Flutter may mature.
React is actually great at embedding individual interactive components on a static HTML page (like an interactive chart or table component, or even a fancy button). You can go a long way just having your Rails app render a navigation menu and application shell, and each page just loads a big React component in the main content section. Great!
But then you need to update a little bit of that application shell in response to a visitor interaction or some newly-fetched data. Maybe one of your menu links needs a little red number next to it to indicate the number of unread messages. Still easy, with JQuery or whatever DOM manipulation library you're using. But then when the visitor clicks on one MessageRow component in your big MessageList React component and reads the message. The unread count didn't change! That's still easy to fix though. But pretty soon you're writing a lot of manual DOM manipulation code to sync every bit of data bidirectionally between every source of mutation and every UI element that depends on that bit of data. You'd be better off with an SPA, or at least with having React grow to own a little bit more of your application shell!
Where this line gets drawn is tricky, and I don't think the conclusion is "always use an SPA framework from the beginning of every web site project." But I do think the options to conveniently and maintainably use SPA frameworks to render traditional HTML pages on the server are improving a lot more than the options to gradually introduce whole-page-level interactivity to traditional server-rendered HTML frameworks.
I've been building web-related things since 1998, and IME NextJS has the best DX and most flexibility of any framework I've encountered.
Portals are awesome for use cases where you're sprinkling dynamic bits into an SSR'd shell. And for all parts of your app that don't need that level of interactivity, you've got plain old templates in your server side language of choice.
There's some limits to this but it's a neat trick.
Due to missing leadership and absent mentorship many developers are hoping tools provide the guidance they need.
A non-trivial number of technical solutions turn out to be half-measures for unsolved social problems.
Some calculations are less heavy on the client side. It's not building the html itself once you know what you need that is heavy, it's that awful dropdown menu with dozens of nested filters that rely on user-input data which is awful to build serverside, but incredibly easy to build client side.
Except you will anyway, to do all those API queries you need to fill the page. That involves multiple handshakes back the server, and yet more server-side resources tied up.
> or you're offloading large per-user objects to the client
This access happens either way, and will be discarded in short order by any cache, even using the most naive LRU policy.
BitBucket and Jira have gotten so much worse since they moved to React. With all my computers resources at its disposal, it takes longer now to load a single jira ticket than it did when it was all handled server side 10 years ago. If you look at the chrome debugger, its no wonder why. React fans can stand back, cross their arms, and explain about how atlassian must be doing it the wrong way, but it seems pretty consistent behavior across many react apps.
I'd like to see some analysis on that. I'm assuming if you're building an SPA or any kind of app, many of your visitors and clicks are repeat visitors and won't have to download that bundle... probably once a day, M-Th assuming daily release schedule w/ lets-not-break-it-before-the-weekend policy.
I think all that client-side caching would outweigh the cost of the initial bloated bundle.
I think this isn't a guarantee and depends on what kind of application you're trying to build. A DMV website is (hopefully?) not going to have many users returning every day or even every week or month. If it's not social media or gaming, it's probably not going to have any sort of consistent userbase, so most visitors are not going to benefit from client side caching.
> You think heavy HTML responses are cheaper than one extra-heavy initial JS request?
If we assume "cheap" means cost-wise here, almost certainly. Consider a search engine like Google. If you are generating HTML server side (ex. PHP), the row count is limited by whatever you assume the user's screen resolution will be. That means a few hundred results returned at most, since no user is going to scroll through thousands of results on the same screen. So you perform a DB query and generate the HTML for a hundred rows or so and return it, job done.
Now consider the JS equivalent: the user downloads up to a megabyte of bundled JS. Then, the JS has to perform a fetch call to some API which probably returns the rows in JSON. At last, the client side JS iterates over the JSON and generates some new DOM elements for each row. Job done.
In the JS example, the user's browser had to download the bundle and the API response in order to render the rows, while the PHP example only queried the DB in order to render them. You might think, well the PHP way still uses up bandwidth to get results from the database right? Which is technically true, but pricing wise your database is most likely in the same data center as your web server so you're not paying anything for that bandwidth (since it's going over a physical direct connection cable instead of the Internet proper). Whereas the user is 100% not going to be in the same data center as your API server, so you're going to get whacked with bandwidth charges wherever your API is hosted on top of serving the JS bundle.
Of course, for the majority of people we're talking about pennies here. It really doesn't matter until you start getting more than 1 request per second, at which point every hour of every day of every month of every year is going to compound your bandwidth pricing problem until you figure out a way to slim down your payloads. Or, just do what most news sites do and keep adding third party advertiser JS until your ad profits outweigh your bandwidth expenses. Lots of options in this brave new frontier!
See 1MB club: https://1mb.club/
For the client the experience is worse and the cost is higher, so it's definitely a worse solution. SPAs really only make sense when you have a mostly offline application, which is just a very tiny bit of websites out there.
It's very deliberate. It's even what is taught in colleges.
I've had debates with recent graduates who believe the proper way to build anything from a web site to an app is to offload as much of it as possible on the client. If the client doesn't have the latest gear? Too bad. They're an "edge case" and shouldn't be allowed to be on the internet. Go curl up in a corner and die, you old and poor people.
The tech world would be an entirely different world if ethics were part of the required curriculum.
You don't offload things to the client in order to save money. You offload things when it will improve performance. Most of the processing power and bandwidth will still be incurred by the server, just at a different time in the lifecycle of the app.
That's still saving money in disguise.
I see this a lot. Especially with languages - of course I would love to write a big app in Haskell, but the tooling for Java / JavaScript / C# is just so much better (before Swift / Kotlin it was so much worse).
And what is happening with React is just like what happened with those languages: all of the big drawbacks are getting their workarounds. Bundle splitting and server-side rendering address large bundles and long load times, as the author mentions. Of course they have their own issues, but as time goes on I'm sure more workarounds will be created.
I wouldn't be surprised if in the next 5 years, React's drawbacks don't fully go away, but they're a lot less. Although I'd rather like React gone too, personally I really don't like using it.
firefox "https://en.wikipedia.org/w/index.php?limit=500&profile=all&search=spa"
At the top is the link to the Disambiguation.https://en.wikipedia.org/wiki/Spa_(disambiguation)
A more specific search, e.g., "single page", will not redirect.
In some ways, for discovery, Wikipedia's search engine is better than Google's. For one, it is non-commercial and does serve ads based on past surveillance of the user's activity. Second, the user can retrieve larger numbers of results and page through them quickly without triggering a (false positive?) defensive measure than temporarily blocks her IP address from retrieving results for a defined period. Third, it is curated to remove commercial content rather than curated to further a business purpose in online advertising.
No wonder Google steals Wikipedia content for "instant answers" or whatever they call it. Wikipedia search works quite well.
https://en.wikipedia.org/wiki/Spa_(disambiguation)
In that sense Wikipedia is a bit like Google in that they try to guess what the user is searching for, perhaps what is most popular. Thus, a search for "SPA" automatically redirects to the article on Spa as in therapeutic water treatment. A link to the Disambiguation page, if it exists, will always be provided (cf. "Did you mean ....").
However, change the search string "spa" to something more specific and then see all the search results.
For example:
https://en.wikipedia.org/w/index.php?limit=500&profile=all&s...
Increase limit= to a number greater 500 if desired, or smaller if want to speed up the search.
Some of you might want to read the excellent book that introduced the concept - https://equilibriabook.com/
The hadoop thing is so unusual, really strange. I'm fairly certain, to very certain, that Sql is the industry standard while hadoop is a small corner of the mindshare.
Perhaps it's time to widen your sources, and e.g. cycle through different browsers to reduce search profiling.
The moment you need to integrate it with server side validations, authentication, add a database, migrations, background jobs, etc. it becomes a mess. In fact, a custom undocumented mess.
Just like finding beer money by making a youtube channel on trendy topic.. the short term effort/reward is higher than doing quality stuff (or even finding a better job, which can be hell) and this web being the trend, everybody will be nice to you if you want to make a youtube channel..
Reminds me of a job about four years ago: New hire, right out of college, "I studied Java". Surprise! Your team is PHP! Now learn that without any help from your team leader or we're gonna fire you. And they did. Poor kid.