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: invoke component node create hooks before insertion #7823

Merged
merged 1 commit into from Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions flow/options.js
Expand Up @@ -2,8 +2,6 @@ declare type InternalComponentOptions = {
_isComponent: true;
parent: Component;
_parentVnode: VNode;
_parentElm: ?Node;
_refElm: ?Node;
render?: Function;
staticRenderFns?: Array<Function>
};
Expand Down Expand Up @@ -81,8 +79,6 @@ declare type ComponentOptions = {
_componentTag: ?string;
_scopeId: ?string;
_base: Class<Component>;
_parentElm: ?Node;
_refElm: ?Node;
};

declare type PropOptions = {
Expand Down
2 changes: 0 additions & 2 deletions src/core/instance/init.js
Expand Up @@ -77,8 +77,6 @@ export function initInternalComponent (vm: Component, options: InternalComponent
const parentVnode = options._parentVnode
opts.parent = options.parent
opts._parentVnode = parentVnode
opts._parentElm = options._parentElm
opts._refElm = options._refElm

const vnodeComponentOptions = parentVnode.componentOptions
opts.propsData = vnodeComponentOptions.propsData
Expand Down
9 changes: 1 addition & 8 deletions src/core/instance/lifecycle.js
Expand Up @@ -62,14 +62,7 @@ export function lifecycleMixin (Vue: Class<Component>) {
// based on the rendering backend used.
if (!prevVnode) {
// initial render
vm.$el = vm.__patch__(
vm.$el, vnode, hydrating, false /* removeOnly */,
vm.$options._parentElm,
vm.$options._refElm
)
// no need for the ref nodes after initial patch
// this prevents keeping a detached DOM tree in memory (#5851)
vm.$options._parentElm = vm.$options._refElm = null
vm.$el = vm.__patch__(vm.$el, vnode, hydrating, false /* removeOnly */)
} else {
// updates
vm.$el = vm.__patch__(prevVnode, vnode)
Expand Down
17 changes: 3 additions & 14 deletions src/core/vdom/create-component.js
Expand Up @@ -34,12 +34,7 @@ import {

// inline hooks to be invoked on component VNodes during patch
const componentVNodeHooks = {
init (
vnode: VNodeWithData,
hydrating: boolean,
parentElm: ?Node,
refElm: ?Node
): ?boolean {
init (vnode: VNodeWithData, hydrating: boolean): ?boolean {
if (
vnode.componentInstance &&
!vnode.componentInstance._isDestroyed &&
Expand All @@ -51,9 +46,7 @@ const componentVNodeHooks = {
} else {
const child = vnode.componentInstance = createComponentInstanceForVnode(
vnode,
activeInstance,
parentElm,
refElm
activeInstance
)
child.$mount(hydrating ? vnode.elm : undefined, hydrating)
}
Expand Down Expand Up @@ -215,15 +208,11 @@ export function createComponent (
export function createComponentInstanceForVnode (
vnode: any, // we know it's MountedComponentVNode but flow doesn't
parent: any, // activeInstance in lifecycle state
parentElm?: ?Node,
refElm?: ?Node
): Component {
const options: InternalComponentOptions = {
_isComponent: true,
parent,
_parentVnode: vnode,
_parentElm: parentElm || null,
_refElm: refElm || null
parent
}
// check inline-template render functions
const inlineTemplate = vnode.data.inlineTemplate
Expand Down
7 changes: 4 additions & 3 deletions src/core/vdom/patch.js
Expand Up @@ -212,14 +212,15 @@ export function createPatchFunction (backend) {
if (isDef(i)) {
const isReactivated = isDef(vnode.componentInstance) && i.keepAlive
if (isDef(i = i.hook) && isDef(i = i.init)) {
i(vnode, false /* hydrating */, parentElm, refElm)
i(vnode, false /* hydrating */)
}
// after calling the init hook, if the vnode is a child component
// it should've created a child instance and mounted it. the child
// component also has set the placeholder vnode's elm.
// in that case we can just return the element and be done.
if (isDef(vnode.componentInstance)) {
initComponent(vnode, insertedVnodeQueue)
insert(parentElm, vnode.elm, refElm)
if (isTrue(isReactivated)) {
reactivateComponent(vnode, insertedVnodeQueue, parentElm, refElm)
}
Expand Down Expand Up @@ -681,7 +682,7 @@ export function createPatchFunction (backend) {
}
}

return function patch (oldVnode, vnode, hydrating, removeOnly, parentElm, refElm) {
return function patch (oldVnode, vnode, hydrating, removeOnly) {
if (isUndef(vnode)) {
if (isDef(oldVnode)) invokeDestroyHook(oldVnode)
return
Expand All @@ -693,7 +694,7 @@ export function createPatchFunction (backend) {
if (isUndef(oldVnode)) {
// empty mount (likely as component), create new root element
isInitialPatch = true
createElm(vnode, insertedVnodeQueue, parentElm, refElm)
createElm(vnode, insertedVnodeQueue)
} else {
const isRealElement = isDef(oldVnode.nodeType)
if (!isRealElement && sameVnode(oldVnode, vnode)) {
Expand Down