-
Notifications
You must be signed in to change notification settings - Fork 668
fix: reconcile the overridden prototype of component and _Vue mocks and mixins #912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@eddyerburgh could you please donate some time to review it? |
Yes, I was intending to look at it today 👍 |
// we need change the proto chains manually | ||
// @see https://github.com/vuejs/vue-test-utils/pull/856 | ||
const root = getRootVueProto(extendedComponent.prototype) | ||
Object.setPrototypeOf(root, _Vue.prototype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this would mutate components:
const CompA = Vue.extend()
const CompB = CompA.extend().extend()
const savedProto = CompA.prototype.__proto__
const rootProto = CompB.prototype.__proto__.__proto__
Object.setPrototypeOf(rootProto, null)
console.log(savedProto === CompA.prototype.__proto__) // false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it could if you set the proto of rootProto to be null.
But here we actually did was Object.setPrototypeOf(rootProto, _Vue.prototype)
const rootProto = CompB.prototype.__proto__.__proto__
Object.setPrototypeOf(rootProto, Vue.prototype)
console.log(savedProto === CompA.prototype.__proto__) // true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you set it to _Vue
then I think it would still mutate the protoype, it just wouldn't be as severe:
const CompA = Vue.extend()
const CompB = CompA.extend().extend()
const _Vue = Vue.extend()
const savedProto = CompA.prototype.__proto__
const rootProto = CompB.prototype.__proto__.__proto__
Object.setPrototypeOf(rootProto, _Vue.prototype)
console.log(savedProto === CompA.prototype.__proto__) // false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with what you concerned about, I will add an unit test and find a way to guarantee the super component immutably.
What do you think? Any suggestion? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great, I don't have any suggestions unfortunately. I spent some time two weeks ago investigating, but I couldn't find a solution that didn't mutate the original components
fixed #889
@eddyerburgh please make a review