Skip to content

fix: move URL regex off main thread in MessagingScreen#468

Merged
torlando-tech merged 1 commit intomainfrom
fix/url-regex-off-main-thread
Feb 15, 2026
Merged

fix: move URL regex off main thread in MessagingScreen#468
torlando-tech merged 1 commit intomainfrom
fix/url-regex-off-main-thread

Conversation

@torlando-tech
Copy link
Copy Markdown
Owner

Summary

  • Moves Patterns.WEB_URL.matcher() regex computation off the main thread in LinkifiedMessageText composable
  • Replaces synchronous remember block with LaunchedEffect + withContext(Dispatchers.Default) for background regex execution
  • Initial render shows plain text; links appear after async computation completes (imperceptible single-frame delay)

Context

Sentry issue COLUMBA-3C ("Regex on Main Thread") flagged main-thread regex work. While the Sentry report was triggered by SDK internals, the Patterns.WEB_URL.matcher(text) call in LinkifiedMessageText is a legitimate main-thread regex that could cause UI jank on long messages with many URLs.

Test plan

  • Open a conversation with messages containing URLs — confirm links appear highlighted and are tappable
  • Toggle dark/light mode — link colors should update correctly
  • Send a message with many URLs — verify no UI jank
  • Verify build: ./gradlew :app:compileNoSentryDebugKotlin

🤖 Generated with Claude Code

Replace synchronous Patterns.WEB_URL.matcher() in remember block with
LaunchedEffect + withContext(Dispatchers.Default) to prevent potential
UI jank on long messages with many URLs (COLUMBA-3C).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 15, 2026

Greptile Summary

Moves the Patterns.WEB_URL.matcher() regex computation in LinkifiedMessageText off the main thread by replacing a synchronous remember block with a LaunchedEffect + withContext(Dispatchers.Default) pattern, addressing Sentry issue COLUMBA-3C. The initial render shows plain text while links are computed asynchronously, then updates the composable state with the linkified AnnotatedString.

  • Core change: Regex-based URL detection now runs on Dispatchers.Default instead of blocking the main thread during composition
  • UX trade-off: Single-frame delay before links appear — imperceptible in practice since message text is stable and the regex completes quickly
  • Formatting: Minor import reordering (alphabetical sort) and indentation fixes for LifecycleEventObserver and LazyColumn modifier chains
  • No issues found: The remember and LaunchedEffect keys are correctly synchronized, pointerInput restarts when annotatedText updates, and buildAnnotatedString is safe to call from background threads

Confidence Score: 5/5

  • This PR is safe to merge — it's a straightforward performance optimization with correct coroutine/state management and no behavioral regressions.
  • The change is well-scoped: it moves a single regex computation off the main thread using standard Compose coroutine patterns. The remember and LaunchedEffect keys are correctly aligned, the pointerInput handler properly restarts on state changes, and the fallback behavior (plain text during async computation) is graceful. The remaining changes are purely cosmetic (import sorting, indentation).
  • No files require special attention.

Important Files Changed

Filename Overview
app/src/main/java/com/lxmf/messenger/ui/screens/MessagingScreen.kt Moves URL regex matching off the main thread using LaunchedEffect + withContext(Dispatchers.Default); includes minor import reordering and formatting cleanup. No functional issues found.

Sequence Diagram

sequenceDiagram
    participant C as Composition (Main Thread)
    participant S as State (annotatedText)
    participant BG as Dispatchers.Default
    participant UI as Text Composable

    C->>S: remember(text, linkColor) → plain AnnotatedString
    S->>UI: Render plain text (no links)
    C->>BG: LaunchedEffect → withContext(Dispatchers.Default)
    BG->>BG: Patterns.WEB_URL.matcher(text)
    BG->>BG: buildAnnotatedString with link styles
    BG->>S: Update annotatedText with linkified result
    S->>UI: Recompose with clickable links
    Note over UI: pointerInput restarts with new annotatedText key
Loading

Last reviewed commit: b111c78

@sentry
Copy link
Copy Markdown
Contributor

sentry bot commented Feb 15, 2026

Codecov Report

❌ Patch coverage is 39.47368% with 23 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...a/com/lxmf/messenger/ui/screens/MessagingScreen.kt 39.47% 20 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@torlando-tech torlando-tech merged commit bbcbe5a into main Feb 15, 2026
10 of 11 checks passed
@torlando-tech torlando-tech deleted the fix/url-regex-off-main-thread branch February 15, 2026 18:30
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