{"id":159,"date":"2023-03-27T15:02:31","date_gmt":"2023-03-27T15:02:31","guid":{"rendered":"https:\/\/redmonk.com\/kholterhoff\/?p=159"},"modified":"2023-03-27T17:50:06","modified_gmt":"2023-03-27T17:50:06","slug":"the-server-client-two-step","status":"publish","type":"post","link":"https:\/\/redmonk.com\/kholterhoff\/2023\/03\/27\/the-server-client-two-step\/","title":{"rendered":"The Server\/Client Two-Step"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-full wp-image-161\" src=\"http:\/\/redmonk.com\/kholterhoff\/files\/2023\/03\/two-step-scaled.jpeg\" alt=\"\" width=\"100%\" height=\"1715\" srcset=\"https:\/\/redmonk.com\/kholterhoff\/files\/2023\/03\/two-step-scaled.jpeg 2560w, https:\/\/redmonk.com\/kholterhoff\/files\/2023\/03\/two-step-300x201.jpeg 300w, https:\/\/redmonk.com\/kholterhoff\/files\/2023\/03\/two-step-1024x686.jpeg 1024w, https:\/\/redmonk.com\/kholterhoff\/files\/2023\/03\/two-step-768x514.jpeg 768w, https:\/\/redmonk.com\/kholterhoff\/files\/2023\/03\/two-step-1536x1029.jpeg 1536w, https:\/\/redmonk.com\/kholterhoff\/files\/2023\/03\/two-step-2048x1372.jpeg 2048w, https:\/\/redmonk.com\/kholterhoff\/files\/2023\/03\/two-step-480x322.jpeg 480w, https:\/\/redmonk.com\/kholterhoff\/files\/2023\/03\/two-step-936x627.jpeg 936w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><\/p>\n<p>The future of React is always top of mind for the frontend community, which will inevitably be affected by shifts in this industry-leading JavaScript framework. Indeed, many developers are still reeling from React\u2019s 2019 decision for <a href=\"https:\/\/legacy.reactjs.org\/blog\/2019\/02\/06\/react-v16.8.0.html\">v16.8<\/a> to migrate from class-based components to hooks in order to introduce state and manage side-effects (although, mercifully for overworked devs, <a href=\"https:\/\/legacy.reactjs.org\/docs\/hooks-intro.html\">class-based components are still compatible<\/a>). What happens in React has far reaching repercussions.<\/p>\n<p>In light of the ongoing <a href=\"https:\/\/redmonk.com\/kholterhoff\/2023\/02\/23\/spa-wars\/\">SPA Wars<\/a>, frontend developers are closely following React\u2019s answers to complaints about shipping too much JS and (relatedly) their interest in the rise of compilers, all of which factors into the involved back-and-forth dance I\u2019m calling the server\/client two-step.<\/p>\n<p>Code executed on the client-side has the best interactivity, but server rendered sites are more performant. There are recognized costs and benefits to both approaches, but a growing number of creators and users of JS frameworks argue for a return to the server. The <a href=\"https:\/\/www.sitepen.com\/blog\/intro-to-html-first-frontend-frameworks\">HTML-first<\/a> philosophy, for instance, rejects client-rendered DOM generated by executing JS, and instead favors server-generated HTML. The increased adoption of &#8220;Component Islands,&#8221; usually shortened to just \u201cIslands\u201d (coined in 2019 by <a href=\"https:\/\/twitter.com\/ksylor\">Katie Sylor-Miller<\/a>, frontend architect at Etsy), is another popular response. In the islands pattern, parts of the page are completely static server generated HTML, while other parts are self-contained interactive apps. Astro, 11ty, and Fresh all use islands.<\/p>\n<p>Which brings me to the React Server Component (RSC). A recent episode of JS Party concerning \u201c<a href=\"https:\/\/changelog.com\/jsparty\/267\">The future of React<\/a>\u201d delves deeply into this thorny subject, and is therefore worth discussing for its relevance to the server\/client two-step. In this conversation <a href=\"https:\/\/mobile.twitter.com\/dan_abramov\">Dan Abramov<\/a>, creator of Redux, and <a href=\"https:\/\/twitter.com\/en_js?lang=en\">Joe Savona<\/a>, part of Meta\u2019s React team, outline their vision for the future of React\u2014and, spoiler, it&#8217;s all about server components.<\/p>\n<p>RSCs are a new feature in <a href=\"https:\/\/react.dev\/blog\/2022\/03\/29\/react-v18\">React 18<\/a>, and considered \u201cstill experimental.\u201d However, they have drummed up a significant amount of excitement. Huge names in the space including Vercel\u2019s <a href=\"https:\/\/nextjs.org\/\">Next.js<\/a>, Shopify\u2019s <a href=\"https:\/\/hydrogen.shopify.dev\/\">Hydrogen<\/a>, and <a href=\"https:\/\/remix.run\/\">Remix<\/a> have all announced their involvement in polishing this feature in order to ensure its success. And this enthusiasm from the community appears merited owing to its grand promise. According to <a href=\"https:\/\/nextjs.org\/docs\/advanced-features\/react-18\/server-components\">Next.JS\u2019s documentation<\/a>:<\/p>\n<blockquote><p>React Server Components allow developers to build applications that span the server and client, combining the rich interactivity of client-side apps with the improved performance of traditional server rendering.<\/p><\/blockquote>\n<p>React\u2019s answer to the server\/client two-step could be groundbreaking for the JS community. But what came across in the JS Party interview was the intractable complexity involved in balancing client with server in the frontend space. In host <a href=\"https:\/\/changelog.com\/person\/jerodsanto\">Jerod Santo<\/a>\u2019s words: \u201cI\u2019m sitting here thinking, all right, this sounds really complicated.\u201d Why this difficulty in communicating RSCs? According to Savona:<\/p>\n<blockquote><p>It\u2019s almost hard to talk about server components because depending on where you\u2019re coming from I think different pieces might appeal to you.<\/p><\/blockquote>\n<p>Abramov echoes this sentiment:<\/p>\n<blockquote><p>With server components it is a little difficult to wrap your mind around if you are used to React because the way you add state, it forces you to create kind of a split point, so if you\u2019re used to just creating components and putting state anywhere, built in within <a href=\"https:\/\/beta.nextjs.org\/docs\/routing\/fundamentals\">JS app router<\/a> (that\u2019s [NextJS\u2019s] new version with server components) it does require you to learn how to compose components a little bit differently.<\/p><\/blockquote>\n<p>Despite difficulties in terms of cognitive load, explaining <i>how<\/i> RSCs work is of less importance than ensuring <i>that<\/i> it works. Recall that server-side rendering (SSR) has long provided the kind of background optimization that work-a-day frontend engineers want, but don\u2019t necessarily need to understand in detail. And Abramov and Savona assure listeners that its server components do work. They explain that RSCs are currently in production in several projects including at Meta.<\/p>\n<p>The complexity of RSCs is largely responsible for the bottlenecks and developer experience sacrifices Hydrogen noted last fall in their <a href=\"https:\/\/hydrogen.shopify.dev\/roadmap\/\">Roadmap<\/a>, which resulted in their decision to abandon server components. Although Hydrogen continues to harbor high hopes for this technology:<\/p>\n<blockquote><p>We\u2019ve found that keeping a clear separation around where your server is doing the work, and worrying less about how your server and client components might mix together, has resulted in a simpler developer experience that\u2019s less prone to mistakes. We also heard from a number of developers that with most of their pages requiring some level of interactivity, the mental model of routes in a .server file, with interactive components in .client components became repetitive and error prone.<\/p><\/blockquote>\n<p>Although <a href=\"https:\/\/twitter.com\/acdlite\">Andrew Clark<\/a>, a React core contributor currently working on React and Next.js at Vercel, assures the community that there are no hard feelings, the dream of harnessing the advantages of client and server in a single, well-packaged solution remains elusive.<\/p>\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\">\n<p lang=\"en\" dir=\"ltr\">Happy for my friends at <a href=\"https:\/\/twitter.com\/remix_run?ref_src=twsrc%5Etfw\">@remix_run<\/a> and Shopify!<\/p>\n<p>Even though Hydrogen is moving away from Server Components I deeply appreciate their work testing and iterating on the original proposal. Remix is great technology, and as RSC matures I hope it\u2019ll find its way into the framework. <a href=\"https:\/\/t.co\/MqhyAQQttn\">https:\/\/t.co\/MqhyAQQttn<\/a><\/p>\n<p>&mdash; Andrew Clark (@acdlite) <a href=\"https:\/\/twitter.com\/acdlite\/status\/1587112983548895235?ref_src=twsrc%5Etfw\">October 31, 2022<\/a><\/p><\/blockquote>\n<p><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<p>Interestingly, <a href=\"https:\/\/www.zachleat.com\/web\/react-criticism\/\">Zach Leatherman<\/a> speculates that \u201cmiscommunicated expectations around React Server Components\u201d may be at least partially responsible for the failure of Next.js v13 to ship with \u00f8JS, as Guillermo Rauch, CEO at Vercel, had promised in a 2021 tweet (\u201c<a href=\"https:\/\/twitter.com\/rauchg\/status\/1437494013137805312\">\u00f8JS is coming to Next<\/a>\u201d).<\/p>\n<p>I\u2019ll leave the technical aspects of the client\/ server two-step to the lights of the JS community, and particularly framework developers who have studied this issue deeply and therefore have the best sense of how to harness the best of client and server. Although RSCs promise to combine client-side interactivity with server rendering\u2019s recognized performance, it has a ways to go to pivot away from today\u2019s clunky but functional two-step between client and server to a single, well-packaged solution that negates the need for a choreographed back-and-forth.<\/p>\n<p><b>Disclosure: <\/b>Vercel (Next.JS) is a RedMonk client.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The future of React is always top of mind for the frontend community, which will inevitably be affected by shifts in this industry-leading JavaScript framework. Indeed, many developers are still reeling from React\u2019s 2019 decision for v16.8 to migrate from class-based components to hooks in order to introduce state and manage side-effects (although, mercifully for<\/p>\n","protected":false},"author":50,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[12,8,4,7],"tags":[],"class_list":["post-159","post","type-post","status-publish","format-standard","hentry","category-devx","category-frontend","category-javascript","category-js-frameworks"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/redmonk.com\/kholterhoff\/wp-json\/wp\/v2\/posts\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redmonk.com\/kholterhoff\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redmonk.com\/kholterhoff\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redmonk.com\/kholterhoff\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/redmonk.com\/kholterhoff\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":0,"href":"https:\/\/redmonk.com\/kholterhoff\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"wp:attachment":[{"href":"https:\/\/redmonk.com\/kholterhoff\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redmonk.com\/kholterhoff\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redmonk.com\/kholterhoff\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}