Cookie Consent by Free Privacy Policy Generator

Server Components: React’s Step Towards Server-Side Rendering

The latest and perhaps one the most significant updates in web technologies. The Server Components of React.

Server Components: React’s Step Towards Server-Side Rendering


In our previous article, we examined the evolution of web applications, focusing on the shift towards client-side rendering and the associated challenges. Despite its advantages, client-side rendering is not without its limitations. As web applications grow in complexity and size, there's a mounting need for efficient, scalable, and performant solutions. This brings us to our topic today: a step towards server-side rendering, featuring React's Server Components.

First Attempt at Server-side Rendering

This isn't the first time that web apps tried off-loading some of their rendering efforts to the server. The initial attempt was with Angular Universal (circa 2016), which essentially spun up a mock browser, ran the Angular code, and then shipped the data it generated, along with the HTML, to the browser. This was followed by the actual JS bundle and some hydration period of the front-end. This process proved challenging to implement and remains so even today. A React implementation quickly followed with Next.JS' server-side rendering. Although it did essentially the same thing, it also provided a framework to supplement React's "library" mentality. Both solutions were incredibly effective, as long as the code was properly written for their use. However, due to their inherent limitations, not all code written for a regular browser worked on the server-side.

Land of Confusion

GitHub and StackOverflow teem with queries about perceived bugs associated with server-side solutions. However, these issues aren't bugs at all, but rather misunderstandings about the solution's use. It was expected that web developers would understand the implications and limitations of server-side rendering. However, only a minority managed to fully grasp its intricacies. Consequently, frameworks added safety features to prevent developers from stumbling. This conundrum was not solely the developers' fault - if they wanted server code with limitations, they'd opt for a server-rendered technology. Conversely, the creators of Universal and Next.JS faced the daunting task of providing exceptional performance, client-side compatibility, hydration, custom bundling, static asset fetching, and more.

Embracing the "dark-side"

After years of refining and utilizing these server-side technologies, React developers introduced the Server Components technology. The idea is to provide clear boundaries between code that runs exclusively in the browser or the server, instead of trying to render the same things in both. These boundaries allow full advantage of the strengths that each side has to offer. For instance, you could move all initial data requests to the server and provide your client components with data at the same instant they load, while mutating data dynamically on the browser.

Looking ahead

There are strong opinions about this technology, with some viewing it as a step backwards, even comparing it to PHP (a comparison often seen as a web-dev taboo). On the other hand, many are embracing the new possibilities it offers. Personally, I believe it's the best of both worlds, combining the fast data fetching abilities and complex rendering calculations that the server can offer with the dynamic nature of client-side rendering. Proper utilization of these new tools can lead to web applications that are not only incredibly fast but also maintain their dynamic nature, reduce their browser-downloaded bundles, and even hide proprietary code on the server. With advancements like these, the future of web development seems promising and exciting. Stay tuned for more!

Subscribe to Tek and Kode

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.