17 ms·
Second-guessing the modern web (2020)
- theteapot 5y ago> "There are decent patterns in the form of GraphQL, but for a React component that loads data with fetch from an API, the solutions have only gotten weirder. There’s great documentation for everything else, but old-fashioned data loading is relegated to one example of how to mock out ‘fetch’ for testing, and lots of Medium posts of varying quality." What is "old-fashioned data loading"?
- svachalek 5y agoThe truly old fashioned way is to load your data and render the page with it in the server. A simplicity that was lost in the SPA, but that's what SSR gives back to you. But since this is an anti-SSR piece I'm not sure what it's getting at.
- epistasis 5y agoThe problem with SSR, as I understand it according to this article, is that it still removed native link handling from clicks, resulting in the need to override all the basics with bulky JavaScript that doesn't load until some time after rendering. Which, as a user, has bitten me many times. I hate hate hate when a page seems loaded, but something has stalled, and I can't interact with anything. As much as I hate Java, I still kind of long for old fashioned Tomcat web apps that sent out fully formed and usable HTML with small bits of JavaScript enhancements.
- deleted 5y ago[deleted]
- madeofpalk 5y ago> The problem with SSR, as I understand it according to this article, is that it still removed native link handling from clicks This is not true. SSR React still returns HTML. You can set hrefs on a tags. They all work fine.
- epistasis 5y agoAha, thanks. So when the author writes: > So, Server-Side Rendering runs your JavaScript frontend code on the backend, creating a filled-out HTML page. The user loads the page, which now has pre-rendered content, and then the JavaScript loads and makes the page interactive. Does this mean that one could make the page interactive with server side rendering, but it's not normally done? Or did I completely misunderstand this paragraph.
- masswerk 5y ago> Does this mean that one could make the page interactive with server side rendering, but it's not normally done? It can be done, it is actually, how things were done a quarter of a century ago: server-side rendered content with tiny triggers for interactivity directly embedded in the code. In the next step, as complexity grew and as an attempt at separating concerns, you would send the content and along with it a bundle of code for interactivity (which may have been sent in the same request or as a separate resource). Then, we got frameworks. Technically, these could do this as well, but it doesn't match their basic pattern.
- tshaddox 5y agoIf you click on an <a> tag before the JavaScript has loaded and React has hydrated, the browser will do a full page load of the URL that you clicked on. Assuming that new page is also rendered on the server, it should work fine and feel just as good as if it was a traditional server-rendered HTML web site or if you had JavaScript turned off. (Of course, things that do require JavaScript for interactivity, like custom tooltips on hover, custom form validation, etc. won't work until the JavaScript has loaded.)
- hmsimha 5y agoJust to add to the above, this is specifically when your pages are server-side rendered. Hydration is a concept of taking a server-rendered page and making it interactive with Javascript. You can have your NextJS/React app server-rendered, and then users visiting a page will get the page. Clicking links within the application will use Javascript routing to load the part of the application that needs to be displayed (and prevent the default navigation from clicking said links). I think in practice it's more likely for users to fall back to default navigation which then relies on full server rendering when they have Javascript disabled, than it is because they've clicked before the front-end router has started working. Also, before this thread I didn't realize React itself could be server-rendered (I thought that was the distinguishing point of Nextjs). Is it common to use non-next React for SSR?
- z3t4 5y agoJSON or XML, using REST or websocket maybe? One request per "page load" is an anti-pattern in SPA's though - you should send all static data once, lazy load large assets like images, and sync only the dynamic non cacheable data.
- shadowgovt 5y agoIt kind of depends on your mental model for your user. For mobile devices in many countries outside the United states, you're doing your user no favors shipping them a bunch of static data that they don't actually need yet because you've wasted their bandwidth if they never use it and bandwidth costs money.
- qbasic_forever 5y agoJQuery document ready handler that makes a XMLHttpRequest and then a pile of jquery DOM manipulation calls to make the DOM state reflect the data you just got back from the server. Basically just a lot of imperative DOM manipulation calls. No templating, no MVC patterns, etc. This is the kind of frontend JS that was all over the web in the early 2000's.
- burlesona 5y agoThis is the money quote for me: > Frameworks should lure people into the pit of success, where following the normal rules and using normal techniques is the winning approach. > I don’t think that React, in this context, really is that pit of success. A naïvely implemented React SPA isn’t stable, or efficient, and it doesn’t naturally scale to significant complexity.
- gr__or 5y agoI would say the popular server-focused frameworks that came before suffered from complementing problems which also did not lead to a pit of success. Namely view code (HTML/CSS/JS) was harder to compose in a scalable fashion, Rails'/Django's template composition feels vastly inferior to proper componentization. Namely limited type checking, globals sharing, ... These things do make it harder to refactor and get rid of unused code, which also has real impact on users. Another biggie was that there is no great gradual path from server-code to client-code, with potentially additional data. Now React SSR does make you work more for the server use case, in that you tend to write code which should also work on the client-side (which might change with React Server Components) but at least you don't have to face lots of decisions when expanding the interactivity of your app. All that said, I also agree with the blog that there is still lots of refinements to be done on the React side of the world, I just view the world we came from as far less rosy.
- dbbk 5y agoReact is famously not a framework though. Next is the relevant example here, which actually does work to address a bunch of the complaint points, including doing full page reloads when you’ve deployed a new version of the app.
- rched 5y agoReact famously claims not to be a framework. Many, myself included, would argue that it is very much a framework in every way that matters.
- frosted-flakes 5y ago
- theteapot 5y agoFor me the clear threshold for when you've gone too far with SSR is if it needs auth. Just do not go there. So this is not an SSR issue per se, it's poor SSR implementation issue IMO.
- tshaddox 5y agoI'm not sure why that threshold needs to exist. It shouldn't be any harder for your SSR to check a cookie than it is for your REST API to check a cookie. There are some benefits of SSR that don't apply to pages with private content, namely being able to cache the HTML response in a CDN and (arguably) being treated better by search engine crawlers, but many of the benefits of SSR apply just as well to private content.
- akersten 5y agoOne day browsers will natively support modules and "Bundle Splitting" as the article calls it will just be the intuitive and automatic thing to do. Until then we have webpack.
- mattacular 5y agoMost browsers do support js modules today but it's kind of an awkward situation to say the least. And if you need to support older browsers you may as well not bother, you probably use Webpack and/or Babel (or TypeScript) anyway for other reasons. Especially if you're trying to do isomorphic stuff for an SSR app, as NodeJS then has its own pile of idiosyncrasies and baggage around module support. This situation has been playing out for many years and it has only gotten more confusing.
- dbbk 5y agoThey do…
- engido9740 5y agoUnless you're still supporting IE, which is a big gotcha for some I know, then modules are a go now: https://caniuse.com/?search=modules https://caniuse.com/?search=modules Vite is one of the first tools I know of taking advantage of this: https://vitejs.dev/ https://vitejs.dev/ "On demand file serving over native ESM, no bundling required!" I just launched a small production site using SvelteKit, which now uses this under the hood.
- epistasis 5y agoAs mostly a user that doesn't develop web apps anymore, all this feels very true to me. I'm soooooo sick of interfaces that load an empty useless shell of UX chrome and then slowly trickle in content at some later time, and leave spinners, or even worse, gray boxes simulating text. Send the text content in the initial reply, please! It's bad enough having to wait for webfonts, but when you wait to start doing the slow database query for content until after an html shell has been loaded, and after a huge JavaScript bundle has been parsed and executed, you're just wasting time. Reminds me of the Google Web Toolkit of yore. We really haven't progressed much in the decade for single-page apps since then, when it comes to the user. And that's a horrifying thought.
- edgyquant 5y agoEasier said than done. When you have to load a number of components, each with possibly multiple rows within them, it can take awhile to pull all the data and it is better to break them into a bunch of smaller backend calls that can be cached as needed than trying to return a single json object containing all the data needed to be displayed on a user generated app.
- dntrkv 5y agoIt's like all of these posters have never worked on a large-scale app, acting like the decision to lazy load content is made just because we don't have anything better to do.
- epistasis 5y agoSure, there's lot of code to write, but is the end goal writing code, or making a web app that's great for users?
- dntrkv 5y agoNot sure I get what your comment is saying, but: > making a web app that's great for users That's what the goal is, and that's what SPAs enable. You can't build a modern web app without it being a SPA. The two are basically synonymous, I don't understand how there is even a discussion around this. No user wants to navigate to another page and lose their context. That's why the industry moved to SPAs. If you ever tried to manage complex UI state in the jQuery/Backbone/Knockout/etc days you would see that a React SPA is a huge improvement. It actually enables devs to build complex apps without getting bogged down in bugs.
- steerpike 5y agoI feel like this post just reached into my head and pulled out all my current thoughts about web development and the dominant architecture paradigm. I love it when someone articulates my thoughts better than I do.
- bacheaul 5y agoI saw this referenced in the job ad for a "Software Engineer: Web" on the Oxide careers page yesterday. More of a meta comment, but it's funny how interesting things link to more interesting things, and the "HN web crawler" inevitably finds and identifies them.
- deleted 5y ago[deleted]
- young_unixer 5y agoI have a very good idea of how the web used to work 10 years ago. But when I try to learn Modern Javascript frameworks, the tutorials rarely do a good job of explaining that they won't teach me how to create a normal, traditional website, or if it's even possible to create a normal website with the framework. They simply assume that the modern way is the standard way. I want a modern alternative to PHP, but the JS community doesn't make it easy to learn JavaScript. At least I know how things used to work. Imagine a newbie that never developed a normal website and now thinks React/client-side rendering is how the web is supposed to work. They won't even be able to understand the tradeoffs being made for them. I want a modern language and framework that still makes sane decisions, and when it does weird things (e.g. client side rendering being the default) at least tells you upfront that it's making those decisions, and their implications.
- Zababa 5y ago> Imagine a newbie that never developed a normal website and now thinks React/client-side rendering is how the web is supposed to work. I had the luck of learning the web "the old way" at the university. First HTML, then CSS, then PHP where we cobbled together a small website (our end projet was a recipe website where you could create an account and post recipes, so there was database usage too). All of this was made in WAMP/XAMP. We had a course on JavaScript the next year but I honestly didn't understand anything. Some time after though, when I started working again on the web, having an understanding of HTML, CSS and what you had to do by yourself made me understand fundamental web technologies on a deeper level than most of my peers that started with the MERN/MEAN/MEVN stack. I'm sure they'll be more attractive to employers though.
- mod 5y ago> modern alternative to PHP Try...well, PHP. It's pretty modern now and a lot better than it used to be. I'm not a PHP guy but I do have a few sites running on it and it's nice to go back to my roots.
- shadowgovt 5y agoThere's nothing particularly weird about client-side rendering (at least, it's no weirder than server-side rendering was in the era when most pages were static data). It could, of course, be considered "weird" if one's mental model is that patching together document description declarations on-the-fly on a server to later be re-interpreted and rendered on the client is "normal."
- breckenedge 5y agoProgramming is always trade-offs. Having programmed interactive web UIs for over a decade now, I really enjoyed it the most when programming using BackboneJS. Enough structure to avoid the JQuery spaghetti, but the library didn’t treat you like a moron. Coffeescript was popular back then too, glad to see the better parts of it make it back into JS (and not the semantic whitespace).
- nemothekid 5y agoOne thing I've seen happen again and again in a lot of technologies is a "framework gravity". A lot of people see this as engineers just wanting to work on "hype" technology but I think what is actually happening is a reflection of global engineering time. 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.
- zabzonk 5y agoSorry, what's a "SPA" - can't seem to find it by Googling.
- deleted 5y ago[deleted]
- grzm 5y agoSingle-page application https://en.wikipedia.org/wiki/Single-page_application https://en.wikipedia.org/wiki/Single-page_application
- felipellrocha 5y agoIt’s like when you’re stressed and need to relax, and you need a webpage done. So you meditate, then crank out code
- thereare5lights 5y agoSeems like some variation of this article gets posted every few weeks
- aryamaan 5y agoCare to share some of those? I am a backend developer and trying my hands in front end development; interested in knowing what's the sane way to be part of this landscape.
- mathgladiator 5y agoI'm no fan of React, and I'm building a new back-end and front-end that is probably heretical to... well.. everything. What I have found is that if you have reactivity from your back-end, then front-end reactivity is... easy. My focus is on board games, but the idea generalized pretty well. As an example, my dumb chat room: https://github.com/mathgladiator/adama-lang/blob/master/demo/html/chat.html#L90 https://github.com/mathgladiator/adama-lang/blob/master/demo... I really need to focus on this, but I believe what we are seeing is an interesting adversarial game between client and server. For instance, if you build your server with a strong API, then clients are going to build tremendous complexity. My personal bet is that we need a streaming protocol such that applications look more like X11.
- deleted 5y ago[deleted]
- tekstar 5y agoLooks like you're trying to reinvent some wheels there. No harm in doing so but just so you know, React (or my preference, a tinier version called Preact) would let you update new chat contents without blowing away all the other InnerHTML content. The way you're doing it now will result in a flicker, and mess with things like highlighted text will unhighlighted when replaced. And that's just with the basic dumping of the chat text into a DOM innerHTML. I'm pretty sure what you're doing there would also be susceptible to XSS without additional filtering.
- mathgladiator 5y agoWait til I tell you about the custom UI system I'm building with canvas. http://www.adama-lang.org/blog/ui-flow-with-adama http://www.adama-lang.org/blog/ui-flow-with-adama
- tekstar 5y agoNice blog post! I read the whole thing. I'm working on something with multiplayer using an unbounded queue of command events, so I learnt a few things about that situation. If you have any posts that elaborate on the typical infrastructure events from running that in production, I'd love to read it as you obviously put a lot of effort into your blog posts.
- interlocutor2 5y agoI choose React for personal projects because it's easy. I'm not too concerned with performance. This article doesnt spend much time on developer experience.
- masswerk 5y agoWell there's also what might be called the "eschatological perspective on technology": time in development is spent only once, but user life time and technical resources are spent million times (at least, if it's a significant project). In this context, we may also speak of the "eschatological debt" of a project.
- rimliu 5y agoIt's about time for developers to start to think about user experience. "Makes it easier for the user and harder for the database" needs to be reborn.
- midrus 5y agoAnd to me this is the root of the problem. Developer experience is awesome so fuck the users, the usability, the performance, the scalability of the business, the time it take to build anything, the stability, the security, the robustness, and whoever will come in 2 years after we left to maintain this. I'll be gone by then. Sounds like a plan. Developer experience rules!
- hackerfromthefu 5y agoBut lots of the developer experience is actually awful. Some is good, but there's so much needless complexity that is just painful. Stockholm syndrome applies if you don't realise there's easier ways, of course.
- ian1321 5y agoThe amazing part to me is that SPAs are so much harder to do right compared to old-school server-side rendered HTML. One could be forgiven if they think a "simple" SPA is a good starter project, but they'd be very wrong. Async programming (Javascript Promises and/or async/await) is difficult, error-prone, and should be avoided whenever possible. On top of this, understanding how data flows through these SPAs is no small task. Compare this to server-side rendering where you run some DB queries, generate some HTML based on those results, and send it to the browser to be rendered. There are some cases where you actually need a rich experience in the browser. In those cases, I would start by seeing if plain old Javascript would work. In writing this, I definitely feel like a "get off my lawn" guy. But I've just seen too many junior and senior engineers (me included) fall flat on their face trying to use these SPA frameworks.
- scrollaway 5y agoIt's absolutely possible, dare I say easy, to do old school SSR wrong. You start with an honest to god html file. Your IDE lints it. You are happy, life is easy. Then you need a second page. So you copy some things over. Then you need a third page, and it becomes apparent that you need a way to share parts of your html pages across multiple files, in a generic way. And kids, that's the story of how I met your templating system. ALL of them suck. ALL of them are incredibly hard to lint, test, get right. They scale badly. They're all awful. It's easy to get things wrong in that world, because nothing gets things right. There's kludges of course, things that generate html entirely programmatically from their own language, or some weird abstraction. These all suck too. You have to learn new languages, or weird shorthands, or at best new APIs. None of them truly took off either so the tooling is poor. You know what's a language that already has tons of tooling? JavaScript. You know what's a robust API for building HTML that you already know, that is already supported by virtually everything? The DOM. And you know what's a markup language you already know and can intuitively parse without having to learn new things? HTML. Well, guess what.
- phist_mcgee 5y agoTo extend your point, I think the linked article suffers from a common trend in web dev editorialism, which is over-generalisation of problems, and reducing the domain into simple binary thinking. A lot of these arguments talk about the dangers of SPAs, but don't talk to the reason why first class interactivity/reactivity exists on the web. It's because for average users, they want to see feedback to their actions immediately. Articles like this talk to SPAs as if they are unnecessary or overused. I disagree, I think SPAs are mostly appropriate for most SaaS, social media, or business tooling. Sure, the poorly implemented version of an SPA is harder to debug than a poorly implemented template generated site, but that's like comparing the complexity of a car built in 2021 to a car built in 1980. And cars from 2021 sell better than cars from 1980. A lot of these articles strike me as opinion pieces decrying the direction of modern web development, and seem to point to the past as a more 'gilded age' of internet browsing. But this was back when users sat at a desk, and scrolled pages using a analog mouse, viewing it on a CRT monitor. Users today want to browse on their phones, want to share and upload, to take live videos, to see when their message was sent, delivered and read. We need SPAs and libraries like React just like we need cars that can do lane assist. It's because it's a feature users want, and on the whole, it is much easier to build using React and SPAs.
- jdwyah 5y agoEvery Product Manager: “I dunno, ever since they started saying React, everything takes 3x longer to ship and we have 2 teams on very challenging technical projects to enable performance that doesn’t suck”.
- tshaddox 5y agoWhat were they using before they started saying React? Backbone.js? JQuery? How big and how interactive was the website at the time they started using React?
- FailMore 5y agoHow is Ruby on Rails viewed in this context? With some of the new magic?
- cknoxrun 5y agoEven outside of SPA apps and new magic, Rails is still faster to develop a prototype or website in than React or dare I say any modern SPA tools. We tested this for fun with some very experienced React and Rails devs at our company, each starting from a freshly formatted laptop to include the time it takes to get an environment up. Requirement was to create a simple blogging site with comments, authors, and tags (with some upfront design). Rails hands-down took the cake, by a large margin, each time. It was for fun obviously, not exactly scientific, but was pretty eye opening seeing how much further ahead the Rails devs were at each step.
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- jkaplan 5y agoI agree with a lot of these points, but differ slightly in two regards: 1. In my experience React DOES lure people into the "pit of success" in at least one important aspect -- modular and re-usable front-end code. React is certainly not the only way to get this, but it does help force you into some good patterns. 2. The "sweet spot" for React is pretty large. If your site is truly static (e.g. a blog, a product landing page), then yes it's overkill... but so is something like Rails/Django! Just use a static site (+ generator, if needed.) If you're building an "app"/you're interacting with a database, then you're almost certainly going to want end up wanting interactivity. And it snowballs -- a little state change here, an ajax call there, and all of a sudden your front-end is ballooning without structure or modularity.
- waingake 5y agoYes this. The article mentions the following as poor candidates for client side rendering. I can agree with blog, but suggesting a tool like React is a poor choice for a shopping cart is naive. > Those are things like blogs, shopping-cart-websites, mostly-CRUD-and-forms-websites.
- kristopolous 5y agoHow? It's the most painful, difficult, slow, frustrating, confusing programming experience I've ever had in my 25 years. It's made me want to leave the industry completely and I honestly think I will after this project. It has single handedly slaughtered and destroyed my quarter century love affair with programming. It's a wildly inflexible architecture that aggressively forces their users to conform to an orthodoxy that's fluid and always changing. So you get a pile of inherently unmaintainable, unavoidably messy code that is deprecated the day you write it. It's sheer insanity. Trying to get horizontal communication between components. I'm slapped and told "no don't do it that way" and then I'm given half a dozen extraordinarily convoluted ways to do it instead. They say "you aren't thinking in react". There is no thinking in react because there's a bunch of different ways to go about it and each one fights against the limitations voluntarily imposed by the framework. Each one is a hack to get around the needless artificial barriers that exist there for no damn reason other than to make life harder. Pass a parameter with an onclick handler. Again, I get slapped around as no that's not how it's done. Why isn't it easier? Why is the Framework requiring me to do more work, to set up an indirection? Why am I working more with it then without it? Why does it give me less, do less, and require more from me? It's literally the most complicated convoluted and elaborately complex way to do what should be simple and direct things. Every task gets a layer or 4 of complexity slapped on top of it. It's like they replaced Galileo's chart with epicycles because they have to appease some invisible theory gods. It's theory that has literally zero hard evidence as to why doing something directly is bad but doing the same thing with a bunch of weird generators callbacks and hooks is good. In my 5 years of working with it, it's always without failure been the worst catastrophic mistake on every project, blowing through budgets and deadlines like nothing else. Productivity is slaughtered. Otherwise 10x engineers become 1/10x. It's remarkable how much it stagnates and destroys everything. This is pure Jim Jones cult magic stuff. It literally only exists to make people feel special and elite while doing what should be simple stuff. I'm quitting engineering after this thing ships. I simply do not have the words for how much I despise react. It's the most despicable creation I've ever laid eyes on. I honestly want to have absolutely nothing to do with programming now. After React it makes me physically nauseous.
- mbgerring 5y agoThere’s a really great fix for this, which is to design JS frameworks to not take over the entire application. I have been waiting for a long time for the framework that will let me write a web component, and then include that web component in a regular HTML page, in a way that’s supported by the idioms and best practices of that framework. It’s also worth pointing out that all of these drawbacks to rendering web pages on the front end via JavaScript were obvious the moment these frameworks were introduced. The critics at the time were right. But we still lack for easy-to-use alternatives.
- TZubiri 5y ago"There’s a really great fix for this, which is to design JS frameworks to not take over the entire application." But then your framework wouldn't replicate itself with the prolific genius of Genghis Khan or the coronavirus.
- dmalik 5y ago> design JS frameworks to not take over the entire application. Facebook did just that with React. React doesn't have to be used only as a single page app. Use it for just a single component on a page if you want.
- mbgerring 5y agoNobody does this in practice. Tooling, tutorials, frameworks, etc are all created around the idea that the entire application is an SPA with a single root element. I understand that it’s possible to do this in theory, and that’s why I said I want to see a framework where the idioms and best practices are geared for this kind of use.
- jkaplan 5y agoI'd encourage you to give React a try for this use-case! I've done this exact thing -- slowly introducing React in certain places in a large web app -- and it's worked great. You're right that tooling/tutorials are mostly geared towards SPA usage, but React itself is designed to work for both. You'll have to decide on a pattern for "bootstrapping" React in a given page or element, since there aren't well-established best practices, but after that it's smooth sailing.
- adreamingsoul 5y agoI have to admit, I’ve been avoiding TypeScript and React for any professional projects. TypeScript due to lack of experience, but I understand the benefits. React due to many reasons, but most of which is that I don’t agree with the “benefits”. I have been working with the Frontend for over a decade and have been on the forefront of its progression. KnockoutJS was a pivotal moment and cemented what followed with Backbone, Angular, Vue, and React (and several others). It don’t think the current state of development is going in the right direction. But that’s just my opinion and a wild one at best.
- onion2k 5y agoThere's no reasonable argument that you can make in favor of Knockout, Backbone (I hope you mean Marionette though... no one used Backbone on its own), Angular, or Vue that doesn't also apply to React.
- stopyellingatme 5y agoI’ve been using typescript for years and I’m still constantly learning new things. Certainly has benefits, but also a large conceptual (and often syntax) hump. On the frontend, maybe look at Svelte? I’m not going to try and sway you from your current chosen stack, but my personal experience with it (compared to the others) is that it’s like coming home. More like the natural evolution of early web tech, imo.
- sergiotapia 5y agoI tried to go the old-school route of server rendered pages. But then I thought to myself: I would need to write an API later so that's double the amount of work. What if I'm also going to make a mobile app? I can spin up a graphql API, use create-react-app, and react native, use apollo client to share lots of code and be done with it. The alternative is more "pure" I guess but it's a lot of double work.
- bmeski 5y agoWhy not just have a function that makes a db call and then send the data into the template? If a mobile app needs to request the same data, simply make a .json version of the route and use that same little db access function, shove the return into res.json({}) and Tada. Sharing ui code between react native and web-react is pointless so you'd be sharing what? some formatting functions? the request functions that the .json and ssr routes effectively return for you?
- tshaddox 5y agoThe part about API changes being incompatible with old versions of the frontend (that are still loaded in someone's tab somewhere) is a valid problem, but honestly isn't significantly worse for SPAs than for traditional server-rendered HTML websites. Your basic HTML web form will break too, if your API has changed in an incompatible way! It's true that traditional websites would coincidentally get a new version if the visitor happened to click a link, but relying on them to do that to avoid seeing an error isn't a better solution than an SPA notifying the visitor that they need to refresh to avoid seeing an error. Also, I don't really agree with the author's view that needing to refresh an SPA to get a new version is "bizarre" or "something from the bad old days of desktop software." On the contrary, it's an extremely prominent UI element and a fundamental action in all web browsers! That said, one "trick" is to have your SPA silently listen to your server for app version updates, and when there's a new version, just make your client-side Link component do a full page load (instead of a client-side route transition). Then at least you'll have the same behavior as traditional HTML websites.
- tylerrobinson 5y ago> That said, one "trick" is to have your SPA silently listen to your server for app version updates, and when there's a new version, just make your client-side Link component do a full page load (instead of a client-side route transition). Then at least you'll have the same behavior as traditional HTML websites. I think the author’s point is that it’s sort of a bummer that we have to deal with this just to get back to “normal”. I agree that it seems under-discussed, too.
- tshaddox 5y agoBut again, the "normal" isn't that great: the visitor might have just so happened to click a link before using a broken form, but that's not some architectural guarantee that you'll avoid errors. It's just a happy accident that the visitor might have unknowingly triggered an entire app update before using an outdated form.
- stevebmark 5y agoFor dynamic websites, React should always be SSR first with optional client hydration. Next.js makes React SSR easier, if you're using Next.js for non-static sites, and not doing SSR, you shouldn't be using Next.js. Browsers have decades of optimization to show HTML to you as fast as possible. Before scripts, sometimes before stylesheets. Browsers can't optimize the extended network dance you need to do to download and parse KB of Javascript before you can _start_ fetching data. SSR with partial client Javascript hydration. It's a solved problem, but few people do it.
- sombremesa 5y agoReact is very good at what it's for, and much of this article is saying that React is not good at what it isn't for. That's a fair point to raise due to the ubiquity of the library, since many will reach for it out of habit or ignorance when it isn't appropriate, but it really doesn't amount to second guessing the modern web in my opinion. There are plenty of people still using Django and even things like Plone. They're just not in the zeitgeist, because those tools have practically congealed at this point and there isn't much reason to have a discourse about them.
- 1vuio0pswjnm7 5y ago"There are decent patterns in the form of GraphQL, but for a React component that loads data with fetch from an API, the solutions have only gotten weirder." Wonder how many people using "GraphQL" realise those decent patterns are from the 1970's, i.e., QBE. https://en.wikipedia.org/wiki/Query_by_Example https://en.wikipedia.org/wiki/Query_by_Example
- catlifeonmars 5y agoHuh? I’m not sure how the page you linked is related to GraphQL, except maybe that they are both querying paradigms. They seem largely orthogonal. Am I missing something?
- deleted 5y ago[deleted]
- disjoinder 5y agoFrom the Wikipedia page: "It is the first graphical query language, using visual tables where the user would enter commands, example elements and conditions. Many graphical front-ends for databases use the ideas from QBE today." GraphQL seems to borrow the name. Graph [ical] Q [uery] L [anguage] It could be a pure coincidence, but then, further down: "GraphQL a QBE for JSON front-ends." As evidenced by the reply, the parent seems to have predicted correctly that there are people who have no idea the two are related, i.e., one is descended from the other.
- catlifeonmars 5y agoAbsolutely I can understand QBE being prior art for a number of querying paradigms. However, the two aren’t closely related. As far as the name goes, the “graph” in GraphQL likely refers to the data graph (as opposed to “graphical”) as data graph traversal is one of the key selling points of the language. The other one being homoiconicity between request and response.
- disjoinder 5y ago
- darepublic 5y agoThe spa paradigm was not invent d by react. Or any framework for that matter. Remember when asynchronous xmlhttp requests were cutting edge?. It's just one step from ajax to spa. I have been growing increasingly dissatisfied with react but there's no clear superior alternative. Server side react is a pretty good solution for most problems and fairly scalable.
- snarkypixel 5y agoPersonally I love SPAs and would still use them all the way instead of Django/Rails. The problem with server-side rendering is you need to start duplicating all the code the moment you need some front-end interaction. Also, I prefer when the interactions are snappy, and having to hit the server on every click to fetch some html feels so slow. I do agree though that building SPAs is too complex and that we haven't yet found the perfect solution.
- TrispusAttucks 5y agoSpot on. There are cases for SPAs but there are also a lot of bad cases. Just the other day there was a news article (don't remember which) here on HN. The entire page "shell" loaded but the content of the article did not. Quick inspection and it appeared that the SSR page was loading fast but some SPA call that loads the data was underperforming terribly so it was blank. Let that sink in... we're in the web, it's 2021, everything BUT the article content loaded. Talk about optimizing the wrong thing. We've all went crazy. The gains are rarely worth the costs.
- least 5y ago> Sure: traditional non-SPA websites are not immune to this pitfall. Someone might load your website, have a form open for many weeks, and then submit it after their session expired or the API changed. But that’s a much more limited exposure to failure than in the SPA case. I don't really understand why this is a much more limited exposure to failure and he doesn't really elaborate why this is the case. It seems like the cause for failure in both cases are identical and the only reason that the SPA one would be a more likely scenario is simply due to the prevalence of SPAs, rather than any technical reason. Overall I broadly agree with the article; that React is often wasted on webpages that simply don't need it. That a lot of technology that is plenty serviceable today is overlooked because it's not 'cool.' I actually think php is great (even though writing it isn't very fun to me) and it was one of my first introductions in creating dynamic webpages when I was a kid outside of some cgi scripts like NewsPro. Vanilla javascript today is very robust but it's not exactly someone will end up writing a lot of unless they're going out of their way to do so. Web components might very well fit the needs someone might have for their website... but that doesn't really matter if you already know how to use components in React and you have to learn web components. There's a lot of momentum towards the known, especially when that known technology is valuable to employers. Ultimately I think that while it's generally excessive, people gravitate towards what they're comfortable with and what makes their development life easier. Sure, this website may not require a React app, but it's something that I'm very familiar with and it's easy for me to create a website with it. It's easy for me to create interactive and dynamic elements in a system that is designed for that purpose. And the reward for having this knowledge is market value. This will always be a problem, regardless of what web technology is popular at any given moment.
- blakewatson 5y agoI always have cognitive dissonance about this kind of stuff. I read this article and “In defense of the modern web” and I feel like I agree with both of them. I think new things don’t necessarily make older things obsolete. We have printers, for example, but it’s not like pens, pencils, and even chalk aren’t useful. Whenever I start a new project (admittedly, these are personal projects so not the same kind of scale—but in my job where the where the scale is bigger I’ve noticed a similar sentiment), I like to think about everything I have available to me. I could make a Vue SPA, a generated static site with 11ty, a backend CRUD app with PHP (I like Fat-Free Framework), WordPress (haters gonna hate), a site with no JavaScript, a site with only vanilla JavaScript, or anything in between. I at once feel like a wide-eyed optimist ready to plow into the future and a curmudgeonly get-off-my-lawn skeptic who’s been burned too many times. It's a good thing I consider building websites/apps good fun or else I would be really stressed out. :-)
- pengwing 5y ago>new things don’t necessarily make older things obsolete. We have printers, for example, but it’s not like pens, pencils, and even chalk aren’t useful. When first reading your example, I expected the printer to be the old technology. I think printers and pens have very different use cases. Using a pen establishes a creative loop with direct feedback, while printing is about making a copy of something that already exists. I think its fairer to compare a printer to digital storage/digital display of a document. The former exists due to ancient legal requirements when signing contracts. Similarly delivering a cached SSR HTML document fast and hydrating it with JS afterwards is the way to go. TTI is only a problem if you don't use regular links as fallbacks to make requests before hydration replaces them with JS-based event Handlers. Implement the modern web by using the established web as a fallback.
- bmeski 5y agoI've seen the issue of new hires, time after time, getting a small ui ticket and immediately asking, "where is the client store?" or "Why aren't we using Redux, it'll clean up our code a bunch." Of 20+ applicants I've interviewed this year, only 2 knew about element.dataset and how to create a basic state scoped to that vanilla JS "component". The issue is groupthink and using the hammer on everything.
- onion2k 5y agoThe point of Redux (or any state library) is to share state between components. Unless you're doing something like putting the state for a child in the data- attributes of a parent somewhere further up the tree I don't think element.dataset does the same job at all. element.dataset is much closer to something like using useState.
- wonnage 5y agoIt's probably because invoking DOM APIs is terribly slow and if you're accessing those fields with any frequency you're better off using a JS object.
- bmeski 5y agoThe point was that there are many ways to solve the problem. For say, a simple tab layout where you add click handlers to the tabs and hide/ show the contents, you would never notice any latency using the DOM apis. The DOM apis are the core of web development. You need to know them and consider them before moving into the abstraction atop.
- jjdeveloper 5y agoI really like the way that Phoenix Liveview is trying to solve for this, trying to find the sweet spot in the middle of building multipage apps and SPAs. Great talk about it from the developer here https://youtu.be/8xJzHq8ru0M?t=409 https://youtu.be/8xJzHq8ru0M?t=409
- Toutouxc 5y ago> unloved, unpopular, uncool things like Django, Rails, Laravel Oh they're loved all right, it's just that they're (all three) very mature, packed with features, easy to pick up and people who work with them don't have a reason to sit around and discuss the tools. I work for a smaller Rails shop and the atmosphere is just so nice there. We work on small (think $20k) projects for different niche customers, we absolutely reject SPAs (for what we do), we host the apps on cheap VMs, we don't worry about scaling at all, we talk to the clients a lot, we prototype fast and it's all just so easy and even brings good money. Rails is the no-bullshit way, and definitely the human way.
- draw_down 5y agoThose frameworks just aren’t alternatives to React/SPA in my opinion. I’ve worked on more than one system that had one of those frameworks on the server and React or some other frontend framework on the client.
- phist_mcgee 5y agoGood you have found your niche, and it's great that you haven't overextended yourself when it comes to delivering value to customers. I would say though that your work is a subset of web dev, and while totally valid in that area, I don't think it applies as concretely to other domains, particularly those with larger audiences, or those with needs for greater reactivity.
- darkhorse13 5y agoSorry, but this is just plain bollocks. Some of the most popular websites run on Rails/PHP/Django, and they are not "reactive" SPAs.
- phist_mcgee 5y agoAre you disagreeing with my assertion that the above poster's view is a bit too narrow in its application? I know a lot of sites run rails/php/django, but that does not mean that they are the majority, or even part of a minority that are the 'most' succesful.
- aphextron 5y ago>I don’t think that everyone’s using the SPA pattern for no reason. For large corporations, it allows teams to work independently: the “frontend engineers” can “consume” “APIs” from teams that probably work in a different language and can only communicate through the hierarchy This is really the main reason. Ultimately just a consequence of Conway's Law [0]. [0] https://en.wikipedia.org/wiki/Conway%27s_law https://en.wikipedia.org/wiki/Conway%27s_law
- throwaway77112 5y agoReally good witty talk on 'The website obesity crisis'. Must watch IMO: https://www.youtube.com/watch?v=iYpl0QVCr6U https://www.youtube.com/watch?v=iYpl0QVCr6U
- wonnage 5y agoMany of these problems are solved: > Most bundle splitting techniques require you to load that ‘index bundle’, and then only once that JavaScript is loaded and executed does your browser know which ‘page bundle’ it needs. So you need two round-trips to start rendering. Hopefully you're performing some server-side rendering, which should know which page is being rendered, and save the browser a round-trip by including the page bundle in the initial response. > So the user will be using an old version of your JavaScript frontend with a new version of your API backend You should never couple your API backend that tightly to your frontend release version. What if you find a critical bug and have to roll back? Anyone that deals with a native app also has to deal with people not installing updates. > (regarding SSR) The first is that the page you initially render is dead You can always make your JS render-blocking if it's really that important. Most people would rather see the content first. > If you do SSR on any pages that are custom to the user, then you need to forward any cookies or authentication-relevant information to your API backend and make sure that you never cache the server-rendered result. This applies to every website. > But no option really lets a web app be careless about its data-fetching layer. This applies to every program that has to fetch data from somewhere. > Speaking of data fetching. It’s really important and really bizarre in React land This is definitely true but also something React expressly considers out of scope, for better or worse. I think the reason the GraphQL clients tend to have a better story here is that a lot of the tricky things about data fetching (data normalization, deduping queries, updating related objects, etc.) are difficult or impossible without a common query schema with standardized field types, which GraphQL provides. All in all, I think the SPA pattern has won out because it's the one pattern that lets you treat your website like an actual long-running program, instead of a series of stateless requests. People will complain about complexity and tout the zen-like purity of their Jekyll blogs, but this complexity is what allows the web, as a platform, to thrive and compete against native apps and the walled garden of app stores.
- tempodox 5y agoI've got one nitpick: > ... frontends [...] have been loyal to one programming language for decades. I wouldn't call using the _only_ thing available “loyalty”, its just do-or-die. Other than that, the article rings true for me.
- codingclaws 5y agoMore front-end JavaScript equals more expensive, less backward compatible and less cross-browser compatible.
- londons_explore 5y ago> "You can buy this Jekyll theme..." Quite why I would spend money on a theme consisting of a white background and unimaginative black text beats me...
- midrus 5y agoMany people compare SPAs vs "traditional" MVC with full page reloads or jQuery spaghetti, not realizing nowadays there are great intermediate solutions which don't take as much effort as SPAs by a long shot, such as Unpoly, Hotwire, etc. It's unfair to compare a highly over engineered React application vs a lazily built jQuery mess.