Skip to content

Commit 35b7099

Browse files
authored
fix: still traverse children when metainfo doesnt return object (#469)
* chore: ignore isServer for coverage * fix: still traverse children when metainfo doesnt return object
1 parent 7404953 commit 35b7099

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

src/shared/getComponentOption.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ export function getComponentOption (options, component, result) {
4040
// because Vue caches those internally
4141
const data = $metaInfo || $options[keyName]
4242

43-
// ignore data if its not an object, then we keep our previous result
44-
if (!isObject(data)) {
45-
return result
43+
// only merge data with result when its an object
44+
// eg it could be a function when metaInfo() returns undefined
45+
// dueo to the or statement above
46+
if (isObject(data)) {
47+
result = merge(result, data, options)
4648
}
47-
48-
// merge with existing options
49-
result = merge(result, data, options)
5049
}
5150

5251
// collect & aggregate child options if deep = true

src/shared/mixin.js

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export default function createMixin (Vue, options) {
135135

136136
// do not trigger refresh on the server side
137137
if (this.$isServer) {
138+
/* istanbul ignore next */
138139
return
139140
}
140141

test/unit/getComponentOptions.test.js

+33
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,37 @@ describe('getComponentOption', () => {
130130
expect(inMetaInfoBranch(wrapper.vm.$children[1].$children[0])).toBe(true)
131131
expect(inMetaInfoBranch(wrapper.vm.$children[2])).toBe(false)
132132
})
133+
134+
test('retrieves child options even if parent returns null', () => {
135+
const localVue = loadVueMetaPlugin({ keyName: 'foo' })
136+
137+
localVue.component('meta-child', {
138+
foo: { bar: 'baz' },
139+
render (h) {
140+
return h('div', this.$slots.default)
141+
}
142+
})
143+
144+
localVue.component('nometa-child', {
145+
render (h) {
146+
return h('div', this.$slots.default)
147+
}
148+
})
149+
150+
const component = localVue.component('parent', {
151+
foo: () => {},
152+
render: h => h('div', null, [
153+
h('meta-child')
154+
])
155+
})
156+
157+
const wrapper = mount(component, { localVue })
158+
159+
const mergedOption = getComponentOption({ keyName: 'foo' }, wrapper.vm)
160+
161+
expect(mergedOption).toEqual({ bar: 'baz' })
162+
expect(wrapper.vm.$children[0]._vueMeta).toBe(true)
163+
164+
expect(inMetaInfoBranch(wrapper.vm.$children[0])).toBe(true)
165+
})
133166
})

0 commit comments

Comments
 (0)