Skip to content

Commit 43e2ea8

Browse files
committed
chore: adjust warning
1 parent ea56705 commit 43e2ea8

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

packages/reactivity/__tests__/computed.spec.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import {
1616
import { DirtyLevels } from '../src/constants'
1717
import { COMPUTED_SIDE_EFFECT_WARN } from '../src/computed'
1818

19-
const normalizedSideEffectWarn = `[Vue warn] ${COMPUTED_SIDE_EFFECT_WARN}`
20-
2119
describe('reactivity/computed', () => {
2220
it('should return updated value', () => {
2321
const value = reactive<{ foo?: number }>({})
@@ -491,7 +489,7 @@ describe('reactivity/computed', () => {
491489
expect(c3.effect._dirtyLevel).toBe(
492490
DirtyLevels.MaybeDirty_ComputedSideEffect,
493491
)
494-
expect(normalizedSideEffectWarn).toHaveBeenWarned()
492+
expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
495493
})
496494

497495
it('should work when chained(ref+computed)', () => {
@@ -506,7 +504,7 @@ describe('reactivity/computed', () => {
506504
expect(c2.value).toBe('0foo')
507505
expect(c2.effect._dirtyLevel).toBe(DirtyLevels.Dirty)
508506
expect(c2.value).toBe('1foo')
509-
expect(normalizedSideEffectWarn).toHaveBeenWarned()
507+
expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
510508
})
511509

512510
it('should trigger effect even computed already dirty', () => {
@@ -529,7 +527,7 @@ describe('reactivity/computed', () => {
529527
expect(c2.effect._dirtyLevel).toBe(DirtyLevels.Dirty)
530528
v.value = 2
531529
expect(fnSpy).toBeCalledTimes(2)
532-
expect(normalizedSideEffectWarn).toHaveBeenWarned()
530+
expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
533531
})
534532

535533
// #10185
@@ -573,7 +571,7 @@ describe('reactivity/computed', () => {
573571
expect(c3.effect._dirtyLevel).toBe(DirtyLevels.MaybeDirty)
574572

575573
expect(c3.value).toBe('yes')
576-
expect(normalizedSideEffectWarn).toHaveBeenWarned()
574+
expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
577575
})
578576

579577
it('should be not dirty after deps mutate (mutate deps in computed)', async () => {
@@ -595,7 +593,7 @@ describe('reactivity/computed', () => {
595593
await nextTick()
596594
await nextTick()
597595
expect(serializeInner(root)).toBe(`2`)
598-
expect(normalizedSideEffectWarn).toHaveBeenWarned()
596+
expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
599597
})
600598

601599
it('should not trigger effect scheduler by recurse computed effect', async () => {
@@ -618,6 +616,6 @@ describe('reactivity/computed', () => {
618616
v.value += ' World'
619617
await nextTick()
620618
expect(serializeInner(root)).toBe('Hello World World World World')
621-
expect(normalizedSideEffectWarn).toHaveBeenWarned()
619+
expect(COMPUTED_SIDE_EFFECT_WARN).toHaveBeenWarned()
622620
})
623621
})

packages/reactivity/src/computed.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ export interface WritableComputedOptions<T> {
2626
}
2727

2828
export const COMPUTED_SIDE_EFFECT_WARN =
29-
`Computed keep dirty after evaluation.` +
30-
` This might happen when you mutate the deps of computed in the getter.` +
29+
`Computed is still dirty after getter evaluation,` +
30+
` likely because a computed is mutating its own dependency in its getter.` +
31+
` State mutations in computed getters should be avoided. ` +
3132
` Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`
3233

3334
export class ComputedRefImpl<T> {

0 commit comments

Comments
 (0)