2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-06 05:32:24 +03:00

don't perform client-side render if data-vue-meta-server-rendered attribute exists on html tag

This commit is contained in:
Declan de Wet
2016-11-02 00:50:55 +02:00
parent d89f76ce9b
commit 7d294e627f
2 changed files with 15 additions and 5 deletions
+1
View File
@@ -1 +1,2 @@
export const VUE_META_ATTRIBUTE = 'data-vue-meta'
export const SERVER_RENDERED_ATTRIBUTE = 'data-vue-meta-server-rendered'
+14 -5
View File
@@ -1,5 +1,6 @@
import updateTitleTag from './updateTitleTag'
import updateHtmlTagAttributes from './updateHtmlTagAttributes'
import { SERVER_RENDERED_ATTRIBUTE } from './constants'
/**
* Performs client-side updates when new meta info is received
@@ -7,10 +8,18 @@ import updateHtmlTagAttributes from './updateHtmlTagAttributes'
* @param {Object} newInfo - the meta info to update to
*/
export default function updateClientMetaInfo (newInfo) {
if (newInfo.title) {
updateTitleTag(newInfo.title)
}
if (newInfo.htmlAttrs) {
updateHtmlTagAttributes(newInfo.htmlAttrs)
const htmlTag = document.getElementsByTagName('html')[0]
// if this is not a server render, then update
if (htmlTag.getAttribute(SERVER_RENDERED_ATTRIBUTE) === null) {
if (newInfo.title) {
updateTitleTag(newInfo.title)
}
if (newInfo.htmlAttrs) {
updateHtmlTagAttributes(newInfo.htmlAttrs)
}
} else {
htmlTag.removeAttribute(SERVER_RENDERED_ATTRIBUTE)
}
}