Faire / mjml-react

React component library to generate the HTML emails on the fly
https://www.npmjs.com/package/@faire/mjml-react
MIT License
375 stars 16 forks source link

Remove `renderToJSON` and `renderToJSON2` #103

Open Scott-Fischer opened 1 year ago

Scott-Fischer commented 1 year ago

I noticed there's two module files related to rendering to JSON. What's the difference between the renderToJSON and renderToJSON2 exports? The types seem identical.

IanEdington commented 1 year ago

I honestly have no idea. This is left over from when mjml-react was maintained by wix-incubator. We were planning on removing them in v4.

What are you hoping to use them for?

They are defined here: https://github.com/Faire/mjml-react/blob/ab2829a70d8e49823a141e256c78dd47506c6651/src/utils/render-to-json.js#L90-L94

https://github.com/Faire/mjml-react/blob/ab2829a70d8e49823a141e256c78dd47506c6651/src/utils/render-to-json2.js#L72-L76

emmclaughlin commented 1 year ago

I believe these were created to be used with: https://documentation.mjml.io/#using-mjml-in-json. The exported function is identical, but the difference is in the defined reconciler. This dictates how to convert the mjml-react code into json, so I can only assume renderToJSON2 had some improvements. Unfortunately, looking at the commit history I can't figure out exactly what they are, so I have no idea either.

Scott-Fischer commented 1 year ago

I honestly have no idea. This is left over from when mjml-react was maintained by wix-incubator. We were planning on removing them in v4.

What are you hoping to use them for?

They are defined here:

https://github.com/Faire/mjml-react/blob/ab2829a70d8e49823a141e256c78dd47506c6651/src/utils/render-to-json.js#L90-L94

https://github.com/Faire/mjml-react/blob/ab2829a70d8e49823a141e256c78dd47506c6651/src/utils/render-to-json2.js#L72-L76

I believe these were created to be used with: https://documentation.mjml.io/#using-mjml-in-json. The exported function is identical, but the difference is in the defined reconciler. This dictates how to convert the mjml-react code into json, so I can only assume renderToJSON2 had some improvements. Unfortunately, looking at the commit history I can't figure out exactly what they are, so I have no idea either.

Thanks for getting back to me! Honestly I was mostly just curious since I was digging around in the internals + types and thought it was really peculiar to see two identical type signatures like that. (especially with the naming convention being used).

IanEdington commented 1 year ago

🎉 Thanks for digging in and looking around our project! I'll turn this into a issue to remove renderToJSON and renderToJSON2 and leave it for a while to see if anyone else comments with a reason to keep it.

tobiechvarria commented 1 year ago

HI!

Please don't remove this utility function since my current application uses renderToJSON. I'm primarily using renderToJSON to build mjml body component in json form and store them in the back-end. This way I can save & retrieve custom mjml components and load them into my application via mjml renderer & createElement. If you do remove this util function then I won't be able to update to future version of this lib. Thanks for taking over this lib, btw!

IanEdington commented 1 year ago

Thank you @tobiechvarria. I'm trying to understand this better so we can evaluate if we remove it from the core package and offer it as a secondary package or leave it in the main bundle.

to build mjml body component in json form and store them in the back-end.

Is the idea that the json contains all the data required to render the component? Are there any code snippets you can share to demonstrate the serialization and deserialization of components into json and back?

Also, do you use renderToJSON2 or renderToJSON?

tobiechvarria commented 1 year ago

Hi @IanEdington,

"Is the idea that the json contains all the data required to render the component?' Yes, to this question.

My application is an email builder which a user can add mjml body component types to build out a custom email design. I'm using renderToJSON to help build out the user interface. Using JSON, I able to easily traverse the mjml object and grab the attributes for each tag and present an appropriate UI element for the user to interact with.

I can create my own mjml to json parser to do this, but why would I if one already exist :).

Thanks for the reply!