Skip to content

querySelectorAllExt returns unexpected null which impacts findAttributeTargets #3055

@san4d

Description

@san4d

Summary

querySelectorAllExt can return [null] which violates the documented return type of findAttributeTargets: (Node|Window)[]. This has upstream effects on methods like disableElements, which iterate through a collection of elements returned by findAttributeTargets, expecting each to be not null.

  function findAttributeTargets(elt, attrName) {
    const attrTarget = getClosestAttributeValue(elt, attrName)
    if (attrTarget) {
      if (attrTarget === 'this') {
        return [findThisElement(elt, attrName)]
      } else {
        const result = querySelectorAllExt(elt, attrTarget) // <-- This can return [null]
        if (result.length === 0) {
          logError('The selector "' + attrTarget + '" on ' + attrName + ' returned no matches!')
          return [DUMMY_ELT]
        } else {
          return result
        }
      }
    }
  }

Context

In my application, this happens when the elt passed in to findAttributeTargets has no children and the attrTarget would yield no results. The attrName in my context is hx-disabled-elt.

Workaround

In my setup, the inherited hx-disabled-elt was causing the failed lookup. I explicitly set the hx-disabled-elt to a query selector that would return results to unblock myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions