From e888f585d398469ca0d9af8725c83a8dd2902e77 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Wed, 25 Oct 2023 10:59:54 +0800 Subject: [PATCH] asdf --- .../__tests__/deferredComputed.spec.ts | 1 + packages/reactivity/src/ref.ts | 61 ++++++++----------- vitest.config.ts | 3 +- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/packages/reactivity/__tests__/deferredComputed.spec.ts b/packages/reactivity/__tests__/deferredComputed.spec.ts index 6a75daa98e6..8e78ba959c3 100644 --- a/packages/reactivity/__tests__/deferredComputed.spec.ts +++ b/packages/reactivity/__tests__/deferredComputed.spec.ts @@ -15,6 +15,7 @@ describe('deferred computed', () => { expect(spy).toHaveBeenCalledTimes(1) src.value = 3 + src.value = 5 // should trigger because latest value changes expect(spy).toHaveBeenCalledTimes(2) }) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 90c564ed8b5..5a4dd710eab 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -41,30 +41,21 @@ type RefBase = { export function trackRefValue(ref: RefBase) { if (shouldTrack && activeEffect) { ref = toRaw(ref) - if (__DEV__) { - trackEffect( - activeEffect, - ref.dep || - (ref.dep = createDep( - () => (ref.dep = undefined), - ref instanceof ComputedRefImpl ? ref : undefined - )), - { - target: ref, - type: TrackOpTypes.GET, - key: 'value' - } - ) - } else { - trackEffect( - activeEffect, - ref.dep || - (ref.dep = createDep( - () => (ref.dep = undefined), - ref instanceof ComputedRefImpl ? ref : undefined - )) - ) - } + trackEffect( + activeEffect, + ref.dep || + (ref.dep = createDep( + () => (ref.dep = undefined), + ref instanceof ComputedRefImpl ? ref : undefined + )), + __DEV__ + ? { + target: ref, + type: TrackOpTypes.GET, + key: 'value' + } + : void 0 + ) } } @@ -76,16 +67,18 @@ export function triggerRefValue( ref = toRaw(ref) const dep = ref.dep if (dep) { - if (__DEV__) { - triggerEffects(dep, dirtyLevel, { - target: ref, - type: TriggerOpTypes.SET, - key: 'value', - newValue: newVal - }) - } else { - triggerEffects(dep, dirtyLevel) - } + triggerEffects( + dep, + dirtyLevel, + __DEV__ + ? { + target: ref, + type: TriggerOpTypes.SET, + key: 'value', + newValue: newVal + } + : void 0 + ) } } diff --git a/vitest.config.ts b/vitest.config.ts index 38bd6a469b0..a829c130725 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -22,8 +22,7 @@ export default defineConfig({ }, test: { globals: true, - // threads must be disabled because FinalizationRegistry.register is used in the code - // and multi-threading causes thread locks for some reasons + // threads must be disabled as FinalizationRegistry causes vitest zombie process somehow threads: false, setupFiles: 'scripts/setupVitest.ts', environmentMatchGlobs: [