<commit_before>import updateTitle from './updaters/updateTitle'
import updateTagAttributes from './updaters/updateTagAttributes'
import updateTags from './updaters/updateTags'
import { SERVER_RENDERED_ATTRIBUTE } from '../shared/constants'

// tags to watch
const tags = [
  'meta',
  'link',
  'base',
  'style',
  'script',
  'noscript'
]

// hoisted vars but only in the browser
if (typeof window !== 'undefined' && window !== null) {
  var htmlTag = document.getElementsByTagName('html')[0]
  var bodyTag = document.getElementsByTagName('body')[0]
  var headTag = document.getElementsByTagName('head')[0]
}

/**
 * Performs client-side updates when new meta info is received
 *
 * @param  {Object} newInfo - the meta info to update to
 */
export default function updateClientMetaInfo (newInfo, $root) {
  // if this is not a server render, then update
  if (htmlTag.getAttribute(SERVER_RENDERED_ATTRIBUTE) === null) {
    // initialize tracked changes
    const addedTags = {}
    const removedTags = {}

    // update the title
    updateTitle(newInfo.title)

    // update <html> attrs
    updateTagAttributes(newInfo.htmlAttrs, htmlTag)

    // update <body> attrs
    updateTagAttributes(newInfo.bodyAttrs, bodyTag)

    // update tags
    for (let i = 0, len = tags.length; i < len; i++) {
      const tag = tags[i]
      const { oldTags, newTags } = updateTags(tag, newInfo[tag], headTag)
      if (newTags.length) {
        addedTags[tag] = newTags
        removedTags[tag] = oldTags
      }
    }

    // emit event
    if (typeof newInfo.changed === 'function') {
      newInfo.changed(newInfo, addedTags, removedTags)
    }
  } else {
    htmlTag.removeAttribute(SERVER_RENDERED_ATTRIBUTE)
  }
}
<commit_msg>fix for lazy rendering + scripts in <head> causing errors<commit_after>import updateTitle from './updaters/updateTitle'
import updateTagAttributes from './updaters/updateTagAttributes'
import updateTags from './updaters/updateTags'
import { SERVER_RENDERED_ATTRIBUTE } from '../shared/constants'

// tags to watch
const tags = [
  'meta',
  'link',
  'base',
  'style',
  'script',
  'noscript'
]

/**
 * Performs client-side updates when new meta info is received
 *
 * @param  {Object} newInfo - the meta info to update to
 */
export default function updateClientMetaInfo (newInfo, $root) {
  const htmlTag = document.getElementsByTagName('html')[0]
  // if this is not a server render, then update
  if (htmlTag.getAttribute(SERVER_RENDERED_ATTRIBUTE) === null) {
    // initialize tracked changes
    const addedTags = {}
    const removedTags = {}

    // update the title
    updateTitle(newInfo.title)

    // update <html> attrs
    updateTagAttributes(newInfo.htmlAttrs, htmlTag)

    // update <body> attrs
    updateTagAttributes(newInfo.bodyAttrs, document.getElementsByTagName('body')[0])

    // update tags
    for (let i = 0, len = tags.length; i < len; i++) {
      const tag = tags[i]
      const { oldTags, newTags } = updateTags(tag, newInfo[tag], document.getElementsByTagName('head')[0])
      if (newTags.length) {
        addedTags[tag] = newTags
        removedTags[tag] = oldTags
      }
    }

    // emit event
    if (typeof newInfo.changed === 'function') {
      newInfo.changed(newInfo, addedTags, removedTags)
    }
  } else {
    htmlTag.removeAttribute(SERVER_RENDERED_ATTRIBUTE)
  }
}

{'fraction_non_alphanumeric': 0.12114866886030512, 'fraction_numerical': 0.0023930601256356566, 'mean_word_length': 3.3769633507853403, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5089375', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1049, 'n_words': 275}