I’m sorry; I forgot to contextualize it.
TLDR: Yojson doesn’t support Melange; the alternative on the client is melange-json, which doesn’t support Ocaml native. We want a universal code that could run on both sides with the same file and syntax. To achieve it, I created (primarily for fun) this universal code inspired by Yojson, which has a similar contract to melange-json but can run on native ocaml and Melange. So there is nothing wrong with Yojson, it just can’t (for now) fulfill the universal needs.
The SSR problem with reason-react
We have a while the Reasonml and Reason-React allow us to build React applications with Reasonml, which compiles to JS.
One of the problems front-end developers face with React is that everything is rendered on the browser. This has costs for UX because the page can be slow to appear, and for SEO because robots can’t see the markup with the semantic details since they are going to be built after running the JS and then running the render function from React, adding all the applications to the DOM.
It would be nice to see the application (All the structure and styles) before the JS and react start to work. React provides a way to handle it with the renderToString which runs your application into an HTML-structured string. That string is provided to the browser, and React hydrates it instead of rendering it; this can be a lot faster than Client-side rendering. So, the same app entry point can run on both server and client, but it is only compatible with the node. Then, to use reason-react for render on SSR, we need to have our reasonml code compiled to a JS on the server.
Here is where server-reason-react enters. It is a library that allows us to have a Server-side rendering react app with a native OCaml/reason server. It works because it creates an OCaml native way to handling with reason-react code.
It can be 10x faster than node on rendering, reference: Server-side rendering React in OCaml | sancho.dev.
So it works like this:
Step II and Step V should use the same code. Components/Utils/Hooks/Services should work both for the browser engine (JS) and the OCaml/Reason server as @davesnx demonstrated here: Server-side rendering React in OCaml | sancho.dev.
However, many libraries have been developed for the client (Melange) that can be run on a native OCaml server. We need universal code that can run on both native and compiled JS, sometimes adapting it, such as server-reason-react.js which universalize part of the Melange Js module.
So, yojson isn’t available to work for Melange, and melange-json isn’t meant to work on native serve either. The alternatives was to universalize the melange-json to ocaml, universalize yojson to Melange, or create an already universalized code. As I’m learning more of ocaml I decide to create it as a community helper to handle JSON on reason universal applications, and have some fun.
I don’t know if I was too deep, but it is here for anyone how wants to know. :3
Does it make sense @Kakadu ?