Closed MartinXPN closed 1 week ago
What email client are you testing this on?
This might be because justify-content
does not have the best support, not sure why this would work on an older version of ours as this isn't really very well-supported.
Gmail (both web and mobile). It used to work just fine. Doesn't work anymore and I'm not sure why.
What version did it work on?
Was fine with these:
"@react-email/components": "^0.0.12",
"react-email": "^1.10.0"
I don't see any changes that could break or help this behavior along those versions. If you want to center here, you can use tables since it will probably be more reliable, but it should not work on Gmail with justify-content
.
Interesting... it used to work fine. Can you provide a bit more details on what would be the right way to center the button with the latest version?
But I'm pretty sure there have been some changes that affect how things render. Please see the screenshots below. I just took them. One is from Feb 19 (that centers the button) and the other one is from today (the one that failed to center the button). There are no code changes on our end.
I don't think looking at a screenshot of what happened back then is going to be reliable to understand if the issue is on our side, since Gmail might have updated things back and forth on this. Not sure. Will be more reliable if you roll back the version and check if it is working with Gmail right now or not.
Can you provide a bit more details on what would be the right way to center the button with the latest version?
Something like this should work:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<Button style={button} href="https://profound.academy/">
Continue Learning
</Button>
</td>
</tr>
</table>
Thanks for the provided code. This worked:
<table width="100%" border={0} cellSpacing={0} cellPadding={0}>
<tbody>
<tr>
<td align="center">
<Button style={{...button}} href="https://profound.academy">
Continue Learning
</Button>
</td>
</tr>
</tbody>
</table>
Seems like most react-email
examples (like this one) use way simpler methods to center buttons. Do you think there is a better/simpler way of reliably centering a div in emails?
P.S. I tried to downgrade the libraries and the button is not centered anymore. So, it seems like there has been some update to how Gmail renders things.
Good to know that it's a Gmail issue.
Yeah, those examples align it with a text-align: center
, it should work in your case as well if you do it with that. But I don't remember exactly if that works because Section
uses a table under the hood, or if it's because Button is an <a>
. It might be the former.
Going to close the issue as not planned since this is a Gmail issue.
Sounds good, thank you so much for your help!
Describe the Bug
Seems like after the latest update, the buttons that used to be centered in the emails are not centered anymore. When running in
dev
mode, everything renders perfectly. Yet, when sending an actual email, the buttons are not centered anymore.Which package is affected (leave empty if unsure)
@react-email/button, @react-email/components, @react-email/container, @react-email/section
Link to the code that reproduces this issue
https://github.com/MartinXPN/nextjs-firebase-mui-starter/tree/main/functions/emails
To Reproduce
Here is the code to reproduce the issue:
Expected Behavior
The button should be centered. It used to be centered using the previous version. It's shifted to the left instead now (see the screenshot below)
What's your node version? (if relevant)
20