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
The align
property is stripped from td
elements, breaking styling
#47
Comments
Hi! They are not the same but they are equivalent in React as far as I am aware. For you actual use case:
|
Thanks for the information @wooorm
This may have been true at one point, but modern React (e.g. both React 17 and 18) supports I went ahead, forked this package, and simply removed import tableCellStyle from '@mapbox/hast-util-table-cell-style' And now everything works as expected. I can certainly imagine that sometimes it would be desirable to transform deprecated properties/css/syntax into more modern equivalents, but in my experience it's not desirable for email (the use of Would you accept a PR to add an option to disable the problematic behavior? For example function compiler(node) {
/** @type {ReactNode} */
// @ts-expect-error: assume `name` is a known element.
let result = toH(h, options.transformTableCellStyles ? tableCellStyle(node) : node, options.prefix)
I'm not sure what you mean by this? As demonstrated in the video above,
Unfortunately I do need/want to process the HTML. Thanks! |
Where does it say that on that page?
Do you have a source? I’ve changed behavior in these packages several times because it didn‘t emit warnings in production build (stackblitz maybe?). And then after a month someone mentioned that it actually still emits warnings. So I’d rather not do the same again.
They are equivalent according to the HTML spec. The HTML spec specifies how align should be treated:
Interesting! Thanks for the video! What type of tool is that, which you are showing? I guess the thing here, with emails, is the bit about and to align descendants to the center in the HTML spec.
Sure |
This comment was marked as resolved.
This comment was marked as resolved.
👍
It's at the very bottom: I updated the demo to include an example of this.
My fork doesn't appear to be causing any React warnings. I'll note that in the current (non-forked) package I do see warnings like the following: These warnings also exist in my forked version of the package, but there are no new warnings.
Seems like a reasonable hypothesis. Ultimately I'm not too concerned with why. Even if Chrome wasn't following the spec, I'd still defer to whatever Chrome did (obviously this won't apply to everyone--hence making the behavior togglable seems prudent in this case).
The video was taken with a tool called Loom, the "correct" behavior was demonstrated with a gmail client called superhuman (the Gmail web app also renders the content the "correct" way), the problematic behavior was shown in an unpublished email client I'm working on. Thanks! |
As far as I am aware, the reason this exists isn’t about whether For the warnings, for lowercase attributes, it doesn’t seem to happen looking here: https://github.com/facebook/react/blame/b6c423daadaa35da3f34048628df9635505eecb1/packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js (line 155) for 6 years.
Understandable, but I am: because if your tool is broken, that’s where the fix should go, not here.
I particularly mean the tool that does not align things if Do you have cells in cells (in more cells)? Then I think it’s the “align descendants to the center” thing that the spec describes. |
Ah, that was/is Google Chrome
Here are two emails exhibiting the behavior that you can inspect.
Note that I think that these "view email in browser" links will expire and stop working at some point in the not-too-distant future.
I now realize that it was unclear that the problematic behavior was being demoed using Google Chrome. |
Sidenote: if you haven't had the misfortune of working with emails before, it's very common for emails to be rendered with HTML like it's 1995. |
So this is indeed table cells (in tables) in table cells.
Yeah, I just wonder how much I should care about things that are removed from the HTML spec. |
Initial checklist
Affected packages and versions
rehype-react 7.1.2
Link to runnable example
https://stackblitz.com/edit/react-ts-whdlcz?file=App.tsx
Steps to reproduce
Open this stackblitz link and inspect the
<td />
element in the dom. Notice how it's properties don't match the input HTML. It appears as thoughalign="center"
is being converted tostyle="text-align: center;"
, which isn't equivalent. I suspect that this was an intentional decision because thealign
property is deprecated ontd
elements and the MDN docs suggest that it can be replaced withtext-align: center
css, but as previously mentioned the two are not equivalent (regardless of what MDN says). Here is a video demonstrating how convertingalign="center"
totext-align: center
breaks the CSS styling in an email.Expected behavior
I expect the output JSX to match the input HTML. Specifically, I expect input HTML of
<td align="center"></td>
to be output as JSX<td align="center" />
.Actual behavior
The output JSX does not match the input HTML. Specifically, input HTML of
<td align="center"></td>
is output as JSX<td style="text-align: center;" />
.Runtime
Node v16
Package manager
yarn 1
OS
macOS
Build and bundle tools
Vite
The text was updated successfully, but these errors were encountered: