react-pdf: Hangs when unbreakable component larger than page
Describe the bug
When a component e.g. View is set to unbreakable via wrap={false}, and it is also taller than a single page, then rendering seems to go into an infinite loop.
To Reproduce Steps to reproduce the behavior including code snippet (if applies):
- Go to https://react-pdf.org/repl?example=disable-wrapping
- Change the
unbreakablestyle height from400to900 - Notice the blank preview
Expected behavior
I think in the case where a component can’t fit on a single page and has wrap={false}, it should wrap as that is better than just failing.
Desktop (please complete the following information):
- OS: Linux
- Browser: Chromium, Firefox
- React-pdf version: latest (REPL) - v1.5.6
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 25 (11 by maintainers)
Commits related to this issue
- Trying to fix https://github.com/diegomura/react-pdf/issues/600 — committed to asgerhallas/page-wrapping by asgerhallas 5 years ago
No worries @diegomura. The work you’re doing on this project is awesome! I’ve been able to work around this in the mean time!
Yep. Agreed! This is currently a limitation of the breaking algorithm. I’ll try to fix it soon. Thanks!
Hey @diegomura, I see that https://github.com/react-pdf/page-wrapping/commit/c198f2ec1b0ba9baebe9b6a5e848dcf0acafe322 has been merged into
page-wrappingbut as far as I can see there was no elease ofreact-pdfto use it. Will there be a release including it anytime soon?Hi @maldimirov, I don’t believe the issue should be closed yet. The fix from @asgerhallas does work except for one case, which I believe might be the problem @rmolinamir is having. The variable
heightis not being calculated correctly. It does not take all page padding into consideration, specificallypaddingTop.This causes
elementFitsFullPageHeight = truewhenheight > element.height > height - paddingTopwhich will again cause the application to hang.I’m not sure if this should be a new issue or if the current issue just needs to be reopened for the time being, I’ll leave that up to @diegomura . 😊 Thanks to everyone who contributes to this library, it is fantastic!
Hey @asgerhallas , your fix has not been applied to react-pdf. Any plan on creating a PR?
Hi @maldimirov, thanks for letting us know. I appreciate this library a lot, it’s really amazing.
In my case, it’s still hanging. I reproduced it with big lorem ipsum so it’s a bit forced. Bear in mind that in actuality, these components receive dynamic data, it is now impossible for this issue to happen on our end because we ended up restricting the character limit of our inputs & in the backend models (or at the very least, really hard to happen), so I had to use lorem ipsum to reproduce this. Here is the component that I’m using. It’s a styled
Textcomponent, from the@react-pdf/styled-componentspackage:Is it possible that either
heightorelement.heightmight be falsy in this line?It would result in
elementShouldBreakbeing alwaysfalse(assumingelement.breakisfalse) because ofelementFitsFullPageHeightbeing falsy in the following expression:So it never ignores the
wrap={false}prop. I’m wondering because I used the debugger and saw that height was falling back toNaNin another function, but I’m not sure if it’s the same parameter:Basically, not using
wrap={false}any time the content might ever exceed the page height. Not a very elegant solution but we have gotten by that way for now 🤷♂️@jtart @diegomura Yeah, I completely forgot to make a PR for react-pdf too, using the new version of page-wrapping. I’ll gladly do that 😃
Sorry I couldn’t take a look at this yet. Wish the day had more hours 😅