Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork13
Description
Description
Improve the client_props and start the movement to align the behavior of SRR RSC to what React expects.
Why
The react expect that response of the RSC, which evolves actions response and props response to the client, to be composable.
letprops= { bar: { element: <div/> }, foo:"Hey", baz:[<div/>,"Yah!"]}
But our type nowadays is:
and client_prop=(* TODO: Do we need to add more types here?*)|Json :Yojson.Basic.t -> client_prop|Element :element -> client_prop|Promise : 'aJs.Promise.t* ('a ->Yojson.Basic.t) -> client_prop
As we can see,Json does not support any otherclient_prop inside it, similar toPromise that does not support it. They always handle aYojson.Basic.t.
So we cannot have: React.Promise(promise, (response) => React.Element(response)).
How would we have such response:
// Server content that needs to be serializedletprops= { bar: { element: <div> {React.String("I'm a nested element :3")} </div> }, foo:[<div> {React.String("Hey")} </div>,"Yah!"], baz: <div> {React.String("Who isLola?")} </div>}//Let's see it as client prop{"bar":React.???(["element",React.Element(<div> {React.String("I'm a nested element :3")} </div> )])"foo":React.???([React.Element(<div> {React.String("Hey")} </div>,React.Json(`String("Yah!")))])"baz":React.Promise(React.Element(<div> {React.String("Who isLola?")} </div>))// This is not valid nowaday)
We need to support those React.??? and we need to make Promise to acceptclient_prop instead only Yojson type.
For example (not the final code):
and client_prop=|List :client_proplist -> rsc_value|Assoc : (string *client_prop)list -> rsc_value|Json :Yojson.Basic.t -> client_prop|Element :element -> client_prop|Promise : 'aJs.Promise.t* ('a ->client_prop) -> client_prop
Then we can handle all those types recursively, and the final return must always be either aYojson.Basic.t or aReact.element.
{"bar":React.Assoc(["element",React.Element(<div> {React.String("I'm a nested element :3")} </div> )])"foo":React.List([React.Element(<div> {React.String("Hey")} </div>,React.Json(`String("Yah!")))])"baz":React.Promise(React.Element(<div> {React.String("Who isLola?")} </div>)))