Skip to content

fix(core): sort channels with disposed state last instead of crashing - #2887

Merged
testableapple merged 2 commits into
masterfrom
alexeyalterpesotskiy/flu-692-streamchannellistcontroller-local-sort-crashes-on-channels
Aug 14, 2026
Merged

fix(core): sort channels with disposed state last instead of crashing#2887
testableapple merged 2 commits into
masterfrom
alexeyalterpesotskiy/flu-692-streamchannellistcontroller-local-sort-crashes-on-channels

Conversation

@testableapple

@testableapple testableapple commented Aug 14, 2026

Copy link
Copy Markdown
Member

Submit a pull request

Linear: FLU-692

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

StreamChannelListController's value setter sorts the page locally whenever a channelStateSort is active (including when a predefinedFilter resolves an effectiveSort), using a null assert on the channel state:

(it) => it.state!.channelState,

Channel.dispose() nulls state, so an in-flight doInitialLoad/loadMore that resumes after channels were disposed — a logout/disconnect racing an in-flight pagination, or a channel removed by a deleted/hidden event while a query is in flight — crashes with Null check operator used on a null value. Caught by the nightly e2e run (iOS 18.5, channel_list_test.dart), where the teardown's client.dispose() raced a scroll-triggered loadMore.

The sort key is now it.state?.channelState with a nulls-last comparator, so disposed channels sort to the end instead of crashing. No further lifecycle guards are needed: the base PagedValueNotifier already discards value writes after the controller itself is disposed.

Testing: added a regression test (fails with a null-check _TypeError on the unfixed code) that mixes a state-less channel into a sorted page and asserts it lands last while live channels keep the sort order.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed channel list sorting during in-flight queries when a channel has been disposed.
    • Disposed or unavailable-state channels are now placed after active channels instead of causing an error.
    • Active channels continue to follow the configured sorting order.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5f7f35b2-6652-42d1-be66-2ccb3381a416

📥 Commits

Reviewing files that changed from the base of the PR and between 02ba6a2 and 2f41b78.

📒 Files selected for processing (3)
  • packages/stream_chat_flutter_core/CHANGELOG.md
  • packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart
  • packages/stream_chat_flutter_core/test/stream_channel_list_controller_test.dart

📝 Walkthrough

Walkthrough

StreamChannelListController now sorts channels with null state safely. Disposed channels sort last, while active channels continue using the configured comparator. A regression test and changelog entry document the fix.

Changes

Channel sorting

Layer / File(s) Summary
Null-state sorting behavior
packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart, packages/stream_chat_flutter_core/test/stream_channel_list_controller_test.dart, packages/stream_chat_flutter_core/CHANGELOG.md
The controller handles null channel states without a null assertion. Active channels use the configured comparator, disposed channels sort last, and regression coverage verifies the ordering. The changelog records the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 2f41b

This localized change makes disposed channels sort last instead of causing a crash, with a regression test covering the behavior. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: velikovpetar, xsahil03x

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the fix for sorting channels with disposed state without a crash.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch alexeyalterpesotskiy/flu-692-streamchannellistcontroller-local-sort-crashes-on-channels

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…listcontroller-local-sort-crashes-on-channels
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.96%. Comparing base (09a918b) to head (37e9b83).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2887   +/-   ##
=======================================
  Coverage   73.96%   73.96%           
=======================================
  Files         435      435           
  Lines       28147    28149    +2     
=======================================
+ Hits        20818    20821    +3     
+ Misses       7329     7328    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@testableapple
testableapple merged commit cb43fc4 into master Aug 14, 2026
29 checks passed
@testableapple
testableapple deleted the alexeyalterpesotskiy/flu-692-streamchannellistcontroller-local-sort-crashes-on-channels branch August 14, 2026 10: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.

2 participants