Skip to content

Take padding into consideration when deciding to break on minPresenceAhead#2895

Closed
cosdon wants to merge 1 commit intodiegomura:masterfrom
cosdon:master
Closed

Take padding into consideration when deciding to break on minPresenceAhead#2895
cosdon wants to merge 1 commit intodiegomura:masterfrom
cosdon:master

Conversation

@cosdon
Copy link

@cosdon cosdon commented Oct 3, 2024

Fixes #2884

Changes splitPage to pass the box paddingTop through to shouldBreak to be used when deciding if breaking a node will improve its presence. Without this shouldBreak can return true for a node that's already as high as it can go on the page, causing an infinite loop.

@changeset-bot
Copy link

changeset-bot bot commented Oct 3, 2024

⚠️ No Changeset found

Latest commit: 6e6852d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@BI-JBrown
Copy link

We've been experiencing the issue in question and I can confirm this PR solves the problem. We've added a workaround for now to use margin instead of padding but it's a little hacky. Would love to see this one get merged.

@Andrei101Alex
Copy link

We've also been experiencing the same issue when it comes to images that push other nodes outside the view in multiple wrapped pages. Accounting for padding in the breaking logic would fix this issue as we use padding to style our wrapped page breaks. This PR should get more attention

@georeith
Copy link

georeith commented May 7, 2025

We're also seeing infinite loops and page hanging when the content overflows a single page. I removed the padding values from our PDF and this fixed them.

MendyLanda added a commit to MendyLanda/react-pdf that referenced this pull request Jun 15, 2025
…o break on minPresenceAhead

Fixes diegomura#2884 - Changes splitPage to pass the box paddingTop through to shouldBreak to be used when deciding if breaking a node will improve its presence. Without this shouldBreak can return true for a node that's already as high as it can go on the page, causing an infinite loop.
carlobeltrame added a commit to carlobeltrame/react-pdf that referenced this pull request Aug 18, 2025
When a node is already at the top of the page, it does not help to break
it to the next page. We knew that already, but the implementation of
this knowledge has been flawed. Apparently, page paddings, page borders,
fixed elements and possibly other things can cause the previous
position-based detection method to not work correctly.

This commit replaces the flawed implementation with a hopefully more
solid one: When there are no non-fixed nodes before the current one on
the page, we can assume that the current node will not be placed higher
up on the page even if we were to break it to the next page.

Fixes diegomura#2884
Fixes diegomura#2895
Fixes further parts of diegomura#2974
carlobeltrame added a commit to carlobeltrame/react-pdf that referenced this pull request Aug 18, 2025
When a node is already at the top of the page, it does not help to break
it to the next page. We knew that already, but the implementation of
this knowledge has been flawed. Apparently, page paddings, page borders,
fixed elements and possibly other things can cause the previous
position-based detection method to not work correctly.

This commit replaces the flawed implementation with a hopefully more
solid one: When there are no non-fixed nodes before the current one on
the page, we can assume that the current node will not be placed higher
up on the page even if we were to break it to the next page.

Fixes diegomura#2884
Fixes diegomura#2895
Fixes further parts of diegomura#2974
Copy link
Collaborator

@carlobeltrame carlobeltrame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there, this is the author of the current version of the page breaking algorithm speaking. Thanks for all the debugging and the proposed fix! I have had a detailed look, and I found that the same problem can also be caused by other (albeit more rare) causes, e.g. page borders or fixed non-absolutely-positioned elements before the element in question. Therefore I have created a similar but more general fix, taking the idea of your change but generalizing it to a more robust form. I have pushed my fix onto an existing PR of mine which is connected to #2884 as well: 3789d74

Please have a look and test it with your reproduction documents if you can. I have already tested the two reproduction cases from the issue #2884 locally, my fix also seems to solve those.

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.

Infinite loop when splitting pages

5 participants