Skip to content

fix(web): make og:image render correctly — background + font weights - #128

Merged
iskhakovt merged 2 commits into
mainfrom
fix/og-bg-inline
May 3, 2026
Merged

iskhakovt merged 2 commits into
mainfrom
fix/og-bg-inline

Conversation

@iskhakovt

@iskhakovt iskhakovt commented May 2, 2026 •

Copy link
Copy Markdown
Owner

Two bugs in the OG-image rasterization pipeline that combine to produce a thin, transparent-bordered card.

Summary

1. Background was missing entirely

The OG PNGs were rendering fully transparent everywhere outside the white card. Pixel-sampling the corners and bg-tile region returned rgba(0,0,0,0).

Root cause: the outer SVGs reference the background pattern via <image href="./og-bg.svg">, but @resvg/resvg-js 2.6.2's resolveImage only accepts PNG/JPEG/GIF magic bytes — SVG bytes are rejected as UnsupportedImage and the area silently rasterizes to zero alpha. Upstream resvg fixed nested embedded images in 0.46 (linebender/resvg#958), but resvg-js still pins resvg 0.34 and the bump PRs (thx/resvg-js#379, #293) sit open.

Fix: inline the bg rects directly into both OG SVGs, delete og-bg.svg, drop the now-unused imagesToResolve loop from the rasterize plugin.

2. Title text was rendering at Regular weight, not Bold

After fixing #1 it became visible that the 'Spreadsheet' / 'Your turn' titles (font-weight="700") didn't look bold.

Empirical check: rendering the same SVG at font-weight 100, 300, 400, 500, 700, 900 with only the variable Lexend.ttf registered produced six byte-for-byte identical PNGs. resvg-js / usvg 0.34 doesn't honor the variable font's wght axis — every weight collapses to the file's default (Regular 400).

Fix: replace the variable Lexend.ttf with three static instances (Regular 400 / Medium 500 / Bold 700) generated via fontTools.varLib.instancer with updateFontNames=True. Register all three in the plugin; resvg's font matcher picks the right face per font-weight. Re-running the probe confirms weights 400, 500, 700 now produce three distinct byte streams.

Why not switch rasterizer

Investigated sharp, skia-canvas, @vercel/og, rsvg-convert. All three libs that handle variable fonts natively (sharp, skia-canvas, rsvg-convert) require either fontconfig setup per environment, a source/Canvas-API rewrite, or a system binary on every dev machine + CI. Static instances + resvg-js is the smallest fix and is portable to any rasterizer if we ever migrate.

Test plan

  • pnpm -r typecheck
  • pnpm test — 588/588 passing
  • pnpm test:e2e --grep "static assets" — 9/9 passing
  • Pixel sample of regenerated PNGs: corners + bg-tile region opaque (e.g. (100,70) is #7aab8e green tile) instead of (0,0,0,0)
  • Probe SVG rendered at weights 400 / 500 / 700 with the new fontFiles produces three distinct PNG byte streams (matching Regular / Medium / Bold respectively)

🤖 Generated with Claude Code

The OG PNGs were rendering fully transparent everywhere outside the
white card. Root cause: the outer SVG referenced the background pattern
via `<image href="./og-bg.svg">`, and resvg-js's `resolveImage` only
accepts PNG/JPEG/GIF magic bytes — it rejects SVG bytes as
`UnsupportedImage` and the area silently rasterizes to (0,0,0,0). The
upstream resvg crate fixed nested embedded images in 0.46
(linebender/resvg#958), but resvg-js is still pinned to 0.34 and the
bump PRs (#379, #293) have been sitting open.

Inline the background rects directly into og-image.svg and
og-invite.svg, delete og-bg.svg, and drop the now-unused
imagesToResolve loop from the rasterize plugin. Two static cards, ~50
lines of decorative tiles — duplication cost is bounded and the diff
is readable end-to-end.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented May 2, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • review-ready

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9fd0df9f-8789-4c97-9ff2-75b0dcfb7a02

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/og-bg-inline

Tip

💬 Introducing Slack Agent: Turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get your free trial and get 200 agent minutes per Slack user (a $50 value).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 4 files

Empirical check: rendering the same SVG with font-weight 100, 300, 400,
500, 700, 900 and only Lexend.ttf (variable) registered produces six
byte-for-byte identical PNGs. resvg-js / usvg 0.34 doesn't honor the
wght axis on variable fonts — every weight collapses to the file's
default (Regular 400). So 'Spreadsheet' / 'Your turn' at weight 700
were silently rendering at 400, and the 'SPREADSHEET' kerning row at
500 likewise.

Replace the variable Lexend.ttf with three static instances (Regular
400 / Medium 500 / Bold 700) generated via fontTools.varLib.instancer
with updateFontNames=True so the name table distinguishes the three
faces. Register all three in the rasterize plugin; resvg's font
matcher picks the right face per font-weight in the SVG. Confirmed by
re-running the same probe — weights 400, 500, 700 now produce three
distinct byte streams.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@iskhakovt iskhakovt changed the title fix(web): inline og:image background so resvg-js renders it fix(web): make og:image render correctly — background + font weights May 3, 2026
@iskhakovt
iskhakovt merged commit 7a7a42d into main May 3, 2026
9 checks passed
@iskhakovt
iskhakovt deleted the fix/og-bg-inline branch May 3, 2026 00:08
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.27.7 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant