diff --git a/src/constants.js b/src/constants.js index 64d166e..6ae5ace 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1 +1,2 @@ export const VUE_META_ATTRIBUTE = 'data-vue-meta' +export const SERVER_RENDERED_ATTRIBUTE = 'data-vue-meta-server-rendered' diff --git a/src/updateClientMetaInfo.js b/src/updateClientMetaInfo.js index 618a966..c57c510 100644 --- a/src/updateClientMetaInfo.js +++ b/src/updateClientMetaInfo.js @@ -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) } }