Skip to content
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

[@vue/runtime-core] Child component setup() does not update parent state #804

Closed
Jexordexan opened this issue Mar 6, 2020 · 0 comments
Closed

Comments

@Jexordexan
Copy link

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 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:

const data = reactive([])

const childSetup = () => data.push('update')

effect(() => {
  console.log(data.length) // --> 0
  childSetup() // 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.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant