-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Updates to deep/nested reactive props does not trigger a DOM update #1387
Comments
I'm seeing something similar. But it's an update behind. When the nested object changes, the UI doesn't change until a second render cycle is called. |
The issue is that you create a plain, non-reactive object here: const obj = {
name: 'test (2 child list items should show)',
items: [],
} and then continue to mutate this plain, nonreactive object:
In Vue 3, this change will not be observed, even though before that mutation, you added the object to an reactive array.
So yes, this is a caveat of the new, proxy-based reactivity. The solution is: never work with plain objects that are meant to become reactive. Always make them reactive proactively:
now, This challenge will be covered in the documentation and, where possible, also supported by eslint rules in |
The issue I found was in my code. Once I tried to reproduce it in Beta.15, I couldn't. So I am happy to have it closed. |
Thanks for the detailed feedback @LinusBorg |
Version
3.0.0-beta.15
Reproduction link
https://codepen.io/conrad-sollitt/pen/yLeaoGB
Steps to reproduce
The CodePen contains 4 main options depending on how code is commented:
Vue.reactive
Vue.ref
The HTML allows Vue 2/Vue 3 to be toggled by commenting/un-commenting the correct version.
Based on whether Vue 2 or Vue 3 is used the JS will run code the correct version. When using Vue 3 two constants at the top of the JS file can be changed to affect what API is used:
Once
mounted/onMounted
is called awindow.setTimeout()
runs after 500 milliseconds and makes updates on the nested list.What is expected?
When using Vue 2 (both Prod and Dev) the updates always show in the DOM.
What is actually happening?
When using Vue 3 (regardless of the API used) the updates will only show if one of the top-level properties is set and not one of the deep/nested properties.
Code comments in the
window.setTimeout()
describe how to make it work with Vue 3.This may be related to issue: #262
If it is then this feature will not be supported in Vue 3. If it can't be supported I think it would be a good idea to document deep/nested object updates somewhere in the final documentation.
I'm opening the issue because based on the DOM it's not clear to me if it should update or not. Additionally when using Dev Tools you can see that all nested objects use a Proxy object so this could be a Browser/JavaScript issue as well.
From the API Docs:
https://composition-api.vuejs.org/api.html#reactive
Last Friday I opened the following issue related to the global
window
object: #1353I'm happy to follow up my report that I feel that the new Vue 3 API is easy to work with for migration and keeping Vue 2 Options API while supporting the new Composition API works great and is well thought out! I've been waiting a while to migrate as I wanted to wait till near release rather than making many changes while the new API was in early development.
I was able to migrate 7 mini web apps to Vue 3 while keeping support for Vue 2 (actually running Vue 2 in production still until the final release) but each web app has the option for both Vue 2 or Vue 3 simply by swapping out the CDN link. This was the main issue that I found but it only required a few lines of code extra in one app in order to work.
The text was updated successfully, but these errors were encountered: