-
-
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
Setting a reactive object on a shallowReactive map "unwraps" the nested refs in the reactive object #8501
Comments
As per documentation - https://vuejs.org/api/reactivity-advanced.html#shallowreactive
const msg = ref('ads')
const myReactive = reactive({msg})
const myMap = new Map([['foo1', myReactive]])
const myReactiveMap = shallowReactive(myMap)
const log = key => console.log(key, myMap.get(key).msg, myReactiveMap.get(key).msg)
log('foo1') // foo1 ads ads
myReactiveMap.set('foo2', myReactive)
log('foo2') // foo2 RefImpl RefImpl
myMap.set('foo3', myReactive)
log('foo3') // foo3 ads ads It looks like shallowReactive is working as per the documentation. Also, when I change shallowReactive to reactive, I am getting consistent 'ads' console log for |
In my understanding values being stored "as-is" means they are left untouched. So when you set as a value on the map with a reactive proxy, that would stay a reactive proxy - and that reactive proxy would unwrap nested refs. just like it does for The problem here is that shallowReactive seems to apply a |
@shaileshnighojkar I disagree. as-is means, that nothing is changed in whatever object you pass to shallowReactive.
In a sense the opposite happens because they are going from unwrapped to wrapped @LinusBorg what do you think which behavior makes more sense? |
I think my previous reply is pretty much in sync with your understanding |
Vue version
@a95e612 (current commit after 3.3.4)
Link to minimal reproduction
https://play.vuejs.org/#eNqNkE1ugzAQha8y8sZGoiCyrEikHqCbbuMsEDEEyX/ChqiyfPeOCaJNk0U2lmfe957HE8iHtcU8CfJOateOg/XghJ/sgetBWTN6CDCKLsejaf0wixzcpZHSXL/WBkToRqOAYgrlGoDr1mjnQbke9snMaHN2NNv635s1ybcrC4jHJ8xnYxH79ybT4gqosOORdsZUNP/jOJ0yzOH6LqPAX7HE7u7YBUxPGikKaXr2KxU40DrPo5gS+zWxotnL7G5j6/K2blw0Fl4oKxsvsAKoL9UhhGV/MdYlVkt30HbyML8pcxZyzwnqnKBUl5sbSPwBWo+lvA==
Steps to reproduce
Open the example. In the console you see the message printed twice but once you see the internal ref printed.
The issue only shows itself when using "set" on a shallow Reactive map (foo2)
If you initialize the map with the same value, it is correct (foo1)
What is expected?
The behavior should be consistent.
Either the shallowReactive map should ALWAYS resolves the ref or never.
Imo, the reactive object in the shallowReactive should behave as normal. Hence, in my example, it should always resolve the ref correctly (because thats what the reactive is for)
What is actually happening?
The behavior is inconsistent depending on if the map is initialized with the value or later set
System Info
Any additional comments?
I am aware that you shouldnt have reactive objects in shallowReactive ones :D
The text was updated successfully, but these errors were encountered: