<commit_before>import getWindow from 'get-window'
import { PathUtils } from 'slate'

import DATA_ATTRS from '../../constants/data-attributes'
import SELECTORS from '../../constants/selectors'

/**
 * A set of queries for the React plugin.
 *
 * @return {Object}
 */

function QueriesPlugin() {
  /**
   * Find the native DOM element for a node at `path`.
   *
   * @param {Editor} editor
   * @param {Array|List} path
   * @return {DOMNode|Null}
   */

  function findDOMNode(editor, path) {
    path = PathUtils.create(path)
    const content = editor.tmp.contentRef.current

    if (!path.size) {
      return content.ref.current || null
    }

    const search = (instance, p) => {
      if (!instance) {
        return null
      }

      if (!p.size) {
        if (instance.ref) {
          return instance.ref.current || null
        } else {
          return instance || null
        }
      }

      const index = p.first()
      const rest = p.rest()
      const ref = instance.tmp.nodeRefs[index]
      return search(ref, rest)
    }

    const document = content.tmp.nodeRef.current
    const el = search(document, path)
    return el
  }<commit_msg>gracefully handle null content ref in findDOMNode query (#2774)<commit_after>import getWindow from 'get-window'
import { PathUtils } from 'slate'

import DATA_ATTRS from '../../constants/data-attributes'
import SELECTORS from '../../constants/selectors'

/**
 * A set of queries for the React plugin.
 *
 * @return {Object}
 */

function QueriesPlugin() {
  /**
   * Find the native DOM element for a node at `path`.
   *
   * @param {Editor} editor
   * @param {Array|List} path
   * @return {DOMNode|Null}
   */

  function findDOMNode(editor, path) {
    path = PathUtils.create(path)
    const content = editor.tmp.contentRef.current

    if (!content) {
      return null
    }

    if (!path.size) {
      return content.ref.current || null
    }

    const search = (instance, p) => {
      if (!instance) {
        return null
      }

      if (!p.size) {
        if (instance.ref) {
          return instance.ref.current || null
        } else {
          return instance || null
        }
      }

      const index = p.first()
      const rest = p.rest()
      const ref = instance.tmp.nodeRefs[index]
      return search(ref, rest)
    }

    const document = content.tmp.nodeRef.current
    const el = search(document, path)
    return el
  }
{'fraction_non_alphanumeric': 0.1249482829954489, 'fraction_numerical': 0.0016549441456350847, 'mean_word_length': 2.2412868632707776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6953883', 'n_tokens_mistral': 742, 'n_tokens_neox': 729, 'n_words': 210}