You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create some reactive state in setup() and render it
Allow a child component to access the state (I used provide/inject, but this could be a global store)
Child changes state in its setup()
Observe the state in the parent doesn't update until the next change
What is expected?
The parent reacts and shows the state
What is actually happening?
The state in the parent doesn't display change made by child component
I did some digging and found the cause of the bug. Basically the child's setup() is running within the renderEffect of the parent, and the renderEffect never re-runs after changes are made. There is some logic in the addRunners function that skips adding the activeEffect to be run.
This is functionally the same as:
constdata=reactive([])constchildSetup=()=>data.push('update')effect(()=>{console.log(data.length)// --> 0childSetup()// changes state internally, effect never re-runs})
I realize now that I'm changing state within an "effect" that is dependent on that state, which is a bad idea! I was just confused by the level of abstraction away from whats going on. So I'm not sure it is really a bug, but its something I was not expecting and felt broken.
The text was updated successfully, but these errors were encountered:
Version
3.0.0-alpha.7
Reproduction link
https://codesandbox.io/s/vue-3-reactive-error-spk7o
Steps to reproduce
Create some reactive state in
setup()
and render itAllow a child component to access the state (I used provide/inject, but this could be a global store)
Child changes state in its
setup()
Observe the state in the parent doesn't update until the next change
What is expected?
The parent reacts and shows the state
What is actually happening?
The state in the parent doesn't display change made by child component
I did some digging and found the cause of the bug. Basically the child's
setup()
is running within the renderEffect of the parent, and the renderEffect never re-runs after changes are made. There is some logic in theaddRunners
function that skips adding theactiveEffect
to be run.This is functionally the same as:
I realize now that I'm changing state within an "effect" that is dependent on that state, which is a bad idea! I was just confused by the level of abstraction away from whats going on. So I'm not sure it is really a bug, but its something I was not expecting and felt broken.
The text was updated successfully, but these errors were encountered: