Skip to content

fix(replay): text layouts with center/end alignment return incorrect masking bounding box#5218

Draft
markushi wants to merge 4 commits intomainfrom
markushi/fix/jpc-masking-mismatch-weighted-text
Draft

fix(replay): text layouts with center/end alignment return incorrect masking bounding box#5218
markushi wants to merge 4 commits intomainfrom
markushi/fix/jpc-masking-mismatch-weighted-text

Conversation

@markushi
Copy link
Member

@markushi markushi commented Mar 20, 2026

Description

Fix Compose text masking for layouts where text alignment (TextAlign.Center, TextAlign.End) or weighted layouts produce incorrect masking bounding boxes.

Root Cause

Compose's MultiParagraph always uses constraints.maxWidth as the paragraph width, but the Text composable may size its node to a smaller content width. This causes getLineLeft/getLineRight to return positions in the paragraph coordinate system that don't match the node's actual bounds, resulting in masking rects placed at wrong positions (e.g. off-screen for end-aligned weighted text).

Changes

  • Simplified TextLayout interface: replaced getPrimaryHorizontal, getEllipsisCount, getLineVisibleEnd, getLineStart with getLineLeft/getLineRight — directly using the layout's line bounds instead of computing them from character offsets
  • Fixed paragraph/node width mismatch: when paragraph width exceeds the node width, fall back to lineWidth starting from x=0, since text alignment has no visible effect in content-wrapped nodes
  • Removed hasFillModifier workaround: no longer needed since we use getLineLeft/getLineRight directly
  • Simplified findTextAttributes()findTextColor(): only the color is needed now, the Fill modifier detection is removed

Motivation and Context

The Fill modifier detection was a fragile workaround that didn't cover all cases (e.g. weighted text). The new approach correctly handles all text alignment and sizing scenarios by comparing the paragraph width against the actual node width.

How did you test it?

  • Tested with the Android sample app using various Compose text layouts: blank, fillMaxWidth, center-aligned, end-aligned, weighted, and multiline
  • Existing screenshot snapshot tests pass with updated baselines

Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (replay) Add beforeErrorSampling callback to Session Replay by romtsn in #5214

Bug Fixes 🐛

  • (replay) Text layouts with center/end alignment return incorrect masking bounding box by markushi in #5218

Internal Changes 🔧

  • (deps) Update Native SDK to v0.13.3 by github-actions in #5215

🤖 This preview updates automatically when you update the PR.

@sentry
Copy link

sentry bot commented Mar 20, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
SDK Size io.sentry.tests.size 8.36.0 (1) release Install Build

@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 301.13 ms 349.74 ms 48.61 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
8687935 332.52 ms 362.23 ms 29.71 ms
27d7cf8 309.43 ms 364.27 ms 54.85 ms
f064536 329.00 ms 395.62 ms 66.62 ms
abfcc92 337.38 ms 427.39 ms 90.00 ms
ae7fed0 293.84 ms 380.22 ms 86.38 ms
d15471f 361.89 ms 378.07 ms 16.18 ms
1df7eb6 397.04 ms 429.64 ms 32.60 ms
9fbb112 401.87 ms 515.87 ms 114.00 ms
6405ec5 310.88 ms 354.56 ms 43.69 ms
62b579c 318.48 ms 367.71 ms 49.24 ms

App size

Revision Plain With Sentry Diff
8687935 1.58 MiB 2.19 MiB 619.17 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
f064536 1.58 MiB 2.20 MiB 633.90 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
ae7fed0 1.58 MiB 2.12 MiB 551.77 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
1df7eb6 1.58 MiB 2.10 MiB 532.97 KiB
9fbb112 1.58 MiB 2.11 MiB 539.18 KiB
6405ec5 1.58 MiB 2.12 MiB 552.23 KiB
62b579c 0 B 0 B 0 B

Previous results on branch: markushi/fix/jpc-masking-mismatch-weighted-text

Startup times

Revision Plain With Sentry Diff
4af8342 390.10 ms 494.80 ms 104.69 ms

App size

Revision Plain With Sentry Diff
4af8342 0 B 0 B 0 B

@markushi markushi changed the title fix(replay): Remove Fill modifier workaround and shortcut single-line text masking fix(replay): text layouts with center/end alignment return incorrect masking bounding box Mar 20, 2026
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.

1 participant