Commit 716275d 1 parent c74176e commit 716275d Copy full SHA for 716275d
File tree 2 files changed +46
-1
lines changed
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 ,
@@ -958,4 +961,46 @@ describe('reactivity/computed', () => {
958
961
newValue : 2 ,
959
962
} )
960
963
} )
964
+
965
+ test ( 'should prevent endless recursion in self-referencing computed getters' , async ( ) => {
966
+ const Comp = defineComponent ( {
967
+ data ( ) {
968
+ return {
969
+ counter : 0 ,
970
+ }
971
+ } ,
972
+
973
+ computed : {
974
+ message ( ) : string {
975
+ if ( this . counter === 0 ) {
976
+ this . counter ++
977
+ return this . message
978
+ } else {
979
+ return `Step ${ this . counter } `
980
+ }
981
+ } ,
982
+ } ,
983
+
984
+ render ( ) {
985
+ return [
986
+ h (
987
+ 'button' ,
988
+ {
989
+ onClick : ( ) => {
990
+ this . counter ++
991
+ } ,
992
+ } ,
993
+ 'Step' ,
994
+ ) ,
995
+ h ( 'p' , this . message ) ,
996
+ ]
997
+ } ,
998
+ } )
999
+ const root = nodeOps . createElement ( 'div' )
1000
+ render ( h ( Comp ) , root )
1001
+ expect ( serializeInner ( root ) ) . toBe ( `<button>Step</button><p></p>` )
1002
+ triggerEvent ( root . children [ 1 ] as TestElement , 'click' )
1003
+ await nextTick ( )
1004
+ expect ( serializeInner ( root ) ) . toBe ( `<button>Step</button><p>Step 2</p>` )
1005
+ } )
961
1006
} )
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