diff --git a/packages/twenty-front/src/modules/ui/utilities/scroll/constants/ScrollRestorationTopThreshold.ts b/packages/twenty-front/src/modules/ui/utilities/scroll/constants/ScrollRestorationTopThreshold.ts new file mode 100644 index 0000000000..679b88d5fb --- /dev/null +++ b/packages/twenty-front/src/modules/ui/utilities/scroll/constants/ScrollRestorationTopThreshold.ts @@ -0,0 +1 @@ +export const SCROLL_RESTORATION_TOP_THRESHOLD_PX = 3; diff --git a/packages/twenty-front/src/modules/ui/utilities/scroll/hooks/useScrollRestoration.ts b/packages/twenty-front/src/modules/ui/utilities/scroll/hooks/useScrollRestoration.ts index 9eceed5c3f..db9ad13a3e 100644 --- a/packages/twenty-front/src/modules/ui/utilities/scroll/hooks/useScrollRestoration.ts +++ b/packages/twenty-front/src/modules/ui/utilities/scroll/hooks/useScrollRestoration.ts @@ -1,3 +1,4 @@ +import { SCROLL_RESTORATION_TOP_THRESHOLD_PX } from '@/ui/utilities/scroll/constants/ScrollRestorationTopThreshold'; import { scrollWrapperScrollTopComponentState } from '@/ui/utilities/scroll/states/scrollWrapperScrollTopComponentState'; import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; import { useCallback, useEffect, useState } from 'react'; @@ -43,9 +44,14 @@ export const useScrollRestoration = (componentInstanceId: string) => { ); useEffect(() => { - if (scrollTop > 0 && !isRestoring) { - sessionStorage.setItem(storageKey, scrollTop.toString()); + if (isRestoring) return; + + if (scrollTop <= SCROLL_RESTORATION_TOP_THRESHOLD_PX) { + sessionStorage.removeItem(storageKey); + return; } + + sessionStorage.setItem(storageKey, scrollTop.toString()); }, [scrollTop, storageKey, isRestoring]); useEffect(() => {