fix: fix gradient background export rendering#237
fix: fix gradient background export rendering#237siddharthvaddem merged 2 commits intosiddharthvaddem:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughIntroduces a standalone CSS gradient parser and geometry helpers, adds tests, and updates the frame renderer to use the parser for linear and radial wallpaper gradients with a fallback on parse failure. Changes
Sequence Diagram(s)sequenceDiagram
participant Renderer as FrameRenderer
participant Parser as GradientParser
participant Canvas as Canvas2DContext
Renderer->>Parser: parseCssGradient(wallpaper)
Parser-->>Renderer: ParsedGradient (type, descriptor, stops)
Renderer->>Parser: resolveLinearGradientAngle / getLinearGradientPoints\nor getRadialGradientShape(width,height)
Parser-->>Renderer: geometry (points/center,radius)
Renderer->>Canvas: createGradient(...) and addColorStop(offset,color)
Renderer->>Canvas: fillRect / fill with gradient
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.Add a .trivyignore file to your project to customize which findings Trivy reports. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/exporter/gradientParser.ts`:
- Around line 34-46: The current logic silently drops stops that parseColorStop
cannot represent causing partial gradients to be treated as successful; update
the parsing branch so that if any stop fails (i.e., parseColorStop returns null
for any element of stopArgs) the function returns null instead of filtering them
out. Concretely, after mapping stopArgs with parseColorStop (the parsedStops
variable), check whether parsedStops length matches stopArgs length or use
parsedStops.includes(null)/some(...) to detect failures and return null; only
call normalizeStopOffsets and return the gradient object when all stops parsed
successfully.
- Around line 90-106: getRadialGradientShape currently only handles "at"
position and always returns a circular radius using Math.max(...distances),
ignoring radial keywords accepted by isGradientDescriptor (like ellipse,
closest-side, closest-corner, farthest-side, farthest-corner), which yields
incorrect shapes on non-square canvases; update getRadialGradientShape to parse
the shape/extent tokens (e.g. "ellipse" vs "circle" and "closest-*/farthest-*")
in the descriptor, compute ellipse radii (radiusX, radiusY) when "ellipse" is
specified using distances to edges in x and y, and select min/distances for
"closest-*" or max for "farthest-*" (and side vs corner differences) to return
appropriate cx, cy and either a single radius for circles or separate radii for
ellipses; alternatively, if you prefer rejecting unsupported descriptors, have
getRadialGradientShape validate against isGradientDescriptor's accepted keywords
and throw or return null for unimplemented tokens so callers can handle the
error.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 67607f51-561e-4115-be61-80e701c52a14
📒 Files selected for processing (3)
src/lib/exporter/frameRenderer.tssrc/lib/exporter/gradientParser.test.tssrc/lib/exporter/gradientParser.ts
Description
Fixes an export-only background rendering issue where certain gradient backgrounds, especially the first preset using
rgba(...)color stops, were not rendered correctly in exported video output.Motivation
The editor preview displayed these gradients correctly via CSS, but the export pipeline used a custom gradient parser that split on every comma. That broke gradients containing
rgba(...)values, causing theexported background to disappear or fall back incorrectly. This change makes export parsing robust and aligns export behavior with the preview.
Type of Change
Related Issue(s)
#236
Screenshots / Video
Screenshot (if applicable):
before:


after:
Testing
Commands run:
Checklist
Thank you for contributing!
Summary by CodeRabbit
New Features
Bug Fixes
Tests