-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
number -> px seems like it could result in a bug #87
Comments
I don't really understand why converting to if (typeof value === "number") {
if (numberToPixel.includes(name)) {
return `${value}px`;
} else {
return value;
}
} I ran into a nasty issue where previously we were using |
Looking at this line it seems as though border was included in a prop types override. In general we just pull the prop types from the mjml component definition. If we were to remove that override, border would actually not accept a number, e.g. mj-column in docs is defined as a string. In my opinion removing the override is probably the best solution, as it will enforce the types to be what mjml wants. So |
I did some experimenting and <mjml>
<mj-head>
<mj-attributes>
<mj-column border="5px solid black"/>
</mj-attributes>
</mj-head>
<mj-body>
<mj-section>
<mj-column border="0">
<mj-text>text</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml> From what I understand the conversion from The mjml docs are a little confusing, because in a lot of places it says the unit is Another thought,
https://github.com/Faire/mjml-react/blob/main/scripts/generate-mjml-react-utils/getPropTypeFromMjmlAttributeType.ts#L38 I'm guessing this line is trying to make autocomplete better? e.g. so instead of https://github.com/Faire/mjml-react/blob/main/scripts/generate-mjml-react-utils/getPropTypeFromMjmlAttributeType.ts#L44 since this is also allowing I think all in all I'm leaning towards my patch where the "silently discard numbers" scenario is fixed. I think while removing the type override might be a step in the right direction, there would still be a big foot gun with passing numbers through as prop values. |
Thank you for the detailed investigation here! I agree that having a silent return is a poor programming experience. I think in the short term just returning the value and letting mjml handle throwing the errors is a good idea. We have had examples in the past of others getting burned by this, e.g. #99. In the long term, there may still room for improvement though. It would be great to improve the type safety so issues are identified as early as possible. That would go beyond a bug fix, and is still open for more detailed investigation/discussion. |
MJML already converts numbers into pixels in certain cases. This seems like it could result in a bug where we convert a number to a px for an underlying mjml component that doesn't do the conversion. If possible I'd rather have number be converted to a string instead.
mjml-react/src/utils/mjml-component-utils.ts
Lines 67 to 69 in e8befa5
The text was updated successfully, but these errors were encountered: