It's commonly referred to as the RSC payload. This payload is an internal representation and is often considered as implementation detail. RSC is renderer-independent, which means, while it might be frequently used with react-dom, RSC isn't strictly tied to the DOM.
Also, as you see in this example, we supply an option to nulljs, react-server-condition. It's essential because without this, the code doesn't run. This specification is to determine if the code runs under an RSC environment.
Next, we'll look at how the deserialization process takes place. In this demo, we're focusing on deserialization. Let's look at the code. The react-server.webpack slash client refers to the client side of the library. Typically it's used in browsers, but for the sake of this demo, we are using the node.js version. The function createFromNodeStream is to deserialize the RSC payload. To make the demo work in a single Node.js instance, we are using the paththrough stream. In real-world scenarios, the data from this stream might be sent over a network.
The outcome on the console might look familiar. It's the same as the JSX element we discussed in our first example. In fact, executing the console.log statement which is commented at the end of the code will show the identical result twice. This is the core functionality of RSC. Serializing a JSX element, transferring its stream by any method and then deserializing it to reproduce the same result elsewhere. We'll dive a little deeper in the upcoming examples.
RSC's ability to serialize data isn't just for React. It can actually handle any JavaScript values. I would think of it this way. RSC supports JSX elements on top of standard JavaScript values. Now, taking a look at the code and its output, this basic example demonstrates that RSC can handle objects, arrays, strings, and numbers. While we are highlighting the serialization in this example, deserialization would just work similarly. At first glance, this might seem very basic. Something we can do with JSON string file and JSON parts. So, what would be the unique aspect of RSC? You might notice an extra prefix before the JSON string, which in this case is zero column. Remember, the RSC payload is designed as a string meaning data is transferred step by step.
Comments