Skip to content

Commit

Permalink
fix: ssr compat
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Oct 27, 2023
1 parent be977c7 commit 9240573
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/useSpring.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
computed,
onMounted,
onUnmounted,
reactive,
ref,
watch,
Expand All @@ -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'
Expand Down Expand Up @@ -98,7 +97,8 @@ export function useSpring<T extends MaybeRefOrGetter<SpringValue>>(
let idealValues = current[0]
let idealVelocities = current[1]

onMounted(() => {
// only run this code on client
if (typeof window === 'undefined') {
prevTime = now()
accumulatedTime = 0

Expand All @@ -111,11 +111,11 @@ export function useSpring<T extends MaybeRefOrGetter<SpringValue>>(
idealVelocities = ideal[1]

animate()
})
}

let animationId: number | void | undefined | null
// TODO: also cancel when a new value comes
onUnmounted(() => {
onScopeDispose(() => {
if (animationId) {
cancelRaf(animationId)
}
Expand Down

0 comments on commit 9240573

Please sign in to comment.