mirror of https://github.com/vuejs/core.git
fix(reactivity): rely on dirty check only when computed has deps (#11931)
close #11929
This commit is contained in:
parent
346bfaf760
commit
aa5dafd2b5
|
@ -23,6 +23,7 @@ import {
|
|||
ref,
|
||||
shallowRef,
|
||||
toRaw,
|
||||
triggerRef,
|
||||
} from '../src'
|
||||
import { EffectFlags, pauseTracking, resetTracking } from '../src/effect'
|
||||
import type { ComputedRef, ComputedRefImpl } from '../src/computed'
|
||||
|
@ -1004,4 +1005,10 @@ describe('reactivity/computed', () => {
|
|||
await nextTick()
|
||||
expect(serializeInner(root)).toBe(`<button>Step</button><p>Step 2</p>`)
|
||||
})
|
||||
|
||||
it('manual trigger computed', () => {
|
||||
const cValue = computed(() => 1)
|
||||
triggerRef(cValue)
|
||||
expect(cValue.value).toBe(1)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -352,7 +352,12 @@ export function refreshComputed(computed: ComputedRefImpl): undefined {
|
|||
// and therefore tracks no deps, thus we cannot rely on the dirty check.
|
||||
// Instead, computed always re-evaluate and relies on the globalVersion
|
||||
// fast path above for caching.
|
||||
if (dep.version > 0 && !computed.isSSR && !isDirty(computed)) {
|
||||
if (
|
||||
dep.version > 0 &&
|
||||
!computed.isSSR &&
|
||||
computed.deps &&
|
||||
!isDirty(computed)
|
||||
) {
|
||||
computed.flags &= ~EffectFlags.RUNNING
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue