Skip to content

Conversation

testableapple
Copy link
Contributor

@testableapple testableapple commented Sep 19, 2025

Relates to #955

🎯 Goal

Ensure the chat composer TextField is reliably cleared after sending a message, when autocorrection is active and a SwiftUI TextField is used.

For context, my usecase requires me to use a custom configured TextField instead of ComposerInputView (UIViewRepresentable implementation) provided by this SDK. There is a race condition caused by clearing the text twice and the system autocorrection.


📝 Summary

  • Removed immediate text = "" call from clearInputData()
  • Kept deferred clear in clearText() to reset input after UIKit finishes applying autocorrections
  • Prevented a race condition between app state updates and UIKit’s delayed autocorrect commit

🛠 Implementation

  • Clearing text immediately conflicted with this delayed commit, causing the autocorrected text to reappear in the input field.
  • The fix removes the redundant immediate clear and relies solely on the deferred clear (DispatchQueue.main.asyncAfter).
  • This ensures the field is reset only after UIKit has finished its autocorrection cycle.

🎨 Showcase

Before After
Input sometimes still shows autocorrected text after sending Input reliably clears after sending

🧪 Manual Testing Notes

  1. Type a word that triggers autocorrection (e.g., tehthe).
  2. Without manually accepting the suggestion, tap Send.
  3. ✅ The message is sent and the input clears immediately.
  4. Repeat with different autocorrections and verify consistent behavior.

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

@testableapple testableapple requested a review from a team as a code owner September 19, 2025 11:03
@testableapple testableapple force-pushed the fix/textfield_clear_race_condition branch from a5d68bf to 9692c6c Compare September 19, 2025 11:04
@testableapple testableapple enabled auto-merge (squash) September 19, 2025 11:04
@testableapple testableapple enabled auto-merge (squash) September 19, 2025 11:07
@testableapple testableapple changed the title Fix race condition when clearing text (#955) Fix race condition when clearing text Sep 19, 2025
@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Sep 19, 2025

SDK Size

title develop branch diff status
StreamChatSwiftUI 9.43 MB 9.43 MB 0 KB 🟢

Copy link

Public Interface

🚀 No changes affecting the public interface.

Copy link

Copy link
Member

@nuno-vieira nuno-vieira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✅

@testableapple testableapple merged commit a52ff7b into develop Sep 19, 2025
11 checks passed
@testableapple testableapple deleted the fix/textfield_clear_race_condition branch September 19, 2025 13:20
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.

4 participants