perf: tweaks to speed up sidebar transition on desktop #3120
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.
(partially) Fixes LAND-1360 by reducing re-rendering throughout the Sidebar and GroupSidebar components and their children.
One major source of re-rendering was the data from useGroup() getting wiped on navigating away from a group, which caused the GroupSidebar itself to re-render and show loading state/skeleton on the way out. I added
keepPreviousData
to the useGroup() query to keep current data until we want to load in a new group.I also memoized as much as seemed appropriate throughout.
I played around with animationConfig settings in GroupsNav, but nothing stood out as actually improving the perceived speed.
I also attempted to use framer-motion's
useIsPresent
hook to prevent certain components from rendering (including preventing group images from loading in the sidebar), but it usually either didn't make an appreciable difference or it added too much overhead for it to be worth it.I also realized that the number of notifications in the Activity list in the home screen has an effect on how quickly we transition from viewing a group to returning to the home screen, and attempted to mitigate this by using Virtuoso to turn the notifications list into a virtualized list. This didn't make any appreciable difference. I think we ought to think of other ways to optimize here (maybe we ought to page the notifications?).
To get a good feel of how these changes will actually feel in production, I recommend running a build, running serve, and pointing the frontend at your personal ship. If you want to see what I'm talking about, re: the notifications themselves causing it to feel slow, make sure you have a lot of notifications. You ought to also test in Safari, where the issue was most pronounced.
Here is how it looks now in that scenario:
Screen.Recording.2023-12-11.at.2.54.32.PM.mov