Skip to content

Commit 3cabce2

Browse files
fix: update blog post title and enhance content clarity on React Server Components and bundler integration
1 parent 6035f5e commit 3cabce2

1 file changed

Lines changed: 75 additions & 34 deletions

File tree

Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Why rsc need a bundler"
2+
title: "How React Server Component Integrates with Bundler"
33
description: "A deep dive into how React state updates really work, from hooks to batching"
44
date: "2026-02-24"
55
topic: "React"
@@ -8,64 +8,105 @@ draft: true
88

99

1010
# Intro
11-
I have been trying to build a react server component from a scratch for a learning and it's been a fun quite not gonna lie.
12-
In this blog i wanna share with you all my learning, why RSC integrates with a bundler and how different is React server component
13-
from the CSR app we build or the spa app we build
1411

15-
this blog is not going to be about why we need a RSC or benefite of RSC rather it will be on a internal implementation detail,
16-
if you are nerdy about these things then buckle up we are going to see through those in this blog
12+
I have been experimenting with building a [small version](https://github.com/sankalpaacharya/drop) of React Server Components to understand how the system works internally.
1713

14+
This blog is not about why RSC is useful or what benefits it brings. It’s more focused on how it actually works under the hood,
15+
especially how the server and client parts of a React app end up split during build time.
1816

1917

20-
# Little History
18+
# Interesting parts
2119

22-
Before we move to a react server component let's have a quick recap, For many years react has always been on
23-
the client side only, if you needed a data from the database you would have to wait till the browser downloads all the JavaScript,
24-
parse it compile it and react renders all components commit them and after that the fetch call will begin. This way SEO suffers,
25-
user will just have to stare at the blank screen while all these things is being processed
20+
React server component has a protocl called a flight protocol which genereates a flight stream. This is not real JSON, but it looks similar in structure. It is closer to a structured wire format that React can parse incrementally while streaming.
2621

27-
considering a same problem react team during 2021 introduced a New Suspense SSR Architecture in React 18, RSC was still in experimental
28-
phase that time, but i guess react team prepared the new suspense SSR Architecture considering the RSC they were working that time.
29-
tho the initial RSC accountment was already done during the 2020 ie [Introducing Zero-Bundle-Size React Server Components](https://react.dev/blog/2020/12/21/data-fetching-with-react-server-components)
22+
One reason this format is not plain JSON is that React needs to support values that JSON normally cannot represent cleanly during serialization, such as async boundaries and server-side computations that may resolve over time.
3023

24+
```tsx
3125

32-
# Interesting parts
26+
const promise = new Promise((resolve) => {
27+
setTimeout(() => resolve("Sanku"), 1000);
28+
});
3329

34-
react server component introduced a new protocl called a flight protocol which genereates a flight stream which looks something
30+
const json = JSON.stringify(promise); // => '{}'
3531

36-
React server component needs a tight integreation with the bundler, In a RSC paradigm we can have a both client and a server components
32+
```
3733

38-
RSC gives a ability to generate a UI on server side and send that built UI on the client side as a flight protocl and none
39-
of the JavaScript for this component needs to be shipped to a browser, since RSC sends a serialized flight stream not a HTML, client
40-
side state are also preserved as well.
41-
https://overreacted.io/jsx-over-the-wire/#composing-viewmodels
34+
Instead of trying to force everything into JSON semantics, React uses a custom format that can represent these cases in a streaming way.
4235

43-
This can be pretty much confusing to a lot of people, is RSC is just a new SSR but that's actually not the truth cause
44-
when you are doing SSR you are sending a rendered HTML to a client side and after that react on the client side takes a full control
45-
you can't just ask few portion of your UI to get revalidated in SSR, you would need a full page re-fresh on that.
36+
- [You can serialize a promise in React](https://twofoldframework.com/blog/you-can-serialize-a-promise-in-react)
4637

47-
so what actually mean in RSC is that a new version of a server subtree is streamed to the client and reconciled into the existing React tree
4838

49-
React server component paradigm we can have a client component and a server component both,
39+
Take this as an example
5040

51-
like this
41+
```tsx
42+
// Server-Component.tsx
43+
async function Page() {
44+
const user = await db.user.findFirst()
5245

53-
[why cleint component need ssrd](https://github.com/reactwg/server-components/discussions/4)
46+
return (
47+
<div>
48+
<h1>Dashboard</h1>
49+
<p>{user.name}</p>
50+
<AddToCart />
51+
</div>
52+
)
53+
}
54+
```
5455

55-
# Let's begin
56+
Now during a runtime RSC renderer will generate a flight stream for this which would look something like this
57+
58+
```json
59+
1:["$","div",null,{
60+
"children":[
61+
["$","h1",null,{
62+
"children":"Dashboard"
63+
}],
64+
65+
["$","p",null,{
66+
"children":"Sanku" // from DB result
67+
}],
68+
69+
["$","$L1",null,{}]
70+
]
71+
}]
72+
```
5673

57-
React UI is a tree in itself, this UI tree has leaves 🍃 in this tree, some leaves is for browser(client components) and some leaves
58-
is for the server(server component).
74+
On the client side, this stream is reconstructed back into a React tree. This is what allows React Server Components to send UI from the server without shipping the implementation code for server components to the browser.
75+
Because you are sending a rendered UI as a flight stream which will be constructued on client side.
5976

60-
when we are building RSC app we build app from two prespective from a client world and from a server world.
77+
while client components are resolved later using the referenced modules.
78+
79+
```json
80+
1:["$","div",null,{
81+
"children":[
82+
["$","h1",null,{
83+
"children":"Counter"
84+
}],
85+
86+
["$","$L1",null,{}]
87+
]
88+
}]
89+
```
90+
91+
92+
This can be pretty much confusing to a lot of people, is RSC is just a new SSR but that's actually not the truth cause
93+
when you are doing SSR you are sending a rendered HTML to a client side and after that react on the client side takes a full control
94+
you can't just ask few portion of your UI to get revalidated in SSR, you would need a full page re-fresh on that.
95+
96+
# Let's begin
6197

62-
when it's a client build it's it goes from your entry file and your module graph, it travers your module graph and when it
63-
encounters a servre component it will execute
98+
A React UI is a tree. Some parts of this tree run on the server, and some parts run in the browser.
6499

100+
In a React Server Components setup, we are no longer dealing with a single build target. Instead, the same codebase is processed from two perspectives: a server world and a client world.
65101

102+
On the server side, the application is executed starting from the entry file. React walks through the module graph and renders all Server Components. These components run in a Node.js environment using the server renderer from react-server-dom, which does not include browser APIs like useState or event handlers.
66103

104+
Instead of rendering the component, the server emits something like a module reference using registerClientReference. This reference does not contain implementation details. It only points to where the component exists in the client bundle.
67105

68106

107+
```tsx
108+
let out = `import { registerClientReference } from "react-server-dom-webpack/server";\n`;
109+
```
69110

70111

71112

0 commit comments

Comments
 (0)