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

Simplify [UI/UX] [Chat] [Front End] scrollDomToBottom #4021

Closed
wants to merge 1 commit into from

Conversation

H0llyW00dzZ
Copy link
Contributor

  • [+] refactor(chat.tsx): improve smooth scrolling behavior in useScrollToBottom function

Issues:

- [+] refactor(chat.tsx): improve smooth scrolling behavior in useScrollToBottom function
Copy link

vercel bot commented Feb 7, 2024

@H0llyW00dzZ is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

github-actions bot commented Feb 7, 2024

Your build has completed!

Preview deployment

@H0llyW00dzZ
Copy link
Contributor Author

H0llyW00dzZ commented Feb 7, 2024

Note

This so smoothly unlike stupid typescript using requestAnimationFrame that complexity

@kyboi
Copy link

kyboi commented Feb 21, 2024

This works well, also allows scrolling back up while response is still streaming. However, sometimes it won't keep scrolling down even if nothing was touched and the answer is still streaming in.

@H0llyW00dzZ
Copy link
Contributor Author

H0llyW00dzZ commented Feb 21, 2024

This works well, also allows scrolling back up while response is still streaming. However, sometimes it won't keep scrolling down even if nothing was touched and the answer is still streaming in.

haven't improve yet, its very complexity because of codebase too large and other, Also I am still figure out to made it better

@H0llyW00dzZ
Copy link
Contributor Author

anyway its difficult to maintain especially for improve, because of stupid complexity that I don't fucking understand about frontend especially react,typescript unlike backend written in go

@kyboi
Copy link

kyboi commented Feb 22, 2024

If found it's the actual smooth scrolling that breaks this. If you make it immediately update the scrolling position it keeps scrolling down, unless the user scrolls back up.

See 4b3c41a for an example

@H0llyW00dzZ
Copy link
Contributor Author

If found it's the actual smooth scrolling that breaks this. If you make it immediately update the scrolling position it keeps scrolling down, unless the user scrolls back up.

See 4b3c41a for an example

wait I think I know how to improve it

@H0llyW00dzZ
Copy link
Contributor Author

H0llyW00dzZ commented Feb 22, 2024

this a better one but not smoothly, can scroll up to 999999+ messages combine with this commit 4b3c41a + using react custom hook

https://imgur.com/hmmDqkt

@H0llyW00dzZ
Copy link
Contributor Author

the custom hook:

// Custom hook for debouncing a function
function useDebouncedEffect(effect: () => void, deps: any[], delay: number) {
  // Include `effect` in the dependency array for `useCallback`
  const callback = useCallback(effect, [effect, ...deps]);

  useEffect(() => {
    const handler = debounce(callback, delay);

    handler();

    // Cleanup function to cancel the debounced call if the component unmounts
    return () => handler.cancel();
  }, [callback, delay]); // `callback` already includes `effect` in its dependencies, so no need to add it here again.
}

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.

3 participants