Skip to content

fix(layout): parse inherited rgba/rgb SVG stroke and fill colors#3434

Open
Manitej66 wants to merge 1 commit into
diegomura:masterfrom
Manitej66:fix/svg-inherited-rgba-stroke
Open

fix(layout): parse inherited rgba/rgb SVG stroke and fill colors#3434
Manitej66 wants to merge 1 commit into
diegomura:masterfrom
Manitej66:fix/svg-inherited-rgba-stroke

Conversation

@Manitej66
Copy link
Copy Markdown

@Manitej66 Manitej66 commented May 28, 2026

Fix inherited SVG rgba()/rgb() stroke and fill rendering

Summary

Fixes an issue where inherited SVG stroke and fill properties using functional color syntax (rgba(), rgb()) were not rendered correctly in @react-pdf/renderer.

Previously, inherited color values from parent <Svg> elements reached child nodes before color normalization occurred, leaving raw rgba(...) strings untransformed when passed to PDFKit.

Broken example

The following SVG failed to render strokes correctly:

<Svg
  viewBox="0 0 24 24"
  stroke="rgba(115, 123, 117, 1)"
  strokeWidth={1.5}
  strokeLinecap="round"
  strokeLinejoin="round"
>
  <Path d="M4 21H20" />
  <Path d="M4 18V6C4 4.34315 5.34315 3 7 3H17C18.6569 3 20 4.34315 20 6V18" />
</Svg>

Observed behavior:

  • child <Path> strokes were not rendered
  • moving stroke="rgba(...)" directly onto each <Path> worked
  • replacing the inherited color with a hex value also worked

Example workaround:

<Path
  d="M4 21H20"
  stroke="rgba(115, 123, 117, 1)"
/>

or:

<Svg stroke="#737B75">

Root cause

The compose chain executed:

resolveChildren(container)
→ inheritProps(...)

This caused child nodes to be resolved before inheriting parent paint properties. As a result:

  • inherited rgba(...) / rgb(...) values bypassed transformColorSafe
  • raw functional color strings reached the PDF renderer
  • PDFKit failed to render those stroke/fill values

Hex and named colors appeared unaffected because they already passed through unchanged.

Fix

Swapped the compose order so inherited props are applied before child resolution:

inheritProps(...)
→ resolveChildren(container)

This ensures inherited paint properties are normalized during child resolution through transformColorSafe.

Result

Inherited SVG paint properties now render correctly for:

  • rgba()
  • rgb()
  • hex colors
  • named colors

Example now working correctly:

<Svg
  stroke="rgba(115, 123, 117, 1)"
  strokeWidth={1.5}
>
  <Path d="M4 21H20" />
</Svg>

Before:
Screenshot 2026-05-28 at 10 03 24 AM

After:
Screenshot 2026-05-28 at 10 04 55 AM

Notes

  • No behavioral changes for existing hex or named color usage.
  • Fix applies to both inherited stroke and fill properties.
  • Direct per-node color definitions were already working and remain unaffected.

Inherited stroke/fill properties from parent `<Svg>` elements with
functional color syntax (`rgba()`, `rgb()`) were not being parsed to
hex before reaching the PDF renderer. This happened because
`inheritProps` ran after `resolveChildren(container)` in the compose
chain, so children were parsed before receiving the parent's raw
color strings — leaving untransformed `rgba(...)` values that PDFKit
cannot render.

Swap the order so `inheritProps` propagates raw color strings to
children first, then `resolveChildren` parses them through
`transformColorSafe` during child resolution. Hex and named colors
(already pass-through) are unaffected.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 28, 2026

⚠️ No Changeset found

Latest commit: 5f3bcb0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant