Skip to content
FramesField
FIX 55 · AGENTS, MCP & DESIGN-TO-CODE
raw .md ↗ Verified Dec 1, 2026

Fix Satori OG Card Flexbox Crashes and Missing Font Glyphs

Direct Fix: Load local .woff (WOFF 1.0), .ttf, or .otf font buffers once via readFileSync (never .woff2), register every used fontWeight explicitly, add display: "flex" + flexDirection to every multi-child container, resolve all colors to literal hex, and rasterize Satori SVG with sharp.
Exact Error / Visual Signature
Error: Expected <div> to have explicit "display: flex", "display: contents", or "display: none" if it has more than one child node | Error: Unsupported OpenType signature wOF2 | No fonts are loaded | Blank bold glyphs or tofu boxes in 1200x630 PNG
OBSERVED SYMPTOM

Your static Astro or Next.js build crashes while generating 1200×630 Open Graph share images with Satori + sharp—throwing Flexbox child-count errors, Unsupported OpenType signature wOF2, or silently outputting cards with missing bold text, blank arrows/em-dashes, or smashed overlapping columns.

TECHNICAL ROOT CAUSE

Satori’s Yoga layout engine enforces explicit display: "flex" on every multi-child container and rejects CSS Grid or CSS variables, while its built-in opentype.js font parser accepts only .woff (WOFF 1.0), .ttf, or .otf buffers—crashing immediately on Brotli-compressed .woff2 files or missing weight registrations.

Copy-Paste Verified Fix

Font-Header Pre-Flight Audit & Production Satori + Sharp OG Renderer render-og-safe.ts
// src/lib/render-og-safe.ts — Deterministic 1200x630 Satori + sharp OG generator
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import satori from 'satori';
import sharp from 'sharp';

function loadSatoriFont(relPath: string): Buffer {
  const buf = readFileSync(resolve(process.cwd(), relPath));
  const sig = buf.subarray(0, 4).toString('ascii');
  if (sig === 'wOF2') {
    throw new Error(`Satori cannot parse WOFF2 (${relPath}). Switch to .woff (WOFF 1.0), .ttf, or .otf.`);
  }
  return buf;
}

// Cache buffers once at module import (zero re-reads across 250+ static routes)
const fontRegular = loadSatoriFont(
  'node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-400-normal.woff'
);
const fontSemiBold = loadSatoriFont(
  'node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-600-normal.woff'
);

function safeTruncate(text: string, maxLen: number): string {
  // Normalize glyphs outside latin subset if needed, then cut on clean word boundary
  const clean = text.replace(/[\u2018\u2019]/g, "'").replace(/[\u201C\u201D]/g, '"');
  if (clean.length <= maxLen) return clean;
  const cut = clean.slice(0, maxLen);
  const lastSpace = cut.lastIndexOf(' ');
  return `${(lastSpace > maxLen * 0.6 ? cut.slice(0, lastSpace) : cut).replace(/[.,;:\-–—]+$/, '')}...`;
}

export async function renderOgPng(input: { kicker: string; title: string; subtitle: string }): Promise<Buffer> {
  const title = safeTruncate(input.title, 76);
  const subtitle = safeTruncate(input.subtitle, 145);

  const svg = await satori(
    {
      type: 'div',
      props: {
        style: {
          display: 'flex',
          flexDirection: 'column',
          justifyContent: 'space-between',
          width: '1200px',
          height: '630px',
          padding: '48px',
          backgroundColor: '#F7F7F5',
          color: '#111111',
          fontFamily: 'IBM Plex Mono',
        },
        children: [
          {
            type: 'div',
            props: {
              style: { display: 'flex', fontSize: '16px', fontWeight: 600, color: '#C83614' },
              children: input.kicker.toUpperCase(),
            },
          },
          {
            type: 'div',
            props: {
              style: { display: 'flex', flexDirection: 'column', gap: '18px' },
              children: [
                {
                  type: 'div',
                  props: {
                    style: { display: 'flex', fontSize: title.length > 48 ? '38px' : '46px', fontWeight: 600, lineHeight: 1.15 },
                    children: title,
                  },
                },
                {
                  type: 'div',
                  props: {
                    style: { display: 'flex', fontSize: '21px', fontWeight: 400, lineHeight: 1.45, color: '#575754' },
                    children: subtitle,
                  },
                },
              ],
            },
          },
          {
            type: 'div',
            props: {
              style: { display: 'flex', justifyContent: 'space-between', borderTop: '1px solid #E4E4DF', paddingTop: '18px', fontSize: '15px', color: '#575754' },
              children: [
                { type: 'div', props: { style: { display: 'flex' }, children: 'FRAMESFIELD.COM' } },
                { type: 'div', props: { style: { display: 'flex' }, children: '1200x630 VERIFIED' } },
              ],
            },
          },
        ],
      },
    },
    {
      width: 1200,
      height: 630,
      fonts: [
        { name: 'IBM Plex Mono', data: fontRegular, weight: 400, style: 'normal' },
        { name: 'IBM Plex Mono', data: fontSemiBold, weight: 600, style: 'normal' },
      ],
    }
  );

  return sharp(Buffer.from(svg)).png({ compressionLevel: 9 }).toBuffer();
}

Before vs. After (Broken Pattern vs. Verified Fix)

Broken · Broken Satori Renderer (.woff2 Buffer + Implicit Block Multi-Child div + var())
// BUG 1: .woff2 throws "Unsupported OpenType signature wOF2"
const font = readFileSync('node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-400-normal.woff2');
// BUG 2: Multi-child <div> missing display: "flex" crashes Yoga; CSS var() renders black/empty
const svg = await satori(
  { type: 'div', props: { style: { color: 'var(--ink-primary)' }, children: ['Kicker', 'Headline'] } },
  { width: 1200, height: 630, fonts: [{ name: 'Mono', data: font, weight: 400 }] }
);
Verified · Verified Satori + Sharp Renderer (Local .woff 400+600 + Explicit Flex + Hex)
// Load WOFF 1.0 (.woff) or .ttf buffers once at module scope (400 + 600 registered)
const mono400 = readFileSync(resolve(process.cwd(), 'node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-400-normal.woff'));
const mono600 = readFileSync(resolve(process.cwd(), 'node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-600-normal.woff'));

const svg = await satori(
  {
    type: 'div',
    props: {
      style: { display: 'flex', flexDirection: 'column', width: '1200px', height: '630px', backgroundColor: '#F7F7F5', color: '#111111', fontFamily: 'IBM Plex Mono' },
      children: [
        { type: 'div', props: { style: { display: 'flex', fontSize: '16px', fontWeight: 400 }, children: 'FIX 55' } },
        { type: 'div', props: { style: { display: 'flex', fontSize: '46px', fontWeight: 600 }, children: 'Deterministic OG Cards' } },
      ],
    },
  },
  {
    width: 1200,
    height: 630,
    fonts: [
      { name: 'IBM Plex Mono', data: mono400, weight: 400, style: 'normal' },
      { name: 'IBM Plex Mono', data: mono600, weight: 600, style: 'normal' },
    ],
  }
);
const png = await sharp(Buffer.from(svg)).png({ compressionLevel: 9 }).toBuffer();

Why this works: Using local .woff (WOFF 1.0) or .ttf buffers avoids the wOF2 parser crash and offline CI failures, registering both 400 and 600 weights renders crisp hierarchy, and setting explicit display: "flex" with literal hex values satisfies Yoga completely.

Under the Hood

Why This Failure Happens in Real Pipelines

Unlike a full Chromium browser where every <div> defaults to display: block and flows children vertically, Vercel Satori compiles JSX/VNode trees directly into SVG paths through Facebook’s Yoga Flexbox layout engine. Whenever ANY container node receives two or more children—including subtle cases like a string adjacent to a <span> or an array with a conditionally rendered badge—Satori throws immediately unless that parent explicitly declares display: "flex". Even after adding display: "flex", forgetting flexDirection: "column" silently lays stacked headlines and subtitles side-by-side horizontally because CSS Flexbox defaults to row.

The second guaranteed build-breaker involves font loading. Modern web packages such as @fontsource and Google Fonts serve Brotli-compressed .woff2 binaries by default, yet Satori’s underlying opentype.js parser only understands raw TrueType (.ttf), OpenType (.otf), and legacy WOFF 1.0 (.woff) headers. Passing a .woff2 buffer throws "Unsupported OpenType signature wOF2" on the very first card. Furthermore, fetching remote font URLs over HTTPS inside static site builds fails inside offline sandboxes or rate-limits when building 250+ OG endpoints, and registering only weight: 400 while styling a title with fontWeight: 600 causes missing bold contrast or fallback glyph drops.

Finally, Satori ignores CSS Grid, calc(), and var(--token) custom properties, and it cannot synthesize missing Unicode symbols (such as →, —, …, or CJK glyphs) if the loaded Latin-only .woff subset omits those codepoints. Bundling local .woff or .ttf buffers once at module top-level via readFileSync(resolve(process.cwd(), ...)), registering every exact weight (400 and 600/700) in the fonts array, enforcing a strict Flexbox-only VNode helper with explicit word-boundary truncation, and rasterizing with sharp(Buffer.from(svg)).png({ compressionLevel: 9 }).toBuffer() produces deterministic 1200×630 PNGs in milliseconds.

Step-by-Step Resolution & Verification

  1. 01

    Audit font buffer signatures and replace any .woff2 files with .woff, .ttf, or .otf

    Inspect the first 4 bytes of every font file loaded into Satori; switch any wOF2 file to its sibling .woff (WOFF 1.0) or .ttf binary inside @fontsource or your repo’s assets/fonts/ directory, and register every fontWeight (400, 600, 700) used by your card.

  2. 02

    Enforce display: "flex" and explicit flexDirection on every container node

    Add display: "flex" to every <div> with more than one child (and flexDirection: "column" on vertically stacked blocks), remove any CSS Grid, calc(), or var(--*) values, and wrap conditional siblings cleanly so Yoga never rejects mixed text/element children.

  3. 03

    Rasterize via sharp and visually inspect one built 1200×630 PNG card

    Convert Satori’s SVG string with sharp(Buffer.from(svg)).png({ compressionLevel: 9 }).toBuffer(), confirm exact 1200×630 pixel output via sharp metadata, and open a rendered card visually to confirm zero clipped titles or missing punctuation glyphs.

Verification Check · Verify Font Binary Headers Are Not WOFF2 & Confirm Rendered 1200x630 PNG Dimensions
node -e 'const fs=require("fs"); for (const p of ["node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-400-normal.woff","node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-600-normal.woff"]) { console.log(p, "sig=", fs.readFileSync(p).subarray(0,4).toString("ascii")); }'
Expected healthy output:
node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-400-normal.woff sig= wOFF
node_modules/@fontsource/ibm-plex-mono/files/ibm-plex-mono-latin-600-normal.woff sig= wOFF
# Must print "wOFF", "OTTO", or binary 00010000 (TTF) — NEVER "wOF2"

How to Prevent This Error From Recurring

GUARDRAIL 01

Cache font buffers once at module top-level instead of inside the route handler

Reading local .woff files once at import keeps 250+ static Astro or Next.js OG card builds fast and completely immune to remote CDN rate limits or offline sandboxes.

GUARDRAIL 02

Guard long dynamic titles with word-boundary truncation and dynamic font sizing

Stepping title fontSize down (for example 46px -> 38px when length exceeds 48 characters) and capping output at ~76 characters prevents 4-line headline overflow across bottom metadata footers.

GUARDRAIL 03

Inline raster logos or thumbnails as base64 data URIs with explicit width and height

Satori cannot resolve relative /images/logo.png paths from disk on its own; encoding small PNG/SVG badges as data:image/png;base64,... with numeric width/height prevents silent blank image boxes.

Troubleshooting FAQs

Why does Satori reject .woff2 files even though every modern browser supports WOFF2?
Satori parses font glyph outlines in JavaScript using opentype.js to convert text directly into SVG <path> vectors, and opentype.js does not bundle a Brotli WOFF2 decompressor. Use .woff (WOFF 1.0), .ttf, or .otf font buffers instead.
Why did my conditional {badge && <div>...</div>} trigger Satori’s display: flex error?
Even if badge evaluates to false or null at runtime, a container passing a multi-element children array to Satori is treated as multi-child unless you explicitly set display: "flex" on the parent element—always declare display: "flex" on every layout wrapper.
Why do arrows (→) or em-dashes (—) vanish or render as blank spaces in Satori PNGs?
Single-subset web fonts like latin-only .woff files frequently exclude extended Unicode punctuation or math arrows. Either load a fuller .ttf font (plus latin-ext/symbols fallback in the fonts array) or normalize punctuation to characters verified inside your primary font.
Should I rasterize Satori SVG output with sharp or @resvg/resvg-js?
Both work well: sharp (libvips + librsvg) is ideal if your repo already uses sharp for responsive WebP/AVIF pipelines, while @resvg/resvg-js is a pure-Rust alternative helpful on edge runtimes where native libvips binaries are unavailable.
Can I use Tailwind class names inside Satori via the tw prop instead of inline style objects?
Satori supports a limited experimental tw prop for basic Flexbox/spacing utilities, but it does not read your custom Tailwind v4 @theme inline CSS variables. Plain inline style objects with explicit hex colors and pixel dimensions are far more predictable and never drift.
Use this page in AI tools or notes
raw .md