perf(desktop): memoize composer and timeline to fix typing lag#143
Merged
wesbillman merged 1 commit intomainfrom Mar 20, 2026
Merged
perf(desktop): memoize composer and timeline to fix typing lag#143wesbillman merged 1 commit intomainfrom
wesbillman merged 1 commit intomainfrom
Conversation
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
Fix typing lag/stutter in the message composer caused by unnecessary React re-renders cascading from
AppShellthrough the entire component tree on every keystroke.Problem
When typing in the
MessageComposer, every keystroke triggered re-renders of:ChannelPane(not memoized)MessageTimeline(not memoized — potentially hundreds of message rows)MessageComposerToolbar(not memoized)Additionally, inline arrow functions in
AppShell(onSend,onCancelReply,onReply,onToggleReaction,onTargetReached) created new references every render, defeating any potential memoization.Solution
Component memoization (
React.memo)ChannelPane— highest-impact change, prevents timeline re-renders on keystrokesMessageTimeline— belt-and-suspenders with ChannelPane memoMessageComposerToolbar— prevents toolbar re-renders during typingChannelAutocomplete,MentionAutocomplete,ComposerEmojiPicker— defensive memoizationCallback stabilization
useChannelPaneHandlershook — extractshandleSend,handleReply,handleCancelReply,handleToggleReactionwith stable references usinguseCallback+ ref pattern.mutateAsyncstashed in refs since mutation objects are new references on every state transition (idle → pending → success)contentRefpattern inMessageComposer— callbacks read from ref instead of closing overcontentstate, removing it from dependency arrayshandleCaptureSelection,handlePaperclipClick,handleTargetReached,effectiveToggleReactionMinor optimizations
lineHeightcached in ref (avoidsgetComputedStyleon every keystroke)sendDisabledmemoized viauseMemoFiles Changed (9 files)
desktop/src/app/AppShell.tsx— stable handler refs, extracted callbacksdesktop/src/app/ChannelPane.tsx—React.memodesktop/src/app/useChannelPaneHandlers.ts— NEW stable callback hookdesktop/src/features/messages/ui/ChannelAutocomplete.tsx—React.memodesktop/src/features/messages/ui/ComposerEmojiPicker.tsx—React.memodesktop/src/features/messages/ui/MentionAutocomplete.tsx—React.memodesktop/src/features/messages/ui/MessageComposer.tsx— ref-based callbacks, cached lineHeightdesktop/src/features/messages/ui/MessageComposerToolbar.tsx—React.memodesktop/src/features/messages/ui/MessageTimeline.tsx—React.memoFuture Work (low priority)
MessageComposeritself + stabilize computed props inChannelPaneTypingIndicatorRowlineHeightRefinvalidation on theme/font-size changesTesting
tsc --noEmit✅biome check✅ (only pre-existing warnings)