Skip to content

readonly() breaks reactivity of Map #1772

@0x009922

Description

@0x009922

Version

3.0.0-rc.5

Reproduction link

https://codepen.io/liquid-solid/pen/ZEWzqpX?editors=0012

Steps to reproduce

Open CodePen and see console logs, or you can see an example below:

const {
  readonly,
  reactive,
  isReactive
} = Vue

const map = reactive(new Map())
const roMap = readonly(map)

map.set(4, { foo: 'bar' })

const mapItem = map.get(4)
const roMapItem = roMap.get(4)

console.log(`
Is map reactive?         - ${isReactive(map)}
Is map item reactive?    - ${isReactive(mapItem)}
Is RO map reactive?      - ${isReactive(roMap)}
Is RO map item reactive? - ${isReactive(roMapItem)}
`)

This code outputs:

Is map reactive?         - true
Is map item reactive?    - true
Is RO map reactive?      - true
Is RO map item reactive? - false

What is expected?

I expect that objects from a reactive Map will always be reactive, even if the Map is readonly.

What is actually happening?

When I get an item from readonly reactive Map it loses reactivity.


Is it a bug? If not, i don't understand how to work with maps, sets and other structs with new reactivity system. So far, plain objects still seem to be the best solution for storing data as an associative array due to the intricacies of the reactivity system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions