page-wrapping does not provide totalPages
See original GitHub issueDescribe the bug
When using render
prop on Text
, the totalPages
value is not provided until the second pass.
This would usually be fine (and is appropriately called out in the docs to watch out for), however, if the fixed
prop is not defined on Text
then render
is only called once and 1/undefined
gets rendered to the page.
Looks like the second pass render is deliberately skipped if fixed
is not supplied. Assuming as a performance optimization. But it seems maybe this is not a valid optimization that can be made.
To Reproduce Steps to reproduce the behavior including code snippet (if applies):
<Document>
<Page>
<Text render={({ totalPages }) => /* totalPages is undefined */} />
</Document>
Expected behavior
Either totalPages should be defined on the first pass, or render
should always be called twice.
Screenshots
Desktop (please complete the following information):
- OS: MacOS
- Browser: N/A (node)
- React-pdf version: 1.1.1
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:10 (3 by maintainers)
Top GitHub Comments
For anyone running into this problem still, I found this work around:
`
` This line is required <Text style={styles.hidden}>{JSON.stringify(props)}</Text> … not sure why I keep finding these hacks where rendering props and hiding it causes the component props to be as expected. (Ran into this with react-hook-form library also). In this case, display: none doesn’t seem to work, so I blended the stringified props text into the background by changing it to white.
Thanks for reporting this @arahansen
To be honest I don’t remember very well why I as forcing
render
to be called just once on non-fixed elements. It could be a performance optimization 🤔Anyways, it does not make much sense now, so I’m removing that check. Unfortunately making
render
to be called just one time would involve a bit much of effort, and I’m not sure even if would be possible, so the only way of fixing this now is by just removing that line 😄