Skip to content
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

'Unexpected closing tag "td". Help! #1838

Open
jimapl opened this issue Dec 24, 2024 · 11 comments
Open

'Unexpected closing tag "td". Help! #1838

jimapl opened this issue Dec 24, 2024 · 11 comments

Comments

@jimapl
Copy link

jimapl commented Dec 24, 2024

Describe the Bug

After bumping react and nextjs to latest, I get this error on all my email renders:

import {render} from "@react-email/render";
...
export const customVerificationRequest = async ({token, identifier: email} : {
    token: string;
    identifier: string;
}) => {
    try {

        const html = await render(<MagicSigninEmail token={token}/>, {
            pretty: true,
        });
       ...

    } catch (e) {
        console.error({e})
    }
}

Which throws

[cause]: t {
  span: [h],
  msg: 'Unexpected closing tag "td". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags',
  level: 1,
  elementName: 'td'
}
    "@react-email/components": "^0.0.28",
    "@react-email/render": "^1.0.3",
     "react-email": "3.0.4",

Which package is affected (leave empty if unsure)

No response

Link to the code that reproduces this issue

Private repo

To Reproduce

Switching to stable branch everything works. Meaning react 18 / nextjs 14.
Have not changed any code, both render and renderAsync this happens.

Expected Behavior

Email to be rendered

What's your node version? (if relevant)

v20.10.0

@jimapl jimapl added the Type: Bug Confirmed bug label Dec 24, 2024
@gabrielmfern
Copy link
Collaborator

gabrielmfern commented Dec 24, 2024

We can't reproduce your issue if you don't share a reproduction for it. What was the content for the email template that generates the error? If we were to guess, it would be almost impossible and a waste of time.

Going to close this issue as not planned, since it is basically unsolvable without the proper instructions. Share the reproduction and I might reopen if it is satisfactory.

@gabrielmfern gabrielmfern closed this as not planned Won't fix, can't repro, duplicate, stale Dec 24, 2024
@gabrielmfern gabrielmfern added the Resolution: Needs More Information More information is needed on this issue label Dec 24, 2024
@jimapl
Copy link
Author

jimapl commented Dec 24, 2024

It’s a straight copy from the react email templates.
Will paste it here later when home. Brb
Same code does not break in react 18

Will get back

@jim-spr
Copy link

jim-spr commented Dec 31, 2024

The email template in question:

https://gist.github.com/jim-spr/c3668ec9dc36277e63e744e9fb33565f

it's pretty much from the react-email templates.
Again, I have not changed any code. I bumped next to latest and react version to 19. Anything else I should provide?

@gabrielmfern

Edit:

even sending an empty column. All other components commented out, it breaks.
When I comment column out, it sends successfully!

@jim-spr
Copy link

jim-spr commented Dec 31, 2024

Managed to solve this issue by deleting the Column component. Is this deprecated?

@EleanorLee42
Copy link

@gabrielmfern I'm seeing this issue, too, with @react-email/[email protected] and above. It appears to be an issue with render expecting tag omission. This:

await render(
   <p>
      <div>Hi</div>
   </p>,
   { pretty: true }
);

fails, while this:

await render(
   <p>
      <span>Hi</span>
   </p>,
   { pretty: true }
);

works without error.

@jimmailcamp
Copy link

@gabrielmfern gabrielmfern

@EleanorLee42
Copy link

@gabrielmfern if it helps, I'm wondering if this change from js-beautify to prettier is what caused this issue. I've noticed that the render only fails when { pretty: true } is passed.

@gabrielmfern gabrielmfern reopened this Jan 15, 2025
@gabrielmfern
Copy link
Collaborator

Sorry for the delay, looking into this right now!

@gabrielmfern
Copy link
Collaborator

as @EleanorLee42 mentioned, this is an issue happening with the way we currently prettify the output from render, so as a workaround you can simply disable the pretty option for now

@gabrielmfern
Copy link
Collaborator

The error itself seems to point to this in the HTML standard

13.2.6.3 Closing elements that have implied end tags
When the steps below require the UA to generate implied end tags, then, while the current node is a dd element, a dt element, an li element, an optgroup element, an option element, a p element, an rb element, an rp element, an rt element, or an rtc element, the UA must pop the current node off the stack of open elements.

If a step requires the UA to generate implied end tags but lists an element to exclude from the process, then the UA must perform the above steps as if that element was not in the above list.

When the steps below require the UA to generate all implied end tags thoroughly, then, while the current node is a caption element, a colgroup element, a dd element, a dt element, an li element, an optgroup element, an option element, a p element, an rb element, an rp element, an rt element, an rtc element, a tbody element, a td element, a tfoot element, a th element, a thead element, or a tr element, the UA must pop the current node off the stack of open elements.

@gabrielmfern gabrielmfern added Package: @react-email/render and removed Resolution: Needs More Information More information is needed on this issue labels Jan 16, 2025
@gabrielmfern
Copy link
Collaborator

gabrielmfern commented Jan 21, 2025

React doesn't disallow users to write down any invalid HTML, like having divs inside paragraphs, but prettier's HTML formatter seem to be very strict in this sense.

It goes without saying, though, that you should not write HTML with divs inside paragraphs, or tds inside tds, since once this HTML gets to the browser they will be rendered differently by following the definitions from the spec and will lead to unexpected behavior.

As for the solution on this, I am not quite 100% sure but will keep you all updated. An idea is to still error, but have something clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants