File tree Expand file tree Collapse file tree 4 files changed +25
-4
lines changed Expand file tree Collapse file tree 4 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ export class ComputedRefImpl<T> {
42
42
43
43
public _cacheable : boolean
44
44
45
+ /**
46
+ * Dev only
47
+ */
48
+ _warnRecursive ?: boolean
49
+
45
50
constructor (
46
51
private getter : ComputedGetter < T > ,
47
52
private readonly _setter : ComputedSetter < T > ,
@@ -74,7 +79,9 @@ export class ComputedRefImpl<T> {
74
79
}
75
80
trackRefValue ( self )
76
81
if ( self . effect . _dirtyLevel >= DirtyLevels . MaybeDirty_ComputedSideEffect ) {
77
- __DEV__ && warn ( COMPUTED_SIDE_EFFECT_WARN , `\n\ngetter: ` , this . getter )
82
+ if ( __DEV__ && ( __TEST__ || this . _warnRecursive ) ) {
83
+ warn ( COMPUTED_SIDE_EFFECT_WARN , `\n\ngetter: ` , this . getter )
84
+ }
78
85
triggerRefValue ( self , DirtyLevels . MaybeDirty_ComputedSideEffect )
79
86
}
80
87
return self . _value
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ export {
43
43
type WritableComputedOptions ,
44
44
type ComputedGetter ,
45
45
type ComputedSetter ,
46
+ type ComputedRefImpl ,
46
47
} from './computed'
47
48
export { deferredComputed } from './deferredComputed'
48
49
export {
Original file line number Diff line number Diff line change 1
- import { computed as _computed } from '@vue/reactivity'
2
- import { isInSSRComponentSetup } from './component'
1
+ import { type ComputedRefImpl , computed as _computed } from '@vue/reactivity'
2
+ import { getCurrentInstance , isInSSRComponentSetup } from './component'
3
3
4
4
export const computed : typeof _computed = (
5
5
getterOrOptions : any ,
6
6
debugOptions ?: any ,
7
7
) => {
8
8
// @ts -expect-error
9
- return _computed ( getterOrOptions , debugOptions , isInSSRComponentSetup )
9
+ const c = _computed ( getterOrOptions , debugOptions , isInSSRComponentSetup )
10
+ if ( __DEV__ ) {
11
+ const i = getCurrentInstance ( )
12
+ if ( i && i . appContext . config . warnRecursiveComputed ) {
13
+ ; ( c as unknown as ComputedRefImpl < any > ) . _warnRecursive = true
14
+ }
15
+ }
16
+ return c
10
17
}
Original file line number Diff line number Diff line change @@ -110,6 +110,12 @@ export interface AppConfig {
110
110
* @deprecated use config.compilerOptions.isCustomElement
111
111
*/
112
112
isCustomElement ?: ( tag : string ) => boolean
113
+
114
+ /**
115
+ * TODO document for 3.5
116
+ * Enable warnings for computed getters that recursively trigger itself.
117
+ */
118
+ warnRecursiveComputed ?: boolean
113
119
}
114
120
115
121
export interface AppContext {
You can’t perform that action at this time.
0 commit comments