DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Mastering React App Configuration With Webpack
  • Overcoming React Development Hurdles: A Guide for Developers

Trending

  • Traditional Testing and RAGAS: A Hybrid Strategy for Evaluating AI Chatbots
  • SaaS in an Enterprise - An Implementation Roadmap
  • Go 1.24+ Native FIPS Support for Easier Compliance
  • Creating a Web Project: Caching for Performance Optimization
  1. DZone
  2. Coding
  3. JavaScript
  4. What to Expect From Zero-Bundle-Size React Server Components

What to Expect From Zero-Bundle-Size React Server Components

I have tested the demo version in my project with maps and here is what I can say about the technology and its current pros and cons.

By 
Oleksii Demennikov user avatar
Oleksii Demennikov
·
Mar. 20, 21 · Review
Likes (3)
Comment
Save
Tweet
Share
9.3K Views

Join the DZone community and get the full member experience.

Join For Free

Initially, React was mainly a frontend framework that focused on the client-side. And now it is interesting to watch how the Facebook team is developing React server-side.

In December 2020, the React team announced a new feature called React Server Components, which is still in development but you can try the demo. Since then, the React community has been actively discussing this new way of building React applications. Most of the feedback is positive, so I decided to try it myself. 

What We Have Now

For server-side rendering, you need to either set up your own server and write a custom bundler or employ server-side React frameworks like NextJs, AfterJs, Gatsby.

And it is OK when you just started. However as the codebase grows, so does the bundle size and the cost of maintenance. 

Sometimes the logic for building the markup is based on databases. So you have to run it on several levels of abstraction and then pack. It’s even worse when you need to output exactly HTML from a server. You can fix it with dangerouslySetInnerHTML, but it is considered an anti-pattern.

What React Offers

Zero-bundle-size react server components are not a replacement for traditional Server-side rendering (SSR). The components complement SSR. Paired with, let’s say, Next.js, they create an intermediate format and enable rendering by sending no bundles to the client-side. This allows merging the server-tree with the client-side tree without a loss of state and enables scaling up to more components.

SSR has the principle of sending the pre-built HTML markup and then hydrating it with JS, so a user can not interact with your website until the JS is loaded. Server components behave in a different way, they can be called multiple times and not on the first load and have their own format of transferring data over the network.

Benefits

1. Integration with NodeJS ecosystem, so you are able to use familiar developer tools.

2. React teams worked a lot to prepare the React wrapper packages for Fetch and Postgres, which are now quite common in most apps. They are currently in the experimental phase.

3. Data optimization over the network is visible. If you look at network calls, you will see just JSX transferred from the frontend.

4. You will have no problems with using the feature thanks to the uniform interface of the components. So, I think it won’t be a hard task to implement zero-bundle-size react server components into your current projects. 

Limitations 

1. Since it is upgraded but still server-side rendering, we face problems with libraries that are programmed to have access to the window. In practice, we have access to the global, but not the window in the backend. 

For my test project, I used the Leaflet app for maps. But maps don’t load if rendered in the backend. So you have to transfer the maps to the frontend (through .client.js).

2. If you initially have a create-react-app (CRA), you can’t use the new components so you will need to eject from its ecosystem and tweak webpack configuration the way you need it. Taking into account that a lot of projects are developed with CRA, it is a considerable problem because they don’t have an easy opportunity to upgrade. 

3. Since the feature is not finished yet, there is no documentation, and you have to read code, download the demo-app, and use the debugger to discover the requests between the frontend and backend. 

4. Also without documentation it is not clear how to work with pipeToNodeWritable, and how it interacts with unstable_useTransition.

Wrapping Up

Probably, with the server components, we will get a good user experience, cheap maintenance, and fast performance at the same time. 

For now, developers do need to think about the optimal compositing of the network requests and working with the backend resources. This includes proper planning of architecture, isolation of logic for the server-side and client-side part. With React server-side components, these two concerns are merged, but in more intuitive way. And what’s more important, it’s up to you if you want to use them. You can combine it with existing architecture and use familiar technologies and techniques with this new approach because React is not an opinionated framework, it’s a library which can be used in many different ways. 

There are still interesting and not covered cases such as sharing the react context and redux-like libraries as well as the ways they will behave with this new ecosystem. Also, the documentation does not mention how you can use this feature with typed languages, like TypeScript. But the React team states that they value developers’ feedback, so you can mention them on social media to let them know which cases are crucial for you.

React (JavaScript library)

Opinions expressed by DZone contributors are their own.

Related

  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Mastering React App Configuration With Webpack
  • Overcoming React Development Hurdles: A Guide for Developers

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!