React Server Component -- "RSC"
Server Components are an experimental feature and are not ready for adoption.
Recommend reading this article firstly: Introducing Zero-Bundle-Size React Server Components
In the frontend development, we will meet some pain points, all We want:
- Good(User experience)
But for sure we can't get all. Here is an example:
Component usually exchanges data with the server by:
- Fetch data in the parent node and dispatch to all children components(waiting until dispatching)
- Fetch data in every respective children component (data maybe exists duplicated part) The first way needs to wait and maintain easily-- Cheap but no fast. Second-way waste resource and hard to maintain but fast -- Good, fast but no cheap
One word, React Server Component is: Asynchronously dispatch react component by serialized JSON from server-side.
Actually, We already have GraphQL, it also can fetch the data that component needs just enough. why we need RSC?
Actually not every team welcome GraphQL, it needs a special frontend and backend API, it's pretty complex, many teams don’t like such high costs on learning and maintaining.
Server-Side Rendering(SSR), RSC is basically different from SSR. SSR responds with the whole HTML and refreshes the page when the user triggers some action, but RSC still keeps the way of asynchronous interaction and refreshing partial.
of course, you can use RSC with all of the technologies above, you can use RSC in SSR and communicate between client and server by GraphQL If you like and god bless you.
RSC can bring us:
- Less bundle size, load the code that is necessary(Both app itself and imported libraries)
- Speed up data grab process, from server to server side
- No need to consider the possible bandwidth waste through data API
- No need to consider components should be imported asynchronously or packaged in advance
- Less SPA's white screen time
What kind of component suits RSC (for now):
- No much interaction
- Do have some data rely on
- Flexible content components
In my opinion, If RSC production-ready, we can use it as a normal way to develop react applications (like hooks).
More interesting concepts:
- Client and server component looks the same
- "Shared Component"
- Transfer data from server to server in RSC, That's way fast and it has many approaches
- Get rid of some libraries which just be used few times in the corner
- Server mental model
- A mixed component tree
React Server Components are still in research and development. But this concept is pretty inspired, we can develop at server side, reduce the SPA's white screen time, lighten bundle size and we have a new approach to improve user experience.