Re: [csswg-drafts] HTMLElement.prototype.offsetParent leaks a node inside a shadow tree

@TakayoshiKochi: Something along the line of the code below should do 
the trick.  Basically, you want to walk up the tree up until the 
“retargeted” `offsetParent`, and return `offsetParent` of a node 
assigned to the deepest slot that’s different from the original 
`offsetParent`.  **Note**: I didn’t think through every edge case so 
the code’s mostly certainly a bug in the code.

```
function composedParentNode(node) {
    let offsetParent = node.offsetParent;
    let ancestor = node;
    let foundInsideSlot = false;
    while (ancestor && ancestor != offsetParent) {
        let assignedSlot = ancestor.assignedSlot;
        if (assignedSlot) {
            ancestor = assignedSlot;
            let newOffsetParent = assignedSlot.offsetParent;
            if (offsetParent != newOffsetParent)
                foundInsideSlot = true;
        } else if (ancestor.host && foundInsideSlot)
            break;
        ancestor = ancestor.host || ancestor.parentNode;
    }
    return offsetParent;
}
```


-- 
GitHub Notification of comment by rniwa
Please view or discuss this issue at 
https://github.com/w3c/csswg-drafts/issues/159#issuecomment-266972341 
using your GitHub account

Received on Wednesday, 14 December 2016 08:24:15 UTC