Opened 6 years ago

Closed 6 years ago

#18824 closed defect (worksforme)

"ancestor.contains is not a function" after upgrading to 1.11.1

Reported by: paulrutter Owned by:
Priority: undecided Milestone: tbd
Component: General Version: 1.11.1
Keywords: Cc:
Blocked By: Blocking:


After upgrading to 1.11.1, i've found the following error to occur quite often when hovering over domNodes.

"ancestor.contains is not a function" 

In dom.js line 104. I've tried to debug and found out that sometimes the "ancestor" var is not a domNode, but a Dojo widget (which does not have "contains" as a method). Please investigate this issue and provide a patch.

I will monkeypatch dom.js for now, so the "old" check is used.

Change History (6)

comment:1 Changed 6 years ago by paulrutter

Patch used to workaround this issue:

  dom.isDescendant = has("dom-contains") ?
      // FF9+, IE9+, webkit, opera, iOS, Android, Edge, etc.
      function(/*DOMNode|String*/node, /*DOMNode|String*/ancestor) {
        return !!(( ancestor = dom.byId(ancestor)) && ancestor.contains && ancestor.contains(dom.byId(node)) );
      } : function(/*DOMNode|String*/node, /*DOMNode|String*/ancestor) {
        // summary:
        //    Returns true if node is a descendant of ancestor
        // node: DOMNode|String
        //    string id or node reference to test
        // ancestor: DOMNode|String
        //    string id or node reference of potential parent to test against
        // example:
        //    Test is node id="bar" is a descendant of node id="foo"
        //  | require(["dojo/dom"], function(dom){
        //  |   if(dom.isDescendant("bar", "foo")){ ... }
        //  | });

        try {
          node = dom.byId(node);
          ancestor = dom.byId(ancestor);
          while (node) {
            if (node == ancestor) {
              return true;
              // Boolean
            node = node.parentNode;
        } catch(e) {/* squelch, return false */
        return false;
        // Boolean
Last edited 6 years ago by paulrutter (previous) (diff)

comment:2 Changed 6 years ago by bill

Status: newpending

Please attach a test case or give instructions to reproduce this against existing tests. Also, list the browser where it fails.

comment:3 Changed 6 years ago by paulrutter

Status: pendingnew

Sorry, this issue got on the backlog here. I'll try to come back with a reproduction path.

comment:4 Changed 6 years ago by bill

Status: newpending

comment:5 Changed 6 years ago by paulrutter

Status: pendingnew

I can reproduce it in my project, but i cannot can reproduce it with plain Dojo. So, i will investigate it and re-open if needed.

It seems to have something to do with "touch" support which calls "dom.isDescendant" with wrong parameters (a widget instead of a domNode).

comment:6 Changed 6 years ago by bill

Resolution: worksforme
Status: newclosed

OK thanks, I'd be interested to know what's causing the problem in your code. I do see the call to dom.isDescendant() in dojo/touch.js but I can't imagine why it would get passed a widget.

Note: See TracTickets for help on using tickets.