多层嵌套effect时,会多次执行子effect
Vue version
3.0
Link to minimal reproduction
Steps to reproduce
const observed = (window.observed = reactive({ count1: 0, count2: 10, }));
effect(() => { effect(() => { console.log('count2 is:', observed.count2); }); console.log('count1 is:', observed.count1); });
What is expected?
执行 observed.count1++ 后 再执行 observed.count2++ 只打印一次 console.log('count2 is:', observed.count2);
What is actually happening?
多次执行 observed.count1++ 后 , 再执行 observed.count2++ 会打印多次 console.log('count2 is:', observed.count2);
System Info
No response
Any additional comments?
原函数的effectStack=[] 为栈时的操作,以及dep里面存的Set 根据栈的对应数组里值的存储地址,多次执行外层effect后,会导致不同的activeEffect,此时的dep.has(activeEffect)还是拦截不了的。
The test case should allow nested effects
:
https://github.com/vuejs/core/blob/8a123ac34fd30fc36ac9e0c252dd345d6d7c7f50/packages/reactivity/__tests__/effect.spec.ts#L605-L636
font{
line-height: 1.6;
}
ul,ol{
padding-left: 20px;
list-style-position: inside;
}
好滴,我的想法有点问题,谢谢尤大。
1418556630
***@***.***
---- 回复的原邮件 ----
发件人
Evan ***@***.***>
发送日期
2022年06月16日 16:50
收件人
***@***.***>
抄送人
***@***.***>
,
***@***.***>
主题
Re: [vuejs/core] 多层嵌套effect时,会多次执行子effect (Issue #6118)
你的用法每次外层 effect 都在创建新的子 effect,当然越来越多...
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>