Skip to content

Commit 915fedf

Browse files
pimlieTheAlexLichter
authored andcommitted
feat: child can indicate parent vmid to be removed (resolves: #288)
1 parent 22e456c commit 915fedf

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/shared/merge.js

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, conte
2525
return
2626
}
2727

28+
// if source specifies null as content then ignore both the target as the source
29+
if (sourceItem[contentKeyName] === null || sourceItem.innerHTML === null) {
30+
// remove current index from source array so its not concatenated to destination below
31+
source.splice(sourceIndex, 1)
32+
return
33+
}
34+
2835
// we now know that targetItem is a duplicate and we should ignore it in favor of sourceItem
2936
// now we only need to check if the target has a template to combine it with the source
3037
const targetTemplate = targetItem[metaTemplateKeyName]

test/getMetaInfo.test.js

+48
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,52 @@ describe('getMetaInfo', () => {
671671
__dangerouslyDisableSanitizersByTagID: {}
672672
})
673673
})
674+
675+
test('child can indicate to remove parent vmids', () => {
676+
Vue.component('merge-child', {
677+
render: h => h('div'),
678+
metaInfo: {
679+
title: 'Hi',
680+
meta: [
681+
{
682+
vmid: 'og:title',
683+
content: null
684+
}
685+
]
686+
}
687+
})
688+
689+
const component = new Vue({
690+
metaInfo: {
691+
title: 'Hello',
692+
meta: [
693+
{
694+
vmid: 'og:title',
695+
property: 'og:title',
696+
content: 'Test title',
697+
template: chunk => `${chunk} - My page`
698+
}
699+
]
700+
},
701+
el: document.createElement('div'),
702+
render: h => h('div', null, [h('merge-child')])
703+
})
704+
705+
expect(getMetaInfo(component)).toEqual({
706+
title: 'Hi',
707+
titleChunk: 'Hi',
708+
titleTemplate: '%s',
709+
htmlAttrs: {},
710+
headAttrs: {},
711+
bodyAttrs: {},
712+
meta: [],
713+
base: [],
714+
link: [],
715+
style: [],
716+
script: [],
717+
noscript: [],
718+
__dangerouslyDisableSanitizers: [],
719+
__dangerouslyDisableSanitizersByTagID: {}
720+
})
721+
})
674722
})

0 commit comments

Comments
 (0)