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

This issue has been created since 2022-09-21.

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.

xiaxzp wrote this answer on 2022-09-21

background

My team have an inner lib using class & static for enums. When we upgrade fron 2.6 to 2.7, and delete composition api, this bug comes out. I finally find out that we use the Object.freeze in the enums lib, and this causes error with another lib, which is using readonly on it.

More Details About Repo
Owner Name vuejs
Repo Name vue
Full Name vuejs/vue
Language TypeScript
Created Date 2013-07-29
Updated Date 2022-09-27
Star Count 199644
Watcher Count 6098
Fork Count 32848
Issue Count 587

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Cannot find gem bundler 0 2019-03-21 2022-07-17
robloxlsp is broken ples fix 2 2021-11-27 2022-05-12
Which CPU atomic implementation should be enabled by default? 5 2022-01-17 2022-09-05
Trouble getting ICON results 12 2022-02-14 2022-09-19
ModuleNotFoundError: No module named '_tkinter' 1 2022-08-30 2022-09-24
Info - powertoys enables svg preview 3 2020-05-30 2022-09-13
umi.js from Terser TypeError: _jestWorker.Worker is not a constructor 1 2021-07-08 2022-09-09
Standardize on JSON serialization format 12 2016-07-18 2022-08-25
search argument for user names with spaces 1 2022-02-14 2022-07-05
Implementation of match-dg 2 2021-03-17 2022-09-15
"Instance of 'Panda' has no 'qr' member; maybe 'q'?" Error 0 2022-02-15 2022-09-12
Use custom upstream DoH server 3 2019-10-04 2022-09-19
Terraform cannot destroy a VM with protection enabled 1 2021-05-08 2022-08-31
Clock conflict when using both Stretch and Cross 0 2022-04-14 2022-06-16
every console.log wrap individually 0 2022-09-22 2022-09-17
Add a changelog 4 2021-10-15 2022-01-08
Tutorial for example projects after generation codes 2 2021-06-15 2022-09-24
'Not null' constraint prevents record creation during migration 1 2021-07-21 2022-09-06
COCO per Category evaluation problem 0 2022-09-16 2022-09-19
Feature Request: Allow secret refs as env's 1 2021-03-30 2022-09-23
Invalid markup in WHFB PKI config docs 2 2021-08-25 2022-09-05
Implement `clone` on `ReportBuilder` 0 2021-11-12 2022-09-23
[Chore] Use single payload validator in all handlers 2 2021-11-25 2022-09-25
Document non-trivial dockers 0 2022-04-04 2022-08-08
consider breaking apart var calling from WholeGenome pipelines 2 2021-12-15 2022-08-08
PBFlowcell need attention for performance 1 2022-04-08 2022-08-08
Build all dockers for intensive tasks to contain a locally invokable monitoring script 0 2022-03-31 2022-08-08
Best way to obtain next to_states for event? 4 2014-09-26 2022-09-05
[Feature] Support multiple shipping options 2 2021-11-08 2022-09-25
set up vnet and subnet 1 2021-04-22 2022-09-23
Cannot create a new folder via in-editor file manager 1 2022-04-06 2022-08-27
Vulkan: LightmapGI's `bake()` function is not exposed to scripting (unlike BakedLightmap in `3.x`) 0 2022-03-16 2022-09-25
Support for Payment Card Industry Data Security Standard (PCI DSS) standard 1 2020-08-11 2022-09-02
Mismatch of entities in the document: inventory_source_item Source: 2316 Destination: 1 5 2019-01-05 2022-09-16
unicode bug 6 2021-08-09 2022-01-19
Notification is not removing when we set setForegroundService in mqtt client 1 2021-12-14 2022-09-23
GPU name not accurate 0 2021-12-07 2022-09-26
CASC configuration 4 2021-07-15 2022-01-15
[BUG] Color contrast needs to be detected and measured automatically 5 2021-11-12 2022-09-03
FR: for pushing streaming features into BigQuery, use BigQuery's streaming API 0 2022-09-14 2022-09-26
Push api call to a push source that doesn't exist returns 200 1 2022-09-13 2022-09-26
Add materials of rarity 4 to items API and sprites for Planner merging 1 2020-02-17 2022-04-12
wifi check at write time 2 2022-04-04 2022-09-17
Support for Huawei Mobile Services 1 2022-01-27 2022-09-25
表格结构识别在pubtabnet验证集上测试结果不能复现。 0 2022-07-29 2022-09-05
The file has too many nested expressions or statements. 6 2021-12-26 2022-09-14
Check for accessibility issues in the new UI (for WW 2.17) 7 2022-01-31 2022-09-08
🐛[BUG] Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. at ProDescriptions 1 2022-02-24 2022-07-25
🐛[BUG] BetaSchemaForm组件中对formList类型的组件数据解析错误 0 2022-02-25 2022-09-13
Way to reduce memory usage for long-running app on Linux. 25 2021-10-15 2022-09-20