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

Nested <Text>'s with a render function don't render

Open tom2strobl opened this issue 11 months ago • 1 comments

Describe the bug https://react-pdf.org/components#text states that Text supports nesting of other Text or Link components to create inline styling. but nesting Text with a render function does not render the text at all. This worked in 3.x previously, if that helps.

To Reproduce

const Test = () => (
  <Document>
    <Page>
      <Text>
      	<Text render={() => <Text>This does not render</Text>} />
      </Text>
      <Text>
      	<Text render={() => "This does not render"} />
      </Text>
      <Text render={() => <Text>This does render</Text>} />
      <View>
        <Text render={() => <Text>This does render</Text>} />
      </View>
    </Page>
  </Document>
);

ReactPDF.render(<Test />);

react-pdf REPL to reproduce

Expected behavior Nested Texts are expected to render when using a render function.

Likely related: https://github.com/diegomura/react-pdf/issues/3083 https://github.com/diegomura/react-pdf/issues/2988 https://github.com/diegomura/react-pdf/issues/3044

Why do we want to nest Texts in the first place? We have textboxes with arbitrary content which can also be variables that are interpolated on generation. Within a Textblock there should be flow and one of the variables is pageNumber, where we need to use a render function to get the number. Now a pageNumber can be within a paragraph which should be a <Text> element to enable inline flowing.

tom2strobl avatar Mar 11 '25 10:03 tom2strobl

Probably related: https://github.com/diegomura/react-pdf/issues/2258

tom2strobl avatar Mar 11 '25 12:03 tom2strobl