Repository navigation
fix(reactive): use isExtensible instead of isFrozen - #1753
Merged
Merged
Conversation
Member
|
A non-extensible object may still be mutable, and can be observed. Also Vue 2 uses the same |
Contributor
Author
|
thanks for commented! ! but....
const { reactive } = Vue
const obj = reactive(Object.preventExtensions({a: 1}))it will cause an error, beacuse a non-extensible object may not be a Frozen obejct, so we try to define a property(__v_reactive) for a non-extensible object in source code. - Uncaught TypeError: Cannot define property __v_reactive, object is not extensible
at Function.defineProperty (<anonymous>)
at def (vue.global.js:327)
at createReactiveObject (vue.global.js:970)
at reactive (vue.global.js:927)
at setup (test.html:13)
at callWithErrorHandling (vue.global.js:1277)
at setupStatefulComponent (vue.global.js:6814)
at setupComponent (vue.global.js:6775)
at mountComponent (vue.global.js:5107)
at processComponent (vue.global.js:5083)
export function observe (value: any, asRootData: ?boolean): Observer | void {
if (!isObject(value) || value instanceof VNode) {
return
}
let ob: Observer | void
if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
ob = value.__ob__
} else if (
shouldObserve &&
!isServerRendering() &&
(Array.isArray(value) || isPlainObject(value)) &&
Object.isExtensible(value) && // use Object.isExtensible to check
!value._isVue
) {
ob = new Observer(value)
}
if (asRootData && ob) {
ob.vmCount++
}
return ob
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
use isExtensible instead of isFrozen