From 86bd8e8f355b34a56bd69dc78b9e108f848b6c6a Mon Sep 17 00:00:00 2001 From: Nico Prat Date: Thu, 9 Nov 2023 19:12:37 +0100 Subject: [PATCH] fix(useScroll): trigger once `onMounted` to get correct inital arrivedStates values (#3384) Co-authored-by: Anthony Fu --- packages/core/useScroll/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/useScroll/index.ts b/packages/core/useScroll/index.ts index b664565fec2..0988c125eb4 100644 --- a/packages/core/useScroll/index.ts +++ b/packages/core/useScroll/index.ts @@ -1,6 +1,6 @@ import { computed, reactive, ref } from 'vue-demi' import type { MaybeRefOrGetter } from '@vueuse/shared' -import { noop, toValue, useDebounceFn, useThrottleFn } from '@vueuse/shared' +import { noop, toValue, tryOnMounted, useDebounceFn, useThrottleFn } from '@vueuse/shared' import { useEventListener } from '../useEventListener' import type { ConfigurableWindow } from '../_configurable' import { defaultWindow } from '../_configurable' @@ -250,6 +250,10 @@ export function useScroll( eventListenerOptions, ) + tryOnMounted(() => { + setArrivedState(toValue(element)) + }) + useEventListener( element, 'scrollend',