Skip to content

Deep readonly is not preserved through array iteration methods #14119

@Roan-Elven

Description

@Roan-Elven

Vue version

3.5.24

Link to minimal reproduction

https://play.vuejs.org/#eNp9Uk1P4zAQ/SsjX0ghStiFvUBaaXfVw65WCwJudYWidNoaHNvyRymK8t8ZJ01bBOIQx37z3nw8u2E/jck2AdkVK1xlhfHg0Acz4UrURlsPDVhcprSUC63kawqVrk3wuIAWllbXcELyE664qrRyHqSgZbznJ6ROZk2bQv/NR6PrA3nI9a8XDcckGcF4Ag1XQFgkKnzZcWZz0kNXJtuUMmC21HZaVutkGzU7YmaCI2RXDCA/JRYkEj0ISnJ+Tb/iOIlEtfJrgs/ORn1heJ/rwJ2JeUwL0Ob5aR43liyzauBTrI2EIu8dJS/p4LE2svRIJ4Bi/W3SNL1XbVvkdDyC37nyMRxVs/M5jMcHxyI1Ynt2kR8VZCnzjoxcilX25LSi2+5G5CzqhUR7Y7wgozm7GobnrJRSv/ztMG8DpgNerbF6/gR/ctuIcXZr0aHdIGf7mC/tCn0fnt7/xy3t98FaL4Ik9hfBO3RahthjT/sV1ILaPuJ13f7p3qxQqwc33XpUbhgqNtpdWcfnjN7s7y9GP7R7kV12OrpTcvFxgzbmJAMvsh/Z90vWvgGg8xTu

Steps to reproduce

The repro shows that computedList[0] and list[0] are not the same object when using list.value.forEach to push the array elements into another list.
If you uncomment the imperative style for loop (and comment the forEach) then you will see the computedList[0] and list[0] are now the same object.

What is expected?

Both the initial code and the commented code should have the same effect i.e Accessing the array elements via forEach (or map, or filter, or find etc.) should return the same result as accessing via index.

What is actually happening?

The elements in the callback of the .forEach are MutableReactiveHandler proxies (as can be confirmed by console.log). The elements accessed via index (and what you'd expect in a readonly array) are ReadonlyReactiveHandler proxies.
This seems to affect all the methods which iterate through the array and provide elements in a callback including for...of loops

System Info

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔨 p3-minor-bugPriority 3: this fixes a bug, but is an edge case that only affects very specific usage.scope: reactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions