You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HTMLElement.prototype.offsetParent leaks a node inside a shadow tree #497
We need to patch offsetParent so that when a node's container block is inside a shadow tree, we don't leak a node inside a shadow tree.
Chrome seems to return null in such cases. It's somewhat undesirable in that this makes the feature useless (since you can't determine where your containing block is) but I don't have a strong opinion about this as long as we don't leak a node inside a shadow tree.
It looks like Chrome returns null whenever the offset parent is inside a shadow tree. I think a better change would be to return null if the offset parent is not an unclosed node of the context object.
We’re exposing any node that’s not closed-shadow-hidden here, which means we’d return an element inside shadow tree as an offset parent. I don’t think we want that even in an open shadow tree.
Let’s imagine you’re trying to traverse over ancestor offsetParents. Such a code would now walk over elements inside a shadow tree. I don’t think this is desirable just as much as finding nodes via querySelector or getElementsByTagName inside shadow trees are not desirable.
Note: This behaviour appears to have now been updated in Chrome 109 (and earlier versions of Firefox/Webkit) so that it no longer leaks elements within a shadow DOM.
Activity
rniwa commentedon May 7, 2016
@annevk @zcorpan @hayatoito @travisleithead
rniwa commentedon May 7, 2016
It looks like Chrome returns
nullwhenever the offset parent is inside a shadow tree. I think a better change would be to returnnullif the offset parent is not an unclosed node of the context object.rniwa commentedon May 7, 2016
An alternative solution is to walk up
offsetParentenough to find the first offset parent that is unclosed node to the context object.This is probably a better fix since authors won't be able to determine the location of an element which is assigned to a slot otherwise.
kojiishi commentedon May 8, 2016
Should
offsetLeftandoffsetTopbe adjusted accordingly?rniwa commentedon May 8, 2016
Right. Since offsetTop and offsetLeft are defined to use offsetParent already, that's kind of automatic.
hayatoito commentedon Jun 1, 2016
I have filed an issue for csswg: w3c/csswg-drafts#159
hayatoito commentedon Jun 20, 2016
PR is merged. Let me close this issue.
rniwa commentedon Dec 10, 2016
Sorry, it looks like I missed an crucial point in w3c/csswg-drafts#159
We’re exposing any node that’s not closed-shadow-hidden here, which means we’d return an element inside shadow tree as an offset parent. I don’t think we want that even in an open shadow tree.
Let’s imagine you’re trying to traverse over ancestor offsetParents. Such a code would now walk over elements inside a shadow tree. I don’t think this is desirable just as much as finding nodes via querySelector or getElementsByTagName inside shadow trees are not desirable.
rniwa commentedon Oct 26, 2018
Rough consensus at TPAC F2F: Use the retargeting algorithm to find the offset parent, and the compute left and top from that node.
offsetLeft and offsetParent should adjust across shadow boundaries
rniwa commentedon Apr 25, 2019
We need to resolve CSS OM View spec change in w3c/csswg-drafts#159
offsetLeft and offsetParent should adjust across shadow boundaries
Update offsetParent behavior in shadow trees
Update offsetParent behavior in shadow trees
Update offsetParent behavior in shadow trees
Update offsetParent behavior in shadow trees
Update offsetParent behavior in shadow trees
Bug 1700509 [wpt PR 28201] - Update offsetParent behavior in shadow t…
eKoopmans commentedon Dec 7, 2022
Note: This behaviour appears to have now been updated in Chrome 109 (and earlier versions of Firefox/Webkit) so that it no longer leaks elements within a shadow DOM.
If you need the original behaviour, see this comment from October 2022 and the linked polyfill:
https://github.com/josepharhar/offsetparent-polyfills
Bug 1700509 [wpt PR 28201] - Update offsetParent behavior in shadow t…