From fd408652dc653a6019fda08b5f55de7c4ef60522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 8 Jun 2022 10:34:44 +0200 Subject: [PATCH] Dashboard: Fixes random scrolling on time range change (#50379) * Dashboard: Fixes random scrolling on time range change * fix ts issue * removed logging --- .../CustomScrollbar/CustomScrollbar.tsx | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx b/packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx index f860dccebd0..9fb2443c081 100644 --- a/packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx +++ b/packages/grafana-ui/src/components/CustomScrollbar/CustomScrollbar.tsx @@ -1,6 +1,5 @@ import { css } from '@emotion/css'; import classNames from 'classnames'; -import { isNil } from 'lodash'; import React, { FC, RefCallback, useCallback, useEffect, useRef } from 'react'; import Scrollbars, { positionValues } from 'react-custom-scrollbars-2'; @@ -46,28 +45,24 @@ export const CustomScrollbar: FC = ({ children, }) => { const ref = useRef(null); - useEffect(() => { - if (ref.current) { - scrollRefCallback?.(ref.current.view); - } - }, [ref, scrollRefCallback]); const styles = useStyles2(getStyles); - const updateScroll = () => { - if (ref.current && !isNil(scrollTop)) { - ref.current.scrollTop(scrollTop); + useEffect(() => { + if (ref.current && scrollRefCallback) { + scrollRefCallback(ref.current.view); } - }; + }, [ref, scrollRefCallback]); useEffect(() => { - updateScroll(); - }); + if (ref.current && scrollTop != null) { + ref.current.scrollTop(scrollTop); + } + }, [scrollTop]); /** * Special logic for doing a update a few milliseconds after mount to check for * updated height due to dynamic content */ - useEffect(() => { if (!updateAfterMountMs) { return;