🧵 fix: Prevent Unnecessary Re-renders when Loading Chats #5189
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
I optimized to prevent unnecessary re-renders when loading conversations initially
useCallback
to preventbuildTree
from unnecessarily invoking more than once on initial conversation load.queryClient
to reset message data when initiating a new conversation.data-testid
attributes for consistency and improved code readability.useQueryParams
cleanup.Closes #5185
Change Type
Testing
I tested the changes by loading conversations with over 1000 messages and verified that the application does not re-render unnecessarily or crash with recursion error. I ensured that starting new conversations resets message data correctly and that icon rendering works as expected. I also checked that
data-testid
attributes are consistent and that there are no console errors or warnings.Checklist