Clear stale mention suggestions when the query ends - #1568
Conversation
Cancel in-flight suggestion requests and ignore superseded results so deleting an @mention query does not briefly re-show the suggestions list.
Forward clearSuggestions through command handlers so MentionsCommandHandler cancels in-flight work and clears provider results when the composer leaves mention mode.
Use the LLC fix/mention-suggestions-large-channels branch so SwiftUI picks up clearResults and MemberSearch while that PR is open.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe composer now cancels obsolete suggestion requests, clears stale command results, and applies results only for the current command and query. Mention handlers expose cancellation and provider cleanup. Tests cover text deletion, command removal, and in-flight cancellation. ChangesSuggestion cleanup flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Mergeability Score: ⚪ Minimal · up to The change clears stale mention suggestions when a query ends and cancels superseded searches; no actionable merge-blocking risk remains after normal checks and review. Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Composer as MessageComposerViewModel
participant Commands as CommandsHandler
participant Mentions as MentionsCommandHandler
participant Provider as SuggestionsProvider
Composer->>Commands: clearSuggestions()
Commands->>Mentions: clearSuggestions()
Mentions->>Provider: clearResults()
Composer->>Mentions: request suggestions for command and query
Mentions->>Provider: fetch suggestions
Composer->>Composer: accept only matching command and query
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (2)
Sources/StreamChatSwiftUI/ChatComposer/MessageComposerViewModel.swift (1)
215-216: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the private documentation comment.
suggestionsCancellableis private. Its name describes its purpose. Do not add///documentation for private declarations.As per coding guidelines: “Write concise
///documentation only for public SDK declarations; do not document internal, private, or test code.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Sources/StreamChatSwiftUI/ChatComposer/MessageComposerViewModel.swift` around lines 215 - 216, Remove the private documentation comment immediately above suggestionsCancellable in MessageComposerViewModel, leaving the property declaration unchanged.Source: Coding guidelines
Package.swift (1)
19-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPin the temporary StreamChat dependency to revision
900c626dd3b4c0036962fd1ab3febc119b657239.Use this revision in both
Package.swiftandStreamChatSwiftUI.xcodeproj/project.pbxproj. Update it after the upstream change merges.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Package.swift` at line 19, Pin the temporary StreamChat dependency to revision 900c626dd3b4c0036962fd1ab3febc119b657239 instead of the branch reference in Package.swift and StreamChatSwiftUI.xcodeproj/project.pbxproj (1546-1547); update both dependency declarations consistently, and switch back after the upstream change merges.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Sources/StreamChatSwiftUI/ChatComposer/MessageComposerViewModel.swift`:
- Around line 39-47: Update the command-removal flow in MessageComposerViewModel
so clearComposerSuggestions() is invoked only once when composerCommand is set
to nil. Remove or conditionally skip the explicit call after the animated
assignment, while preserving suggestion clearing for paths where the command
observer is not triggered.
In `@Sources/StreamChatSwiftUI/ChatComposer/Suggestions/CommandsHandler.swift`:
- Around line 268-272: Update CommandsHandler.clearSuggestions() to also call
mentionsCommandHandler.clearSuggestions(), ensuring TwoStepMentionCommand clears
its suggestions task and provider results. Preserve the existing loop that
clears suggestions for registered commands.
In
`@Sources/StreamChatSwiftUI/ChatComposer/Suggestions/Mentions/MentionsCommandHandler.swift`:
- Around line 127-131: Update clearSuggestions() and the mention-request flow to
track or serialize the provider.clearResults() task, ensuring cleanup completes
in ordering with subsequent requests. Prevent an untracked cleanup from
cancelling or clearing newer searches while preserving cancellation of the
current suggestionsTask.
In
`@StreamChatSwiftUITests/Tests/ChatChannel/Suggestions/MentionsCommandHandler_Tests.swift`:
- Around line 311-313: Replace the fixed 50 ms sleep in MentionsCommandHandler
tests with an XCTestExpectation fulfilled when the provider’s clear operation
completes, then wait for that expectation before asserting
clearResultsCallCount. In
StreamChatSwiftUITests/Tests/ChatChannel/Suggestions/MentionsCommandHandler_Tests.swift
lines 311-313, update the provider-clear flow; in
StreamChatSwiftUITests/Tests/ChatChannel/MessageComposerViewModel_Tests.swift
lines 730-731, inject a controlled delayed suggestion request, fulfill an
XCTestExpectation on completion, and await it before asserting stale results are
rejected.
- Around line 352-383: Synchronize the mutable state in
MockMentionSuggestionsProvider by protecting receivedRequests and
clearResultsCallCount with an actor or lock. Update mentionSuggestions(for:) and
clearResults() to use that synchronization while preserving their existing
behavior and the provider’s Sendable conformance.
---
Nitpick comments:
In `@Package.swift`:
- Line 19: Pin the temporary StreamChat dependency to revision
900c626dd3b4c0036962fd1ab3febc119b657239 instead of the branch reference in
Package.swift and StreamChatSwiftUI.xcodeproj/project.pbxproj (1546-1547);
update both dependency declarations consistently, and switch back after the
upstream change merges.
In `@Sources/StreamChatSwiftUI/ChatComposer/MessageComposerViewModel.swift`:
- Around line 215-216: Remove the private documentation comment immediately
above suggestionsCancellable in MessageComposerViewModel, leaving the property
declaration unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 308f0c74-93a0-4cf2-9555-7ac0ec7d19da
📒 Files selected for processing (7)
Package.swiftSources/StreamChatSwiftUI/ChatComposer/MessageComposerViewModel.swiftSources/StreamChatSwiftUI/ChatComposer/Suggestions/CommandsHandler.swiftSources/StreamChatSwiftUI/ChatComposer/Suggestions/Mentions/MentionsCommandHandler.swiftStreamChatSwiftUI.xcodeproj/project.pbxprojStreamChatSwiftUITests/Tests/ChatChannel/MessageComposerViewModel_Tests.swiftStreamChatSwiftUITests/Tests/ChatChannel/Suggestions/MentionsCommandHandler_Tests.swift
Clear suggestions once when emptying text, and replace sleep-based stale-mention coverage with expectation-driven delayed provider requests.
Generated by 🚫 Danger |
laevandus
left a comment
There was a problem hiding this comment.
✅ I did some testing and did not get any odd behaviour. Left 2 minor comments.
Use develop revision 8263bddc2 now that #4213 is merged.
Drop the debug log from the suggestions sink and use removeAll when clearing suggestions.
The Future publisher's sink requires both receiveCompletion and receiveValue closures; the previous commit dropped receiveCompletion, causing a type mismatch.
Public Interface extension CommandHandler
+ public func clearSuggestions()
public final class MentionsCommandHandler: CommandHandler
+ public func clearSuggestions()
public class CommandsHandler: CommandHandler
- public func handleCommand(for text: Binding<String>,selectedRangeLocation: Binding<Int>,command: Binding<ComposerCommand?>,extraData: [String: Any])
+ public func clearSuggestions()
- public func executeOnMessageSent(composerCommand: ComposerCommand,completion: @escaping @MainActor (Error?) -> Void)
+ public func handleCommand(for text: Binding<String>,selectedRangeLocation: Binding<Int>,command: Binding<ComposerCommand?>,extraData: [String: Any])
- public func canBeExecuted(composerCommand: ComposerCommand)-> Bool
+ public func executeOnMessageSent(composerCommand: ComposerCommand,completion: @escaping @MainActor (Error?) -> Void)
+ public func canBeExecuted(composerCommand: ComposerCommand)-> Bool |
SDK Size
|
StreamChatSwiftUI XCSize
|
|



🔗 Issue Links
🎯 Goal
Prevent stale mention suggestions from resurfacing while deleting an
@…query, and clear LLC search state when mention mode ends.📝 Summary
MessageComposerViewModelwhen the active mention query changes or endsdisplayInfo == nil)CommandHandler.clearSuggestions()and implement it inMentionsCommandHandlerto cancel in-flight work and callMentionSuggestionsProvider.clearResults()fix/mention-suggestions-large-channelswhile the LLC PR is open🛠 Implementation
Deleting
@iOScharacter-by-character could race a slower search and leave suggestions visible after the query was cleared. The view model now cancels the active suggestions subscription, ignores results that no longer match the current command/query, and clears suggestions whencomposerCommandbecomesnil.MentionsCommandHandlertracks the suggestionTask, cancels it on clear, and forwards to the providerclearResults()API added in the LLC PR.🧪 Manual Testing Notes
@+ a few characters in a channel, then delete back to empty☑️ Contributor Checklist
docs-contentrepoSummary by CodeRabbit
Bug Fixes
Tests