From 92405735cfe844bc5714571121aa1e8947427a0c Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 27 Oct 2023 14:29:59 +0200 Subject: [PATCH] fix: ssr compat --- src/useSpring.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/useSpring.ts b/src/useSpring.ts index 3992336..24ed0f2 100644 --- a/src/useSpring.ts +++ b/src/useSpring.ts @@ -1,7 +1,5 @@ import { computed, - onMounted, - onUnmounted, reactive, ref, watch, @@ -10,6 +8,7 @@ import { Ref, isRef, UnwrapRef, + onScopeDispose, } from 'vue-demi' import { SpringConfig, noWobble } from './presets' import { raf, cancelRaf, now, isArray, stepper } from './utils' @@ -98,7 +97,8 @@ export function useSpring>( let idealValues = current[0] let idealVelocities = current[1] - onMounted(() => { + // only run this code on client + if (typeof window === 'undefined') { prevTime = now() accumulatedTime = 0 @@ -111,11 +111,11 @@ export function useSpring>( idealVelocities = ideal[1] animate() - }) + } let animationId: number | void | undefined | null // TODO: also cancel when a new value comes - onUnmounted(() => { + onScopeDispose(() => { if (animationId) { cancelRaf(animationId) }