-
Notifications
You must be signed in to change notification settings - Fork 717
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
Tailwind not parsing the rendered children from components #1021
Comments
Can you maybe elaborate more on what is happening to your email template? Does it work under some circumstances and others not, and if so, can you please tell me what circumstances? |
Same problem here, with For example: <Link href={t("common.appStore.href")} className="inline-block">
<Img
src={t("common.appStore.img")}
width="119"
height="40"
alt={t("common.appStore.label")}
className="max-w-full h-auto inline"
/>
</Link> is generating <a href="xxx" class="inline-block" style="color:#067df7;text-decoration:none" target="_blank"><img class="max-w-full h-auto inline" alt="xxx" height="40" src="xxx" style="display:block;outline:none;border:none;text-decoration:none" width="119"></a> After some test, I found that the problem apply when I load custom components in an email template, for example: import * as React from "react";
import MainLayout from "../components/ui/MainLayout";
import Email1 from "../components/views/Email1";
import { useGetToken } from "../hooks/useGetToken";
const locale = "en";
export const Email1En = () => {
const { t } = useGetToken(locale);
return (
<MainLayout
title={t("pnp23bf1_22.title")}
preview={t("pnp23bf1_22.preview")}
>
<Email1 locale={locale} />
</MainLayout>
);
};
export default Email1En; import { Body, Head, Html, Preview } from "@react-email/components";
import React from "react";
import TailwindProvider from "./TailwindProvider";
interface MainLayoutProps {
title?: string;
preview?: string;
children?: React.ReactNode;
}
export const MainLayout = ({ title, preview, children }: MainLayoutProps) => {
return (
<Html>
<Head>
<title>{title}</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin="true"
/>
<link
href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap"
rel="stylesheet"
/>
<style>
{`
@media screen and (max-width: 600px) {
h1 {
font-size: 30px !important;
}
}
`}
</style>
</Head>
{preview && <Preview>{preview}</Preview>}
<TailwindProvider>
<Body className="text-gray-900 bg-white my-auto mx-auto font-sans leading-snug">
{children}
</Body>
</TailwindProvider>
</Html>
);
};
export default MainLayout; Most Tailwind classes into |
yes, I maked an example |
Going to take a look into fixing this to unblock you guys, a PR is coming that is going to improve a lot of things about the Tailwind component. |
I think it might be related with recent react update. Essentially, they "fixed bug" when rendering functions take context into account. |
Working on a fix for this on a new PR that also improves performance. The problem here is that only the children passed through props to components are handled, This is indeed a bug and we are on it. |
PR that solves this is basically done, this problem will go away soon guys. If it takes too long for us to merge and release a new version out, I made a quick patch that fixes the issue as a workaround diff --git a/dist/index.js b/dist/index.js
index 12a4d02aac2b2364deb79d7785bb5b2d735d9e12..12a042dd383a3e91cbfe803af11210c5b40457a7 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -154,6 +154,17 @@ function processElement(element, headStyles, twi) {
...processedChildren
);
}
+ if (typeof modifiedElement.type === "function") {
+ const component = modifiedElement.type;
+ const renderedComponent = component(modifiedElement.props);
+ if (React.isValidElement(renderedComponent)) {
+ modifiedElement = processElement(
+ renderedComponent,
+ headStyles,
+ twi
+ );
+ }
+ }
return modifiedElement;
}
function processHead(child, responsiveStyles) {
diff --git a/dist/index.mjs b/dist/index.mjs
index 2e58d8425e6bf5ed3928e99d20fd1e1006d70e36..3f7b69f98aaf9ab4c45c27153d55b774e6e326f8 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -121,6 +121,17 @@ function processElement(element, headStyles, twi) {
...processedChildren
);
}
+ if (typeof modifiedElement.type === "function") {
+ const component = modifiedElement.type;
+ const renderedComponent = component(modifiedElement.props);
+ if (React.isValidElement(renderedComponent)) {
+ modifiedElement = processElement(
+ renderedComponent,
+ headStyles,
+ twi
+ );
+ }
+ }
return modifiedElement;
}
function processHead(child, responsiveStyles) { |
Still not working for me.
|
can you maybe give a reproduction so I can narrow down the problem on your case? |
In my case its just that when I import this in to my email-template the tailwind styles dont get applied to the component.
|
Could you try importing from |
I installed the Tailwind component and used it directly instead as you suggested but no styles get applied 🙁 |
how did you install the patch? |
Ahh maybe that the issue. I just installed it like this:
|
As mentioned more above in the issue, we don't yet have a release with the issue fixed, but it is coming, so you'll have to use the patch for now. To use the patch you can either use If you prefer using pnpm, you will need to go through the following:
"pnpm": {
"patchedDependencies": {
"@react-email/[email protected]": "patches/@[email protected]"
}
}
diff --git a/dist/index.js b/dist/index.js
index 12a4d02aac2b2364deb79d7785bb5b2d735d9e12..12a042dd383a3e91cbfe803af11210c5b40457a7 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -154,6 +154,17 @@ function processElement(element, headStyles, twi) {
...processedChildren
);
}
+ if (typeof modifiedElement.type === "function") {
+ const component = modifiedElement.type;
+ const renderedComponent = component(modifiedElement.props);
+ if (React.isValidElement(renderedComponent)) {
+ modifiedElement = processElement(
+ renderedComponent,
+ headStyles,
+ twi
+ );
+ }
+ }
return modifiedElement;
}
function processHead(child, responsiveStyles) {
diff --git a/dist/index.mjs b/dist/index.mjs
index 2e58d8425e6bf5ed3928e99d20fd1e1006d70e36..3f7b69f98aaf9ab4c45c27153d55b774e6e326f8 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -121,6 +121,17 @@ function processElement(element, headStyles, twi) {
...processedChildren
);
}
+ if (typeof modifiedElement.type === "function") {
+ const component = modifiedElement.type;
+ const renderedComponent = component(modifiedElement.props);
+ if (React.isValidElement(renderedComponent)) {
+ modifiedElement = processElement(
+ renderedComponent,
+ headStyles,
+ twi
+ );
+ }
+ }
return modifiedElement;
}
function processHead(child, responsiveStyles) {
Also make sure you have For context, a patch would be a manual change to a installed module that has some kind of problem that has not been fixed on a new version, its a sad reality, but sometimes we need patches on certain modules. So instead of needing to do it manually there are these tools (such as Let me know if this works for you |
Appreciate this temporary alternative. It's not perfect but a better workaround than wrapping multiple components around |
Hey @OussamaFadlaoui we have a new canary with a PR that should've fixed these kinds of issues, try out |
Unfortunately this still does not work for me event with EDIT: My components were wrapped with |
me too |
Hey guys @lunoob @tomaszczura, the original underlying problem here was fixed. |
Hey @gabrielmfern Is it not possible to use react hooks within the Tailwind component? If I try using a React hook inside of my e-mail components wrapped in
Minimal reproduction looks like: const TestA = () => {
const [foo] = React.useState("hello")
return <p>{foo}</p>
}
const html = render(
<Tailwind>
<TestA />
</Tailwind>
) The use case is to wrap a React context around the e-mail with common props and then consume them from some child components. |
@chris-trait |
@gabrielmfern that does seem a little weird to me, as I do expect hooks to run for other "static" use cases like static site generation or server-side rendering, especially as async server side rendering is becoming more of a thing, and indeed hooks run fine with For now my workaround is using |
That's interesting, then I think this is an actual issue with the new Tailwind version, can you open an issue on this so we can reference it on a PR and discuss it there? |
Describe the Bug
Before version 0.0.8, the following code is working normally
After version 0.0.8, I found that it only analyzes Component with the Children attribute
Which package is affected (leave empty if unsure)
@react-email/tailwind
Link to the code that reproduces this issue
example in codesandbox
To Reproduce
I compared the latest version and the source code of version 0.0.8, and found that the 0.0.8 version was replaced by the entire HTML, while the latest version only analyzes Children after the version 0.0.8.
0.0.8

0.0.8+

Expected Behavior
it can be parse the whole template component
What's your node version? (if relevant)
No response
The text was updated successfully, but these errors were encountered: