enkilee opened a new pull request, #4715:
URL: https://github.com/apache/rocketmq-dashboard/pull/4715
<!-- Make sure the base branch is `master`: that is the RocketMQ Studio
trunk. -->
### Which Issue(s) This PR Fixes
<!-- Link the issue with a keyword so it closes on merge. Trivial fixes need
no issue.
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->
- Fixes #<issue-id>
### Brief Description
<!-- What changes and why. Keep it short — the diff already shows how. -->
- The unread count effect of `ChatThread` relies on `[bubbleCount]`. When
`bubbleCount` decreases (due to the removal of `liveBlocks` caused by streaming
output failure/abortion), the effect will still execute and increment `unread`,
resulting in an incorrect increase in the badge number.
- Introduce `prevBubbleCountRef` to track the previous `bubbleCount`, and
increment `unread` only when `bubbleCount` **increases**.
## Root Cause
```tsx
useEffect(() => {
if (atBottomRef.current) return;
setUnread((count) => count + 1);
}, [bubbleCount]);
```
`bubbleCount = bubbles.length + (liveBlocks?.length > 0 ? 1 : 0)`. When the
streaming output fails, `liveBlocks` is cleared, `bubbleCount` decreases from
N+1 to N, the effect still triggers, and the `unread` error is incremented by 1.
## Fix
```tsx
const prevBubbleCountRef = useRef(bubbles.length);
useEffect(() => {
const previous = prevBubbleCountRef.current;
prevBubbleCountRef.current = bubbleCount;
if (atBottomRef.current || bubbleCount <= previous) return;
setUnread((count) => count + 1);
}, [bubbleCount]);
```
### How Did You Test This Change?
<!-- Paste the commands you ran and what they printed. Typical verification:
backend `cd server && mvn -B -ntp test` (integration tests need
MySQL 8, see CONTRIBUTING.md)
frontend `cd web && npm test && npm run lint && npm run build`
A pull request with no verification will not be merged. -->
### Checklist
- [ ] One coherent change; unrelated modifications are not bundled in
- [ ] Commit subject follows Conventional Commits (`feat:` / `fix:` /
`refactor:` / `chore:` / `docs:` / `perf:`)
- [ ] Tests added or updated for non-trivial changes, test methods named
`...Test`
- [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
- [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit
checks)
- [ ] New source files carry the ASF license header
- [ ] Documentation touched where behaviour changed (README / `docs/` /
in-app help)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]