File tree 2 files changed +18
-3
lines changed
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -1022,4 +1022,19 @@ describe('reactivity/computed', () => {
1022
1022
state . a ++
1023
1023
expect ( p . value ) . toBe ( 3 )
1024
1024
} )
1025
+
1026
+ test ( 'computed dep cleanup should not cause property dep to be deleted' , ( ) => {
1027
+ const toggle = ref ( true )
1028
+ const state = reactive ( { a : 1 } )
1029
+ const p = computed ( ( ) => {
1030
+ return toggle . value ? state . a : 111
1031
+ } )
1032
+ const pp = computed ( ( ) => state . a )
1033
+ effect ( ( ) => p . value )
1034
+
1035
+ expect ( pp . value ) . toBe ( 1 )
1036
+ toggle . value = false
1037
+ state . a ++
1038
+ expect ( pp . value ) . toBe ( 2 )
1039
+ } )
1025
1040
} )
Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ function prepareDeps(sub: Subscriber) {
292
292
}
293
293
}
294
294
295
- function cleanupDeps ( sub : Subscriber ) {
295
+ function cleanupDeps ( sub : Subscriber , fromComputed = false ) {
296
296
// Cleanup unsued deps
297
297
let head
298
298
let tail = sub . depsTail
@@ -302,7 +302,7 @@ function cleanupDeps(sub: Subscriber) {
302
302
if ( link . version === - 1 ) {
303
303
if ( link === tail ) tail = prev
304
304
// unused - remove it from the dep's subscribing effect list
305
- removeSub ( link )
305
+ removeSub ( link , fromComputed )
306
306
// also remove it from this effect's dep list
307
307
removeDep ( link )
308
308
} else {
@@ -394,7 +394,7 @@ export function refreshComputed(computed: ComputedRefImpl): undefined {
394
394
} finally {
395
395
activeSub = prevSub
396
396
shouldTrack = prevShouldTrack
397
- cleanupDeps ( computed )
397
+ cleanupDeps ( computed , true )
398
398
computed . flags &= ~ EffectFlags . RUNNING
399
399
}
400
400
}
You can’t perform that action at this time.
0 commit comments