Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Consolidate Message Scrolling & other Logic to Custom Hooks 🔄 #1257

Merged
merged 2 commits into from
Dec 2, 2023

Conversation

danny-avila
Copy link
Owner

@danny-avila danny-avila commented Dec 2, 2023

Summary

I've made significant changes to improve the message scrolling functionality. My main motivation was to eliminate unnecessary prop drilling and the direct invocation of the ScrollToBottom method scattered across different components. ScrollToBottom was being called on each message render; while not a performance blocker, it was unnecessary and added confusing intermingling of logic.

To achieve this, I created a custom hook useMessageScrolling that centralizes all scrolling logic. Additionally, I introduced useMessageHelpers, a new hook dedicated to housing message utilities and abstracting logic away from the main Message component. These changes not only lead to cleaner code and enhanced maintainability, but will pave the way for virtualization in a later update.

With the growing number of custom hooks, I am starting to organize these as subfolders in the hooks directory with this update.

Ensured all scrolling behavior works as before.

Change Type

  • New feature (non-breaking change which adds functionality)
  • Refactor (non-breaking change which optimizes code)

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

- feat: useMessageScrolling: consolidates all scrolling logic to hook
- feat: useMessageHelpers: creates message utilities and consolidates logic from UI component
@danny-avila danny-avila merged commit 4674a54 into main Dec 2, 2023
1 check passed
@danny-avila danny-avila deleted the messages-refactor branch December 2, 2023 00:54
shortpoet pushed a commit to shortpoet/LibreChat that referenced this pull request Dec 3, 2023
… 🔄 (danny-avila#1257)

* refactor: remove unnecessary drilling/invoking of ScrollToBottom
- feat: useMessageScrolling: consolidates all scrolling logic to hook
- feat: useMessageHelpers: creates message utilities and consolidates logic from UI component

* fix: ensure automatic scrolling is triggered by messagesTree re-render and is throttled
cnkang pushed a commit to cnkang/LibreChat that referenced this pull request Feb 6, 2024
… 🔄 (danny-avila#1257)

* refactor: remove unnecessary drilling/invoking of ScrollToBottom
- feat: useMessageScrolling: consolidates all scrolling logic to hook
- feat: useMessageHelpers: creates message utilities and consolidates logic from UI component

* fix: ensure automatic scrolling is triggered by messagesTree re-render and is throttled
BertKiv pushed a commit to BertKiv/LibreChat that referenced this pull request Dec 10, 2024
… 🔄 (danny-avila#1257)

* refactor: remove unnecessary drilling/invoking of ScrollToBottom
- feat: useMessageScrolling: consolidates all scrolling logic to hook
- feat: useMessageHelpers: creates message utilities and consolidates logic from UI component

* fix: ensure automatic scrolling is triggered by messagesTree re-render and is throttled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant