Skip to content

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

Open
markushi wants to merge 6 commits intomainfrom
markushi/fix/jpc-masking-mismatch-weighted-text
Open

fix(replay): text layouts with center/end alignment return incorrect masking bounding box#5218
markushi wants to merge 6 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 305.96 ms 359.02 ms 53.07 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
27d7cf8 314.17 ms 347.00 ms 32.83 ms
ff8eea4 313.42 ms 337.08 ms 23.66 ms
b750b96 408.98 ms 480.32 ms 71.34 ms
0eaac1e 322.53 ms 389.31 ms 66.78 ms
18c0bc2 306.73 ms 349.77 ms 43.03 ms
abf451a 332.82 ms 403.67 ms 70.85 ms
62b579c 349.26 ms 426.26 ms 77.00 ms
f064536 335.52 ms 408.79 ms 73.27 ms
70118e9 380.00 ms 475.72 ms 95.72 ms
85d7417 347.21 ms 394.35 ms 47.15 ms

App size

Revision Plain With Sentry Diff
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
ff8eea4 1.58 MiB 2.28 MiB 718.64 KiB
b750b96 1.58 MiB 2.10 MiB 533.19 KiB
0eaac1e 1.58 MiB 2.19 MiB 619.17 KiB
18c0bc2 1.58 MiB 2.13 MiB 557.33 KiB
abf451a 1.58 MiB 2.20 MiB 635.29 KiB
62b579c 0 B 0 B 0 B
f064536 1.58 MiB 2.20 MiB 633.90 KiB
70118e9 1.58 MiB 2.29 MiB 719.84 KiB
85d7417 1.58 MiB 2.10 MiB 533.44 KiB

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
c20e90d 301.13 ms 349.74 ms 48.61 ms

App size

Revision Plain With Sentry Diff
4af8342 0 B 0 B 0 B
c20e90d 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
@markushi markushi marked this pull request as ready for review March 23, 2026 14:31
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.

2 participants