News for hackers. Stuff that matters.
Re:Front-end design, React, and a bridge over the great divide by ng12 on Thursday July 18, 2019 @09:05PM (#20475430)
> While I’m definitely a lot more fluent in it now, I dunno, it just still feels a bit weird to me. I could share some specifics but that would only invite a bunch of angry nitpicking comments. All I’ll say is that when I go over to projects where I’m writing HTML or HTML-like stuff (Vue, for instance), it feels like a breath of fresh air.

JSX is fine, the real power is building your HTML in pure JavaScript. I'll never go back to a template language, in my mind they're a fundamentally flawed design. They necessitate introducing extra concepts and implementing some magic rendering voodoo -- for what? So I can write my code twice, once in the JavaScript and once in whatever weird template directive language the framework uses.

So for me the only real alternative to JSX is to do elm-html style nested function calls which tends to be much uglier. JSX isn't perfect but it's the best we have by a mile.

Re:Front-end design, React, and a bridge over the great divide by zbentley on Thursday July 18, 2019 @11:14PM (#20475909)
I suspect that, in 2-3 years, server-side rendering is going to be rediscovered as a cure for the plague of spaghetti frontend code, just as current template-in-javascript metalanguages are being discovered now as a cure for spaghetti frontend-plus-backend-rendered code.
Re:Front-end design, React, and a bridge over the great divide by jasode on Friday July 19, 2019 @05:57AM (#20477318)
>I suspect that, in 2-3 years, server-side rendering is going to be rediscovered as a cure for the plague of spaghetti frontend code,

Maybe your prediction is informed by different internet usage scenarios but for general mainstream web surfers, I can't see how the industry will migrate back to server-side rendering in 3 years.

The unavoidable technical issue is the round-trip latency of the network. The same delays from the speed-of-light will still be there in 3 years. Most of the world is accessing the web through mobile phones which has worse latency than desktops. Server-side rendering (which means painful page reloads) is user hostile on slow network connections.

Re:Front-end design, React, and a bridge over the great divide by save_ferris on Friday July 19, 2019 @09:02AM (#20478273)
You didn’t mention all of the new features coming to HTTP 2 that will alleviate network performance issues (prefetch, multiplex connections, etc.)

I’ve found many sites that use frameworks like react to be much more user hostile, particularly from a performance and accessibility standpoint. The reddit redesign comes to mind. It’s so much slower now than it used to be on a browser (perhaps they’re intentionally doing this to push people to their mobile app), that it’s noticeably reduced the quality of the experience.

I guess I just don’t understand how people see page reloads with proper caching as unacceptable from a performance standpoint compared some JavaScript app maintaining a virtual DOM, which is also likely regularly communicating with a server.

Re:Front-end design, React, and a bridge over the great divide by digitaltrees on Friday July 19, 2019 @10:59AM (#20479172)
Same with TechCrunch, every time I visit I am reminded how frustrating react sites can be compared to server rendered pages with all the flicker, slow page reveal, and odd navigation it introduced.
Re:Front-end design, React, and a bridge over the great divide by rhizome on Friday July 19, 2019 @09:29PM (#20483669)
Late loading artifacts is all the fault of JS, not server-side rendering. Not sure what you mean by "odd navigation."
Re:Front-end design, React, and a bridge over the great divide by digitaltrees on Saturday July 20, 2019 @12:32AM (#20484195)
To close an article there is a x button and back swipe is disabled. I agree that flicker is introduced by Javascript. That is what I was saying. Might be ok for an app, but a content driven site seems like it should stick to the concept of pages where navigation is like turning a page. Just seems like server rendering fits that mental model better. Not sure why react even makes sense for a blog.
Re:Front-end design, React, and a bridge over the great divide by ng12 on Saturday July 20, 2019 @08:31PM (#20489189)
It doesn't, but blogs aren't built to present content they're built to sell advertisements and collect data. That's much easier with an SPA than a SSR app.
Re:Front-end design, React, and a bridge over the great divide by rhizome on Sunday July 21, 2019 @07:47PM (#20494435)
they're built to sell advertisements and collect data. That's much easier with an SPA than a SSR app

How easier? By dint of additional JS that an SSR doesn't have/need? Not sure how pulling a header nav (or any cell/element) from a server on pageload plays into that, but even today I've watched sites (plural) loading, pushing loaded parts all over the page for 30sec until everything settles down. Maybe blogs aren't quite so affected by this set of popular dark- and anti-patterns, but even so the post is almost always the last thing to load. Presumably, the monetization and data collection takes precedence over all else.

Re:Front-end design, React, and a bridge over the great divide by tambourine_man on Friday July 19, 2019 @08:40AM (#20478104)
>Server-side rendering (which means painful page reloads) is user hostile on slow network connections.

So is downloading an entire app when you only want to read one page.

Re:Front-end design, React, and a bridge over the great divide by TomMarius on Friday July 19, 2019 @05:58AM (#20477322)
I believe in a mix of these two. It's going to be server rendered JS app that will download itself on the background and install itself as a PWA. The best of both worlds.
Re:Front-end design, React, and a bridge over the great divide by medof on Friday July 19, 2019 @06:17AM (#20477387)
So you mean universal application? That's how nuxt.js/next.js works
Re:Front-end design, React, and a bridge over the great divide by TomMarius on Friday July 19, 2019 @06:51AM (#20477512)
Yes I am aware of these technologies, and it's basically what I mean, in an abstract way
Re:Front-end design, React, and a bridge over the great divide by efdee on Friday July 19, 2019 @07:04AM (#20477577)
That is what we have today.
Re:Front-end design, React, and a bridge over the great divide by TomMarius on Friday July 19, 2019 @08:00AM (#20477885)
It is not nearly as polished and as widespread as it could be.
Re:Front-end design, React, and a bridge over the great divide by vast on Friday July 19, 2019 @08:25AM (#20478001)
So parallelism after one initial slow load is the cure all? I also propose that front end will rediscover that parallelism is hard and isn't always the best fit.
Re:Front-end design, React, and a bridge over the great divide by ng12 on Thursday July 18, 2019 @11:32PM (#20475969)
I don't think so, at least not for the kinds of apps I build. My biggest problem is largely around interactivity -- shuffling lots of data back-and-forth between the client and the server. If I'm going to have a SSR app with lots of AJAX code running on the client, I might as well just go all-client.
Re:Front-end design, React, and a bridge over the great divide by kangoo1707 on Friday July 19, 2019 @12:36AM (#20476210)
SSR can be used with React (NextJS), Vue (NuxtJS) and Angular (Universal Angular).
Re:Front-end design, React, and a bridge over the great divide by sooheon on Friday July 19, 2019 @12:58AM (#20476289)
Isn't that use case just to save time on initial load? An SPA with SSR for load times is different from a webapp structured to have logic mostly in the server.
Re:Front-end design, React, and a bridge over the great divide by vetinari on Friday July 19, 2019 @05:48AM (#20477283)
That and for the bots, that cannot run javascripts, but do render the page thumbnail for others (facebook et al).
Re:Front-end design, React, and a bridge over the great divide by skrebbel on Friday July 19, 2019 @01:41AM (#20476424)
This supports the argument you're replying to.
Re:Front-end design, React, and a bridge over the great divide by atombender on Friday July 19, 2019 @12:23PM (#20479969)
This already happened. Frameworks like Next.js, Vue and Gatsby do server-side rendering out of the box.

Svelte also extremely promising. It brings a brilliant hybrid solution to the table.

Re:Front-end design, React, and a bridge over the great divide by ebiester on Friday July 19, 2019 @01:13PM (#20480531)
...and then they'll hit POST-redirect-GET and all the problems with the back button and holding state on the server.
Re:Front-end design, React, and a bridge over the great divide by magicnubs on Friday July 19, 2019 @12:35AM (#20476206)
So, basically video-streaming, but with websites instead of tv shows?
Re:Front-end design, React, and a bridge over the great divide by pjmlp on Friday July 19, 2019 @03:20AM (#20476776)
Basically what most web frameworks have been doing since we moved beyond CGIs.
Re:Front-end design, React, and a bridge over the great divide by cljs-js-eval on Thursday July 18, 2019 @10:14PM (#20475686)
You should check out CLJS's reagent. It mixes the best of both worlds, everything is a plain CLJS object without special syntax, but it's also obviously HTML/CSS:

  [:div {:style {:display "flex", :flex-direction "row"}}
   [:label {:for "email"}]
   [:input {:type "text"}]]
Re:Front-end design, React, and a bridge over the great divide by benbristow on Friday July 19, 2019 @03:27AM (#20476804)
That looks really ugly IMHO, compared to JSX which is more HTML-like.

Perhaps it might look better if there's a bigger example?

Re:Front-end design, React, and a bridge over the great divide by pcr910303 on Friday July 19, 2019 @03:43AM (#20476879)
> That looks really ugly IMHO, compared to JSX which is more HTML-like.

The point of this is not of asthetics, (IMO it’s not that ugly :-)) but more that it just consists of common data structures that is easy to manipulate. If you’re a React person, think of directly writing JSON instead of using indirect React.createElement calls. Writing components in JSON would be impractical; (actually it might not be - I think I’ve seen blogposts using React without JSX) but writing components in cljs data structures are practical and less tooling is needed!

Re:Front-end design, React, and a bridge over the great divide by rhaksw on Thursday July 18, 2019 @10:44PM (#20475794)
is this much different than JSX?

    <div style="display: flex; flex-direction: row">
        <label for="email"/>
        <input type="text"/>
    </div>
I definitely want to try CLJS some time.

edit Oh I see. You don't need the extra {} to jump into JS mode. And, CLJS requires : to denote keys. I think as long as my editor colors the syntax appropriately I'm okay with either.

Re:Front-end design, React, and a bridge over the great divide by rafd on Thursday July 18, 2019 @11:08PM (#20475892)
The difference is that in the cljs version you are writing clojure at all times using clojure data structures and types (vector, map, keyword, string) which lets you manipulate and generate things easily, and, you don't have to jump between "jsx" mode and "JS" mode.
Re:Front-end design, React, and a bridge over the great divide by sli on Friday July 19, 2019 @12:15PM (#20479880)
This is a major reason why I've left JS behind for CLJS. Reagent code is really just data. It acts like data, you can treat it like data. Sure, it's all well and good to say "code is data and data is code," but in reality doesn't usually work that way quiet so simply. But it does work that way in Lisp.

Compare to alternatives like Om, where the code looks like, well, code. Except in reality it's just Lisp sequences instead of Lisp vectors, so you still get all the same abilities to treat code like data. I don't think I'll ever willingly go back to JS. Maybe Purescript once of these days, but never JS.

Additionally, re-frame is absolutely wonderful and I cannot believe I waited as long as I did to switch to CLJS considering how much I prefer re-frame (and reagent) it over Redux (and React). Writing JS for immutability feels like such a chore now (Immer helps), since that part already just works in Clojure.

Re:Front-end design, React, and a bridge over the great divide by sooheon on Friday July 19, 2019 @01:00AM (#20476295)
Also the CLJS you see is using the vectors and hashmaps of the language, meaning much more direct manipulation the same way you'd program any other datastructure.
Re:Front-end design, React, and a bridge over the great divide by cljs-js-eval on Friday July 19, 2019 @01:51PM (#20480897)
The :display is a keyword, which works like keywords in Ruby or Erlang; it's a special, never-garbage-collected string for when you use the same string over and over. Though I'm not sure whether the implementation is the same when compiling to Javascript instead of the JVM.
Re:Front-end design, React, and a bridge over the great divide by cljs-js-eval on Thursday July 18, 2019 @11:08PM (#20475891)
Not really - and that's why I like it. I like JSX too.
Re:Front-end design, React, and a bridge over the great divide by kylecordes on Thursday July 18, 2019 @10:53PM (#20475827)
I totally get the preference for the JSX approach. Also echoing other commenters, CLJS/reagent and similar tools did a pretty amazing job of this some years ago.

But I think it is wise to consider that there are advantages and trade-offs to a compiled template approach as used by Angular, Svelte, and probably some others I’m forgetting.

* potentially more concise syntax

* potentially more familiar syntax

* do more of the work at compile time, less of it at runtime in downloaded code

* avoid the GC pressure and other overhead of VDOM

Re:Front-end design, React, and a bridge over the great divide by tuesdayrain on Friday July 19, 2019 @12:36AM (#20476215)
I was initially a pretty big fan of JSX, but after using Vue it just feels like extra overhead. In my experience, parsing complex JSX in my head results in constant context switches depending on whether the specific parts I'm looking at are closer to HTML or closer to JS. And for the tasks I've generally been doing at work, there rarely seems to be a good reason to combine the two. If I'm trying to fix a bug for example, it's almost always clearly restricted to either HTML, JS, or CSS. And I really appreciate how Vue minimizes the amount of code I need to search through in those situations.
Re:Front-end design, React, and a bridge over the great divide by ergothus on Friday July 19, 2019 @02:15AM (#20476533)
I keep hearing all of these "Vue just makes more sense than React" converts, and I'm baffled. I recently did some Vue after doing React for a few years, and it felt like a major step backward. It felt very JSP - here was a different syntax that was HTML except when it chose not to be - managing data was done in a custom expression language, and I was left to figure out what scope a given value had. Need to loop something ten times? It's one tag with a special "v-for" property. Want do to that loop with a condition? Special "v-if" property, and is that evaluated in the scope of a variable created by v-for or not? No idea! And that's not even getting into the various parts a Vue component object has.

JSX is just javascript. It's HTML looking, but is ALL (not some) a wrapper to write a JS function that outputs HTML. Need to have a loop? Loop in JS. Need to have a conditional? Condition in JS. What scope? This is all a JS function, so the scope rules are all JS scope rules.

I have no idea if I'm a weird minority, or if I'm just running into more people that felt better with Vue than React, but I really don't understand why.

Re:Front-end design, React, and a bridge over the great divide by moksly on Friday July 19, 2019 @08:12AM (#20477934)
I don’t think you’re a weird minority. I work for a Danish city and we operate around 500 different IT systems. They are all slowly migrating to web, with some backend typically JAVA or C# and a JavaScript MVVM front. Only one of them uses Vue, all the others use React or Angular.

If you look at the job market around here, it’s 70% react and 30% angular with almost no Vue jobs right now. The ones listing Vue as a requirement almost all use React, who are willing to retrain Vue developers. It used to be more evenly distributed between angular and react, but it would seem that react won the front end war.

This is HN though, it’s not very representative of what goes on outside of Silicon Valley. Right now there isn’t a single Rust job in my country as an example, at least not in any of our major jobbanks. There are thousands of PHP jobs though. But if you took HN to be representative for languages, you’d think it was the opposite.

Re:Front-end design, React, and a bridge over the great divide by pjmlp on Friday July 19, 2019 @04:18AM (#20476992)
JSX feels like PHP and ASP all over again.

Apparently they aren't that bad after all.

Re:Front-end design, React, and a bridge over the great divide by Marazan on Friday July 19, 2019 @07:22AM (#20477664)
I hesitate to tell people. They are doing it wrong but if you write JSX like how we all wrote PHP back in the day then you are doing it wrong.
Re:Front-end design, React, and a bridge over the great divide by pjmlp on Friday July 19, 2019 @09:41AM (#20478544)
So how do you modularize content in separate files?
Re:Front-end design, React, and a bridge over the great divide by efdee on Friday July 19, 2019 @07:09AM (#20477613)
How can you say that? PHP and ASP were dumb text template processors. JSX creates object graphs. They are almost nothing alike at all.
Re:Front-end design, React, and a bridge over the great divide by pjmlp on Friday July 19, 2019 @09:40AM (#20478532)
Mixed content on the same file, looks pretty much the same, regardless how it is implemented.
Re:Front-end design, React, and a bridge over the great divide by efdee on Saturday July 20, 2019 @07:16AM (#20485163)
The problem with ASP/PHP (or at least, the one we are addressing here) always mixing presentational logic with business logic. Something you still shouldn't do, and React doesn't advocate doing so at all.
Re:Front-end design, React, and a bridge over the great divide by arvinsim on Friday July 19, 2019 @12:25PM (#20479986)
I totally disagree. VueJS and AngularJS feel like PHP/ASP but I never got that feeling from JSX.
Re:Front-end design, React, and a bridge over the great divide by pjmlp on Friday July 19, 2019 @12:41PM (#20480177)
I fail to see how proper component based frameworks, with clean separation of concerns, provide such experience.

JSX is the one mixing echo like statements with proper JavaScript.

Re:Front-end design, React, and a bridge over the great divide by TomMarius on Saturday July 27, 2019 @08:16AM (#20541670)
That is pretty impossible since JSX is just JavaScript, including all of its scope separation. It might be that you're not well versed in using it.
Re:Front-end design, React, and a bridge over the great divide by ngrilly on Saturday July 20, 2019 @09:43AM (#20485707)
JSX let's us define components, usable with the usual HTML syntax. PHP does not. That's why Facebook developed XHP (XML fragments in PHP), which inspired JSX.
Re:Front-end design, React, and a bridge over the great divide by Existenceblinks on Friday July 19, 2019 @03:28AM (#20476814)
After doing Elm or PhoenixLiveView, I'll never go back to React stuff. Every time people trying to re-invent html, it will end up pretty much HTML. It's simple and powerful. The sad part is developer resources spent on optimizing for JS instead of joining force improving HTML standard.
Re:Front-end design, React, and a bridge over the great divide by bwindels on Friday July 19, 2019 @07:50AM (#20477828)
I think you can get pretty close to the comfort of JSX with plain JS, without needing a preprocessor. Local development is so much nicer without webpack, babel, source maps, ...

I've been trying trying this out [1] with a thin 300-line DOM wrapper, and works wonderfully well so far.

There are also libraries like lit-html but I prefer to construct html as an object tree, and not a string.

1: https://github.com/bwindels/brawl-chat/blob/master/src/ui/we...

Re:Front-end design, React, and a bridge over the great divide by dsego on Friday July 19, 2019 @05:18AM (#20477192)
Extra concepts in templates aren't that difficult, it's usually just binding directive, conditionals and loops. You know, the bread and butter of every programmer. How hard is that? I'd say not harder than learning the many nuances of JSX. And the magic rendering voodoo enables you to do compile-time optimizations, because of the limited set of directives supported by this magical templating engine.
Re:Front-end design, React, and a bridge over the great divide by dahfizz on Thursday July 18, 2019 @10:54PM (#20475831)
Server side rendering has one big advantage - it's fast. Client side rendering frameworks may be easier and sexier, but serving html is always going to be faster.
Re:Front-end design, React, and a bridge over the great divide by onion2k on Friday July 19, 2019 @01:00AM (#20476300)
If you need custom data in the page on a per request basis then SSR is usually the fastest method to generate the final HTML but it isn't the fastest method of getting something on the user's screen. Its "time to render" that counts, and that means doing as little work as possible to send something to the user.

Serving the same static, "prerendered" HTML file with no customization to every user is always going to be the fastest method of getting something to display in the user's browser, so perceptually it's much faster to serve a static html file and then hydrate it with any custom data using frontend JS.

Re:Front-end design, React, and a bridge over the great divide by dahfizz on Friday July 19, 2019 @07:49AM (#20477821)
I hear this often, but I am unconvinced. This just leads to jittery pages that keep moving when I try to do something to them.

Just seeing the skeleton of the web page doesn't make it fast. The page will be unresponsive for longer and will visually stutter while rendering. It's a much worse user experience imo.

Re:Front-end design, React, and a bridge over the great divide by onion2k on Friday July 19, 2019 @09:24AM (#20478406)
Just seeing the skeleton of the web page doesn't make it fast.

I didn't say it does. Skeleton loading is slower. It feels faster though, and that perceptive improvement is more important than the actual time something takes. If you ask users which they think is faster they usually say the skeleton version regardless of the facts. When your key metric is user satisfaction rather than raw download speed that's important.

The page will be unresponsive for longer and will visually stutter while rendering.

That doesn't have to be the case though. There are plenty of techniques for writing client side code that doesn't block user interaction.

Re:Front-end design, React, and a bridge over the great divide by briantakita on Thursday July 18, 2019 @10:58PM (#20475852)
Sapper & Next.js support server side rendering.
Re:Front-end design, React, and a bridge over the great divide by leadingthenet on Friday July 19, 2019 @07:39AM (#20477751)
So does Nuxt.js (for Vue).
Re:Front-end design, React, and a bridge over the great divide by shareIdeas on Thursday July 18, 2019 @11:14PM (#20475911)
So what alternatives?

I don't want to program iOS and Android and web.

Re:Front-end design, React, and a bridge over the great divide by pjmlp on Friday July 19, 2019 @04:18AM (#20476995)
Then just focus on one platform.

Plenty of gigs available.

Re:Front-end design, React, and a bridge over the great divide by shareIdeas on Friday July 19, 2019 @10:41AM (#20479025)
I'm beyond gigs