Lwc: Node.contains API is broken, returns false for node itself

Created on 31 Mar 2020  路  4Comments  路  Source: salesforce/lwc

Description

Node.contains API doesn't work like it is described in MDN. Latter states that

The Node.contains() method returns a Boolean value indicating whether a node is a descendant of a given node, i.e. the node itself,

Steps to Reproduce

See this playground app:
https://developer.salesforce.com/docs/component-library/tools/playground/OhXG7B2Gh/3/edit

Expected Results


true is shown on the page

Actual Results


false is shown

Browsers Affected


Fails in chrome and firefox. Issue promises to be cross-browser

BUG P3

Most helpful comment

I see a PR with a fix already. Very impressive!

All 4 comments

Sorry we could wait until Heroku connect make the syncronization.

Workaround:

const contains = Node.prototype.contains;
Node.prototype.contains = function (value) {
    if (value === this) {
        return true;
    }
    else {
        return contains.apply(this, arguments);
    }
}

I was afraid it won't help given the amount of encapsulation and protection, but it did.

I see a PR with a fix already. Very impressive!

@bmblb thanks for reporting the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jodarove picture jodarove  路  5Comments

juvian picture juvian  路  5Comments

priandsf picture priandsf  路  5Comments

gonzalocordero picture gonzalocordero  路  4Comments

ravijayaramappa picture ravijayaramappa  路  4Comments