From fc324d07cdf78456ed15d0a26c78b0dceb3ac284 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 8 Jun 2022 07:17:00 -0400 Subject: [PATCH] Dashboard: Fixes random scrolling on time range change (#50379) (#50383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Dashboard: Fixes random scrolling on time range change * fix ts issue * removed logging (cherry picked from commit fd408652dc653a6019fda08b5f55de7c4ef60522) Co-authored-by: Torkel Ödegaard --- .../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 a5091495894..301add0db67 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'; @@ -44,28 +43,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;