Repository navigation
fix(layout): paginate nested first children that do not fit instead of clipping them - #3613
Open
JoelBrenstrum wants to merge 2 commits into
Open
JoelBrenstrum wants to merge 2 commits into
JoelBrenstrum wants to merge 2 commits into
Conversation
…f clipping them When every child of a node moves to the next page, splitNodes kept the node on the current page if it had no earlier siblings, on the assumption that the page was empty. The check only looked at the node's own siblings, so it also fired for a node that was merely the first child of its parent further down a page. The node was then clamped to the page edge and its children drawn past the bottom margin, over the footer, with no warning. Thread a pageStart flag from splitPage through splitNodes, split, splitView and splitChildren so the keep-on-page behaviour only applies when every ancestor is at the top of the page too. Fixed and zero-height siblings are ignored when deciding that, so a page footer or an empty element does not count as content. The same flag lets shouldBreak honour minPresenceAhead on a first child that is not at the page start. Direct callers that omit the flag keep the previous behaviour. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
@JoelBrenstrum is attempting to deploy a commit to the diegomura Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 43a1103 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
JoelBrenstrum
marked this pull request as ready for review
October 28, 2026 02:37
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
splitNodeshas a special case for a node whose children all end up on the next page: ifcurrentChildren.length === 0it keeps the whole node on the current page, on the assumption that the page is empty and moving the node would only produce an empty page. That check only looks at the node's own siblings, so it also fires for a node that is merely the first child of its parent, however deep it sits on a page that already has content.When that happens the node's box is clamped to the page edge by
splitNode, but its children keep their full layout and are drawn past the bottom margin, over the footer. No warning is logged.A minimal document that shows it:
The unwrappable view fits on a page but not in the 70pt left under the first view. Its parent has no earlier siblings, so the parent is kept on page 1 with the 80pt view clipped at the page edge, and the document stays one page long.
We hit this with form documents that render option groups as
wrap={false}rows inside a chain of single-child containers: whenever the group started near the bottom of a page its last rows were cut off.Related issues
splitNodes; this PR additionally ignores zero-height siblings when deciding whether the page is empty above a node, and carries the flag intoshouldBreak.minPresenceAheadon the first child of aViewthat is not the first element on the page.wrap={false}#3588, two columns whose first child is a smallwrap={false}block near the page bottom. Its first case, awrap={false}block taller than a page, is a separate limitation and is not changed here.wrap={false}view in Text in nested view with wrap={false} being compressed/squished after upgrading from v3.1.2 to v3.4.4 #2904.I ran the repros from #3449, #3586 and #3588 against this branch. In each one the block starts the next page and nothing is drawn past the bottom margin.
Only the legacy engine is affected. The new engine behind
experimentalPagination(#3502) already paginates these documents correctly, but the legacy engine is still the default in@react-pdf/layout5.2.0.Reproduction
Open in the REPL (runs against the published packages,
@react-pdf/layout5.2.0 with the default legacy engine at the time of writing).Page 1 ends with the pink block drawn through the bottom margin and over the footer, and page 2 contains nothing but the footer. With this change the block starts page 2.
REPL source
Fix
pageStartflag fromsplitPagethroughsplitNodes→split→splitView→splitChildren, so the keep-on-page behaviour only applies when every ancestor is also at the top of the page. Fixed and zero-height siblings are ignored when deciding that, so a page footer or an empty element does not count as content.shouldBreakreceives the same flag and honoursminPresenceAheadon a first child that is not at the page start. Previously a first child could never break for presence, which stranded headings at the foot of a page. Direct callers that omit the argument keep the previous behaviour.Nothing changes for nodes that genuinely are at the start of a page, so the existing infinite-loop guards still hold. The new
should keep a nested first child on the page when it is already at the page starttest covers that.Tests
resolvePagination.test.ts: nested first child moves to the next page; nested first child at the page start stays;minPresenceAheadon a first child that is not at the page start.shouldBreak.test.ts: the non-page-startminPresenceAheadcase.The two behavioural pagination tests fail on
masterand pass with this change. The full@react-pdf/layoutsuite passes (365 tests).Includes a changeset for
@react-pdf/layout.🤖 Generated with Claude Code