Closed Dricosta closed 1 year ago
Thanks for reporting. It seems like an issue inside html-minifier
.
You could try replacing the @faire/mjml-react/utils/render
with this render function that doesn't use html-minifier
.
import mjml2html from "mjml";
import { MJMLJsonObject, MJMLParseError, MJMLParsingOptions } from "mjml-core";
import React from "react";
import ReactDOMServer from "react-dom/server";
function renderToMjml(email: React.ReactElement): string {
return ReactDOMServer.renderToStaticMarkup(email);
}
interface ConvertedHtml {
html: string;
json?: MJMLJsonObject;
errors?: MJMLParseError[];
}
export function render(
email: React.ReactElement,
options: MJMLParsingOptions = {}
): ConvertedHtml {
return mjml2html(renderToMjml(email), options);
}
@emmclaughlin I think we should try to get rid of html-minifier
in version 4. Thoughts?
@emmclaughlin I think we should try to get rid of
html-minifier
in version 4. Thoughts?
I agree. The reason we kept it originally was to make migrating from v2 to v3 easier by not changing the render function. The long term goal would definitely be to allow the user to dictate if and how to minimize their HTML on their own.
As an added note to the previous answer, you may also have to use mjml-browser
(https://www.npmjs.com/package/mjml-browser) instead of mjml
. See this issue more discussion about mjml-browser
vs mjml
.
import mjml2html from "mjml-browser"; // This line is changed
import { MJMLJsonObject, MJMLParseError, MJMLParsingOptions } from "mjml-core";
import React from "react";
import ReactDOMServer from "react-dom/server";
function renderToMjml(email: React.ReactElement): string {
return ReactDOMServer.renderToStaticMarkup(email);
}
interface ConvertedHtml {
html: string;
json?: MJMLJsonObject;
errors?: MJMLParseError[];
}
export function render(
email: React.ReactElement,
options: MJMLParsingOptions = {}
): ConvertedHtml {
return mjml2html(renderToMjml(email), options);
}
I am getting the following error in the console when trying to render the most basic example component
I am using the version: @faire/mjml-react: "^3.1.1" node: 16.14.2 vite: "^4.0.4"