Skip to content

Commit

Permalink
Fix (hopefully?) janky scroll behavior
Browse files Browse the repository at this point in the history
Previously it had essentially been hand-calculating offsets for the top
of the scroll element, I basically just removed the offsets; I believe
that it was intended to work with the math of the newly added elements
to track what is visible and what needs to be rendered, but you don't
actually need to offset it by the width of the scroll on the page to do
that I think?

Anyways this keeps the virtualization element intact - spam words and
then open inspector on it and scroll up/down and you'll see the list
being of the same size.
  • Loading branch information
MoyTW committed Oct 21, 2022
1 parent 6a0cd95 commit b969d0f
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/components/MessageList/hooks/useAutoscroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const useAutoscroll = (

virtualizaitonDispatch({
type: 'setViewportScrollHeight',
payload: scrollContainerRef.current.clientHeight
payload: 0
})

dispatch(ChatReadyAction())
Expand All @@ -62,20 +62,6 @@ export const useAutoscroll = (
({ currentTarget }) => {
const { clientHeight, scrollTop, scrollHeight } = currentTarget

/**
* prevent scrolling back past the first/oldest message
*/
const minScrollTop =
viewportScrollHeightRef.current - clientHeight < clientHeight
? viewportScrollHeightRef.current - clientHeight
: clientHeight
if (
// scrollTop < viewportScrollTopRef.current &&
scrollTop < minScrollTop
) {
currentTarget.scrollTop = minScrollTop
}

/**
* enable/disable "autoscroll" which is, scroll to the end of the
* viewport's scroll height as messages come in
Expand All @@ -97,7 +83,7 @@ export const useAutoscroll = (
*/
virtualizaitonDispatch({
type: 'setViewportScrollTop',
payload: Math.max(minScrollTop, scrollTop)
payload: Math.max(scrollTop)
})
},
[autoscrollChat, dispatch, virtualizaitonDispatch]
Expand Down

0 comments on commit b969d0f

Please sign in to comment.