Skip to content

fix(MessageList): don't count thread replies toward channel unread UI state#3229

Open
MartinCupela wants to merge 1 commit into
masterfrom
fix/prevent-unread-indicator-threads
Open

fix(MessageList): don't count thread replies toward channel unread UI state#3229
MartinCupela wants to merge 1 commit into
masterfrom
fix/prevent-unread-indicator-threads

Conversation

@MartinCupela

@MartinCupela MartinCupela commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Problem

Posting a reply into a thread could surface the UnreadMessagesNotification in the main MessageList. handleMessageNew incremented channelUnreadUiState.unread_messages for every message.new event when the list was scrolled up, marked unread, or the tab was hidden — including pure thread replies that don't render in the main list. With no UnreadMessagesSeparator present, the notification then popped.

Fix

Early-return from handleMessageNew when the event doesn't update the main channel (parent_id set and not show_in_channel), so thread-only replies never touch the channel's unread UI state. Replies with show_in_channel: true still increment correctly.

Thread unread indicators are unaffected — they come from stream-chat's separate ThreadState store, and the notification is !threadList-gated.

Tests

Added regression coverage for the three increment triggers (scrolled-up, marked-unread, document-hidden) with a thread reply, plus a positive show_in_channel case. Verified the new tests fail without the fix.

Summary by CodeRabbit

  • Bug Fixes
    • Improved unread count handling for thread replies so messages that aren’t shown in the channel no longer incorrectly increase unread counts or trigger read updates.
    • Hidden tabs and non-bottom scroll states now behave more consistently, avoiding unexpected read status changes.
    • Thread replies shown in the channel now update unread state correctly when the list isn’t at the bottom.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

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

Run ID: 525ef6c4-4215-4f8a-99f6-3e6553dc9515

📥 Commits

Reviewing files that changed from the base of the PR and between a768e30 and c7488c9.

📒 Files selected for processing (2)
  • src/components/MessageList/hooks/__tests__/useMarkRead.test.tsx
  • src/components/MessageList/hooks/useMarkRead.ts

📝 Walkthrough

Walkthrough

useMarkRead adds an early return in handleMessageNew for thread replies not shown in the channel, preventing them from incrementing unread counts or triggering markRead. The markRead condition is simplified accordingly. New parameterized tests cover these thread-message scenarios.

Changes

Thread reply unread state fix

Layer / File(s) Summary
handleMessageNew early return and condition simplification
src/components/MessageList/hooks/useMarkRead.ts
Adds early return when an incoming message is not a main-channel update (thread replies not shown in channel), and removes the now-redundant mainChannelUpdated check from the markRead condition.
New tests for thread message unread behavior
src/components/MessageList/hooks/__tests__/useMarkRead.test.tsx
Adds parameterized tests asserting no unread UI state change or markRead call for thread replies when not scrolled to bottom, when previously marked unread, or when document.hidden is true; also tests show_in_channel thread messages updating unread state correctly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A thread reply sneaks in, but the rabbit says "Nay!"
No unread count bumping for messages astray.
If show_in_channel waves, then we'll count it right,
Otherwise exit early — keep the state tight.
🐇✨ Clean logic hops forward into the light!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: excluding thread replies from channel unread UI state.
Description check ✅ Passed The description covers the problem, fix, and tests, though it doesn't use the template headings and omits UI screenshots.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/prevent-unread-indicator-threads

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.

@github-actions

Copy link
Copy Markdown

Size Change: -20 B (0%)

Total Size: 797 kB

📦 View Changed
Filename Size Change
dist/cjs/index.js 259 kB -10 B (0%)
dist/es/index.mjs 256 kB -10 B (0%)
ℹ️ View Unchanged
Filename Size
dist/cjs/audioProcessing.js 1.74 kB
dist/cjs/channel-detail.js 22.9 kB
dist/cjs/emojis.js 2.56 kB
dist/cjs/mp3-encoder.js 814 B
dist/cjs/ReactPlayerWrapper.js 547 B
dist/cjs/useChannelHeaderOnlineStatus.js 37.7 kB
dist/cjs/useMessageComposerController.js 1.01 kB
dist/cjs/useNotificationApi.js 52.8 kB
dist/css/channel-detail.css 2.84 kB
dist/css/emoji-picker.css 178 B
dist/css/emoji-replacement.css 456 B
dist/css/index.css 41.3 kB
dist/es/audioProcessing.mjs 1.65 kB
dist/es/channel-detail.mjs 22.6 kB
dist/es/emojis.mjs 2.48 kB
dist/es/mp3-encoder.mjs 768 B
dist/es/ReactPlayerWrapper.mjs 485 B
dist/es/useChannelHeaderOnlineStatus.mjs 37.1 kB
dist/es/useMessageComposerController.mjs 937 B
dist/es/useNotificationApi.mjs 51.5 kB

compressed-size-action

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.18%. Comparing base (a768e30) to head (c7488c9).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3229      +/-   ##
==========================================
- Coverage   84.20%   84.18%   -0.02%     
==========================================
  Files         485      485              
  Lines       14867    14868       +1     
  Branches     4704     4705       +1     
==========================================
- Hits        12519    12517       -2     
- Misses       2348     2351       +3     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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