ITADN
vuejs/core/Issues

`reactive` silently skips un-extensible objects, which seems undocumented and unnecessary

#14893Openedave64 创建于 2026-05-30
E
edave64commented
### What problem does this feature solve? In the code of my project, I have some code like this: ```ts export const ui = reactive( Object.seal({ [...] useDarkTheme: null as boolean | null, [...] }) ); ``` To me, the intent was clear. I want changes to properties like `useDarkTheme` to be observable, but didn't want to allow and new properties to be added. What I didn't know, and what seemingly isn't mentioned in the documentation (https://vuejs.org/api/reactivity-core.html#reactive ), is that `reactive` will silently just return the target object without any proxy if it's non-extendable. This has caused an issue in the currently shipped version of the app, where, among other things, setting the theme just doesn't work. This happens here: https://github.com/vuejs/core/blob/86ad0764fd9f7b01cef75b4fc941b03419306bf8/packages/reactivity/src/reactive.ts#L288 Best I can tell this is done because `reactive` used to set a `reactiveFlag` directly on the target object (https://github.com/vuejs/core/blob/848d9ce2ea757a0963257544645f1774f8701ffe/packages/reactivity/src/reactive.ts#L158 ) which caused runtime errors (https://github.com/vuejs/core/issues/1784 ) This is, as far as I can tell, no longer the case, and the reactivity flags are just directly handled by the `get` handler of the proxy, without modifying the target object. ### What does the proposed API look like? Either the function should be changed to allow `reactive(Object.seal(...))` to work, or this behavior should be cemented and documented as intended behavior. It should be safe to keep the current behavior with `Object.isFrozen()`, since those cannot mutate anyway. <!-- generated by vue-issues. DO NOT REMOVE -->
0 条评论