Optimize chat message rendering and message-tree updates with memoization#2706
Merged
hayescode merged 6 commits intoChainlit:mainfrom Dec 4, 2025
Merged
Optimize chat message rendering and message-tree updates with memoization#2706hayescode merged 6 commits intoChainlit:mainfrom
hayescode merged 6 commits intoChainlit:mainfrom
Conversation
…ing and structured content display.
…ies for nested message management.
Contributor
There was a problem hiding this comment.
2 issues found across 5 files
Prompt for AI agents (all 2 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="frontend/src/components/chat/Messages/Message/index.tsx">
<violation number="1" location="frontend/src/components/chat/Messages/Message/index.tsx:92">
P1: `useMemo` is called inside the conditional user-message branch, violating React’s hook rules because hooks must run unconditionally and in the same order every render. Move the memoized JSX computation to the top level (e.g., assign it to a variable with useMemo before the return) and reference that variable inside the conditional instead of invoking the hook there.</violation>
</file>
<file name="frontend/src/components/chat/Messages/Message/Content/index.tsx">
<violation number="1" location="frontend/src/components/chat/Messages/Message/Content/index.tsx:130">
P2: `sections` prop changes are ignored by the new memo comparator, so toggling which sections render no longer updates the UI.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
hayescode
approved these changes
Dec 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the performance and clarity of the chat message rendering flow by adding proper memoization, refining render-relevant props, and optimizing message-tree update utilities.
Changes
memocomparison forMessageContentto prevent unnecessary re-renders based on only the props that affect rendering.UserMessageandMessageinmemoand introduceduseMemowhere appropriate to avoid repeated child rendering.getMessageRenderPropsto ensure stable message-dependent render comparisons.useMemofor consistent scorable-message detection.Motivation
Summary by cubic
Optimized chat message rendering with targeted memoization and faster message-tree updates to reduce re-renders and smooth streaming.
Written for commit ab96750. Summary will update automatically on new commits.