Subscribe on changes!

Unwrapping of deep ref in Map is not correct

avatar
Sep 28th 2023
avatar
Oct 4th 2023

Hello @bergmorten I checked the code and I believe this is the expected behaviour:

  1. when you access map2.get('count') the check is done on map2 which is a Map so it's marked as TargetType.COLLECTION thus its content won't be unwrapped (here is an object {foo: ref(0)})
  2. then when you access .foo the check is done on map2.get('count') which is now an object, it'll be marked as TargetType.COMMON thus unwrapped (no need for .value)

In comparison to

const map = reactive(new Map([['count', ref(0)]]))
// need .value here
console.log(map.get('count').value)

Accessing map.get('count') won't unwrap the content, thus resulting in the ref(0) for which you need .value

avatar
Oct 4th 2023

I thought the reason for not unwrapping inside map or array was a performance decision and therefor though this was an error, If this is expected behaviour then the typing is wrong (and possible documentition). The type hint says that you need foo.value (which returns undefined when executed).

avatar
Oct 5th 2023

I created a PR to update the typing to infer the type of the collection value (Map, Set..) and tries to recursively unwrap it, I believe that the documentation can be more clear around this detail

avatar
Oct 13th 2023

Duplicate of #8904