React Server Components: The Future of React Development

August 28, 2024 by
[ad_1] React’s been a powerhouse for building web apps over the last ten years. We’ve all seen it evolve from those clunky class components to the elegance of hooks. But React Server Components (RSCs)? We don’t think anyone expected such a dramatic shift in how React worked. So, what exactly are React Server Components? How […]
[lwptoc]

[ad_1]

React’s been a powerhouse for building web apps over the last ten years.

We’ve all seen it evolve from those clunky class components to the elegance of hooks.

But React Server Components (RSCs)?

We don’t think anyone expected such a dramatic shift in how React worked.

So, what exactly are React Server Components? How do they work? And what do they do differently that React couldn’t already do?

To answer all these questions, we’ll quickly go over the fundamentals. If you’re in need of a refresher, have a quick look at this guide on how to learn React as a beginner.

In this post, we’ll walk you through why we needed React Server Components, how they work, and some of the major benefits of RSCs.

Let’s get started!

What Are React Server Components?

Tree Diagram Of React Server Components Shows The Hierarchy And Where Different Component Types Are Rendered In The App.
React Server Components: The Future Of React Development 16

Think of React Server Components as a new way of building React applications. Instead of running in the browser like typical React components, RSCs execute directly on your server.

“I think RSCs are designed to be the “componentization” of the back end, i.e., the back end equivalent of what SPA React did for the front end. In theory, they could largely eliminate the need for things like REST and GraphQL, leading to a much tighter integration between the server and client since a component could traverse the entire stack.” — ExternalBison54 on Reddit

Since RSCs execute directly on the server, they can efficiently access backend resources like databases and APIs without an additional data fetching layer.

DreamHost Glossary

API

An Application Programming Interface (API) is a set of functions enabling applications to access data and interact with external components, serving as a courier between client and server.

Read More

But why did we need RSCs anyway?

To answer this question, let’s rewind a bit.

Traditional React: Client-Side Rendering (CSR)

React has always been a client-side UI library.

The core idea behind React is to divide your entire design into smaller, independent units we call components. These components can manage their own private data (state) and pass data to each other (props).

Think of these components as JavaScript functions that download and run right in the user’s browser. When someone visits your app, their browser downloads all the component code, and React steps in to render everything:

Flowchart: Client-Side Rendering Workflow, From User Request To Page Load, Including Server Response And Browser Processing.
React Server Components: The Future Of React Development 17
  • The browser downloads the HTML, JavaScript, CSS, and other assets.
  • React analyzes the HTML, sets up event listeners for user interactions, and retrieves any required data.
  • The website transforms into a fully functional React application right before your eyes and everything is done by your browser and computer.

While this process works, it does have some downsides:

  • Slow load times: Loading times can be slow, particularly for complex applications with lots of components since now the user has to wait for everything to be downloaded first.
  • Bad for search engine optimization (SEO): The initial HTML is often barebones — just enough to download the JavaScript which then renders the rest of the code. This makes it hard for search engines to understand what the page is about.
  • Gets slower as apps grow larger: The client-side processing of JavaScript can strain resources, leading to a rougher user experience, especially as you add more functionality.

Get Content Delivered Straight to Your Inbox

Subscribe now to receive all the latest updates, delivered directly to your inbox.

The Next Iteration: Server-Side Rendering (SSR)

To address the issues caused by client-side rendering, the React community adopted Server-Side Rendering (SSR).

With SSR, the server handles rendering the code to HTML before sending it over.

This complete, rendered HTML is then transferred to your browser/mobile, ready to be viewed — the app doesn’t need to be compiled during runtime like it would without SSR.

Here’s how SSR works:

Diagram Showing How Server-Side Rendering Works, With Browser Requesting Html From Server And Receiving Fully Rendered Page.
React Server Components: The Future Of React Development 18
  • The server renders the initial HTML for each request.
  • The client receives a fully formed HTML structure, allowing for faster initial page loads.
  • The client then downloads React and your application code, a process called “hydration,” which makes the page interactive.

The HTML structure rendered on the server has no functionality — yet. 

React adds event listeners, sets up internal state management, and adds other functionality to the HTML after it’s been downloaded to your device. This process of adding “life” to the page is known as hydration.

Why does SSR work so well?

  1. Faster initial load times: Users see the content almost instantly because the browser receives fully formed HTML, eliminating the time required for the JavaScript to load and execute.
  2. Improved SEO: Search engines easily crawl and index server-rendered HTML. This direct access translates to better search engine optimization for your application.
  3. Enhanced performance on slower devices: SSR lightens the load on a user’s device. The server shoulders the work, making your application more accessible and performant, even on slower connections.

SSR, however, caused a number of additional problems, calling for an even better solution:

  • Slow Time to Interactive (TTI): Server-side rendering and hydration delay the user’s ability to see and interact with the app until the entire process is complete.
  • Server load: The server needs to do more work, further slowing down response times for complex applications, especially when there are many users simultaneously.
  • Setup complexity: Setting up and maintaining can be more complex, especially for large applications.

Finally, the React Server Components

In December 2020, the React team introduced the “Zero-Bundle-Size React Server Components” or RSCs.

This changed not only how we thought about building React apps but also how React apps work behind the scenes. RSCs solved many problems we had with CSR and SSR.

“With RSCs, React becomes a fully server-side framework and a fully client-side framework, which we’ve never had before. And that allows a much closer integration between the server and client code than was ever possible before.” — ExternalBison54 on Reddit

Let’s now look at the benefits that RSCs bring to the table:

1. Zero Bundle Size

RSCs are rendered entirely on the server, eliminating the need to send JavaScript code to the client. This results in:

  • Dramatically smaller JavaScript bundle sizes.
  • Faster page loads, particularly on slower networks.
  • Improved performance on less powerful devices.

Unlike SSR, where the entire React component tree is sent to the client for hydration, RSCs keep server-only code on the server. This leads to those significantly smaller client-side bundles we talked about, making your applications lighter and more responsive.

2. Direct Backend Access

RSCs can interact directly with databases and file systems without requiring an API layer.

As you can see in the code below, the courses variable is fetched directly from the database, and the UI prints a list of the course.id and course.name from the courses.map:

async function CourseList() {
  const db = await connectToDatabase();
  const courses = await db.query('SELECT * FROM courses');

  return (
   

          {courses.map(course => (
           

  • {course.name}
  •       ))}
       

  );
}

This is simpler in contrast to traditional SSR where you’d need to set up separate API routes for fetching individual pieces of data.

3. Automatic Code Splitting

With RSCs, you also get more granular code splitting and better code organization.

React keeps server-only code on the server and ensures that it never gets sent over to the client. The client components are automatically identified and sent to the client for hydration.

And the overall bundle becomes extremely optimized since the client now receives exactly what’s needed for a fully functional app.

On the other hand, SSR needs careful manual code splitting to optimize performance for each additional page.

4. Reduced Waterfall Effect and Streaming Rendering

React Server Components combine streaming rendering and parallel data fetching. This powerful combination significantly reduces the “waterfall effect” often seen in traditional server-side rendering.

Waterfall Effect

The “waterfall effect” slows down web development. Basically, it forces the operations to follow one another as if a waterfall were flowing over a series of rocks.

Each step must wait for the previous one to finish. This “wait” is especially noticeable in data fetching. One API call must be completed before the next one begins, causing page load times to slow.

Table From Chrome Network Tab Displays The Waterfall Effect Of Network Requests, Showing Various Api Calls And Their Timing.
React Server Components: The Future Of React Development 19

Streaming Rendering

Streaming rendering offers a solution. Instead of waiting for the entire page to render on the server, the server can send pieces of the UI to the client as soon as they’re ready.

Diagram Shows Streaming Server Rendering: Network Requests And Javascript Execution Timeline, Including Fcp And Tti Markers.
React Server Components: The Future Of React Development 20

React Server Components make rendering and fetching data much smoother. It creates multiple server components that work in parallel avoiding this waterfall effect.

The server starts sending HTML to the client the moment any piece of the UI is ready.

So, compared to server-side rendering, RSCs:

  • Allow each component to fetch its data independently and in parallel.
  • The server can stream a component as soon as its data is ready, without waiting for other components to catch up.
  • Users see the content loading one after the other, enhancing their perception of performance.

5. Smooth Interaction With Client Components

Now, using RSCs doesn’t necessarily imply that you have to skip using client-side components. 

Both components can co-exist and help you create a great overall app experience.

Think of an e-commerce application. With SSR, the entire app needs to be rendered server side.

In RSCs, however, you can select which components to render on the server and which ones to render on the client side.

For instance, you could use server components to fetch product data and render the initial product listing page.

Then, client components can handle user interactions like adding items to a shopping cart or managing product reviews.

Should You Add RSC Implementation on Your Roadmap?

Our verdict? RSCs add a lot of value to React development.

They solve some of the most pressing problems with the SSR and CSR approaches: performance, data fetching, and developer experience. For developers just starting out with coding, this has made life easier.

Now, should you add RSC implementation to your roadmap? We’ll have to go with the dreaded — it depends.

Your app may be working perfectly fine without RSCs. And in this case, adding another layer of abstraction may not do much. However, if you plan to scale, and think RSCs can improve the user experience for your app, try making small changes and scaling from there.

And if you need a powerful server to test RSCs, spin up a DreamHost VPS.

DreamHost offers a fully managed VPS service where you can deploy even your most demanding apps without worrying about maintaining the server.

VPS Hosting

VPS Hosting

We Know You’ve Got Lots of VPS Options

Here’s how DreamHost’s VPS offering stands apart: 24/7 customer support, an intuitive panel, scalable RAM, unlimited bandwidth, unlimited hosting domains, and SSD storage.

Change Your VPS Plan

Ian is a Product Designer based in Los Angeles, California. He is responsible for driving brand and product design at DreamHost, developing and maintaining our internal design system, and writing frontend code when he can. In his free time, he enjoys walking his dog, learning history, and discovering new music online and irl. Connect with him on LinkedIn: https://www.linkedin.com/in/ianhernandez23/

[ad_2]

Your Dream Website Is Just One Click Away

At Ericks Webs Design, we believe every business deserves a stunning online presence — without the stress. We offer flexible payment options, a friendly team that truly cares, and expert support every step of the way.

Whether you’re a small business owner, a church, or a growing brand, we’re here to bring your vision to life.

✨ Let’s build something amazing together.

— no pressure, just possibilities.

Latest News & Website Design Tips

Stay up-to-date with the latest insights, trends, and tips in business website design. Explore our newest articles to discover strategies that can help you elevate your online presence and grow your business.

Should You Maintain Your Own Website or Hire Someone?

Should You Maintain Your Own Website or Hire Someone?

The article “Should You Maintain Your Own Website or Hire Someone?” discusses the importance of a strong online presence for small businesses in South Texas. It highlights the necessity of assessing your business needs, goals, and target audience before deciding on DIY website management or hiring a professional, like Ericks Webs Design. Maintaining your own website can save costs and provide control but may require significant time and effort. Conversely, hiring a professional offers expertise, stress relief, and customized solutions to enhance your site’s effectiveness. Ultimately, the choice depends on your skills, budget, and the level of professionalism you seek for your online presence.

Not Collecting Leads or Contact Info Efficiently

Not Collecting Leads or Contact Info Efficiently

Many construction business owners in South Texas struggle with generating leads due to inadequate online visibility. Relying on word-of-mouth is no longer sufficient, as potential clients increasingly search for contractors online. A custom website acts as an essential tool, showcasing your work and streamlining client communication. By enhancing your online presence, you can effectively attract and convert prospects into clients. In a competitive market, it’s crucial to stand out, and a strong online identity can significantly impact your credibility and lead generation. Embracing robust digital strategies will ensure you capture the opportunities necessary for growth and success.

Mobile Shopping Is Here—Is Your Store Ready?

Mobile Shopping Is Here—Is Your Store Ready?

The article “Mobile Shopping Is Here—Is Your Store Ready?” emphasizes the importance of adapting to the growing trend of mobile shopping. With 72% of consumers expected to make purchases via smartphones, businesses must ensure their websites are mobile-friendly and easy to navigate. Key strategies include simplifying the checkout process, optimizing for search engines, leveraging social media for engagement, and providing effective customer service. By recognizing the significance of mobile shopping, business owners can enhance customer experience and capture a larger audience. The message is clear: those who don’t adapt risk losing out to their competitors.

How to Check if Your Website Is Down

How to Check if Your Website Is Down

In “How to Check if Your Website Is Down,” the article emphasizes the importance of maintaining a reliable online presence for small businesses in South Texas. It outlines steps to determine if your website is down, including using online tools like IsItDownRightNow, checking your internet connection, and clearing your browser cache. The article also highlights common causes of downtime, like server issues and traffic overload. By regularly monitoring website health with tools such as Google Search Console, businesses can ensure functionality, maintain customer trust, and avoid missing sales opportunities. Overall, understanding how to check if your website is down is crucial for success in a competitive market.

Difficulty Standing Out from Other Contractors

Difficulty Standing Out from Other Contractors

In a competitive market, many construction businesses struggle to gain visibility, often losing potential clients to competitors. A robust online presence is essential; without it, even the best craftsmanship can go unnoticed. To combat this, a custom website can effectively showcase projects, manage leads, and enhance search visibility, transforming challenges into opportunities. Such a website conveys professionalism, builds trust, and ensures that clients can easily find and engage with your services. By prioritizing a strong digital footprint, construction firms can attract more job opportunities and ultimately increase revenue. Embracing these strategies can significantly differentiate your business from the rest in a crowded market.

Boost Your Product Sales with Better Product Pages

Boost Your Product Sales with Better Product Pages

The article “Boost Your Product Sales with Better Product Pages” emphasizes the importance of well-designed product pages in driving sales for small and medium businesses. It underscores the need for high-quality visuals, compelling descriptions that tell a story, and a clear, user-friendly layout. Incorporating authentic customer reviews and ensuring mobile optimization are also crucial. The article encourages businesses to track their performance through analytics and highlights the significance of strong branding in creating emotional connections with customers. Overall, improving product pages not only enhances aesthetics but also helps convert casual visitors into loyal buyers.

Unprofessional or Outdated Website (or None at All)

Unprofessional or Outdated Website (or None at All)

In today’s digital landscape, an effective online presence is crucial for construction businesses. Relying on traditional marketing methods can lead to missed opportunities and stagnant growth. Potential clients often search for companies online, and without a professional website, you’re invisible in a competitive market. A custom website not only showcases your work but also streamlines client interactions, offering easy access to quotes and information. This engagement can significantly increase lead generation and conversion rates. By investing in tailored web solutions, construction companies can enhance their visibility on search engines, solidifying their status as industry leaders and ultimately boosting client trust and business success.

What to Do If Your Website Gets Hacked

What to Do If Your Website Gets Hacked

If your website gets hacked, remain calm and assess the damage. Change all passwords and restore your site from a backup if available. Scan for malware and notify your users if their data may be compromised. To prevent future hacks, regularly update your CMS and plugins, use HTTPS, implement firewalls and security plugins, and conduct regular security audits. By taking these steps, you can enhance your website security and build a trustworthy online presence. Seeking professional help, like Ericks Webs Design, can also ensure robust protection tailored to your business needs.

No Clear Way for Clients to Request a Quote Online

No Clear Way for Clients to Request a Quote Online

Many construction business owners in South Texas struggle with losing potential clients due to ineffective online visibility. Without an easy way for clients to request quotes, companies miss valuable leads. In today’s competitive environment, convenience is crucial; complicated quote processes drive potential clients away. A custom website simplifies this by allowing clients to swiftly request quotes while showcasing past projects. This not only builds trust but also enhances credibility, vital for standing out in the market. Investing in a tailored online presence can dramatically improve lead generation and help overcome the challenges of lost inquiries and no-show clients. It’s time for construction businesses to adapt and thrive.

How a Website Can Help You Sell More Products

How a Website Can Help You Sell More Products

A website can significantly boost your sales by providing 24/7 visibility and accessibility for potential customers. It serves as your digital storefront, making it easier for customers to find and connect with your brand. A professional website builds trust and credibility, which is vital for attracting buyers. Using SEO strategies enhances discoverability, positioning your products in front of interested shoppers. Engaging content, like blogs, fosters customer relationships and encourages repeat business. Additionally, a website enables you to reach broader markets beyond your local area. Regular updates and maintenance ensure smooth operation. Embrace this opportunity to sell more products and grow your business in the digital landscape.