The Forensics Of React Server Components (RSCs)<\/h1>\nLazar Nikolov<\/address>\n 2024-05-09T13:00:00+00:00
\n 2025-06-20T10:32:35+00:00
\n <\/header>\n
This article is sponsored by Sentry.io<\/b><\/p>\n
In this article, we\u2019re going to look deeply at React Server Components (RSCs). They are the latest innovation in React\u2019s ecosystem, leveraging both server-side and client-side rendering as well as streaming HTML<\/a> to deliver content as fast as possible.<\/p>\nWe will get really nerdy to get a full understanding of how RSCs fit into the React picture, the level of control they offer over the rendering lifecycle of components, and what page loads look like with RSCs in place.<\/p>\n
But before we dive into all of that, I think it\u2019s worth looking back at how React has rendered websites up until this point to set the context for why we need RSCs in the first place.<\/p>\n
The Early Days: React Client-Side Rendering<\/h2>\n
The first React apps were rendered on the client side, i.e., in the browser. As developers, we wrote apps with JavaScript classes as components and packaged everything up using bundlers, like Webpack, in a nicely compiled and tree-shaken heap of code ready to ship in a production environment.<\/p>\n
The HTML that returned from the server contained a few things, including:<\/p>\n
\n- An HTML document with metadata in the
<\/code> and a blank \n<\/div>\n<\/code> in the <\/code> used as a hook to inject the app into the DOM;<\/li>\n- JavaScript resources containing React\u2019s core code and the actual code for the web app, which would generate the user interface and populate the app inside of the empty
\n<\/div>\n<\/code>.<\/li>\n<\/ul>\n<\/p>\n <\/p>\n
<\/p>\n
<\/a>\n Figure 1. (Large preview<\/a>)
\n <\/figcaption><\/figure>\nA web app under this process is only fully interactive once JavaScript has fully completed its operations. You can probably already see the tension here that comes with an improved developer experience (DX) that negatively impacts the user experience (UX)<\/strong>.<\/p>\nThe truth is that there were (and are) pros and cons to CSR in React. Looking at the positives, web applications delivered smooth, quick transitions<\/strong> that reduced the overall time it took to load a page, thanks to reactive components that update with user interactions without triggering page refreshes. CSR lightens the server load and allows us to serve assets from speedy content delivery networks (CDNs) capable of delivering content to users from a server location geographically closer to the user for even more optimized page loads.<\/p>\nThere are also not-so-great consequences that come with CSR, most notably perhaps that components could fetch data independently, leading to waterfall network requests<\/strong><\/a> that dramatically slow things down. This may sound like a minor nuisance on the UX side of things, but the damage can actually be quite large on a human level. Eric Bailey\u2019s \u201cModern Health, frameworks, performance, and harm<\/a>\u201d should be a cautionary tale for all CSR work.<\/p>\nOther negative CSR consequences are not quite as severe but still lead to damage. For example, it used to be that an HTML document containing nothing but metadata and an empty <\/p>\n<\/div>\n<\/code> was illegible to search engine crawlers that never get the fully-rendered experience. While that\u2019s solved today, the SEO hit at the time was an anchor on company sites that rely on search engine traffic to generate revenue.<\/p>\n
The Shift: Server-Side Rendering (SSR)<\/h2>\n
Something needed to change. CSR presented developers with a powerful new approach for constructing speedy, interactive interfaces, but users everywhere were inundated with blank screens and loading indicators to get there. The solution was to move the rendering experience from the client<\/strong> to the server<\/strong>. I know it sounds funny that we needed to improve something by going back to the way it was before.<\/p>\nSo, yes, React gained server-side rendering (SSR) capabilities. At one point, SSR was such a topic in the React community that it had a moment<\/a> in the spotlight. The move to SSR brought significant changes to app development, specifically in how it influenced React behavior and how content could be delivered by way of servers instead of browsers.<\/p>\n<\/p>\n <\/p>\n
<\/p>\n
<\/a>\n Figure 2. (Large preview<\/a>)
\n <\/figcaption><\/figure>\nAddressing CSR Limitations<\/h3>\n
Instead of sending a blank HTML document with SSR, we rendered the initial HTML on the server and sent it to the browser. The browser was able to immediately start displaying the content without needing to show a loading indicator. This significantly improves the First Contentful Paint (FCP) performance metric in Web Vitals<\/a>.<\/p>\nServer-side rendering also fixed the SEO issues that came with CSR. Since the crawlers received the content of our websites directly, they were then able to index it right away. The data fetching that happens initially also takes place on the server, which is a plus because it\u2019s closer to the data source and can eliminate fetch waterfalls if done properly<\/em><\/a>.<\/p>\nHydration<\/h3>\n
SSR has its own complexities. For React to make the static HTML received from the server interactive, it needs to hydrate<\/strong> it. Hydration is the process that happens when React reconstructs its Virtual Document Object Model (DOM) on the client side based on what was in the DOM of the initial HTML.<\/p>\nNote<\/strong>: React maintains its own Virtual DOM<\/a> because it\u2019s faster to figure out updates on it instead of the actual DOM. It synchronizes the actual DOM with the Virtual DOM when it needs to update the UI but performs the diffing algorithm on the Virtual DOM.<\/p><\/blockquote>\nWe now have two flavors of Reacts:<\/p>\n
\n- A server-side flavor<\/strong> that knows how to render static HTML from our component tree,<\/li>\n
- A client-side flavor<\/strong> that knows how to make the page interactive.<\/li>\n<\/ol>\n
We\u2019re still shipping React and code for the app to the browser because \u2014 in order to hydrate the initial HTML \u2014 React needs the same components on the client side that were used on the server. During hydration, React performs a process called<\/a> reconciliation<\/em><\/a> in which it compares the server-rendered DOM with the client-rendered DOM and tries to identify differences between the two. If there are differences between the two DOMs, React attempts to fix them by rehydrating the component tree and updating the component hierarchy to match the server-rendered structure. And if there are still<\/em> inconsistencies that cannot be resolved, React will throw errors to indicate the problem. This problem is commonly known as a hydration error<\/em>.<\/p>\nSSR Drawbacks<\/h3>\n
SSR is not a silver bullet solution that addresses CSR limitations. SSR comes with its own drawbacks. Since we moved the initial HTML rendering and data fetching to the server, those servers are now experiencing a much greater load than when we loaded everything on the client.<\/p>\n
Remember when I mentioned that SSR generally improves the FCP performance metric? That may be true, but the Time to First Byte (TTFB) performance metric<\/a> took a negative hit with SSR. The browser literally has to wait for the server to fetch the data it needs, generate the initial HTML, and send the first byte. And while TTFB is not a Core Web Vital metric in itself, it influences the metrics. A negative TTFB leads to negative Core Web Vitals metrics.<\/p>\nAnother drawback of SSR is that the entire page is unresponsive until client-side React has finished hydrating it. Interactive elements cannot listen and \u201creact\u201d to user interactions before React hydrates them, i.e., React attaches the intended event listeners to them. The hydration process is typically fast, but the internet connection and hardware capabilities of the device in use can slow down rendering by a noticeable amount.<\/p>\n
The Present: A Hybrid Approach<\/h2>\n
So far, we have covered two different flavors of React rendering: CSR and SSR. While the two were attempts to improve one another, we now get the best of both worlds, so to speak, as SSR has branched into three additional React flavors that offer a hybrid approach in hopes of reducing the limitations that come with CSR and SSR.<\/p>\n
We\u2019ll look at the first two \u2014 static site generation<\/strong> and incremental static regeneration<\/strong> \u2014 before jumping into an entire discussion on React Server Components, the third flavor.<\/p>\nStatic Site Generation (SSG)<\/h3>\n
Instead of regenerating the same HTML code on every request, we came up with SSG. This React flavor compiles and builds the entire app at build time, generating static (as in vanilla HTML and CSS) files that are, in turn, hosted on a speedy CDN.<\/p>\n
As you might suspect, this hybrid approach to rendering is a nice fit for smaller projects where the content doesn\u2019t change much, like a marketing site or a personal blog, as opposed to larger projects where content may change with user interactions, like an e-commerce site.<\/p>\n
SSG reduces the burden on the server while improving performance metrics related to TTFB because the server no longer has to perform heavy, expensive tasks for re-rendering the page.<\/p>\n
Incremental Static Regeneration (ISR)<\/h3>\n
One SSG drawback is having to rebuild all of the app\u2019s code when a content change is needed. The content is set in stone \u2014 being static and all \u2014 and there\u2019s no way to change just one part of it without rebuilding the whole thing.<\/p>\n
The Next.js team created the second hybrid flavor of React that addresses the drawback of complete SSG rebuilds: incremental static regeneration (ISR)<\/strong>. The name says a lot about the approach in that ISR only rebuilds what\u2019s needed instead of the entire thing. We generate the \u201cinitial version\u201d of the page statically during build time but are also able to rebuild any page containing stale data after<\/em> a user lands on it (i.e., the server request triggers the data check).<\/p>\nFrom that point on, the server will serve new versions of that page statically in increments when needed. That makes ISR a hybrid approach that is neatly positioned between SSG and traditional SSR.<\/p>\n
At the same time, ISR does not address the \u201cstale content\u201d symptom, where users may visit a page before it has finished being generated. Unlike SSG, ISR needs an actual server to regenerate individual pages in response to a user\u2019s browser making a server request. That means we lose the valuable ability to deploy ISR-based apps on a CDN for optimized asset delivery.<\/p>\n
The Future: React Server Components<\/h2>\n
Up until this point, we\u2019ve juggled between CSR, SSR, SSG, and ISR approaches, where all make some sort of trade-off, negatively affecting performance, development complexity, and user experience. Newly introduced React Server Components<\/a> (RSC) aim to address most of these drawbacks by allowing us \u2014 the developer \u2014 to choose the right rendering strategy for each individual React component<\/strong>.<\/p>\nRSCs can significantly reduce the amount of JavaScript shipped to the client since we can selectively decide which ones to serve statically on the server and which render on the client side. There\u2019s a lot more control and flexibility for striking the right balance for your particular project.<\/p>\n
Note:<\/strong> It\u2019s important to keep in mind that as we adopt more advanced architectures, like RSCs, monitoring solutions become invaluable. Sentry offers robust performance monitoring<\/a> and error-tracking capabilities that help you keep an eye on the real-world performance of your RSC-powered application. Sentry also helps you gain insights into how your releases are performing and how stable they are, which is yet another crucial feature to have while migrating your existing applications to RSCs. Implementing Sentry in an RSC-enabled framework like Next.js<\/a> is as easy as running a single terminal command.<\/p><\/blockquote>\nBut what exactly is<\/em> an RSC? Let\u2019s pick one apart to see how it works under the hood.<\/p>\nThe Anatomy of React Server Components<\/h2>\n
This new approach introduces two types of rendering components: Server Components<\/strong> and Client Components<\/strong>. The differences between these two are not how<\/em> they function but where<\/em> they execute and the environments they\u2019re designed for. At the time of this writing, the only way to use RSCs is through React frameworks. And at the moment, there are only three frameworks that support them: Next.js<\/a>, Gatsby<\/a>, and RedwoodJS<\/a>.<\/p>\n<\/p>\n <\/p>\n
<\/p>\n
<\/a>\n Figure 3: Example of an architecture consisting of Server Components and Client Components. (Large preview<\/a>)
\n <\/figcaption><\/figure>\nServer Components<\/h3>\n
Server Components are designed to be executed on the server, and their code is never shipped to the browser. The HTML output and any props they might be accepting are the only pieces that are served. This approach has multiple performance benefits and user experience enhancements:<\/p>\n
\n- Server Components allow for large dependencies to remain on the server side.<\/strong>
\nImagine using a large library for a component. If you\u2019re executing the component on the client side, it means that you\u2019re also shipping the full library to the browser. With Server Components, you\u2019re only taking the static HTML output and avoiding having to ship any JavaScript to the browser. Server Components are truly static, and they remove the whole hydration step.<\/li>\n- Server Components are located much closer to the data sources \u2014 e.g., databases or file systems \u2014 they need to generate code.<\/strong>
\nThey also leverage the server\u2019s computational power to speed up compute-intensive rendering tasks and send only the generated results back to the client. They are also generated in a single pass, which avoids request waterfalls and HTTP round trips<\/a>.<\/li>\n- Server Components safely keep sensitive data and logic away from the browser.<\/strong>
\nThat\u2019s thanks to the fact that personal tokens and API keys are executed on a secure server rather than the client.<\/li>\n- The rendering results can be cached and reused between subsequent requests and even across different sessions.<\/strong>
\nThis significantly reduces rendering time, as well as the overall amount of data that is fetched for each request.<\/li>\n<\/ul>\nThis architecture also makes use of HTML streaming<\/strong>, which means the server defers generating HTML for specific components and instead renders a fallback element in their place while it works on sending back the generated HTML. Streaming Server Components wrap components in <\/code><\/a> tags that provide a fallback value. The implementing framework uses the fallback initially but streams the newly generated content when it\u2018s ready. We\u2019ll talk more about streaming, but let\u2019s first look at Client Components and compare them to Server Components.<\/p>\nClient Components<\/h3>\n
Client Components are the components we already know and love. They\u2019re executed on the client side. Because of this, Client Components are capable of handling user interactions and have access to the browser APIs like localStorage<\/code> and geolocation.<\/p>\nThe term \u201cClient Component\u201d doesn\u2019t describe anything new; they merely are given the label to help distinguish the \u201cold\u201d CSR components from Server Components. Client Components are defined by a \"use client\"<\/code><\/a> directive at the top of their files.<\/p>\n\"use client\"\nexport default function LikeButton() {\n const likePost = () => {\n \/\/ ...\n }\n return (\n
\n 2025-06-20T10:32:35+00:00
\n <\/header>\n
We will get really nerdy to get a full understanding of how RSCs fit into the React picture, the level of control they offer over the rendering lifecycle of components, and what page loads look like with RSCs in place.<\/p>\n
But before we dive into all of that, I think it\u2019s worth looking back at how React has rendered websites up until this point to set the context for why we need RSCs in the first place.<\/p>\n
The Early Days: React Client-Side Rendering<\/h2>\n
The first React apps were rendered on the client side, i.e., in the browser. As developers, we wrote apps with JavaScript classes as components and packaged everything up using bundlers, like Webpack, in a nicely compiled and tree-shaken heap of code ready to ship in a production environment.<\/p>\n
The HTML that returned from the server contained a few things, including:<\/p>\n
- \n
- An HTML document with metadata in the
<\/code> and a blank
\n
<\/div>\n<\/code> in the
<\/code> used as a hook to inject the app into the DOM;<\/li>\n
- JavaScript resources containing React\u2019s core code and the actual code for the web app, which would generate the user interface and populate the app inside of the empty
\n
<\/div>\n<\/code>.<\/li>\n<\/ul>\n
<\/p>\n <\/p>\n
<\/p>\n
<\/a>
\n Figure 1. (Large preview<\/a>)
\n <\/figcaption><\/figure>\nA web app under this process is only fully interactive once JavaScript has fully completed its operations. You can probably already see the tension here that comes with an improved developer experience (DX) that negatively impacts the user experience (UX)<\/strong>.<\/p>\n
The truth is that there were (and are) pros and cons to CSR in React. Looking at the positives, web applications delivered smooth, quick transitions<\/strong> that reduced the overall time it took to load a page, thanks to reactive components that update with user interactions without triggering page refreshes. CSR lightens the server load and allows us to serve assets from speedy content delivery networks (CDNs) capable of delivering content to users from a server location geographically closer to the user for even more optimized page loads.<\/p>\n
There are also not-so-great consequences that come with CSR, most notably perhaps that components could fetch data independently, leading to waterfall network requests<\/strong><\/a> that dramatically slow things down. This may sound like a minor nuisance on the UX side of things, but the damage can actually be quite large on a human level. Eric Bailey\u2019s \u201cModern Health, frameworks, performance, and harm<\/a>\u201d should be a cautionary tale for all CSR work.<\/p>\n
Other negative CSR consequences are not quite as severe but still lead to damage. For example, it used to be that an HTML document containing nothing but metadata and an empty
<\/p>\n
<\/div>\n<\/code> was illegible to search engine crawlers that never get the fully-rendered experience. While that\u2019s solved today, the SEO hit at the time was an anchor on company sites that rely on search engine traffic to generate revenue.<\/p>\n
The Shift: Server-Side Rendering (SSR)<\/h2>\n
Something needed to change. CSR presented developers with a powerful new approach for constructing speedy, interactive interfaces, but users everywhere were inundated with blank screens and loading indicators to get there. The solution was to move the rendering experience from the client<\/strong> to the server<\/strong>. I know it sounds funny that we needed to improve something by going back to the way it was before.<\/p>\n
So, yes, React gained server-side rendering (SSR) capabilities. At one point, SSR was such a topic in the React community that it had a moment<\/a> in the spotlight. The move to SSR brought significant changes to app development, specifically in how it influenced React behavior and how content could be delivered by way of servers instead of browsers.<\/p>\n
<\/p>\n <\/p>\n
<\/p>\n
<\/a>
\n Figure 2. (Large preview<\/a>)
\n <\/figcaption><\/figure>\nAddressing CSR Limitations<\/h3>\n
Instead of sending a blank HTML document with SSR, we rendered the initial HTML on the server and sent it to the browser. The browser was able to immediately start displaying the content without needing to show a loading indicator. This significantly improves the First Contentful Paint (FCP) performance metric in Web Vitals<\/a>.<\/p>\n
Server-side rendering also fixed the SEO issues that came with CSR. Since the crawlers received the content of our websites directly, they were then able to index it right away. The data fetching that happens initially also takes place on the server, which is a plus because it\u2019s closer to the data source and can eliminate fetch waterfalls if done properly<\/em><\/a>.<\/p>\n
Hydration<\/h3>\n
SSR has its own complexities. For React to make the static HTML received from the server interactive, it needs to hydrate<\/strong> it. Hydration is the process that happens when React reconstructs its Virtual Document Object Model (DOM) on the client side based on what was in the DOM of the initial HTML.<\/p>\n
Note<\/strong>: React maintains its own Virtual DOM<\/a> because it\u2019s faster to figure out updates on it instead of the actual DOM. It synchronizes the actual DOM with the Virtual DOM when it needs to update the UI but performs the diffing algorithm on the Virtual DOM.<\/p><\/blockquote>\n
We now have two flavors of Reacts:<\/p>\n
- \n
- A server-side flavor<\/strong> that knows how to render static HTML from our component tree,<\/li>\n
- A client-side flavor<\/strong> that knows how to make the page interactive.<\/li>\n<\/ol>\n
We\u2019re still shipping React and code for the app to the browser because \u2014 in order to hydrate the initial HTML \u2014 React needs the same components on the client side that were used on the server. During hydration, React performs a process called<\/a> reconciliation<\/em><\/a> in which it compares the server-rendered DOM with the client-rendered DOM and tries to identify differences between the two. If there are differences between the two DOMs, React attempts to fix them by rehydrating the component tree and updating the component hierarchy to match the server-rendered structure. And if there are still<\/em> inconsistencies that cannot be resolved, React will throw errors to indicate the problem. This problem is commonly known as a hydration error<\/em>.<\/p>\n
SSR Drawbacks<\/h3>\n
SSR is not a silver bullet solution that addresses CSR limitations. SSR comes with its own drawbacks. Since we moved the initial HTML rendering and data fetching to the server, those servers are now experiencing a much greater load than when we loaded everything on the client.<\/p>\n
Remember when I mentioned that SSR generally improves the FCP performance metric? That may be true, but the Time to First Byte (TTFB) performance metric<\/a> took a negative hit with SSR. The browser literally has to wait for the server to fetch the data it needs, generate the initial HTML, and send the first byte. And while TTFB is not a Core Web Vital metric in itself, it influences the metrics. A negative TTFB leads to negative Core Web Vitals metrics.<\/p>\n
Another drawback of SSR is that the entire page is unresponsive until client-side React has finished hydrating it. Interactive elements cannot listen and \u201creact\u201d to user interactions before React hydrates them, i.e., React attaches the intended event listeners to them. The hydration process is typically fast, but the internet connection and hardware capabilities of the device in use can slow down rendering by a noticeable amount.<\/p>\n
The Present: A Hybrid Approach<\/h2>\n
So far, we have covered two different flavors of React rendering: CSR and SSR. While the two were attempts to improve one another, we now get the best of both worlds, so to speak, as SSR has branched into three additional React flavors that offer a hybrid approach in hopes of reducing the limitations that come with CSR and SSR.<\/p>\n
We\u2019ll look at the first two \u2014 static site generation<\/strong> and incremental static regeneration<\/strong> \u2014 before jumping into an entire discussion on React Server Components, the third flavor.<\/p>\n
Static Site Generation (SSG)<\/h3>\n
Instead of regenerating the same HTML code on every request, we came up with SSG. This React flavor compiles and builds the entire app at build time, generating static (as in vanilla HTML and CSS) files that are, in turn, hosted on a speedy CDN.<\/p>\n
As you might suspect, this hybrid approach to rendering is a nice fit for smaller projects where the content doesn\u2019t change much, like a marketing site or a personal blog, as opposed to larger projects where content may change with user interactions, like an e-commerce site.<\/p>\n
SSG reduces the burden on the server while improving performance metrics related to TTFB because the server no longer has to perform heavy, expensive tasks for re-rendering the page.<\/p>\n
Incremental Static Regeneration (ISR)<\/h3>\n
One SSG drawback is having to rebuild all of the app\u2019s code when a content change is needed. The content is set in stone \u2014 being static and all \u2014 and there\u2019s no way to change just one part of it without rebuilding the whole thing.<\/p>\n
The Next.js team created the second hybrid flavor of React that addresses the drawback of complete SSG rebuilds: incremental static regeneration (ISR)<\/strong>. The name says a lot about the approach in that ISR only rebuilds what\u2019s needed instead of the entire thing. We generate the \u201cinitial version\u201d of the page statically during build time but are also able to rebuild any page containing stale data after<\/em> a user lands on it (i.e., the server request triggers the data check).<\/p>\n
From that point on, the server will serve new versions of that page statically in increments when needed. That makes ISR a hybrid approach that is neatly positioned between SSG and traditional SSR.<\/p>\n
At the same time, ISR does not address the \u201cstale content\u201d symptom, where users may visit a page before it has finished being generated. Unlike SSG, ISR needs an actual server to regenerate individual pages in response to a user\u2019s browser making a server request. That means we lose the valuable ability to deploy ISR-based apps on a CDN for optimized asset delivery.<\/p>\n
The Future: React Server Components<\/h2>\n
Up until this point, we\u2019ve juggled between CSR, SSR, SSG, and ISR approaches, where all make some sort of trade-off, negatively affecting performance, development complexity, and user experience. Newly introduced React Server Components<\/a> (RSC) aim to address most of these drawbacks by allowing us \u2014 the developer \u2014 to choose the right rendering strategy for each individual React component<\/strong>.<\/p>\n
RSCs can significantly reduce the amount of JavaScript shipped to the client since we can selectively decide which ones to serve statically on the server and which render on the client side. There\u2019s a lot more control and flexibility for striking the right balance for your particular project.<\/p>\n
Note:<\/strong> It\u2019s important to keep in mind that as we adopt more advanced architectures, like RSCs, monitoring solutions become invaluable. Sentry offers robust performance monitoring<\/a> and error-tracking capabilities that help you keep an eye on the real-world performance of your RSC-powered application. Sentry also helps you gain insights into how your releases are performing and how stable they are, which is yet another crucial feature to have while migrating your existing applications to RSCs. Implementing Sentry in an RSC-enabled framework like Next.js<\/a> is as easy as running a single terminal command.<\/p><\/blockquote>\n
But what exactly is<\/em> an RSC? Let\u2019s pick one apart to see how it works under the hood.<\/p>\n
The Anatomy of React Server Components<\/h2>\n
This new approach introduces two types of rendering components: Server Components<\/strong> and Client Components<\/strong>. The differences between these two are not how<\/em> they function but where<\/em> they execute and the environments they\u2019re designed for. At the time of this writing, the only way to use RSCs is through React frameworks. And at the moment, there are only three frameworks that support them: Next.js<\/a>, Gatsby<\/a>, and RedwoodJS<\/a>.<\/p>\n
<\/p>\n <\/p>\n
<\/p>\n
<\/a>
\n Figure 3: Example of an architecture consisting of Server Components and Client Components. (Large preview<\/a>)
\n <\/figcaption><\/figure>\nServer Components<\/h3>\n
Server Components are designed to be executed on the server, and their code is never shipped to the browser. The HTML output and any props they might be accepting are the only pieces that are served. This approach has multiple performance benefits and user experience enhancements:<\/p>\n
- \n
- Server Components allow for large dependencies to remain on the server side.<\/strong>
\nImagine using a large library for a component. If you\u2019re executing the component on the client side, it means that you\u2019re also shipping the full library to the browser. With Server Components, you\u2019re only taking the static HTML output and avoiding having to ship any JavaScript to the browser. Server Components are truly static, and they remove the whole hydration step.<\/li>\n- Server Components are located much closer to the data sources \u2014 e.g., databases or file systems \u2014 they need to generate code.<\/strong>
\nThey also leverage the server\u2019s computational power to speed up compute-intensive rendering tasks and send only the generated results back to the client. They are also generated in a single pass, which avoids request waterfalls and HTTP round trips<\/a>.<\/li>\n- Server Components safely keep sensitive data and logic away from the browser.<\/strong>
\nThat\u2019s thanks to the fact that personal tokens and API keys are executed on a secure server rather than the client.<\/li>\n- The rendering results can be cached and reused between subsequent requests and even across different sessions.<\/strong>
\nThis significantly reduces rendering time, as well as the overall amount of data that is fetched for each request.<\/li>\n<\/ul>\nThis architecture also makes use of HTML streaming<\/strong>, which means the server defers generating HTML for specific components and instead renders a fallback element in their place while it works on sending back the generated HTML. Streaming Server Components wrap components in
<\/code><\/a> tags that provide a fallback value. The implementing framework uses the fallback initially but streams the newly generated content when it\u2018s ready. We\u2019ll talk more about streaming, but let\u2019s first look at Client Components and compare them to Server Components.<\/p>\n
Client Components<\/h3>\n
Client Components are the components we already know and love. They\u2019re executed on the client side. Because of this, Client Components are capable of handling user interactions and have access to the browser APIs like
localStorage<\/code> and geolocation.<\/p>\n
The term \u201cClient Component\u201d doesn\u2019t describe anything new; they merely are given the label to help distinguish the \u201cold\u201d CSR components from Server Components. Client Components are defined by a
\"use client\"<\/code><\/a> directive at the top of their files.<\/p>\n
\"use client\"\nexport default function LikeButton() {\n const likePost = () => {\n \/\/ ...\n }\n return (\n
- Server Components are located much closer to the data sources \u2014 e.g., databases or file systems \u2014 they need to generate code.<\/strong>
- A client-side flavor<\/strong> that knows how to make the page interactive.<\/li>\n<\/ol>\n
- JavaScript resources containing React\u2019s core code and the actual code for the web app, which would generate the user interface and populate the app inside of the empty