File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -1022,4 +1022,19 @@ describe('reactivity/computed', () => {
10221022 state . a ++
10231023 expect ( p . value ) . toBe ( 3 )
10241024 } )
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+ } )
10251040} )
Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ function prepareDeps(sub: Subscriber) {
292292 }
293293}
294294
295- function cleanupDeps ( sub : Subscriber ) {
295+ function cleanupDeps ( sub : Subscriber , fromComputed = false ) {
296296 // Cleanup unsued deps
297297 let head
298298 let tail = sub . depsTail
@@ -302,7 +302,7 @@ function cleanupDeps(sub: Subscriber) {
302302 if ( link . version === - 1 ) {
303303 if ( link === tail ) tail = prev
304304 // unused - remove it from the dep's subscribing effect list
305- removeSub ( link )
305+ removeSub ( link , fromComputed )
306306 // also remove it from this effect's dep list
307307 removeDep ( link )
308308 } else {
@@ -394,7 +394,7 @@ export function refreshComputed(computed: ComputedRefImpl): undefined {
394394 } finally {
395395 activeSub = prevSub
396396 shouldTrack = prevShouldTrack
397- cleanupDeps ( computed )
397+ cleanupDeps ( computed , true )
398398 computed . flags &= ~ EffectFlags . RUNNING
399399 }
400400}
You can’t perform that action at this time.
0 commit comments