mjmlio / mjml

MJML: the only framework that makes responsive-email easy
https://mjml.io
MIT License
16.87k stars 949 forks source link

`height: 'auto'` in defaultAttributes for 'mj-image' breaks template draft #2578

Closed olgaplaga closed 1 year ago

olgaplaga commented 1 year ago

By default, there are defined defaultAttributes for mj-image tag that include:

static defaultAttributes = {
    align: 'center',
    border: '0',
    height: 'auto',
    padding: '10px 25px',
    target: '_blank',
    'font-size': '13px',
  }

Adding heigt="auto" by default breaks image display inside email drafts in the Apple Mail application. Images are not displayed at all or are not correctly scaled.

Possible solutions for this issue:

  1. Don't add height="auto" by default to images (if it is not really necessary)
  2. Allow skipping height="auto" by MJML (before compilation) without the need to define image height to a particular size.
  3. Compile height to the tag style= without adding it as a separate height attribute.
iRyusa commented 1 year ago

Adding heigt="auto" by default breaks image display inside email drafts in the Apple Mail application.

I'm not sure what's the usecase here as sending HTML email via clients will alter the HTML and most likely break the email.

However you can add height="" to mj-image and reset it with mj-attributes if you want so. I'm not sure if the blank height attribute will do something bad tho.

olgaplaga commented 1 year ago

Thanks for the quick answer @iRyusa .

I'm not sure what's the use case here as sending HTML emails via clients will alter the HTML and most likely break the email.

I know that sad phenomenon, however, I believe that the more such use cases can be captured and corrected from a code perspective, the scope for uncontrolled HTML changes between email clients can decrease. This particular case I reported is an important part of a project I'm working on, and I believe many developers will find the option to have more control over it helpful.

I have tested the blank height attribute and it still causes the same problem as with height="auto" .

iRyusa commented 1 year ago

As fair as I remember the height auto isn't mandatory but it helps some version of Outlook to keep the aspect ratio in some cases.

I'll check if I can do a patch to completely remove height if set as an empty string 👍

TechBill commented 1 year ago

I am wondering if that patch allow the Outlook pixel line bug to appear its' ugly head. I post it over at - https://github.com/mjmlio/mjml/issues/2630

iRyusa commented 1 year ago

Don't think so.

But this has been release in 4.14.x