News for hackers. Stuff that matters.
Re:New React DevTools by mosselman on Friday August 16, 2019 @03:24AM (#20712887)
One of the downsides, depending on implementation mostly of course, that you still need JS to render your component. I prefer server-side rendered HTML over both React and web components because of the compatibility.

After showing the HTML you can still make elements more interactive with things like jQuery, Stimulus or Freudjs (disclaimer: my own)

Re:New React DevTools by ivanhoe on Friday August 16, 2019 @07:48AM (#20714166)
It's great to a point, but when front grows complex enough you sooner or later realize you're repeating a lot of backend logic on the front, and doing a lot of manual labour keeping track of all states, events, etc. What div is visible, which one to hide, which buttons to disable, adding new rows into forms dynamically with pre-populated values... that kind of stuff is way (and I mean waaaay) easier when coded in a declarative reactive way.
Re:New React DevTools by mosselman on Friday August 16, 2019 @08:07AM (#20714276)
> later realize you're repeating a lot of backend logic on the front

So you mean something like keeping state of forms in something like redux and sending out an event every time you press a button so that state gets update and the change is pushed down the tree of elements so that the letter you just pressed gets rendered in the form?

Or did you mean client side validations of forms that you also have in your back-end?

Obviously you didn't and I am being a bit of an ass, but this is what is the somewhat recommended way of going around this and it is so convoluted.

> doing a lot of manual labour keeping track of all states, events, etc.

The state of most web applications can be kept inside of DOM elements and the url just fine.

> What div is visible, which one to hide, which buttons to disable

This is where CSS-classes and the aforementioned JS libraries come in and they do this job just fine.

> adding new rows into forms dynamically with pre-populated values... that kind of stuff is way (and I mean waaaay) easier when coded in a declarative reactive way.

I don't believe you are right. It is not easier at all to add some DOM elements with React than it is when you use small bits of JS. Let's say you use jQuery, then it is 1 dependency you add with a small wrapper script for your dynamic form, with React you add thousands of dependencies and you have to build your complete application in React just to dynamically add a row in one of the forms. How is that easier?

I don't think I'd build Slack mostly using HTML rendering from the back-end, but most of the things that we build are CRUD applications that can easily be built using things like Ruby on Rails. Let's say the Trello's, Githubs and Amazons of our world.

Re:New React DevTools by ivanhoe on Friday August 16, 2019 @10:04AM (#20715240)
> with React you add thousands of dependencies and you have to build your complete application in React just to dynamically add a row in one of the forms. How is that easier?

Because with sufficiently complicated UI you will simply at some point have to start writing abstractions and libraries to help you handle all that mess, and then you'll basically end up building a good part of those "thousands of dependencies" yourself - reinventing the wheel.

For smaller projects it's an overkill obviously, no one says you have to use it everywhere. But for bigger projects it's a way more optimal to sacrifice some performance in order to be able to build faster and maintain the project easier, and even if you try to make your own solution chances are that with time it will evolve into something very close to how big players solve it. At least that's what happened to all my custom frameworks (front and backend), 10+ years ago when I myself still believed in not needing extra bloat of frameworks... you one day realize that someone already solved your problem, and solved it way better than you ever would...

Re:New React DevTools by spookthesunset on Friday August 16, 2019 @07:56PM (#20720831)
> Because with sufficiently complicated UI you will simply at some point have to start writing abstractions and libraries to help you handle all that mess, and then you'll basically end up building a good part of those "thousands of dependencies" yourself - reinventing the wheel.

And oh lord have I seen the result of these home brew “not a framework but actually is a framework” frameworks. They are all a rats nest nightmare for anybody but the original developer to work on.

The first thing that happens when the original developer moves on is the whole thing gets rewritten using the framework du joir.

Re:New React DevTools by mosselman on Friday August 16, 2019 @05:01PM (#20719660)
> Because with sufficiently complicated UI

This is an argument that I often see from people trying to defend front-end frameworks. That mythical complex UI. So far the only thing I can imagine that comes close might be something like a chat application. Apart from off-line ready apps, I grant you. In that case there would be no point in trying to accomplish that with vanilla JS or jQuery.

> But for bigger projects it's a way more optimal to sacrifice some performance in order to be able to build faster and maintain the project easier,

I am arguing that you build slower if you build your front-end separately from your back-end rather than use something like Ruby on Rails.

> you one day realize that someone already solved your problem, and solved it way better than you ever would...

I am saying the problem isn't there 95% of the time. You are just better off rendering HTML and some small pieces of JavaScript.

> 10+ years ago when I myself still believed in not needing extra bloat of frameworks...

I don't believe this at all, I just oppose the current state of affairs in the JavaScript world and don't subscribe to what is generally considered a good stack. I am not saying you should reinvent the wheel either, I am talking about existing tools like jQuery or Stimulus JS.

Re:New React DevTools by ivanhoe on Saturday August 17, 2019 @06:48AM (#20723302)
> So far the only thing I can imagine that comes close might be something like a chat application.

Sorry, but if you think that chat is a complex UI you obviously don't understand what type of complexity I'm talking about. Multi-page, multi-level forms with a lot of conditional rendering are far bigger problem to handle than chat. Challenge is not in a single particularly advanced action, forms I'm talking about are mostly just a bunch of ifs and event handlers that update the DOM accordingly. Problem is the overall complexity arising from a sheer number of different combinations you need to control, so you end up with thousands and thousand of lines of jQuery functions and events interacting and stepping on each other's toes.

For instance I'm currently working on an IP management app for big, international law firm. In order to invoice a client for even a very basic service like trademark registration you need to handle multiple countries, multiple laws, multiple currencies, and it has to be all in one dynamic form because they need to fill hundreds of those and it has to be simple and quick. These forms are huge, each loads a dozen of subforms, dialogs, etc. conditionally based on different business and legal rules that apply and user has to be able to edit all of that interactively. I've built the first version of that app 10 years ago using jQuery and it worked for a long time, but it took us more than 3 years to fully finish and it was huge and hard to maintain and had a number of limitations, as some legal rules were just too complex to handle. We now did a new version in Vue in less than 6 months. Much easier, much cleaner, our code deals just with our logic, not touching DOM at all, so it's much easier to debug and maintain it. Overall much nicer experience and thanks to that we were able to solve a number of problems that the old version had.

And this experience translates to pretty much any serious business web app that I've ever built.

Re:New React DevTools by danabramov on Friday August 16, 2019 @05:44AM (#20713546)
It’s worth nothing you can do server rendering to HTML with React, too.
Re:New React DevTools by tannhaeuser on Friday August 16, 2019 @08:36AM (#20714511)
> worth nothing (sic)

Indeed.

I mean who'd do that when there are plenty of server-side templating solutions that don't have to live by React's constraints (vdom/DOM diffing) only making things difficult? The only use case for React SSR seems quick first-page rendering and SEO.

Re:New React DevTools by jjjmmm on Friday August 16, 2019 @10:05AM (#20715254)
what happens when you want some interactivity after the initial load? That's why you SSR React. If you used a serverside template then once the page loads, how do you deal with interactivity? jQuery? Plain JavaScript?
Re:New React DevTools by tannhaeuser on Friday August 16, 2019 @10:49AM (#20715686)
Yes why not? If you already decided your site is content-oriented by choosing server-side templating, then interactivity will be limited in scope and easily implemented using either vanilla js or jquery, or even basic HTML forms, links, and CSS menu tricks without js at all. In my experience, while I personally like React when it fits, I've seen too many projects that don't benefit from a MVw approach where React or Vue or another MVw framework seems like a decision by developers to pad their resume, or even by managers to win developers by giving them, like babies, something to play with and show off to their peer group when in reality the app is just a basic LOB application, like the old legacy app it replaces.
Re:New React DevTools by mosselman on Friday August 16, 2019 @07:54AM (#20714196)
It is, but I meant more in a 'traditional' way, so rendering with some templating engine whose abstractions aren't so far detached from HTML as they are with React. Mostly by mixing some dynamic parts into HTML rather than the other way around.
Re:New React DevTools by danabramov on Friday August 16, 2019 @08:16AM (#20714342)
What kind of detachment are you referring to? React JSX has a few quirks but it maps pretty straightforwardly to DOM elements and HTML.
Re:New React DevTools by mosselman on Friday August 16, 2019 @09:14AM (#20714803)
A React application gets applied to a certain DOM element. Inside of that application are multiple layers of containing elements that handle things like routing or processing different events on existing DOM elements or triggered remote calls.

If you add redux and something like redux-form you end up with sending each keyup event to the redux store and re-rendering your input fields from that store.

So yes the JSX at the very bottom of your software tree is pretty much like HTML, but it takes a whole lot of engineering to get there and variables get pushed through many layers before they reach the final JSX in which they are rendered.

Some of this has to do with how you implement your application, but in general getting from input to output takes more steps than it does with a server side rendering framework.

This is fine when building something like a mobile application or an off-line-ready application like devdocs.io, but if you use a React application in front of some back-end you are just getting HTML in return for all your engineering efforts. If HTML with a few interactions is all you are after there is too much code and too many layers between the page that has your `<div id='myapp' />` and what you get after React is done rendering.

Re:New React DevTools by danabramov on Friday August 16, 2019 @09:17AM (#20714824)
Sure, I get that. What I'm saying is -- if you prefer to keep things simple and use server rendering, using server rendering alone with React (no routing, Redux, etc) is pretty much identical to using templates.

You can treat React itself as a single-pass server template engine with component support. You don't have to bring all of this single-page app stuff into it. Hope that explains my point. You don't even have to run React on the client at all.

I'm specifically talking about ReactDOMServer.renderToString() on the server and serving that HTML. Not "mounting into a <div>" client use case.

Re:New React DevTools by mosselman on Friday August 16, 2019 @09:31AM (#20714938)
Yes you are totally right. JSX in itself and the way you can nest React components, etc is very nice and could be great as a template engine. I should have said more clearly that I meant React et al. in the context of rendering everything on the client-side.
Re:New React DevTools by chrisweekly on Friday August 16, 2019 @08:58AM (#20714695)
Are you sure your users require the "compatibility" extreme of disabled JS?

SSR and "PRPL"-style hydration are totally compatible with React. See Gatsby's intro docs for a great example.