From 0a49ea4dacbd98cdeb6e4be1bba3bc9347a8845a Mon Sep 17 00:00:00 2001 From: huodoushigemi <2629878269@qq.com> Date: Wed, 9 Nov 2022 09:50:34 +0800 Subject: [PATCH] fix(useTransition): call pause() to stop useRafFn when disabling (#2360) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 李众豪 Co-authored-by: Anthony Fu --- packages/core/useTransition/index.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/core/useTransition/index.ts b/packages/core/useTransition/index.ts index 7c46b5ddbff..ec34a74e622 100644 --- a/packages/core/useTransition/index.ts +++ b/packages/core/useTransition/index.ts @@ -199,15 +199,19 @@ export function useTransition( const timeout = useTimeoutFn(start, delay, { immediate: false }) watch(sourceVector, () => { - if (unref(disabled)) { + if (unref(disabled)) + return + if (unref(delay) <= 0) + start() + else timeout.start() + }, { deep: true }) + + watch(() => unref(disabled), (v) => { + if (v) { outputVector.value = sourceVector.value.slice(0) + pause() } - else { - if (unref(delay) <= 0) - start() - else timeout.start() - } - }, { deep: true }) + }) return computed(() => { const targetVector = unref(disabled) ? sourceVector : outputVector