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): Head component minification issue #1352

Merged
merged 6 commits into from
Mar 13, 2024

Conversation

gabrielmfern
Copy link
Collaborator

Background

After the Tailwind performance improvements, we changed things so that the
requirement for the <head> element being there — when using Tailwind classes that
had media queries — went from being

You need to have a <html> followed by a <head> element or <Head> component

to being

You need a <head> directly bellow your <tailwind> component

This change was for two reasons mostly:

  1. To avoid having to execute regexes on the rendered markup to determine if the
    elements were included
  2. To making the error message more clear while still being concise

This ended up causing two issues:

  1. You just could not use Tailwind classes on your <Html> tag anymore
  2. Upon being minifying the function's name for our <Head> component would be changed
    to something other than "Head" which ended up breaking our check for the <Head> component

How does this fix the issue?

This fixes the issue by keeping track of whether the <head> element was found
and if the non-inlinable styles — currently Tailwind classes with media
queries — were applied to it. The solution also required that I changed
the current error message, as it just didn't apply anymore, and make it a bit more
detailed to whoever is having it.

This solution is also not a breaking change, actually it's more backwards compatible
than the one after the performance improvements.

How can I make sure that it's fixed?

I've added in a unit test with a detailed comment to the code that ensures
that the Tailwind component still applies the styles without throwing
the error. It tests for a custom component that contains the <head> element,
and it tests with it inside a <html> inside the <Tailwind> component.

@gabrielmfern gabrielmfern self-assigned this Mar 12, 2024
Copy link

vercel bot commented Mar 12, 2024

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

Name Status Preview Updated (UTC)
react-email ✅ Ready (Inspect) Visit Preview Mar 12, 2024 6:18pm
react-email-demo ✅ Ready (Inspect) Visit Preview Mar 12, 2024 6:18pm

@gabrielmfern gabrielmfern merged commit 64e4326 into canary Mar 13, 2024
9 checks passed
@gabrielmfern gabrielmfern deleted the fix/tailwind-head-component-minification-issue branch March 13, 2024 17:40
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.

None yet

2 participants