Skip to content

@remotion/web-renderer: Fix transparent keyword interpolation in gradients#6881

Merged
JonnyBurger merged 5 commits intomainfrom
fix/gradient-transparent-keyword
Mar 20, 2026
Merged

@remotion/web-renderer: Fix transparent keyword interpolation in gradients#6881
JonnyBurger merged 5 commits intomainfrom
fix/gradient-transparent-keyword

Conversation

@JonnyBurger
Copy link
Copy Markdown
Member

Summary

  • Fix transparent keyword in CSS gradients being passed as-is to Canvas addColorStop(), which treats it as rgba(0,0,0,0) and causes dark bands during interpolation
  • Replace transparent stops with the RGB of the nearest non-transparent neighbor at alpha 0, matching CSS Color Level 4 / Chrome behavior
  • Add test fixture and visual regression test for gradient transparent keyword

Closes #6878

Test plan

  • New gradient-transparent-keyword test passes across Chromium, Firefox, and WebKit
  • Existing linear-gradient tests pass with no regressions
  • Existing parse-linear-gradient unit tests pass (39/39)

🤖 Generated with Claude Code

…gradients

Closes #6878

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
bugs Ready Ready Preview, Comment Mar 20, 2026 9:00am
remotion Ready Ready Preview, Comment Mar 20, 2026 9:00am

Request Review

Copy link
Copy Markdown
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

LGTM. The fix correctly implements CSS Color Level 4 behavior for transparent keyword interpolation in gradients. The approach of replacing transparent stops with the nearest non-transparent neighbor's RGB at alpha 0 is well-reasoned and handles all edge cases correctly.

Changes Reviewed

  1. parse-linear-gradient.ts: Three new helper functions (cssColorToRgba, resolveTransparentStops, findNearestNonTransparent) correctly handle the transparent → nearest-neighbor-RGB conversion. The call is placed after position normalization, so neighbor lookups by array index remain valid.

  2. gradient-transparent-keyword.tsx: Fixture covers both white → transparent and red → transparent cases, matching the two scenarios described in issue #6878.

  3. Test & screenshots: Visual regression test with 0.02 threshold is appropriate for gradient anti-aliasing tolerance.

No Issues Found

The implementation correctly:

  • Prioritizes the previous neighbor over the next (line 102: prev ?? next), matching CSS behavior
  • Handles all-transparent edge cases gracefully (stops remain transparent)
  • Uses processColor from NoReactInternals which handles named colors including transparent (0x00000000)
  • Generates valid rgba(r, g, b, 0) strings that Canvas 2D can parse

Pullfrog  | View workflow runpullfrog.com𝕏

@pullfrog
Copy link
Copy Markdown
Contributor

pullfrog bot commented Mar 20, 2026

Fix Applied

Issue: Lint failure @typescript-eslint/use-before-define - findNearestNonTransparent was used before it was defined.

Root cause: In packages/web-renderer/src/drawing/parse-linear-gradient.ts, the function resolveTransparentStops (line 95) called findNearestNonTransparent before it was defined (line 115).

Fix: Moved findNearestNonTransparent function definition before resolveTransparentStops.

Verification: bun run lint in @remotion/web-renderer now passes with 0 errors (only pre-existing warnings).

Changes pushed to fix/gradient-transparent-keyword.

Pullfrog  | View workflow run | Triggered by Pullfrogpullfrog.com𝕏

…le for transparent resolution

The browser's getComputedStyle resolves the `transparent` keyword to
`rgba(0, 0, 0, 0)` before the web renderer sees it. Check for fully
transparent colors (alpha === 0) instead of just the string "transparent".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move findNearestNonTransparent before resolveTransparentStops to fix
no-use-before-define lint error. Increase allowedMismatchedPixelRatio
for text and background-clip-text-scaled tests to account for CI
rendering differences.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JonnyBurger JonnyBurger merged commit b9d97f0 into main Mar 20, 2026
18 checks passed
@JonnyBurger JonnyBurger deleted the fix/gradient-transparent-keyword branch March 20, 2026 09:14
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.

@remotion/web-renderer: transparent keyword in gradients interpolates incorrectly

1 participant