48 ms·
Things I wish I knew before moving 50K lines of code to React Server Components
- swyx 3y agohttps://docs.mux.com/ https://docs.mux.com/ doesnt seem very interactive at all. i guess i'm being that guy but i'm wondering why it had to be in React, much less RSCs.
- CipherThrowaway 3y agoIt seems most of the content is dynamically rendered (at build time with SSG). What alternative did you have in mind?
- psd1 3y agoI'd rather use Blazor, or Jinja. But I hate react, js, and front end work, so maybe I'm not the target audience. I clicked the link out of morbid horror.
- CipherThrowaway 3y agoI haven't used Blazor, but I shudder at the thought of using Jinja to generate the HTML here. Rendering documents from OpenAPI spec benefits from being able to easily transform data, map, filter and so on - especially if you are displaying the JSON schema for request and response bodies (which docs.mux.com appears to be doing). The experience of doing these transformations in template languages is pretty sub par.
- sodapopcan 3y agoI use Phoenix LiveView and I’m really big on frontend. I also do a lot of backend, though, so I’m one of those “full stack” generalists that no one likes anymore.
- quickthrower2 3y agohttp://motherfuckingwebsite.com/ http://motherfuckingwebsite.com/ styling is sufficient for technical docs. I hate the scroll hijacking and other shenanigans on modern docs sites.
- CipherThrowaway 3y agoI agree re: scroll hijacking and with a preference for minimal styling, while noting that the styling on docs.mux.com is pretty minimal compared to other docs sites. What I'm wondering is what the anti-React folks are recommending for generating HTML and/or DOM itself in the docs use case, since most of it needs to be dynamically generated from OpenAPI definitions.
- Osiris 3y agoStatic file generation. People are suggesting that tooling creates HTML files from templates at compile time and then served as plain HTML.
- CipherThrowaway 3y agoGoing by the response headers, it seems that most if not all of the HTML served by docs.mux.com consists of cacheable static files. As the OP article mentions, using React for static generation is one of the big use cases for RSC and Next. Which templating technology would you recommend for the use case instead? Keep in mind that generating HTML from OpenAPI specs can become complex and will require plenty of maps, filters, recursion and indexing into the data in the course of transforming it into HTML.
- jmull 3y ago> plenty of maps, filters, recursion and indexing into the data Are there a lot of server side template languages that can’t do this? This is straight-forward stuff.
- 3y ago
- deleted 3y ago[deleted]
- tqkxzugoaupvwqr 3y agoYet performance is abysmal. I clicked on “API reference” and nothing happened for a second. Then the submenu opened in the sidebar. Another second later the content view updated. There is no indication of anything loading, there are no network requests to await. Incredibly, it’s dog slow on an M1 Mac. If the viewport is 800 px or narrower, click on the menu icon (horizontal bars, top right), then click on a sidebar link. Do that a few times, you’ll notice it’s incredibly slow to react. Same with resizing the viewport, very sluggish.
- treis 3y agoWow you weren't kidding. Very slow and very frustrating to use.
- FridgeSeal 3y agoGood lord it’s awful haha. Some more unhinged stuff I noticed: - swiping backwards exists the drop down menu for some inexplicable reason - clicks on menu bar items take so long I genuinely thought I hadn’t tapped on it correctly. - taps on the menu bar sometimes just don’t work. Like, at all. Oh scratch that, the menu was there after I swapped tabs to write this sentence. - massive chunks load in at different times: the signing key page shifts as more content loads in 3.5 seconds later.
- phist_mcgee 3y agoThere's something to be said for optimistic routing, server or client side. It seems like they're using suspense to wait for the page to be rendered before swapping the route. It's a noticeable breach of the standard pattern of instant navigation, and then wait for content to appear.
- FridgeSeal 3y agoI really wish it was possible for users browsers to opt-out of stuff like this. I don’t want some unhinged developer deciding they’d like to arbitrarily delay things like this, just render the page and stop making things worse.
- brailsafe 3y agoThat seems like a tremendous commitment for such a recent technology.
- bottlepalm 3y agoYea I give stuff like this at least a major revision or two for things to settle. Maybe Next.js v15.
- Takennickname 3y agoMy thinking as well. Reflects poorly on the company. I'm not in the market for whatever they're doing but if I was my impression is they have a bunch of hipsters drinking coffee and reimplementing stuff no one asked for.
- bdlowery 3y ago“This technology we heavily rely on is completely changing the way it works. Should we update now and get into the ecosystem?” “Nah, this guy on hacker news said we’re dumb hipsters for adopting the new normal for react. We should stay on the old versions.” That’s like saying you don’t trust a company because they updated from PHP 5 to PHP 8.2
- raverbashing 3y agoMore like "hey we just spent 8 months of investor money on a rewrite and this works much worse than the previous solution. But hey, they're throwing this out and the new thing is ReactWebLogic, let's do a new rewrite!"
- mmcclure 3y agoThis might be fair if this was a rewrite in a vacuum (or took anywhere close to 8 months) but it wasn't. We were also undergoing a large design refresh for the site, which was going to require a ton of work on the existing site anyway. Using the opportunity to also update to the newest version of the technology we were using wasn't nothing, but I'd argue it was also probably a pretty small marginal increase.
- sam0x17 3y agoAt the point of server components I sort of giggle to myself that we've come full circle and maybe I can come out of my SSR bomb shelter and enjoy life again
- Osiris 3y agoI also am baffled by the return to server side rendering as the new thing. It’s like people forgot that’s how it used to be. I’m sure they’ll claim it’s different now because… hydration or something or another. As a former PHP developer who spent a lot of time both working on server rendered pages and converting server rendered pages to be API/JS (render the core in HTML+JS and use APIs with two way data binding to update the UI), I can’t believe we’re going back that way, but with wildly more complicated patterns than we had before.
- sam0x17 3y agoYeah, I've witnessed the entire arc also as an ex-ex-ex PHP developer from the early 00s, and I literally recall the original justification for this whole exodus that lead to the creation of React and a slew of other things was "jquery bad". I just wish we had skipped all the in-between stuff and just arrived at htmx back in 2011 instead of now. Maybe I'd still be doing frontend stuff and not burying my head as far into backend as humanly possible while I wait for a workflow that doesn't require a package.json and a 3 GB node_modules folder so I can make the same frontend widget I could make with 50 lines of js in 2007.
- ytoawwhra92 3y ago> I just wish we had skipped all the in-between stuff and just arrived at htmx back in 2011 instead of now. We kind of did (well, 2013), but it just wasn't backed by a massive developer marketing effort.
- quickthrower2 3y agoSSR is different I think because it can perform better, but given the state of most sites on the internet I think 2003 style rails is sufficient for most sites. And I haven’t met a JS-ey UI I have enjoyed using as much as a vanilla HTML one for most online stuff (drawing, games, 3D etc. excepted).
- kqr 3y agoMaybe it's just the circles in which I've been active lately, but I feel like a lot of time and effort is spent these days practically just moving code around between implementations, without much practical change in user experience. What drives this behaviour? I mean the question on a deeper level. An answer like "the technology hype cycle" just begs the question. Why does someone feel like they have to move business logic onto a particular framework (and then realise it's a mistake and move it again to a different framework that's similar to the one they started on?)
- doctoboggan 3y agoI think it's somewhat similar to the "not invented here" syndrome, but more of a "not invented now" syndrome. People (rightly or wrongly) believe the new technology is better suited to their problems.
- kqr 3y agoThat also somewhat begs the question! What makes them believe that?
- SanderNL 3y agoWe are constantly bombarded with the idea that society is progressing - towards.. "something" - and change means "good", because "moving forward". Ergo, yesterday's things are inherently worse. IMO I think that's at least part of the issue. There's also the common notion that movement seems productive. If you are not moving, what are you doing? This effect happens on a lot of levels. Especially managers have to show they are moving needles. Any movement is better than no movement.
- frje1400 3y agoI think that one factor is that staying on old tech is a risky career move both for the individual and the business. At work we have an Angular (the old one) app and while many new devs pick up some React, they definitely don't play around with ancient Angular versions for fun. So now we're stuck with a pretty big app using tech no one is interested in anymore.
- mediumdeviation 3y agoNot sure if the OP is here but on Firefox clicking the "API reference" button on the top left causes the full page transition to stutter. The profiler says more than 150ms is spent in a getBoundingClientRect call in a componentDidMount triggering reflow + style computation and 30ms on set Element.innerHTML. That seems excessive especially since I'm looking at this on a recent M1 Macbook.
- deleted 3y ago[deleted]
- tacker2000 3y agoSame here, and same with “webhook reference” and “changelog”
- dardarbinks 3y agoAuthor, here. This kills me too. I can’t wait to fix it.
- chrisco255 3y ago"This was called client-side rendering (CSR) or single-page applications (SPA) and was widely considered a bad move." Why was it considered a bad move to go SPA? I generally disagree with this statement. But I feel like whenever this conversation comes up we're talking different applications altogether. A SPA is fine for a back office application. What it's not necessarily good for is a splash page or marketing page where each page truly operates independently. But in the case of an app that people use frequently, the client side code all gets cached locally anyways, and SSR doesn't buy you anything for that use case. SSR is great for getting a fast time to render on the very first hit to a page. But if you're making a real, rich app, that people will use daily client side JS is not bad at all. I worked on Trello for a while, it was a single page app with a Node.js API. We served millions of users with it, and people generally loved the UX of our app. But it was a true web app, and not a website. Interactivity was always part of the user experience, and many of the behaviors would be impossible in a pure SSR app.
- onion2k 3y agoWhy was it considered a bad move to go SPA? There are two main advantages of SSR; - API calls necessary to build the page happen in the data center instead of the public internet, so they're much faster. You can use a database query instead of an HTTP API call if you really want to. That results in a huge speed gain for a lot of sites. It also reduces the complexity of the page - devs don't need to build logic to wait for things. The page just doesn't render until it has the data it needs. - You don't send the user code they don't need yet. If someone is viewing a page that doesn't have a widget, but you send them the code for the widget because you've bundled everything the site needs into one JS file, you've wasted the users time and bandwidth. SSR is a very easy way to solve that problem. I'm of the opinion that SSR is a better alternative to a bad SPA, but marginally worse than a good SPA, so for most teams it's a good approach because building a good SPA is hard. If people want to use SSR and that results in me not seeing 4MB homepages any more that can only be considered a win.
- gausswho 3y agoThe first argument leads to waiting to see anything vs at least seeing something. Many use cases the latter is preferable. The second case is a common misconception of modern SPA. Code-splitting has been around for a while now. When split across routes it's trivial to implement.
- mediumsmart 3y agoIn server-side rendering, clients are sent HTML that they can see immediately I noticed this too. You can put a plaintext file on the server and it gets transferred to the browser pretty fast. You can also put another plaintext file ending with .css on the server and it can make things on the first page move and look really nice just because the browser knows what to do with it. It’s a neat trick but still second to useful content on the first page (that is the page you get to read, if it lets you).
- arthur_sav 3y agoWhat is this sorcery you speak of?
- lkrubner 3y agoCareful, my child, for those who speak of these things are forced to leave their tribes and wander forever in the deserts and the wastelands.
- gabereiser 3y agoTruth
- deleted 3y ago[deleted]
- phero_cnstrcts 3y agoI thought we had lost that technology.
- ytoawwhra92 3y agoIt's weird how projects like Turbolinks, intercooler, and pjax just don't get acknowledged in histories like this one.
- Scarbutt 3y agoNetwork effects, react is where the jobs are.
- deleted 3y ago[deleted]
- megalord 3y agoFor now
- popcorncowboy 3y agoReact is as baked in now as Java and Covid.
- kxrm 3y agoA little over 10 years ago we were saying this about jQuery. React definitely solves problems that jQuery just couldn't solve well. I know that there are issues in react we still need to address, so I know it will be a matter of time before some new way is developed that will supplant react and we will talk of react then as we talk of jQuery today.
- uxcolumbo 3y agoStupid question… why roll your own solution for a marketing site and doc site? Why not use already battle-tested CMS solutions (opensource or paid) and focus your dev effort on your actual product, in this case a video platform product.
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- raphaelcosta 3y agoDoesn’t make any sense for me why we are now using React in the backend, to render HTML… Let’s go back to 10 years ago.
- ojkelly 3y agoReacts programming model appeals to people, and react is good at problems that have a predictable output like HTML. Plus if your frontend is react, it’s much easier to keep all the html generation in one place.
- ttfkam 3y agoA combination of the devil you know and Stockholm Syndrome. It was better in many ways than the dominant techniques in 2013, sure, but that's not a terribly high bar, especially when observing the React model a decade later. React served well enough for quick starts. It proved… challenging… for ongoing maintenance and quality control in long-lived projects.
- tmpX7dMeXU 3y agoHaving a templating system in ‘that environment’ is worth its weight in gold IMO. I’ve been switching between Svelte and Django templates a lot lately, and Svelte just…knowing about the DOM, makes the experience so much nicer. I haven’t come across a non-JS template system that does this. And yes, I was there for PHP and jQuery and whatever.
- raverbashing 3y agoI have to agree, Django templating (last I saw) was stuck somewhere in Web 1.0 Jinja2 is better, but most of the time, I would just build the API and not bother with rendering anything on Django itself
- mattmanser 3y agoWe've had templating systems on the server-side for many decades? Do you mean having a javascript templating system maybe? Not really worth it's weight in gold.
- Illotus 3y agoI guess you use what you are familiar with, but using react for doc site instead of using some off the shelf static site generator/cms with caching seems like wasted effort. More fun from dev point of view with react no doubt.
- Osiris 3y agoI agree. It’s static content. Why isn’t it just generated as HTML with some JS for the search bar?
- ojkelly 3y agoGreat doc sites are dynamic in heaps of little ways. Stripe started the trend of showing you code snippets with api keys from your account to test with. Frontend docs sites almost always include runnable examples, that you can play with inside the docs.
- yard2010 3y agoYou can use a static site generator like Gatsby or a variant of Nextjs (or even docosaurus), get MD(X) support and full features of react components when needed
- junon 3y agoYou can get dynamic functionality for docs sites without much JS at all. We've been doing it for years.
- satvikpendem 3y agoIt's easier to integrate JS when the entire toolchain is all in JS. That's my main reason for using React Server Components over other static site generators. Also I like types via TypeScript.
- rrdharan 3y ago> Stripe started the trend of showing you code snippets with api keys from your account to test with. Pretty sure Google started / had this years earlier (before Stripe even existed?). And there may have been others earlier as well.
- pavlov 3y agoI wonder about the code with the heading “A Server Component with data fetching”. It shows a HTTP request made to the company’s publicly visible API endpoint. But this request is being made from their own server (the one that is generating the HTML + JS from these React components). Is the idea really that your front-end generator calls client APIs rather than internal ones (e.g. just making a database request)? That seems kind of wasteful, and also potentially confusing from a API design standpoint.
- morbicer 3y agoIt's a limiting, but saner approach for any larger app/company. It's the same logic why in OOP you have private members/methods. As owner/maintainer of some component you want keep stable public api and be able to iterate on the internals. Letting any client willy-nilly directly fetch from database is unsecure and unmaintainable in future.
- regularfry 3y ago> Letting any client willy-nilly directly fetch from database is unsecure and unmaintainable in future. Surely you'd just want to be calling the internal API that the other endpoint is using behind the HTTP endpoint? If you're in the same process (big if, but nothing to suggest they aren't), there's not a lot of sense serialising out to a socket and back again rather than making a function call.
- morbicer 3y agoSure, calling internal API is sensible. I am not saying it needs to be public API. But you probably can't avoid some serialization (be it REST, GQL, GRPC), the service that owns the data can be different than the one serving the html. I am not saying everybody needs to do microservices but my experience with monolith is bad. You want at least "some" services and the html-serving service shouldn't usually own the data. User data belongs to user service, report/analytics data to analytics service etc. Just from the security point of view, the stuff facing internet should have minimum rights to read/write anything. Definitely not direct function-calling or db access.
- decide1000 3y agoThe article makes a comparison with PHP. I recently worked on a Laravel Livewire project and learned that it could do everything I used to do in React, from PHP.
- regularfry 3y agoThe argument is usually that you don't want a network round trip for interactivity. That's less true than it's usually presented, I think because most folks making that argument think the server is necessarily slow.
- XCSme 3y agoBut... a round trip is usually faster than serving 2MB of JavaScript.
- satvikpendem 3y agoIt feels worse for user experience though. I think people forgot why SPAs were so popular in the first place.
- regularfry 3y agoIt is, but that's not the comparison. The question is how well you can react to a user action if you need a network round trip in the middle. The user's already got the 2MB of JS loaded in their browser. My stance is usually that as long as you can get a response to the user (which can be a DOM fragment, a JS snippet, whatever, doesn't matter) within 200ms, you don't need client-side rendering. And if you haven't yet got under 200ms, you shouldn't be spending time complicating your application to be distributed between the client and the server until that's fixed.
- XCSme 3y ago> The question is how well you can react to a user action if you need a network round trip in the middle I do think this is the question, but the solution is not an SPA, but instant interaction feedback and no content jumping around. If you solve that, a 1-2s response from the server will seem instant, whereas with a bad implementation, you can have everything on the client-side and make that 0ms interaction look more sluggish than the one that goes to the server. Think of a chat application, if you send a message and press send, it doesn't matter the request takes two seconds, if: * The message is immediately shown in the chatbox * There is direct feedback on the status of the message (sent/received/read) * You can continue interacting with the application while the message is being sent (non-blocking) You don't have to send all the data/messages before (server-rendered), just some logic to what happens when an action is taken.
- parham 3y agoSo if I understood correctly RSC are the “next iteration” of iframes?
- alib 3y agoWhat I love about this is how PHP and JavaScript had basically the same syntax (minus a $ symbol here or a var keyword there), and then NodeJS was like, but we want to run JS on the server! And now, 15 years later JavaScript has finally caught up and it’s basically the same as PHP, but with more acronyms and a steeper learning curve (to be fair, streaming data from server to client components using suspense is cool). I’ve been using NextJS 13 and I love how it makes SSR as easily achievable as it always was with PHP and always should have been. I’d recommend it highly.
- awestroke 3y agoWell, PHP has no client-side rendering, so it's a weird comparison
- tacker2000 3y agoOP said PHP + Javascript. JS is used for client side rendering. Nowhere was implied that PHP does that.
- deleted 3y ago[deleted]
- jstummbillig 3y agoPHP has as much client-side rendering as React SSR does. I think the sleight of hand that is happening right now, and that gets people a little confused, is that React is shaping up to be this thing that handles both front and the backend where other solutions can't do that. Sure – but it does that by overloading and complicating what React once was (neither of which per-se negative, I think it's just an apt description of what is going on) Where other solutions might have abstracted the frontend part into a thing with a different name (or not bother doing it at all) React chooses in a rather unprecedented move to call it all just... React (well, there's Remix and such, but alas). Which is fine, as long as you understand that this new "React" will now probably lead to "React Frontend Dev" and "React Backend Dev", because the work and the complexities that these rolls entail did not just disappear by rolling it into the same name. It's not entirely clear if architecturally there are going to be more benefits than footguns, but I think it's cool that they are trying.
- yakshaving_jgt 3y agoThe Yesod Haskell web framework has had this for I think more than a decade, and I'm sure it isn't the only one. It's not a bad idea, but it's strange to see old ideas presented as novel.
- ojkelly 3y agoIsn’t everything a new take on an old idea? And that’s what makes them novel. As Sagan said, “If you want to bake a cake from scratch, you must first invent the universe.” We’re remixing everything all the time, nothing is completely new and that’s fine. We still move forward.
- yakshaving_jgt 3y agoI see what you're saying and in a broader sense that's true. More specifically though — in the world of web development — some ideas are actually [as good as] original. When CSR/SPA became well established as an approach in web development, there wasn't a time before it when that approach had been common. The approach to web development described in the article however is essentially the same approach that web developers commonly used 10-15 years ago. n.b. I'm aware the CSR/SPA approach is more like 20 years old, but I'm making a judgement call on how common common is. Furthermore, when the CSR/SPA approach was first explored in ~2002, what old idea was it a new take on? Flash? If so, what begets Flash? There was a time before the Internet, and it wasn't all that long ago.
- dunk010 3y agoThin vs thick client is a much older debate, but you have to go back to the times before the Web ;-)
- tacker2000 3y agoSo they are basically using Ajax calls to fetch/populate data asynchronously after loading? Or what did i miss here?
- Alifatisk 3y agoThe web tech is truly a swinging pendulum.
- rwoerz 3y agoThe whole IT landscape is and very few are able to tell real progress and fashions apart.
- tomduncalf 3y agoDoes anyone know if CSS-in-JS and Context support is planned for RSC, or is there a technical limitation which means they’ll never be possible?
- sesm 3y agoFor Context support, I think the reason it's not supported is because Server and Client components have different lifetime. In theory they could add something like Server Context, that's accessible only to Server components. For CSS-in-JS, those are all 3rd party libraries, so they need to adapt on their side. For example, `styled-components` uses Context heavily, so they need to re-think their approach. For `css-modules` adapting to Server components looks doable, but requires substantial amount of work.
- satvikpendem 3y agoPandaCSS and Vanilla Extract are subsuming styled-components, precisely because that is runtime CSS while the former two are compile time based and so work for the server.
- willdr 3y agoA better name for context is Client Context. On the server can you not just use a pojo?
- djmashko2 3y agoIf you’re rendering multiple pages concurrently on the server, it’s nice to be able to know, for example, the current user without having to pass it down as a prop through the whole tree. Context is a really nice way to do this.
- btown 3y agoFor Context support, https://github.com/vercel/next.js/discussions/42301 https://github.com/vercel/next.js/discussions/42301 isn't promising, and https://twitter.com/sebmarkbage/status/1587615484870098945 https://twitter.com/sebmarkbage/status/1587615484870098945 explicitly suggests you might need prop drilling. I'm really sad that tree-specific context for server components seems to be an afterthought. As the Twitter thread suggests, if you have something that can be used across all the server components for an entire request, you can use the cache functionality or rely on Next's URL parameters. But if you've relied on Context as a way to let deeply nested components access some kind of business logic that's specific to only a part of a rendered page, and if you want/need those components to be server components, you'll need to switch to explicitly drilling the props through.
- parasti 3y agoI feel the history explanation isn't that great, making it look like the modern web development simply reinvented PHP. There are nuances to every technology that make developers choose it over another. Still looking for a good blog post on the evolution of web development since PHP+jQuery.
- sandGorgon 3y agowould htmx have fixed this problem ?
- foooorsyth 3y agohtmx + django + tailwind fixes 99% of problems on the web, and you get to leave npm behind read the docs / a basic markdown to html converter would’ve been sufficient for static docs. Worked at a company the completely over engineered their docs. Created some job security for the people that knew how the monster worked, but added zero value for users. Never again
- holoduke 3y agoI think i am getting old. These frameworks are so big and complex. For a simple web hello world you need a huge build and compile pipeline. And now its extended with serverside components. I really wonder what the overhead is. How many of layers of frontend and backend framework code is executed to get the hello world example running. I retreat back to my simple 10kb component framework in which i need only f5 to rebuild.
- knubie 3y ago> For a simple web hello world you need a huge build and compile pipeline. These frameworks were not created to solve “Simple hello world” apps.
- lelanthran 3y agoWell they don't look like they were created to manage complexity either, so exactly why are they used?
- csomar 3y agoThey simplify the on-boarding of 6 months boot-camped front-end developers. They can start working and delivering right away despite not being able to tell the difference between front/back ends and having no understanding of servers.
- bsenftner 3y agoExactly! These frameworks enable people with 6 months of "software developer" education to enter the industry and enshitificate our careers with their minimum wage level understanding of actual software engineering, dragging all of us down to their salary level.
- hnfong 3y agoIf your career can be significantly affected by devs fresh from bootcamp, you probably need to sort out your own issues than to complain here mate.
- mgaunard 3y agoWeb tech never ceases to amaze me in how they keep over-engineering simple things. You have a backend service, you implement it in whatever language you want, presumably C++ if you care about performance or are doing something non-trivial. It provides REST and WebSocket endpoints to input and receive data. You have your GUI to visualize the thing. Common sense is to have the overall structure in HTML and fill it in with JavaScript that queries the backend. The advantage is that you have a rapid and interactive development environment in the browser and can quickly iterate on a useful GUI without touching the backend. Then, moving the GUI to be part rendered on a server, that sounds like a terrible idea, a good way to increase latency and to add load onto your servers. If you need to do that to get decent performance then probably your backend API is inadequate. Compiling the code also breaks the whole point as it makes the development non-interactive.
- deleted 3y ago[deleted]
- eureka-belief 3y agoGreat article for catching up on the next cool thing and what common hurdles to expect. However, the next question that needs answering is how the migration to RSC has affected the user experience and their ROI. Without any such data or analysis, how would I ever reasonably approach a product manager and ask them to please give our team weeks of work just to hop on this new technology?
- VagabundoP 3y agoSlight newbie take here. I've just developed a personal webapp with python/flask/htmlx/tailwind. Its for my RPG group and its an interactive GUMSHOE character sheet with discord integrations through webhooks. I used htmlx/hyperscript so I wouldnt have to get into JS - I find it a complete headache. Getting the balance between server-side and client side processing so its not a huge pain in my ass to debug also took a little bit of experimentation. But in the end I think I spend more time on styling the webpage with tailwind then on the htmlx/hyperscript which is a breeze to learn from scratch.
- ManniMo 3y agoI get the impression that React is trying hard to catch up with the more modern, easier, faster and cheaper alternatives. But instead of fixing the root problems (rerendering and often required memoization, leaky abstractions) and make React easier, it becomes more complex. If the end result was great, I would understand all the effort. But it isn't. React is even slower in real world than the benchmarks show. Next is even worth. I've seen recently many dog slow websites built with Next. Really, I don't get. If the React team wants to improve React they should fix the core.
- CharlieDigital 3y agoThey can't. The ecosystem has too many dependencies that break at this point. Consider that Target.com, Walmart.com, Microsoft Teams, and untold masses of sites are React. The huge component ecosystem. Entire companies built around it. The core concept is broken§, but fixing it means possibly breaking everything else. If you're going to break everything, might as well use something else. All we can do is truck along at this point; stuck with React because of the mass of the dependencies. § React is the only library/framework that is opt-out of re-render while Vue, Solid, Preact, Svelte are all opt-in. This is one of the core reasons it's hard to do right and prone to a specific class of bugs that rarely -- if ever -- show up in other frameworks as you constantly have to be aware of opting out, even in what seems like normal JavaScript.
- lacrimacida 3y agoCould you explain how the opt out/opt in works? Im a bit confused
- CharlieDigital 3y agoTake this example: const { useState } = React; function Person(props) { console.log('Render Person'); return (<span>{ props.identity.firstName } { props.identity.lastName }</span>); } function App (props) { console.log('Render Hello'); const [count, setCount] = useState(0); const einstein = { firstName: "Albert", lastName: "Einstein" }; return ( <div> <button onClick={() => setCount(count + 1)}>Increment</button> <Person identity={einstein} /> </div> ); } ReactDOM.render( <App />, document.getElementById('container') ); The `<Person />` component will redraw on each `increment`. Nothing changed. Why would it redraw? Because when the `App` component redraws, the `einstein` variable points to a new reference. React sees this as a change and redraws both `App` and `Person`. What looks like normal JavaScript here is not. To prevent this redraw, you have to opt out like this: const einstein = useMemo(() => ({ firstName: "Albert", lastName: "Einstein" }), []); Or know to move the reference outside of the `App` like this: const einstein = { firstName: "Albert", lastName: "Einstein" }; function App (props) { ... } Which is fine in this case because there are no dependencies on the component tree. This is the most common mistake I see in React that leads to bugs. It's not just objects, but also functions. This is also a redraw: const { useState } = React; function Logger(props) { console.log('Render Log') return (<button onClick={props.onClick}>Log</button>); } function App (props) { console.log('Render Hello'); const [count, setCount] = useState(0); const logConsole = () => console.log("HELLO, WORLD"); return ( <div> <button onClick={() => setCount(count + 1)}>Increment</button> <Logger onClick={logConsole} /> </div> ); } ReactDOM.render( <App />, document.getElementById('container') ); Why? Because on increment, the `logConsole` is a reference to a new function. So the `Logger` redraws as well. So here, you need to opt out once again by using `useCallback` or moving the function out of the component tree (fine in this case since there are no dependencies). The thing is that it looks like normal JavaScript but the React render cycle is the unseen; you have to be aware of moving things "out of the way" and "bringing them back" via a hook. React's render cycle re-evaluates entire component sub-trees for changes and if your component doesn't explicitly opt-out by preserving referential equality (`useState`, `useCallback`, `useMemo`, etc.), you'll trigger a redraw downstream. These hooks effectively move the references out of the component tree and pull them back in when the tree re-renders and thus preserve referential equality. So what teams might do is after experiencing this one time chasing down a bug is wrap every single declaration in a hook to reduce the mental burden. This then creates other issues like performance and memory. Vue, for example, is the opposite because it has fine-grained reactivity. Nothing redraws until you opt in by using the Vue reactivity primitives.
- solatic 3y ago> CSS-in-JS is a non-starter This used to be true, but there are new libraries like PandaCSS that bring CSS-in-build-time-JS, thus bringing Tailwind-like performance and React Server Components compatibility. https://panda-css.com/ https://panda-css.com/
- sickcodebruh 3y agoAgreed! My wife and I are using Panda on our project and it’s wonderful so far.
- justoreply 3y agotime to create jsp pages again?
- dunk010 3y agoYou monster
- chiefalchemist 3y ago> Slow database call? No need to wait; we’ll just send that slow component to the client when it’s ready. Your users can enjoy the rest of the site in the meantime Seems like he buried the leed, or presumed everyone already knows: RSCs are ideal when you're pulling data from multiple APIs, some of which may be slower than others. That said, if the slower one or two are at the top of the page - or at an anchor that might be directly linked to then the UX doesn't really improve, does it? I'm confused how / why their docs would require React-iviness. Sure perhaps there's a video here or there but is that grounds for tearing down the docs just to use RSCs? These tools are great, *when they are the right tool for the job*, else we just seem to be reliving an unhealthy infatuation with shiny new object for the sake of my shiny new object is shinier than yours.
- deleted 3y ago[deleted]
- DigitalSea 3y agoI'm old enough to remember when servers rendered everything and you used CSS and Javascript to enhance the pages after they were rendered. The web is in such a dark and overengineered place. It's almost unbelievable. It's why my approach to building apps is server-rendered first and then enhanced after the fact.
- solardev 3y agoAs a different perspective, I'm also old enough to remember when CSS and Javascript were invented, and I've been making websites since that time. IMO web dev has never seen better tooling than today, and user experience has improved tremendously over the years. What we used to call AJAX has grown from a neat side toy to a basic part of everyday life in the form of client components and SPAs. The server is still as powerful as ever if you want it to be. But having such awesome client-side power is nice for interactive apps like dashboards, maps, games, forums, office apps, online IDEs, etc. It enabled the wholesale migration of everyday apps from bespoke desktop apps for each OS to a universal platform across all laptops and desktops. All that power of course required more complexity. It's very different trying to write a blog or landing page in HTML/CSS vs trying to write a whole web app. Angular and React were invented to help develop apps that were several times more complex than their precesssors, at a time when JS runtimes (and the language itself) were still really primitive compared to the server side languages of the time. Yeah, there was a really painful period there in the late 2010s where different JS frameworks each solved a tiny part of the problem. These days it's less of an issue. Next won, became the default, and deservedly so. It's really good, and has an appropriate level of abstraction for mid complexity apps, and allows a good mix of server-side rendering and client-side pages. Adding React Server Components makes that division a cleaner first class citizen. That only makes sense at a certain complexity though. If you don't need it, don't use it. If you're making a largely static blog or documentation site, there are simpler architectures. You can still use HTML and sprinkle in a few lines of JS as needed. You can still use WordPress or Wix for most small business needs. But if you're building more complex apps, god, React is an absolute dream compared to trying to round-trip every minor interaction to the server for recomputing the UI and sending over an entire HTML page every time, losing context and page position and half filled forms and whatever. It also encouraged the use of form data as state, and work was often lost on an accidental back button or the frequent server crashes before the advent of trivial cloud scaling. IMO it's only overengineered when misapplied. Some of these tools are really useful, even essential, in the proper use cases. Maybe the sad part is that we overteach them and encourage their use even when they're not necessary (or perhaps counterproductive). Right tool for the job and all that. Edit: not really pitching React over Vue or Svelte or HTMX or whatever, just that client-side complexity has its uses. Pros and cons, not strictly better or worse.
- consoomer 3y agoAm I the only one that believes classic Turbolinks (pre-Turbo) is the ideal solution to SSR? It works out of the box with JS disabled. No extra logic is needed on the server side (as is needed with HTMX). You can still perform partial updates HTMX style if you want (data-remote="true", and wrap response with a script/dom insert). I am using it in all of my products (non-Rails) and it has been so great.
- lukaqq 3y agohttps://chillin.online https://chillin.online, build with next.js too. I have to say there are some annoying problems with next.js. You should have some tricks to handle them.
- rco8786 3y agoWord count: complex: 9 complicated: 2 I've tried Nextjs's app router, and server/client components, and there are more footguns and gotchas than you can shake a stick at. Maybe it'll get smoothed out over time, but right now it is downright HARD to keep the mental model of your app when server and client code is constantly being intermingled, imported, and exported back and forth to each other.
- ttfkam 3y agoIn fairness, client and server code negotiation can be an intrinsically hard problem. NextJS just tends to make matters worse more often than better.
- chasd00 3y agoI'm advising a NextJS team now and acting as a liaison to a system they're integrating with. Even the devs in the NextJS code every day get confused about what's running on the server and what's running on the client and the consequences of both. I can see the attractiveness to a setup like this. Back when I was much more involved in actually typing out code it was always a pain to switch mentally from backend side coding to front-end side coding. On the other hand, it made it easier to reason about security. Front-end was the wild west and on the backend you didn't trust anything coming in. Another thing, i understand the supposed advantage of having one language for both backend and frontend but i don't recall that ever being a real issue with me or the teams i worked with. Everyone seemed able to shift from Javascript (and associated Javascript frameworks) to the backend language ( Java and C# in my case) without any issues.
- rco8786 3y ago> the supposed advantage of having one language for both backend and frontend Agreed that switching languages isn’t an issue. But being able to share code between backend and frontend is a pretty nice bonus
- anonyfox 3y agoStop a second before you go into RSCs. Whatever you want to achieve ultimately is much easier/quicker/scalable done in real fullstack (or classic web-) frameworks! Rails/Django/Laravel/… + Turbolinks/Htmx/… or even sprinkle some light clientside JS for fancyness. Or go best-of-all-worlds if you happen to know Elixir/Phoenix. But don’t continue the descent into RSCs, now matter how many people tweet about it. These folks with less than 10y industry experience will run into all the basic problems we had in vanilla PHP sites years ago, I even spotted react components with inline-sql-hooks already. This time with much accidental complexity overhead! Stay sane instead, ship actual products quickly, and earn that lambo!
- ramesh31 3y ago>These folks with less than 10y industry experience will run into all the basic problems we had in vanilla PHP sites years ago, I even spotted react components with inline-sql-hooks already. This time with much accidental complexity overhead! So much this. It's like our industry has a rolling 10 year cycle of amnesia. We moved away from server rendered UI for very, very good reasons. Of course the SEO argument is always there, but if that's your concern just build a traditional server templated site. The vast majority of SPAs have zero need for SSR and the complexity that it introduces.
- rattlyy 3y ago"very, very good reasons" bullshit, you do not need to turn landing pages into 30MB react bundles with 20 morbillion node modules
- CuriouslyC 3y agoThat's more an indictment of node's ecosystem and package management than anything else. Having helper libs for almost everything along with multiple versions of the same modules bundled is just a bit ridiculous. With functional deduplication across versions and a more robust standard library so people didn't need to add 50 NPM modules to do anything that would drop by an order of magnitude. Beyond that, bundle splitting with lazy loading is very helpful, but it requires knowing that you can do it and some additional work on top of baseline bundling. Then you're nearly at parity with static sites in terms of individual page download requirements for the first view (assuming react/etc are cached CDN libs rather than bundled) but each subsequent view of that page is much smaller, faster and more responsive than static html.
- bob1029 3y agoParts of this thread make me feel like I'm on crazy pills. We are currently doing SSR everywhere and it absolutely works in all the weird bleeding edge use cases that are traditionally parroted as reasons for outsourcing your ownership over technology. This isn't some historical, nostalgic experience for us. It is life today. The propaganda being fed into this industry is impossible to navigate in 2023. The best I can do is to find other engineers who still see things my way and team up with them. I am so grateful to have a few of these on my team right now. To be clear - Client-side rendering has its place. A perfect example of this is WebGL. But, this is extremely niche when you consider the total space of all business. PHP-style development is still untouchable for 99% of line-of-business web applications. String interpolation on the server was always the answer. Will continue to be the answer until some dystopian organization(s) decide to make it impossible to do things this way.
- XCSme 3y agoSo, PHP + AJAX is back.
- zoogeny 3y agoI can comment on personal experience with this. I've been building a new application using next.js and its new `app` directory setup. First, it is hard to reason about what is happening where (server or client). If you want to know then you have to investigate and most of the time when I'm cranking out code I don't pay too much attention. As he mentions, it is really easy to make a small change and then all of a sudden some large part of your page wants to move from server to client. I know I'll have to do a careful and time consuming page-by-page verification before I finally ship - and that sucks. Second, many existing React libraries are assumed to run on client because they use hooks. This can drag code onto the client. The whole point of fighting with this new paradigm is that you get server-side rendering which means fast load times and SEO. That is totally wasted if a library you are pulling in refuses to play nice. Third, there are bugs in the new next.js app directory paradigm. It is still new and it is very complex. Things like dynamic routes and parallel routes and their interactions can just completely break. I've personally filed an issue on next.js github that gained a bunch of "me too" comments. One approach I was taking that was broken was recently fixed by a vercel dev but I had already chosen a new approach to work around it. The most annoying though, is that their dev setup does some lazy-loading and caching magic. I think they try to compute the differences on a page and send partial updates over a web socket or something like that. It can get completely broken and you end up on an unrecoverable state. Sometimes a re-compile will trigger some communication from the server to the client and when I tab back to Chrome the tab is completely hung and I have to use the Chrome task manager to kill the process. It is all just very new and in the stage of many rough edges.
- c-hendricks 3y ago> many existing React libraries are assumed to run on client because they use hooks Do you mean context instead of hooks here? Plenty of hooks work on the server side, in that they do nothing other than initialize some values.
- zoogeny 3y agoI might be loose with my terminology, but hooks as standard as `useState` or `useRef` will trigger errors like: You're importing a component that needs useState. It only works in a Client Component but none of its parents are marked with "use client", so they're Server Components by default. There are ways around this, some of which he mentions in the post. It can just get tricky when you are trying to do complex composition. Another thing that hits me is when I have a server component that is marked as `async` and then for some reason it ends up on the client and I get the error that says something like "We don't support async components on the client yet ..." and I have to spend some time looking at my display hierarchy trying to figure out what is causing a client to import it. It reminds me of the "colored functions" blog post about async/await. You end up with colored components in your app which otherwise look and act the same. But now you have to be careful how you compose them together.
- XCSme 3y agoI am pretty sure 99% of the development time is no longer spent on solving problems and implementing features, but on creating unnecessary complex systems, deploying and maintaining them in an auto-scalable cloud, when a single $5 VPS would be performant enough, if all that complexity wasn't there. We should spend more time in writing efficient, simple code with fewer dependencies. We get so much natively nowadays that often choosing to add another framework/library adds more limitations than benefits.
- chasd00 3y agoI blame the devops industrial complex. When cloud providers came online and especially when "devops" became a thing then developers became the marketing target. Social media, the whole influencer concept, and all those manipulation tactics were turned loose on software developers. Look at the breadth and depth of services and tools on the market to produce a web application. Another thing, this isn't the first instance of the pendulum swinging back. Providing what would normally be desktop apps through a browser reminds me of dumb terminals attached to an AS400.
- tunesmith 3y agoWow... well, I'm not here to defend RSC or React as the best solution ever, but some of the objections here are half-baked. React/RSC is not technically equivalent in benefit to having a server return html/css with a smattering of javascript. It's still one app, with more intelligent handling of the client/server boundary (compared to SSR/hydration). I'm all for reading more informed objections about how React may have designed themselves into a corner and what the exit path is, but going back to php isn't it.
- reducesuffering 3y agoHN is not the best place for informed front-end opinions these days. React is not even that hard of a thing to learn (hence why even non-devs pick up the basics in a bootcamp in a few weeks?). JSX is objectively superior to the templating systems of Django, PHP, and Rails. I'm sure half the half-baked objections aren't even benchmarking their projects with things like Lighthouse...
- koromak 3y agoDamn I really don't want to make the frontend even more complicated than it already is.
- valty 3y agoI wonder how many people have attempted to build what they want starting from an empty JS file. I think most people are scared of what they will find. That the decades they have spent twisting themselves around frameworks and learning all these abstractions, is not actually necessary at all. We already have a really nice _declarative_ abstraction in the form of HTML/CSS. I don't know why we decided to cram everything into the view layer. Separate your logic into a view model, and then data bind to it. A simple data binding framework is very easy to write. And then you have full control over everything! Compare the size of the code below and how easy it is to debug/trace....to the enormous React/Angular/etc. codebases. const bindings = [] // {elementId, modelId, componentId} // Allows looking up functions by strings, that are referenced in server-side code. // Normally we could just reference function objects in memory, but in two separate environments we must use strings. const components = {} // Model //////////////////// const models = [{id: shortId(), count: 1}] const model = models[0] // Server-side render route //////////////////// function renderPage() { // Create view const div = createCounterComponent() document.body.appendChild(div) // Send this to the client. const html = document.documentElement.outerHTML const ssrScriptEl = document.createElement('ssr') ssrScriptEl.textContent = JSON.stringify({models, bindings}) document.body.appendChild(ssrScriptEl) return new Response(html) } // Client-side main function //////////////////// function clientMain() { window.ssr = JSON.parse(document.getElementById("ssr").textContent) rehydrate(models, bindings) // Update model and notify view. model.name = 'goodbye' onModelChange(model.id) } function rehydrate(models, bindings) { for (const binding of bindings) { const {modelId, elementId, componentId} = binding const element = document.getElementById(elementId) const component = component[componentId] const {setup, render} = component setup(element, model) } } function onModelChange(changedModelId) { const affectedBindings = window.ssr.models.filter( ({elementId, modelId}) => modelId === changedModelId ) for (const binding of affectedBindings) { const {elementId, render} = binding const element = document.getElementById(elementId) render(element, model) } } // Component //////////////////// function createCounterComponent(model) { const div = createElement('div', model, createCounterComponent) return div } // Doesn't run during SSR rehydration. function render(element, model) { element.innerHTML = model.count } // Does run during SSR hydration. function setup(element, model) { element.onClick = () => { model.count++ } } createCounterComponent.setup = setup createCounterComponent.render = render registerComponent(createCounterComponent) function registerComponent(component) { const componentId = component.name components[componentId] = component } //////////////////// function createElement(elementType, model, componentFunction) { const {render, setup} = componentFunction const componentId = componentFunction.name const element = document.createElement(elementType) const elementId = shortId() element.id = elementId const modelId = model.id bindings.push({elementId, modelId, componentId}) render(element, model) return element }
- grglburgp 3y agoI’ve built 3D renderers with Vulkan in a day. Have orchestrated production cloud setups for big tech companies and startups of all kinds of needs, in a week. It’s been 3 days and I cannot get a value returned from a NextJS route to a React component. All the blog examples look nothing like the project layout the tools generated for me. Frontend toolkits are atrocious to work with. Reminds me of Chef/Puppet, solving hallucinated problems to soak up VC funding. I’ll give it another day or two, because it could be me. But Apache web server, the Rube Goldberg of web software, seems as quaint to use as MS Paint relative to Reacts ecosystem.
- idlewords 3y agoTwist: the 50K lines of code render their site's 'about' page.
- belter 3y agoSo conclusion: Old React not so good, new React (Components) even worst. What is the next best framework? Svelte? Vue?