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

Support for resolving CSS variables defined in the email template #1448

Open
wladpaiva opened this issue May 8, 2024 · 4 comments
Open

Support for resolving CSS variables defined in the email template #1448

wladpaiva opened this issue May 8, 2024 · 4 comments

Comments

@wladpaiva
Copy link

wladpaiva commented May 8, 2024

Describe the Bug

Right now, if you want to use the same Shadcn styles in the react-email you have to duplicate the tailwind config file and manually replace the css variables with the actual values. Apparently react-email strip out <style> tags before transforming classnames to styles.

Which package is affected (leave empty if unsure)

@react-email/tailwind, react-email

Link to the code that reproduces this issue

https://github.com/wladpaiva/react-email-shadcn

To Reproduce

  1. run bun dev
  2. open template and inspect <Text> elements

Expected Behavior

Screenshot 2024-05-08 at 12 34 39

Both <p>s should have background set but only the one using the css variable is set to undefined

What's your node version? (if relevant)

No response

@gabrielmfern
Copy link
Collaborator

gabrielmfern commented May 9, 2024

Apparently react-email strip out <style> tags before transforming classnames to styles.

Hmm, I don't remember we removed any <style> tags, I think they shouldn't be removed, or you have not seen this behavior directly?

Both <p>s should have background set but only the one using the css variable is set to undefined

What Tailwind does is try resolving all CSS variables for the styles associated with each class, meaning that it couldn't find the variable you defined on the so it resolves to undefined. If there is even a style inside its scope, i.e., it's children. That's certainly an issue, but resolving these variables from outside the scope of the email template — assuming this is what you want — is going to be impossible currently.

It's probably going to be better to, at least currently, use actual values as colors on your Tailwind config for the email template. Maybe have a tailwind.config.ts beside your email templates that just imports your original one and modifies it as needed for the time being.

@gabrielmfern gabrielmfern changed the title [Feature] Shadcn support Support for resolving CSS variables defined in the email template May 9, 2024
@wladpaiva
Copy link
Author

That's what I've been doing but kinda sucks having to configure two separate tailwind.configs.
I guess using somehting like inline-css to inline the styles during the render would work fine, no? I've tested here and seems to cover all use cases

Also, not sure if the issue name correctly represents the issue now. The problem seems to be with the <style> tags and not the css variables itself

@gabrielmfern
Copy link
Collaborator

I guess using somehting like inline-css to inline the styles during the render would work fine, no? I've tested here and seems to cover all use cases

@wladpaiva Sadly no, it would only work if we inlined the styles after rendering, but we do it during rendering in the actual React elements for a few reasons.

Also, not sure if the issue name correctly represents the issue now. The problem seems to be with the <style> tags and not the css variables itself

Not sure if I follow what you mean here, but the issue here is with the CSS variables. If you define a CSS variable in your template and then use it through Tailwind somehow, they will not be resolved properly. Are you talking about another problem?

@wladpaiva
Copy link
Author

Forget it. You are right. The problem is with the css variables and not the <style> being striped out before inlining the css.

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

2 participants