mirror of https://github.com/vuejs/core.git
dx(reactivity): disable recursive computed warning by default
Now can be enabled with app.config.warnRecursiveComputed option. close #10341
This commit is contained in:
parent
21e0d6b145
commit
b31dd7468b
|
@ -42,6 +42,11 @@ export class ComputedRefImpl<T> {
|
||||||
|
|
||||||
public _cacheable: boolean
|
public _cacheable: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dev only
|
||||||
|
*/
|
||||||
|
_warnRecursive?: boolean
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private getter: ComputedGetter<T>,
|
private getter: ComputedGetter<T>,
|
||||||
private readonly _setter: ComputedSetter<T>,
|
private readonly _setter: ComputedSetter<T>,
|
||||||
|
@ -74,7 +79,9 @@ export class ComputedRefImpl<T> {
|
||||||
}
|
}
|
||||||
trackRefValue(self)
|
trackRefValue(self)
|
||||||
if (self.effect._dirtyLevel >= DirtyLevels.MaybeDirty_ComputedSideEffect) {
|
if (self.effect._dirtyLevel >= DirtyLevels.MaybeDirty_ComputedSideEffect) {
|
||||||
__DEV__ && warn(COMPUTED_SIDE_EFFECT_WARN, `\n\ngetter: `, this.getter)
|
if (__DEV__ && (__TEST__ || this._warnRecursive)) {
|
||||||
|
warn(COMPUTED_SIDE_EFFECT_WARN, `\n\ngetter: `, this.getter)
|
||||||
|
}
|
||||||
triggerRefValue(self, DirtyLevels.MaybeDirty_ComputedSideEffect)
|
triggerRefValue(self, DirtyLevels.MaybeDirty_ComputedSideEffect)
|
||||||
}
|
}
|
||||||
return self._value
|
return self._value
|
||||||
|
|
|
@ -43,6 +43,7 @@ export {
|
||||||
type WritableComputedOptions,
|
type WritableComputedOptions,
|
||||||
type ComputedGetter,
|
type ComputedGetter,
|
||||||
type ComputedSetter,
|
type ComputedSetter,
|
||||||
|
type ComputedRefImpl,
|
||||||
} from './computed'
|
} from './computed'
|
||||||
export { deferredComputed } from './deferredComputed'
|
export { deferredComputed } from './deferredComputed'
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
import { computed as _computed } from '@vue/reactivity'
|
import { type ComputedRefImpl, computed as _computed } from '@vue/reactivity'
|
||||||
import { isInSSRComponentSetup } from './component'
|
import { getCurrentInstance, isInSSRComponentSetup } from './component'
|
||||||
|
|
||||||
export const computed: typeof _computed = (
|
export const computed: typeof _computed = (
|
||||||
getterOrOptions: any,
|
getterOrOptions: any,
|
||||||
debugOptions?: any,
|
debugOptions?: any,
|
||||||
) => {
|
) => {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
return _computed(getterOrOptions, debugOptions, isInSSRComponentSetup)
|
const c = _computed(getterOrOptions, debugOptions, isInSSRComponentSetup)
|
||||||
|
if (__DEV__) {
|
||||||
|
const i = getCurrentInstance()
|
||||||
|
if (i && i.appContext.config.warnRecursiveComputed) {
|
||||||
|
;(c as unknown as ComputedRefImpl<any>)._warnRecursive = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,12 @@ export interface AppConfig {
|
||||||
* @deprecated use config.compilerOptions.isCustomElement
|
* @deprecated use config.compilerOptions.isCustomElement
|
||||||
*/
|
*/
|
||||||
isCustomElement?: (tag: string) => boolean
|
isCustomElement?: (tag: string) => boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO document for 3.5
|
||||||
|
* Enable warnings for computed getters that recursively trigger itself.
|
||||||
|
*/
|
||||||
|
warnRecursiveComputed?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppContext {
|
export interface AppContext {
|
||||||
|
|
Loading…
Reference in New Issue