Skip to content

fix(layout): stop reading the Buffer global in fetchImage - #3625

Open
ntltd wants to merge 1 commit into
diegomura:masterfrom
ntltd:fix/layout-fetch-image-without-buffer
Open

ntltd wants to merge 1 commit into
diegomura:masterfrom
ntltd:fix/layout-fetch-image-without-buffer

Conversation

@ntltd

@ntltd ntltd commented Nov 13, 2026

Copy link
Copy Markdown

Refs #3225

What

In the browser, every image logs Buffer is not defined while the document renders. fetchImage (@react-pdf/layout) calls Buffer.isBuffer(source) right after the image is resolved; browsers have no Buffer global, so it throws, the catch logs the message, and node.image.key is never set for url or data-URI sources.

The image itself is already loaded at that point, so documents render fine: the visible effects are one warning per image and the missing cache key.

Change

  • fetchImage checks source instanceof Uint8Array instead of Buffer.isBuffer(source). A Node Buffer is a Uint8Array, so the behaviour on Node is unchanged; in line with refactor(pdfkit): replace Buffer usage with Uint8Array #3487, which removed Buffer from pdfkit.
  • Tests for fetchImage: url source keyed, url source keyed with Buffer stubbed out (as in browsers), buffer and blob sources not keyed, and no warning in any case.
  • Changeset: @react-pdf/layout patch.

How to check

yarn vitest run packages/layout/tests/image/fetchImage.test.ts. The "Buffer is not defined" case fails without the change.

Seen with @react-pdf/renderer 4.9.0 / @react-pdf/layout 5.2.0 in a Vite app (Chrome), 8 to 26 warnings per generated document.

@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5bc7f7e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@react-pdf/layout Patch
@react-pdf/renderer Patch
@react-pdf/examples Patch
@react-pdf/math Patch
@react-pdf/mermaid Patch
@react-pdf/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Nov 13, 2026

Copy link
Copy Markdown

@ntltd is attempting to deploy a commit to the diegomura Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant