Repository navigation
perf: message actions hook invocations - #3866
Open
isekovanic wants to merge 4 commits into
Open
isekovanic wants to merge 4 commits into
isekovanic wants to merge 4 commits into
Conversation
Contributor
SDK Size
|
This branch has not been deployed
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.
🎯 Goal
Every
Messagerow builds the full set of message actions on every render, even though the action menu is closed almost all of the time.useMessageActionHandlersruns twice per row (once directly and once insideuseMessageActions),useMessageActionsbuilt 15 action objects with icons and translated titles and themessageActionsfunction from<Channel>was called on every render. On top of that we had store subscriptions as well. In other words, lots and lots of wasted JS work.This PR moves the action work to the moment a message's menu opens and removes the per row subscriptions.
🛠 Implementation details
Messagebuilds its handlers once per row with the new internaluseCreateMessageActionHandlers. The handlers hold no subscriptions and read mute, ban and block state and the translated text for Copy when they run.MessageContext.messageActionHandlers. The menu uses the row's handlers instead of building its own. Queued menu actions run after the overlay closes but before the menu unmounts and Edit relies on deferred work (portal settle and keyboard focus) that the menu's unmount cleanup would otherwise cancel.MessageActionListWithActionsincomponents/MessageMenu, which only mounts while a message's overlay is open. It readsmessageActionsfromMessagesContextand passes the finished list to theMessageActionListslot, so customMessageActionListimplementations receive the same props as before.As usual, here's the actual reduction in JS work (measured on Android):
Messagebody JS while opening and scrolling 100 rows (FlatList, 103 renders, median)mutedUsersStoresubscriptions with 100 rows mountedMessagebody JS spent on that mute (median)Breaking changes
useMessageActions()anduseMessageActionHandlers()no longer take arguments and read everything from the contexts of the message they are called in.MessageActionsHookPropsis removed. Both hooks have to be called inside a message, for example in a custom message component or a customMessageActionList.handleXcallbacks andmessageActionspassed directly to<Message>(for example from a customMessageoverride) no longer reach the action menu. They need to be set on<Channel>. Per-message customisation goes through themessageActionsfunction, which receives the message.messageActionsfunction now runs when a message's menu opens instead of on every render of every row.🎨 UI Changes
/
🧪 Testing
/
☑️ Checklist
developbranch