fix(tailwind): Children always being transformed into an array #1397
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'twork 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>
returnnull
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:
react-email/packages/tailwind/src/tailwind.spec.tsx
Lines 104 to 116 in 16a998a
And you can check that the snapshot actually contains the proper
<h1>
here:react-email/packages/tailwind/src/__snapshots__/tailwind.spec.tsx.snap
Lines 10 to 13 in 16a998a