<commit_before>import ReactDom from 'react-dom'

const containerMarker = 'data-kaliber-component-container'

export function ComponentServerWrapper({ componentName, props, renderedComponent }) {
  const componentInfo = JSON.stringify({ componentName, props })
  return (
    <>
      {/* It is not possible to render the html of a React-rendered component without a container
          because dangerouslySetInnerHTML is the only route to get raw html into the resulting html */}
      <kaliber-component-container dangerouslySetInnerHTML={{ __html: renderedComponent }} />

      {/* Use render blocking script to remove the container and supply the correct  comment nodes.
          This ensures the page is never rendered with the intermediate structure */}
      <script dangerouslySetInnerHTML={{ __html: restructureDomNodes(componentInfo) }} />
    </>
  )
}

export function findComponents({ componentName }) {
  if (typeof window === 'undefined') throw new Error(`The function 'findComponents' can only be used in the browser`)

  const cache = getCache()
  const components = cache[componentName] || []
  if (!components.length) console.warn(`Could not find any component with name '${componentName}', dit you render it to the page?`)
  return components

  function getCache() {
    return findComponents.cache || (findComponents.cache = groupComponentsByName(findAllComponents()))
  }<commit_msg>Improve readability<commit_after>import ReactDom from 'react-dom'

const containerMarker = 'data-kaliber-component-container'

export function ComponentServerWrapper({ componentName, props, renderedComponent }) {
  const componentInfo = JSON.stringify({ componentName, props })
  return (
    <>
      {/* It is not possible to render the html of a React-rendered component without a container
          because dangerouslySetInnerHTML is the only route to get raw html into the resulting html */}
      <kaliber-component-container dangerouslySetInnerHTML={{ __html: renderedComponent }} />

      {/* Use render blocking script to remove the container and supply the correct  comment nodes.
          This ensures the page is never rendered with the intermediate structure */}
      <script dangerouslySetInnerHTML={{ __html: restructureDomNodes(componentInfo) }} />
    </>
  )
}

export function findComponents({ componentName }) {
  if (typeof window === 'undefined') throw new Error(`The function 'findComponents' can only be used in the browser`)

  const findComponentCache = getFindComponentCache()
  const components = findComponentCache[componentName] || []
  if (!components.length) console.warn(`Could not find any component with name '${componentName}', dit you render it to the page?`)
  return components

  function getFindComponentCache() {
    if (!findComponents.cache) findComponents.cache = findAndGroupAllComponents()
    return findComponents.cache

    function findAndGroupAllComponents() {
      return groupComponentsByName(findAllComponents())
    }
  }
{'fraction_non_alphanumeric': 0.08832385413181666, 'fraction_numerical': 0.0, 'mean_word_length': 4.387387387387387, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2995705', 'n_tokens_mistral': 717, 'n_tokens_neox': 711, 'n_words': 271}