Repository navigation
Conversation
lineIndexAtHeight compared a line's float64 bottom against the page room, which Yoga stores as float32, with no tolerance. A line that fits exactly was pushed to the next page, and when that left fewer lines than orphans the whole text moved, leaving a big gap. Use the same 0.001 tolerance that pagination uses to decide whether a node needs splitting. Refs diegomura#3587 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@adarshsm 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: a70860b 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 |
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.
Addresses #3587 (re-opening of #3436). I couldn't open the REPL from the issue, so I reproduced the symptom it describes with a hand-built tree instead.
Problem
When the room left on a page is exactly the height of N lines, the text should keep N lines on that page. It gets N-1, and when that falls below
orphansthe whole text moves to the next page, which leaves the big gap the issue shows. Adding a bit more text pushes it one more line, so the gap goes away.A text of 12 lines at
lineHeight: 13.7on a page6 * 13.7high paginates as[5, 5, 2]lines instead of[6, 6].Root cause
lineIndexAtHeight(used bysplitText) picks the first line whose bottom is strictly greater than the available height. The available height comes from Yoga, which stores it as a float32. The line boxes are float64.Math.fround(6 * 13.7)is a bit smaller than6 * 13.7, so the 6th line "doesn't fit" by a few millionths of a point.resolvePaginationalready knows about this when it decides whether a node must be split at all (SAFETY_THRESHOLD = 0.001inshouldSplit). The line-level check had no tolerance, so the two disagreed.Fix
Use the same 0.001 tolerance in
lineIndexAtHeight.Tests
lineIndexAtHeight: a line that fits to within float32 rounding is kept.resolvePagination: the 12-line example above paginates as[6, 6].5 !== 6,[5, 5, 2]) and pass with it.packages/layout/tests/{steps,text,node}all pass (333 tests). Thepaginate/*andengineSelectionsuites can't load in my checkout (@react-pdf/paginateisn't linked), so I didn't run them.🤖 Generated with Claude Code