-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref is called as a reactive parameter and effectFn is triggered multiple times when updated #6358
Comments
double triggering the effect, might be something that can be fixed, but perhaps with a different approach. Returning the ref when you pass it through let myRef = ref(0)
const myReactive = reactive(myRef)
console.log(isReactive(myReactive)) // actual:false. expected:true
console.log(myReactive === myRef) // true |
core/packages/reactivity/src/computed.ts Lines 55 to 64 in a95554d
@lidlanca There is also handling of duplicate triggers in computed, but this does not seem to fix the problem, it only solves the dependency collection on the _value attribute, but the value attribute still collects dependencies and the number of duplicate triggers is only reduced by one.
Yes, I realise that handling it in |
it will probably be best to avoid passing a ref directly to do you have a practical use case, where that was necessary to do? additionally |
@lidlanca export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>
export function reactive<T extends object>(target: T): UnwrapNestedRefs<T>
Then I saw a similar treatment in This was my original intention in asking the question and the PR. There are many different ways of using the user code and if this is not dealt with, then I think it is only a matter of time before a bug appears. |
This is now triggering twice in 3.5 - once for |
Vue version
3.2.37
Link to minimal reproduction
https://sfc.vuejs.org/#eNp9kE1qwzAQha8yaGMbHIl0aZxAT9ALaOOacepg/TAauQvju3ccpd01AoGe5tMT723qPUa9ZlSd6tNIc2RIyDlerZ9dDMSwEQ4jzyu2QDi1gNOEI+8wUXBQydPK+jH4xEBwEaTAtbD1uWmsL3xdN3C5wmY9wEGHBfUSbnVFXSXGeh2WjELvso2Bj8wxcwcP8buog7P1T1b+evsXFbIMX+relMSSVQSji8vAKKo3f0K1qvRwckPU9xS8NPVIYZ+DZFVXch130sehrfpijqkzJk3j0e896UA3IydN2fPsUGNyp08K3wlJjK06LHZpQO0/O++Bng==
Steps to reproduce
Open the browser console to view the output.
What is expected?
When assigning a value to r.value, effectFn should be called only once.
What is actually happening?
effectFn was triggered three times and the output was printed three times.
System Info
Any additional comments?
Code behaviour does not match type. The reactive function type is:
When target is ref, the target should be returned directly, but instead ref is actually wrapped as responsive, resulting in dependencies being collected on all three properties of value and _value of ref. Eventually, when the value value is updated, it is also updated internally for _value, resulting in effectFn triggering three times.
The text was updated successfully, but these errors were encountered: