Skip to content

fix(textkit): don't break or hyphenate at a text run boundary - #3627

Draft
adarshsm wants to merge 1 commit into
diegomura:masterfrom
adarshsm:fix/3619-run-boundary-hyphen
Draft

adarshsm wants to merge 1 commit into
diegomura:masterfrom
adarshsm:fix/3619-run-boundary-hyphen

Conversation

@adarshsm

Copy link
Copy Markdown

Fixes #3619. Also covers the same break described in #3462.

Problem

A word that continues across a text run boundary can break there. With <Link><Text>Appendix</Text></Link>. in a narrow box, Appendix fits and Appendix. doesn't, so the line is rendered as Appendix- followed by a lone .. It still happens when hyphenation is turned off with Font.registerHyphenationCallback((word) => [word]).

Root cause

wrapWords hyphenates each run separately and concatenates the syllables. Appendix and . come from different runs, so there is no space syllable between them. In the line breaker's getNodes, every syllable whose successor isn't a single space gets a hyphenation penalty, so the run boundary became a break opportunity with a hyphen glyph. The hyphenation callback can't prevent it because it never sees both runs.

Fix

In wrapWords, when the first word of a run directly continues the last syllable of the previous run (no whitespace on either side), join them into one syllable. The run boundary is then no longer a break or hyphenation point; hyphenation points the callback returns inside each run are kept.

Side effect: a word split across two styled runs (Hel + bold lo) can no longer be hyphenated exactly at the style change. Before, that was the only place it could be hyphenated, by accident.

Tests

  • New should not split a word that continues across runs in packages/textkit/tests/layout/wrapWords.test.ts. It fails without the change (['See', ' ', 'Appendix', '.', ...]) and passes with it.
  • packages/textkit and packages/layout suites pass (782 and 424 tests). 5 files in each fail to load here because bidi-js / @react-pdf/paginate aren't installed in my checkout; they're unrelated and fail the same way without my change.
  • I tested at the wrapWords level and did not render a PDF.

🤖 Generated with Claude Code

wrapWords hyphenates each run on its own, so a word that continues into
the next run (a period after a nested <Text>) ended up as two syllables
with no space between them. The line breaker treats every such boundary
as a hyphenation point, so the period could wrap alone and the previous
line gained a hyphen, even with hyphenation disabled.

Join the first word of a run to the previous syllable when neither side
is whitespace.

Fixes diegomura#3619

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 17, 2026

Copy link
Copy Markdown

@adarshsm is attempting to deploy a commit to the diegomura Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7e20b8c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@react-pdf/textkit Patch
@react-pdf/layout Patch
@react-pdf/render Patch
@react-pdf/renderer Patch
@react-pdf/examples Patch
@react-pdf/math Patch
@react-pdf/mermaid Patch
@react-pdf/ui Patch

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

No deployments
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.

Period after a separate text run can start the next line and be hyphenated

1 participant