Skip to content
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

fix: reconcile the overridden prototype of component with _Vue mixins #889

Merged
merged 1 commit into from
Aug 2, 2018

Conversation

kuitos
Copy link
Contributor

@kuitos kuitos commented Aug 2, 2018

refer to #856

@kuitos kuitos changed the title fix: reconcile the overridden prototype of component and _Vue mixins fix: reconcile the overridden prototype of component with _Vue mixins Aug 2, 2018
@kuitos
Copy link
Contributor Author

kuitos commented Aug 2, 2018

@eddyerburgh could you donate some time to review it?

Copy link
Member

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good solution, thanks :)

@eddyerburgh eddyerburgh merged commit 73980c4 into vuejs:dev Aug 2, 2018
@eddyerburgh
Copy link
Member

I had to revert this change again before the release. It was causing issues with this new test—https://github.com/vuejs/vue-test-utils/blob/dev/test/specs/mounting-options/localVue.spec.js#L68.

The problem with modifying the prototype chain, or the super chain ourselves is that it's very difficult to plan for edge cases. So I think the solution would be to provide an option to not extend the component, although that would mean stubs and mocks won't be applied.

If you have other suggested workaround I'll take a look.

@kuitos
Copy link
Contributor Author

kuitos commented Aug 7, 2018

I had tried to change the root prototype of vue component:

function getRootProto (obj) {
    if (Object.getPrototypeOf(obj) === Vue.prototype) {
      return obj
    }
    return getRootProto(Object.getPrototypeOf(obj))
}

function getExtendedComponent(component, instanceOptions) {
  const extendedComponent = component.extend(instanceOptions)
  const root = getRootProto(extendedComponent.prototype)
  Object.setPrototypeOf(root, _Vue.prototype)
  return extendedComponent
}

const Constructor = typeof component === 'function'
    ? getExtendedComponent(component, instanceOptions)
    : _Vue.extend(component).extend(instanceOptions)

I think I'm in the right direction, but the unit test what you added still failed.
I need to check what made it failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants