|
| 1 | +--- |
| 2 | +title: "Why rsc need a bundler" |
| 3 | +description: "A deep dive into how React state updates really work, from hooks to batching" |
| 4 | +date: "2026-02-24" |
| 5 | +topic: "React" |
| 6 | +draft: true |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +# 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 |
| 14 | + |
| 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 |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +# Little History |
| 21 | + |
| 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 |
| 26 | + |
| 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) |
| 30 | + |
| 31 | + |
| 32 | +# Interesting parts |
| 33 | + |
| 34 | +react server component introduced a new protocl called a flight protocol which genereates a flight stream which looks something |
| 35 | + |
| 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 |
| 37 | + |
| 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 |
| 42 | + |
| 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. |
| 46 | + |
| 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 |
| 48 | + |
| 49 | +React server component paradigm we can have a client component and a server component both, |
| 50 | + |
| 51 | +like this |
| 52 | + |
| 53 | +[why cleint component need ssrd](https://github.com/reactwg/server-components/discussions/4) |
| 54 | + |
| 55 | +# Let's begin |
| 56 | + |
| 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). |
| 59 | + |
| 60 | +when we are building RSC app we build app from two prespective from a client world and from a server world. |
| 61 | + |
| 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 |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
0 commit comments