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

fix(tailwind): Children always being transformed into an array #1397

Merged

Conversation

gabrielmfern
Copy link
Collaborator

@gabrielmfern gabrielmfern commented Apr 3, 2024

I noticed that, when testing to make sure that the new canary release of Tailwind actually had
#1391 fixed after #1335 being updated with the small Tailwind refactor from before, the <Heading> didn't
work like when I checked before the fixing of the conflitcs.

After debugging for a while, I noticed that, since we use radix-ui's <Slot> component on the <Heading>,
it expects its children to be exactly one element, not an array, meaning that our mapping of children for elements
was making the <SlotClone> return null which made the <Heading> not render.

The fix for the issue was very simple — just looking at the array and checking if it
has only one value inside, in which case it would return that value instead of the
whole array. Otherwise, is just returning the plain array like it should.

This then fixes the issue, and adds a unit test to make sure that these kinds of issues are
caught before any release:

it("should work with Heading component", () => {
const EmailTemplate = () => {
return (
<Tailwind>
Hello
<Heading>My testing heading</Heading>
friends
</Tailwind>
);
};
expect(render(<EmailTemplate />)).toMatchSnapshot();
});

And you can check that the snapshot actually contains the proper <h1> here:

If you do already have a <head> element at some depth, please file a bug https://github.com/resend/react-email/issues/new?assignees=&labels=Type%3A+Bug&projects=&template=1.bug_report.yml."
`;
exports[`Tailwind component > should work with Heading component 1`] = `"Hello<h1>My testing heading</h1>friends"`;

…dless of the amount of the amonut of children

This was causing the Heading component to now work again
@gabrielmfern gabrielmfern self-assigned this Apr 3, 2024
Copy link

vercel bot commented Apr 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
react-email ✅ Ready (Inspect) Visit Preview Apr 3, 2024 4:58pm
react-email-demo ✅ Ready (Inspect) Visit Preview Apr 3, 2024 4:58pm

@gabrielmfern gabrielmfern merged commit 4d8b119 into canary Apr 3, 2024
9 checks passed
@gabrielmfern gabrielmfern deleted the fix/tailwind-always-transforming-children-into-an-array branch April 3, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants