Skip to content

Commit

Permalink
fix(until): cleanup at next tick to avoid memory leak (#4039)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <github@antfu.me>
Co-authored-by: delaneyb <delaneyb@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 17, 2024
1 parent 06c6f37 commit 8a023fe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/shared/until/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { WatchOptions, WatchSource } from 'vue-demi'
import { isRef, watch } from 'vue-demi'
import { isRef, nextTick, watch } from 'vue-demi'
import { toValue } from '../toValue'
import type { ElementOf, MaybeRefOrGetter, ShallowUnwrapRef } from '../utils'
import { promiseTimeout } from '../utils'
Expand Down Expand Up @@ -76,7 +76,10 @@ function createUntil<T>(r: any, isNot = false) {
r,
(v) => {
if (condition(v) !== isNot) {
stop?.()
if (stop)
stop()
else
nextTick(() => stop?.())
resolve(v)
}
},
Expand Down Expand Up @@ -111,7 +114,10 @@ function createUntil<T>(r: any, isNot = false) {
[r, value],
([v1, v2]) => {
if (isNot !== (v1 === v2)) {
stop?.()
if (stop)
stop()
else
nextTick(() => stop?.())
resolve(v1)
}
},
Expand Down

0 comments on commit 8a023fe

Please sign in to comment.