Customized plain text render to hide select elements #686
Replies: 5 comments 9 replies
-
So, I'm currently looking for the exact same feature. With the code snippet you have linked it seems to be a one line addition (now in here). Just adding a class that hides the element in plainText mode. I've searched for it, but didn't find a PR. Did you open one yet? |
Beta Was this translation helpful? Give feedback.
-
Here is a PR: #1922 |
Beta Was this translation helpful? Give feedback.
-
Here's a better idea: we can simply store the rendering options in some global variable, and return it in a hook-like function import { useRenderingOptions } from '@react-email/render';
function MyEmail() {
const renderingOptions = useRenderingOptions();
if (renderingOptions.plainText) {
return 'This is the text according to what I would prefer';
}
return <a href="https://react.email">This is the text according to what I would prefer</a>;
} @thena-seer I see you made a PR with the other proposal, if you'd like to contribute an implementation of this, feel free to use this instead. I had this planned a while back from a discussion I had on Discord. |
Beta Was this translation helpful? Give feedback.
-
Hey @gabrielmfern, @thena-seer, @djfarrelly, and @bliepp Since using Context can break server-side rendering, and global variables don’t work well for parallel render calls with different option sets, I propose an alternative: pass a Why this approach? Key benefits:
function Logo({ reactEmailRenderOptions }) {
if (reactEmailRenderOptions?.plainText) return null;
return <img src="logo.png" alt="Logo" />;
}
This keeps the solution explicit, portable, and testable, while staying consistent with how React normally handles data flow. Here is a draft PR for it: #2417 Please, let me know your thoughts :) |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, thanks for all the great input on this discussion. I've been following along and wanted to share an idea. It seems like we might be leaning towards solutions that are more complex than necessary. I took a look at the underlying implementation and noticed that Perhaps the simplest path forward would be to just document this feature. We could also take this opportunity to decide if Regarding the other proposals:
In short, I'm proposing we solve this by documenting the selector that's already available. However, I'm happy to help implement whatever path we decide is best. If we feel the What do you all think of this approach? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Background
The company logo in our email template is hyperlinked to our website and rendering our emails to plaintext gives us:
Email code:
What I want is to hide that link that wraps our logo:
Proposal
This could be solved w/ a special classname or data attribute that can be passed which filter uses in it's rules to remove:
https://github.com/resendlabs/react-email/blob/d158ad77e3798808b4efbd322b618922da12529e/packages/render/src/render.ts#L31-L34
Suggested options
dataPlainText={false}
(or similar) attribute inrenderAsPlainText
__react-email-plaintext-skip
to hide elements inrenderAsPlainText
<PlainText hide={true}>{children}</PlainText>
or similar component that can wrap elements to hide on plaintext renders<Visible plaintext>{children}</Visible>
/<Visible html>{children}</Visible>
/<Visible html plaintext>{children}</Visible>
that can wrap elements and the user can explicitly set if they want something to render on one or the other.Current workaround
My current hack is to use
__react-email-preview
, although it's not good HTML to have multiples of the sameid
attr.Beta Was this translation helpful? Give feedback.
All reactions