react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

`toBlob()` crashes when `undefined` is provided to <Text>'s render prop

Open vinibanaco opened this issue 11 months ago • 1 comments

Describe the bug When using the Text component without providing a render prop it works as intended, as it does when providing a function. However, if provided with undefined it crashes when creating the blob ( pdf(doc).toBlob()). It throws a TypeError: node.props.render is not a function.

To Reproduce This works:

const doc = (
  <Document>
    <Page>
      <Text>Something</Text>
    </Page>
  </Document>
);
const blob = await pdf(doc).toBlob();

This doesn't:

const doc = (
  <Document>
    <Page>
      <Text render={undefined}>Something</Text>
    </Page>
  </Document>
);
const blob = await pdf(doc).toBlob();

Expected behavior Even though it's probably not a common issue, it's useful to accept undefined if a variable that can be either a function or undefined is provided.

Desktop (please complete the following information):

  • OS: Linux Mint
  • Browser: Chrome
  • React-pdf version 4.3.0

vinibanaco avatar Mar 07 '25 13:03 vinibanaco

I'm having the same issue with the same React-pdf version

plckr avatar Apr 14 '25 15:04 plckr