Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commit984927a

Browse files
committed
fix: fix regression on duplicate component init when using shared data objects
fixvuejs#7805
1 parentcf0b1b7 commit984927a

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

‎src/core/vdom/create-component.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
renderRecyclableComponentTemplate
3333
}from'weex/runtime/recycle-list/render-component-template'
3434

35-
// hooks to be invoked on component VNodes during patch
35+
//inlinehooks to be invoked on component VNodes during patch
3636
constcomponentVNodeHooks={
3737
init(
3838
vnode:VNodeWithData,
@@ -189,8 +189,8 @@ export function createComponent (
189189
}
190190
}
191191

192-
//merge component management hooks onto the placeholder node
193-
mergeHooks(data)
192+
//install component management hooks onto the placeholder node
193+
installComponentHooks(data)
194194

195195
// return a placeholder vnode
196196
constname=Ctor.options.name||tag
@@ -234,22 +234,11 @@ export function createComponentInstanceForVnode (
234234
returnnewvnode.componentOptions.Ctor(options)
235235
}
236236

237-
functionmergeHooks(data:VNodeData){
238-
if(!data.hook){
239-
data.hook={}
240-
}
237+
functioninstallComponentHooks(data:VNodeData){
238+
consthooks=data.hook||(data.hook={})
241239
for(leti=0;i<hooksToMerge.length;i++){
242240
constkey=hooksToMerge[i]
243-
constfromParent=data.hook[key]
244-
constours=componentVNodeHooks[key]
245-
data.hook[key]=fromParent ?mergeHook(ours,fromParent) :ours
246-
}
247-
}
248-
249-
functionmergeHook(one:Function,two:Function):Function{
250-
returnfunction(a,b,c,d){
251-
one(a,b,c,d)
252-
two(a,b,c,d)
241+
hooks[key]=componentVNodeHooks[key]
253242
}
254243
}
255244

‎test/unit/modules/vdom/create-component.spec.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ describe('create-component', () => {
1919
props:['msg'],
2020
render(){}
2121
}
22-
constinit=jasmine.createSpy()
2322
constdata={
2423
props:{msg:'hello world'},
2524
attrs:{id:1},
2625
staticAttrs:{class:'foo'},
27-
hook:{ init},
2826
on:{notify:'onNotify'}
2927
}
3028
constvnode=createComponent(child,data,vm,vm)
@@ -38,9 +36,6 @@ describe('create-component', () => {
3836
expect(vnode.elm).toBeUndefined()
3937
expect(vnode.ns).toBeUndefined()
4038
expect(vnode.context).toEqual(vm)
41-
42-
vnode.data.hook.init(vnode)
43-
expect(init.calls.argsFor(0)[0]).toBe(vnode)
4439
})
4540

4641
it('create a component when resolved with async loading',done=>{

‎test/unit/modules/vdom/patch/edge-cases.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,36 @@ describe('vdom patch: edge cases', () => {
374374
expect(vm.$el.querySelector('custom-foo').getAttribute('selected')).toBe('1')
375375
Vue.config.ignoredElements=[]
376376
})
377+
378+
// #7805
379+
it('should not cause duplicate init when components share data object',()=>{
380+
constBase={
381+
render(h){
382+
returnh('div',this.$options.name)
383+
}
384+
}
385+
386+
constFoo={
387+
name:'Foo',
388+
extends:Base
389+
}
390+
391+
constBar={
392+
name:'Bar',
393+
extends:Base
394+
}
395+
396+
constvm=newVue({
397+
render(h){
398+
constdata={staticClass:'text-red'}
399+
400+
returnh('div',[
401+
h(Foo,data),
402+
h(Bar,data)
403+
])
404+
}
405+
}).$mount()
406+
407+
expect(vm.$el.textContent).toBe('FooBar')
408+
})
377409
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp