Commit ad9879b4 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: avoid scrollTo on pageload (#7323)

parent c528c616
...@@ -2,6 +2,7 @@ import { BrowserEvent, InterfaceEventName } from '@uniswap/analytics-events' ...@@ -2,6 +2,7 @@ import { BrowserEvent, InterfaceEventName } from '@uniswap/analytics-events'
import { TraceEvent } from 'analytics' import { TraceEvent } from 'analytics'
import { ScrollBarStyles } from 'components/Common' import { ScrollBarStyles } from 'components/Common'
import useDisableScrolling from 'hooks/useDisableScrolling' import useDisableScrolling from 'hooks/useDisableScrolling'
import usePrevious from 'hooks/usePrevious'
import { useWindowSize } from 'hooks/useWindowSize' import { useWindowSize } from 'hooks/useWindowSize'
import { atom } from 'jotai' import { atom } from 'jotai'
import { useAtomValue, useUpdateAtom } from 'jotai/utils' import { useAtomValue, useUpdateAtom } from 'jotai/utils'
...@@ -166,12 +167,13 @@ const CloseDrawer = styled.div` ...@@ -166,12 +167,13 @@ const CloseDrawer = styled.div`
function AccountDrawer() { function AccountDrawer() {
const [walletDrawerOpen, toggleWalletDrawer] = useAccountDrawer() const [walletDrawerOpen, toggleWalletDrawer] = useAccountDrawer()
const wasWalletDrawerOpen = usePrevious(walletDrawerOpen)
const scrollRef = useRef<HTMLDivElement>(null) const scrollRef = useRef<HTMLDivElement>(null)
useEffect(() => { useEffect(() => {
if (!walletDrawerOpen) { if (wasWalletDrawerOpen && !walletDrawerOpen) {
scrollRef.current?.scrollTo({ top: 0, behavior: 'smooth' }) scrollRef.current?.scrollTo({ top: 0, behavior: 'smooth' })
} }
}, [walletDrawerOpen]) }, [walletDrawerOpen, wasWalletDrawerOpen])
// close on escape keypress // close on escape keypress
useEffect(() => { useEffect(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment