Repository navigation
fix(web): make og:image render correctly — background + font weights - #128
Conversation
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]>
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Built for teams:
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. Comment |
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]>
|
🎉 This PR is included in version 1.27.7 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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-js2.6.2'sresolveImageonly accepts PNG/JPEG/GIF magic bytes — SVG bytes are rejected asUnsupportedImageand 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-unusedimagesToResolveloop 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-weight100, 300, 400, 500, 700, 900with only the variableLexend.ttfregistered produced six byte-for-byte identical PNGs. resvg-js / usvg 0.34 doesn't honor the variable font'swghtaxis — every weight collapses to the file's default (Regular 400).Fix: replace the variable
Lexend.ttfwith three static instances (Regular 400 / Medium 500 / Bold 700) generated viafontTools.varLib.instancerwithupdateFontNames=True. Register all three in the plugin; resvg's font matcher picks the right face perfont-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 typecheckpnpm test— 588/588 passingpnpm test:e2e --grep "static assets"— 9/9 passing(100,70)is#7aab8egreen tile) instead of(0,0,0,0)🤖 Generated with Claude Code