mjmlio / mjml

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

Rendering another MJML template in MJML template #2695

Open returnv01d opened 1 year ago

returnv01d commented 1 year ago

Describe the bug When MJML template contains in body another full MJML template (another <mjml>....</mjml>) then it does render only outer template (see screenshot) without throwing any errors.

To Reproduce Steps to reproduce the behavior:

  1. Create a file with this MJML code:

    <mjml>
    <mj-body background-color="#d2f1f6">
    <mj-section>
      <mj-column>
        <mj-text color="#F45E43">Hello World</mj-text>
    
      </mj-column>
    </mj-section>
    
    <mjml>
      <mj-body background-color="#F45E43">
        <mj-section>
          <mj-column>
            <mj-text>Test</mj-text>
          </mj-column>
        </mj-section>
      </mj-body>
    </mjml>
    </mj-body>
    </mjml>
  2. Render it to HTML by doing 'mjml -r --config.validationLevel strict`

Expected behavior There should be at least error about illegal nesting or rendering both templates.

MJML environment (please complete the following information):

Screenshots

image

Additional context Embedding MJML in layout uncovered this issue.

iRyusa commented 1 year ago

Why would you expect this to work ?

returnv01d commented 1 year ago

I would expect it to throw an error, not to work

iRyusa commented 1 year ago

Ok then I misread, the issue first my bad.

Really weird that the validator doesn't catch this https://github.com/mjmlio/mjml/blob/master/packages/mjml-preset-core/src/dependencies.js#L8 this shouldn't be marked as a valid children 🤔

returnv01d commented 1 year ago

I made a fix for this issue: https://github.com/mjmlio/mjml/pull/2709