Skip to content

[2.7.10] readonly on frozen object causing TypeError: Cannot define property __v_rawToReadonly #12799

@xiaxzp

Description

@xiaxzp

Version

2.7.10

Reproduction link

codesandbox.io

Steps to reproduce

reason:
Readonly function sets new property on object recursively. This may cause this error when meeting frozen variables. Of course this error can also happen when using readonly directly on frozen objects.

code:

import { readonly } from 'vue';
const test = {
variable: { tp: 1 },
}
Object.freeze(test.variable);
const readonlyTest = readonly(test);

export default {
name: "App",
setup() {
const { variable } = readonlyTest;
return {
variable,
}
},
};

What is expected?

go well

What is actually happening?

[Vue warn]: Error in setup: "TypeError: Cannot define property __v_rawToReadonly, object is not extensible"
TypeError: Cannot define property __v_rawToReadonly, object is not extensible


solvement:
#12798
This fix can simply solve the issue by checking the extensibility of target, and keep the temp proxy at the same time, but leaving existing proxy cache useless.
The main reason is the "isReadonly" judgement, but it's difficult to change this basic feature, and the frozen target may still contain not frozen things? As this case may happen rarely, this fix is enough now and willing for future improvements.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy