Skip to content

fix(Text): retain the final fitting truncation prefix - #8153

Merged
PavelVanecek merged 1 commit into
recharts:mainfrom
charan-rathore:fix/text-final-fitting-prefix
Nov 3, 2026
Merged

PavelVanecek merged 1 commit into
recharts:mainfrom
charan-rathore:fix/text-final-fitting-prefix

Conversation

@charan-rathore

@charan-rathore charan-rathore commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

When Text overflows with maxLines, the truncation search can return the original overflowing content even though a shorter prefix with an ellipsis fits. The search only saved a result when it found an adjacent fitting/overflowing pair, so a fitting final candidate was lost. For example, with a 30px width and measured widths of 10px for a/b, 80px for W, and 5px for the ellipsis, abW should render as ab….

Keep the last fitting prefix while the binary search advances. This retains the existing search range, already-fitting and scaleToFit guards, grapheme handling, and code-point fallback. It does not change behavior when even the ellipsis cannot fit.

Related Issue

Fixes #8152. This is separate from the broader font/style measurement problem in #4735.

How Has This Been Tested?

The actual Text/Surface component regressions cover the final fitting prefix, a single overflowing glyph or grapheme, word/character wrapping, and the runtime fallback. Seven regressions fail on unchanged production code, with four controls passing; all 110 Text tests pass with this change after npm ci on the current lockfile. Measurement is deterministic in these component tests; this is not browser-font visual evidence.

The normal pre-push gate passes on Node 24.22.2: build, 13 build-output tests, lint (no errors), all 407 unit-test files (18,218 passed, six expected failures, 16 skips, one todo), and all five type-check projects. The successful run used VITEST_MAX_WORKERS=2 to limit contention. Two earlier default-concurrency runs exceeded the unchanged Bar sparsity test's five-second timeout; its isolated nine-test file also passes. No tests or timeouts were changed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or VR test.

No API change; coverage uses the existing actual-component test setup with controlled measurements.

Summary by CodeRabbit

  • Bug Fixes
    • Improved text truncation at line limits so displayed text ends at a fitting word or character boundary, including for graphemes and code points.
    • Corrected behavior when text already fits, an ellipsis cannot fit, or text scaling is enabled.
  • Tests
    • Added coverage for truncation boundaries and fallback behavior when Intl.Segmenter is unavailable.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The Text truncation search now retains the last fitting candidate while checking prefixes. New tests cover truncation boundaries, grapheme and code-point handling, ellipsis fit, and scaleToFit.

Changes

Text truncation

Layer / File(s) Summary
Retain the last fitting prefix
src/component/Text.tsx, test/component/Text.searchBound.spec.tsx
The search checks one midpoint at a time, saves fitting results, and searches later prefixes. Tests cover fitting boundaries, word and character wrapping, grapheme and code-point handling, ellipsis fit, and scaleToFit behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • recharts/recharts#8117: Defines the character-array search input and ellipsis overflow check used by the truncation search.
  • recharts/recharts#8133: Adds grapheme segmentation and code-point fallback used by the candidate-prefix tests.

Suggested reviewers: pavelvanecek

Merge Risk: Minimal · up to 1c7de

No merge-blocking risk was identified in the truncation change.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the Text component fix and the retained final fitting truncation prefix, which matches the main change: calculateWordsByLines now keeps the last fitting prefix during the binary search…
Description check Passed The description follows the repository template. It explains the bug, the fix, and the linked issue (#8152). It describes the testing in detail, marks the bug fix type, and checks the tests box. Items…
Linked Issues check Passed Issue #8152 requires the truncation search to retain a fitting final prefix and preserve existing guards and fallback behavior. src/component/Text.tsx now stores each fitting midpoint result and con…
Out of Scope Changes check Passed The pull request changes only the truncation search in src/component/Text.tsx and adds focused regression tests in test/component/Text.searchBound.spec.tsx. Both changes directly support issue #81…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the Text component fix and the retained final fitting truncation prefix, which matches the main change: calculateWordsByLines now keeps the last fitting prefix during the binary search. It is specific and follows the conventional commit style.

Full details: Description check

Explanation

The description follows the repository template. It explains the bug, the fix, and the linked issue (#8152). It describes the testing in detail, marks the bug fix type, and checks the tests box. Items that remain unchecked or unfilled are the documentation fields, the storybook/VR item, and the Screenshots section, which is optional for this change. The template's 'Motivation and Context' heading is covered by the opening Description paragraph rather than a separate section, and the description does not address the Screenshots heading explicitly.

Full details: Linked Issues check

Explanation

Issue #8152 requires the truncation search to retain a fitting final prefix and preserve existing guards and fallback behavior. src/component/Text.tsx now stores each fitting midpoint result and continues the binary search, so the final fitting candidate is retained. test/component/Text.searchBound.spec.tsx covers the abW case, word and character wrapping, single glyph and grapheme boundaries, the no-Intl.Segmenter fallback, already-fitting text, an interior boundary, an ellipsis that cannot fit, and scaleToFit. The reported verification also covers the full Text test set and the normal build, lint, unit-test, and type-check gates.

Full details: Out of Scope Changes check

Explanation

The pull request changes only the truncation search in src/component/Text.tsx and adds focused regression tests in test/component/Text.searchBound.spec.tsx. Both changes directly support issue #8152. No unrelated implementation, API, documentation, or broader font-measurement work is present.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cd7f3cf6-3a91-4305-b88f-dba3ba5cb65d
Commits

Reviewing files that changed from the base of the PR and between 17b2d29 and 1c7de35.

Files selected for processing: 2
  • src/component/Text.tsx
  • test/component/Text.searchBound.spec.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.36%. Comparing base (17b2d29) to head (1c7de35).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8153      +/-   ##
==========================================
- Coverage   89.36%   89.36%   -0.01%     
==========================================
  Files         690      690              
  Lines       17721    17715       -6     
  Branches     4793     4787       -6     
==========================================
- Hits        15837    15831       -6     
  Misses       1678     1678              
  Partials      206      206              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Bundle Report

Changes will decrease total bundle size by 1.69kB (-0.02%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.84MB -380 bytes (-0.02%) ⬇️
recharts/bundle-es6 1.65MB -380 bytes (-0.02%) ⬇️
recharts/bundle-umd 680.97kB -84 bytes (-0.01%) ⬇️
recharts/bundle-treeshaking-cartesian 937.66kB -421 bytes (-0.04%) ⬇️
recharts/bundle-treeshaking-polar 650.67kB -421 bytes (-0.06%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-treeshaking-cartesian

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js -421 bytes 937.66kB -0.04%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
component/Text.js -380 bytes 31.26kB -1.2%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
component/Text.js -380 bytes 29.27kB -1.28%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js -84 bytes 680.97kB -0.01%
view changes for bundle: recharts/bundle-treeshaking-polar

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js -421 bytes 650.67kB -0.06%

@flakiness-io

flakiness-io Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Test Results Summary

This comment shows the latest test results for this pull request.

Commit Status Test Results CI Runs
1c7de35 ✅ Passed 3528 passed · 432 skipped 9 runs

View full report

ℹ️ About Flakiness.io in GitHub

Your team has set up Flakiness.io pull request comments. This comment is updated when

  • The first test results arrive for this pull request
  • A later run reports more results for the same commit
  • A new commit is pushed and tested

Flakiness.io rewrites the comment in place, so it always reflects the most recently tested commit.

@PavelVanecek
PavelVanecek merged commit 4fd785e into recharts:main Nov 3, 2026
64 checks passed
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.

Text maxLines returns overflowing content when the final truncation prefix fits

2 participants