fix(button): keep calc and var padding instead of writing 0

HS
2d ago
+180-67

Why

Button copies numeric padding longhands onto the anchor after the author's style. An unparsed token became 0, and that longhand replaced calc() and var(). A unitless 0 failed the same parser, so the pixel sides of a shorthand never became longhands and Outlook's spacer stayed at 0.

Fixes #3929

What changed

A unitless 0 counts as a length. Each side of a shorthand converts on its own. A side that is calc() or var() stays on the original padding declaration and is not written as 0.

Scope

Button padding parsing and the longhands Button writes onto the anchor.

Tradeoffs

A length this parser cannot convert, such as 15cm on one side of a mixed shorthand, still does not become a numeric longhand. The author's padding declaration remains.

Blast Radius

12px 20px and 9pt 15pt still become pixel longhands. Pure calc() and var() no longer gain padding-*:0.

Verification

Rendered the Button with @react-email/render after esbuild, on canary beda35bb plus this branch. calc(8px + 4px) keeps its declaration and has no padding-top:0. 0 16px renders padding-right:16px;padding-left:16px with mso-font-width:400%. 12px 0 renders mso-text-raise:18px. The project pnpm test was not run. pnpm in this environment cannot start.


Summary by cubic

Fixes Button padding parsing so calc() and var() values stay as written instead of being replaced by padding-*:0 longhands, and unitless 0 now counts as a valid length. Resolves #3929.

  • Parse each side of a padding shorthand independently; sides that can't convert to a length keep the author's padding declaration.
  • Shorthands like 0 20px now generate all four longhands, so Outlook spacers still render correctly.
  • Mixed shorthands like 8px calc(4px + 4px) write longhands only for the convertible side.
  • Non-convertible units (for example 15cm) fall back to the original declaration and don't produce longhands.