File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
+ type TestElement ,
3
+ defineComponent ,
2
4
h ,
3
5
nextTick ,
4
6
nodeOps ,
5
7
onMounted ,
6
8
onUnmounted ,
7
9
render ,
8
10
serializeInner ,
11
+ triggerEvent ,
9
12
} from '@vue/runtime-test'
10
13
import {
11
14
type DebuggerEvent ,
@@ -944,4 +947,46 @@ describe('reactivity/computed', () => {
944
947
newValue : 2 ,
945
948
} )
946
949
} )
950
+
951
+ test ( 'should prevent endless recursion in self-referencing computed getters' , async ( ) => {
952
+ const Comp = defineComponent ( {
953
+ data ( ) {
954
+ return {
955
+ counter : 0 ,
956
+ }
957
+ } ,
958
+
959
+ computed : {
960
+ message ( ) : string {
961
+ if ( this . counter === 0 ) {
962
+ this . counter ++
963
+ return this . message
964
+ } else {
965
+ return `Step ${ this . counter } `
966
+ }
967
+ } ,
968
+ } ,
969
+
970
+ render ( ) {
971
+ return [
972
+ h (
973
+ 'button' ,
974
+ {
975
+ onClick : ( ) => {
976
+ this . counter ++
977
+ } ,
978
+ } ,
979
+ 'Step' ,
980
+ ) ,
981
+ h ( 'p' , this . message ) ,
982
+ ]
983
+ } ,
984
+ } )
985
+ const root = nodeOps . createElement ( 'div' )
986
+ render ( h ( Comp ) , root )
987
+ expect ( serializeInner ( root ) ) . toBe ( `<button>Step</button><p></p>` )
988
+ triggerEvent ( root . children [ 1 ] as TestElement , 'click' )
989
+ await nextTick ( )
990
+ expect ( serializeInner ( root ) ) . toBe ( `<button>Step</button><p>Step 2</p>` )
991
+ } )
947
992
} )
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ export class Dep {
46
46
}
47
47
48
48
track ( debugInfo ?: DebuggerEventExtraInfo ) : Link | undefined {
49
- if ( ! activeSub || ! shouldTrack ) {
49
+ if ( ! activeSub || ! shouldTrack || activeSub === this . computed ) {
50
50
return
51
51
}
52
52
You can’t perform that action at this time.
0 commit comments