Does not work with mjml-react components
Describe the Bug
Created with https://react.email/docs/getting-started/automatic-setup and added the dependency of mjml-react.
Mjml components do not render.
Which package is affected (leave empty if unsure)
react-email
Link to the code that reproduces this issue
https://github.com/ReMatter/react-email-mjml
To Reproduce
npm install
npm run dev
navigate to mjml-text component
Expected Behavior
The components renders
What's your node version? (if relevant)
18.16.0
Hi @nicoabie,
TLDR
This is not a bug with react-email as MJML is converted using the MJML engine which has its own render function for converting the components to HTML. React email also has its own engine for converting the React-email components to HTML.
From the MJML docs
MJML is a markup language designed to reduce the pain of coding a responsive email. Its semantic syntax makes it easy and straightforward and its rich standard components library speeds up your development time and lightens your email codebase. MJML’s open-source engine generates high quality responsive HTML compliant with best practices.
From the React-email docs
In order to use React Email with any email service provider, you’ll need to convert the components made with React into a HTML string. This is done using the render utility.
Combining React-email and MJML (which I think is not an ideal solution)
In order to use React Email with MJML-React, you would have to come up with some creative solution that makes use of the Render functions for MJML-React and React-email packages .
// from mjml-react
import { render } from 'mjml-react';
// from react-email
import { render } from "@react-email/render";
Thanks a lot for explaining this @lordelogos
I called the render function of mjml-react and I get the html, is there some way to send that html string to react-email without it escaping it?
react-email is replacing < by < and so on
If it were able to just accept html it would work.
The reason of why I need this is bc we are today using old mjml templates and we use react-html-email to just generate the previews which is a killer, it is too heavy. So I would like to replace it with react-email as a first step and then replace the old mjml templates with the ones provided by react-email.
Hi @nicoabie, Sorry for the delay in my response.
I setup a sort of demo on how I think it can work Find it here
Things to note
- Converting your existing full mjml templates incrementally is my best advice
- Try to avoid using
Headfrom react-email in combination withMjmlHeadas they serve the same function to provide metadata - Using external css is a bit tricky with this method but i'll leave that up to you
Let me know if I can be of any more help
Thanks a lot! Just browsed at the code and it is definitely what I needed to dangerously set the inner html after a rendering mjml.
Also thanks for the notes. With this change I can remove 500mb of deps in our project!!