# Case study: the react-pdf bug that's still in the latest release

> A performance commit in react-pdf's text engine turned parts of non-Latin documents into empty boxes, and it has been in every release for over three months. react-pdf already compares 210 screenshots in its tests. We replayed the commit with VisualCI and four realistic documents, and the build flagged the one document it breaks.

Source: https://visualci.com/blog/react-pdf-case-study/

2026-12-05, Nathan Broadbent

[react-pdf](https://react-pdf.org) turns React components into PDFs. It's one of the most widely used PDF libraries in JavaScript: `@react-pdf/renderer` had about 9.6 million npm downloads in the week to 2 December 2026. And it already does visual testing. Its repository holds 210 PNG baselines that its tests compare with jest-image-snapshot.

So we asked a narrower question than usual: **when a project already compares screenshots, what does a visual check of real documents add?**

## The bug

react-pdf's text engine, `@react-pdf/textkit`, picks the font that draws each character. When the first font in a `fontFamily` list lacks a character, it falls back to the next font in the list.

On 24 August 2026, [6dc0901](https://github.com/diegomura/react-pdf/commit/6dc0901) ("perf(textkit/font): drop omit('font') pass, trim Knuth-Plass, cache AFM lookups") made text layout faster. It also broke fallback for text written in several pieces, which is how JSX writes `<Text>{vat}%</Text>` or `<Text>{day}/{month}/{year}</Text>`. When two pieces in a row both need the fallback font, the second is drawn with the first font anyway. If the first font doesn't have those characters, they come out as empty boxes.

That happens in real documents, because web fonts are usually split by script. Google Fonts and Fontsource serve Noto Sans Arabic's Arabic subset with no Latin digits or punctuation, and expect those to come from a second font. That is exactly what a `fontFamily` list is for.

It shipped in textkit 7.0.1 the same day, and it's in every react-pdf release since. The latest renderer, 4.9.2, installs textkit 7.1.0, which still has it. A user reported it on 1 September with a script that reproduces it. The fix, [b730d15](https://github.com/diegomura/react-pdf/commit/b730d15) ("fix(textkit): merge flattened runs in input order"), was merged on 27 November and isn't in a release yet. As of 4 December 2026, that's more than three months in released versions.

## Why the existing screenshots didn't catch it

None of the renderer's test documents uses a fallback font list with text in several pieces. react-pdf's own example of font fallback writes each line as a single string ("Roboto / امتحان"), and single strings were never affected. The screenshot tests were there, but they had nothing that could show the bug. The fix added unit tests for the two functions involved.

## The replay

We forked react-pdf ([visualcihq/react-pdf](https://github.com/visualcihq/react-pdf)) and added four documents:

- **An Arabic tax invoice.** Noto Sans Arabic and Noto Sans, as Fontsource serves them, with the invoice number, date, quantities, amounts, discount and VAT written as JSX would write them.
- **An English invoice** for the same customer, with the customer's name in Arabic.
- **react-pdf's own font-fallback example**, ported as it is.
- **A two-page report** in Helvetica, with justified paragraphs, a table and page numbers. The same commit also changed the line breaker, so this checks for reflow.

On every push, a GitHub Actions job builds react-pdf from the commit, renders the four documents and sends the PDFs to VisualCI. We pushed 6dc0901's parent as a baseline, then opened a pull request with 6dc0901 on top.

VisualCI's build for that pull request, [build #2](https://app.visualci.com/visualcihq/react-pdf/builds/2), changed **one of the four documents**: the Arabic invoice. The diff marks seven places on its single page:

- the date, `4/12/2026`, now reads `4` followed by eight boxes;
- the `×` after each of the four quantities is a box;
- the discount line, `(10%): -1,961.80`, and the VAT line's `(5%):` are boxes.

The page's text diff lists each of those lines. The English invoice, react-pdf's example and the report didn't change at all, including the report's line breaks. So the reviewer sees exactly what broke, in the only document it affects. We rejected the build.

![The Arabic invoice before 6dc0901, after it, and the difference in red](https://visualci.com/blog/react-pdf-case-study/react-pdf-build2-invoice-arabic.png)

## What it takes

Four documents, about 250 lines of plain JavaScript, and fonts from the same CDN the web uses. The documents are the point: a visual check is only as good as the documents it renders. A test suite full of screenshots can still miss a bug that every Arabic invoice shows. If your users render documents in more than one script, put one of those documents in CI.

## Try it

[PDFs](https://visualci.com/docs/pdfs.md) · [GitHub Actions](https://visualci.com/docs/ci/github-actions.md)
