Skip to content

Commit 00aa805

Browse files
authored
fix(body): yahoo and AOL not keeping background colors for body (#2325)
1 parent df52e77 commit 00aa805

File tree

6 files changed

+334
-252
lines changed

6 files changed

+334
-252
lines changed

.changeset/fair-regions-cheat.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@react-email/components": minor
3+
---
4+
5+
body: apply all styles of the body to an inner table cell for them to work on Yahoo and AOL
6+
7+

.changeset/tame-impalas-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/body": minor
3+
---
4+
5+
apply all styles of the body to an inner table cell for them to work on Yahoo and AOL
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`<Body> component > renders correctly 1`] = `"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!--$--><body>Lorem ipsum<!--/$--></body>"`;
3+
exports[`<Body> component > renders correctly 1`] = `"<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!--$--><body><table border="0" width="100%" cellPadding="0" cellSpacing="0" role="presentation" align="center"><tbody><tr><td>Lorem ipsum</td></tr></tbody></table><!--/$--></body>"`;

packages/body/src/body.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,34 @@ export type BodyProps = Readonly<React.HtmlHTMLAttributes<HTMLBodyElement>>;
55
export const Body = React.forwardRef<HTMLBodyElement, BodyProps>(
66
({ children, style, ...props }, ref) => {
77
return (
8-
<body {...props} ref={ref} style={style}>
9-
{children}
8+
<body
9+
{...props}
10+
style={{
11+
background: style?.background,
12+
backgroundColor: style?.backgroundColor,
13+
}}
14+
ref={ref}
15+
>
16+
<table
17+
border={0}
18+
width="100%"
19+
cellPadding="0"
20+
cellSpacing="0"
21+
role="presentation"
22+
align="center"
23+
>
24+
<tbody>
25+
<tr>
26+
{/*
27+
Yahoo and AOL remove all styles of the body element while converting it to a div,
28+
so we need to apply them to to an inner cell.
29+
30+
See https://github.com/resend/react-email/issues/662.
31+
*/}
32+
<td style={style}>{children}</td>
33+
</tr>
34+
</tbody>
35+
</table>
1036
</body>
1137
);
1238
},

0 commit comments

Comments
 (0)