Fix possible text styles cache corruption#2629
Merged
MatkovIvan merged 4 commits intojb-mainfrom Dec 9, 2025
Merged
Conversation
MatkovIvan
commented
Dec 9, 2025
| override val topRatio: Float = -1f, | ||
| ) : ComputedStyle { | ||
| private val _foregroundPaint = SkiaTextPaint() | ||
| fun getForegroundPaint(): SkPaint { |
Member
Author
There was a problem hiding this comment.
Note for reviewers: this diff is easier to read in ignoring whitespace mode
ASalavei
reviewed
Dec 9, 2025
.../ui/ui-text/src/skikoMain/kotlin/androidx/compose/ui/text/platform/ParagraphBuilder.skiko.kt
Show resolved
Hide resolved
ASalavei
approved these changes
Dec 9, 2025
igordmn
approved these changes
Dec 9, 2025
MatkovIvan
added a commit
that referenced
this pull request
Dec 9, 2025
…ed between calls (#2634) Follow up after debugging #2629/[CMP-8028](https://youtrack.jetbrains.com/issue/CMP-8028) This fix reduces the number of skia paragraph layout calls from 3 to 2 for each label in the next example: ```kt val textMeasurer = rememberTextMeasurer(cacheSize = 100) Canvas(Modifier.fillMaxSize().background(Color.DarkGray)) { for (i in 0 until 100) { drawText( textMeasurer = textMeasurer, text = "$i", topLeft = Offset(x = i % 10 * 50f, y = i / 10 * 50f), style = TextStyle.Default.copy(color = Color.White) ) } } ``` Unfortunately, a unit test for this behavior is not trivial because we don't have infra to mock final classes even on JVM now ## Release Notes N/A
siarb
added a commit
that referenced
this pull request
Jan 13, 2026
Fixes [CMP-8028](https://youtrack.jetbrains.com/issue/CMP-8028) Text color is sometimes randomly black on iOS when using Compose Multiplatform (BasicText) It's a minimal, simplified version of #2629 ## Testing - Existing tests on CI - Reproducer from [CMP-8028](https://youtrack.jetbrains.com/issue/CMP-8028) ```kt val textMeasurer = rememberTextMeasurer(cacheSize = 100) Canvas(Modifier.background(Color.DarkGray)) { for (i in 0 until 100) { drawText( textLayoutResult = textMeasurer.measure(text = "$i"), color = Color.White, topLeft = Offset(x = i % 10 * 50f, y = i / 10 * 50f) ) } } ``` ## Release Notes ### Fixes - iOS - Fix possible text styles cache corruption (text color is sometimes randomly black)
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.
Fixes CMP-8028 Text color is sometimes randomly black on iOS when using Compose Multiplatform (BasicText)
The main change here is to make sure that keys in
skTextStylesCacheare immutable.However, during the paragraph building, we need this class to be mutable to avoid unnecessary allocations. While it's possible to fix the issue with just a few lines (#2630), it seems really dangerous long term, so this PR replaces
ComputedStyletosealed intefracewith both variants to ensure immutability at compile time instead.In addition to that, it contains a small cleanup of code around:
@InternalTextApito functions withTODO: Remove from public, so we can actually remove them laterTesting
Additional auto tests are problematic because the issue reproduces only on K/N (both macOS and iOS) where we didn't have infrastructure for fonts-related testing yet.
Release Notes
Fixes - iOS