[PR #3224] [MERGED] fix: stop conversation emoji/sticker maps re-rendering the whole transcript every streaming frame (#3223) #5848

Closed
opened 2026-10-22 04:20:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3224
Author: @kolacheee
Created: 7/5/2026
Status: ✅ Merged
Merged: 7/5/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/conversation-emoji-map-identity


📝 Commits (2)

  • 9702783 fix: stop conversation emoji/sticker maps breaking message memoization every render (#3223)
  • 94a9bc9 Merge branch 'staging' into fix/conversation-emoji-map-identity

📊 Changes

2 files changed (+58 additions, -6 deletions)

View changed files

📝 packages/client/src/hooks/use-conversation-custom-emojis.ts (+29 -3)
📝 packages/client/src/hooks/use-conversation-custom-stickers.ts (+29 -3)

📄 Description

Fixes #3223

Summary

useConversationCustomEmojis() and useConversationCustomStickers() returned a fresh list array and a fresh Map on every render. ConversationView passes those Maps as emojiMap/stickerMap props to every memo(ConversationMessage), so the memo's shallow compare failed for every mounted message on every ConversationView render — and ConversationView renders once per animation frame during any token stream. Net effect: the whole transcript re-rendered per streaming frame (~15–35 ms/frame measured on a 100-message group chat), the same disease class as #3104/#3164.

The fix applies the ref-backed reuse pattern ChatArea already uses for chatCharacterRows (the #3164 fix): build the resolved list as before, compare it element-wise against the previous one (all fields are primitives), and return the cached { list, map } object when unchanged. Both hooks fixed identically.

Why

Found by a regression/performance sweep of the reaction PRs (#3211/#3221). The bug predates them — but per-segment reactions added more per-message subtrees under the broken memo boundary, so fixing the boundary is what makes the transcript cheap again during streaming.

Known limitations

  • The element-wise compare is O(emoji+sticker count) per render — trivial, and the price of the useQueries inputs having no stable identity to memo against (a plain useMemo cannot work here, which is why the ref pattern exists).

Test plan (manual verification needed)

  • React DevTools → "Highlight updates when components render": in a long conversation chat, stream a reply — only the streaming message (and composer chrome) should flash per frame, not the whole transcript. Before this fix, every mounted message flashed.
  • Custom emojis/stickers still render in messages, the composer autocomplete, the picker's Custom tab, and the sticker selector; adding/renaming/deleting a custom emoji updates them (the cache must invalidate on real changes).
  • Long group chat scroll + streaming feels smoother on a loaded machine (subjective, but the measurable proxy is the DevTools flashing).

Docs touched

  • None (internal perf fix; no user-facing behavior change).

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency when rendering conversations by keeping custom emoji and sticker results stable across re-renders.
    • Reduced unnecessary updates by reusing previously computed emoji and sticker collections when the content hasn’t changed.
    • Helped preserve UI memoization, which can prevent flicker or extra rendering work in transcript views.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/3224 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 7/5/2026 **Status:** ✅ Merged **Merged:** 7/5/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/conversation-emoji-map-identity` --- ### 📝 Commits (2) - [`9702783`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9702783c8aed041753d227b114b02b5059c144f5) fix: stop conversation emoji/sticker maps breaking message memoization every render (#3223) - [`94a9bc9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/94a9bc9188a03aef279c54540207176f6fa6259e) Merge branch 'staging' into fix/conversation-emoji-map-identity ### 📊 Changes **2 files changed** (+58 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/hooks/use-conversation-custom-emojis.ts` (+29 -3) 📝 `packages/client/src/hooks/use-conversation-custom-stickers.ts` (+29 -3) </details> ### 📄 Description Fixes #3223 ## Summary `useConversationCustomEmojis()` and `useConversationCustomStickers()` returned a fresh `list` array and a fresh `Map` on every render. `ConversationView` passes those Maps as `emojiMap`/`stickerMap` props to every `memo(ConversationMessage)`, so the memo's shallow compare failed for **every mounted message on every ConversationView render** — and ConversationView renders once per animation frame during any token stream. Net effect: the whole transcript re-rendered per streaming frame (~15–35 ms/frame measured on a 100-message group chat), the same disease class as #3104/#3164. The fix applies the ref-backed reuse pattern ChatArea already uses for `chatCharacterRows` (the #3164 fix): build the resolved list as before, compare it element-wise against the previous one (all fields are primitives), and return the cached `{ list, map }` object when unchanged. Both hooks fixed identically. ## Why Found by a regression/performance sweep of the reaction PRs (#3211/#3221). The bug predates them — but per-segment reactions added more per-message subtrees under the broken memo boundary, so fixing the boundary is what makes the transcript cheap again during streaming. ## Known limitations - The element-wise compare is O(emoji+sticker count) per render — trivial, and the price of the `useQueries` inputs having no stable identity to memo against (a plain `useMemo` cannot work here, which is why the ref pattern exists). ## Test plan (manual verification needed) - [ ] React DevTools → "Highlight updates when components render": in a long conversation chat, stream a reply — only the streaming message (and composer chrome) should flash per frame, not the whole transcript. Before this fix, every mounted message flashed. - [ ] Custom emojis/stickers still render in messages, the composer autocomplete, the picker's Custom tab, and the sticker selector; adding/renaming/deleting a custom emoji updates them (the cache must invalidate on real changes). - [ ] Long group chat scroll + streaming feels smoother on a loaded machine (subjective, but the measurable proxy is the DevTools flashing). ## Docs touched - None (internal perf fix; no user-facing behavior change). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved consistency when rendering conversations by keeping custom emoji and sticker results stable across re-renders. * Reduced unnecessary updates by reusing previously computed emoji and sticker collections when the content hasn’t changed. * Helped preserve UI memoization, which can prevent flicker or extra rendering work in transcript views. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:20:08 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5848
No description provided.