question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select2 inside ShadowRoot Broke In 4.0.11

See original GitHub issue

#5584 breaks the usage of Select2 inside a ShadowRoot, because $.contains() returns false, even though the Node is actually connected to the document.

I’d propose changing the following code:

    if ($.contains(document.body, $offsetParent[0])) {
      parentOffset = $offsetParent.offset();
    }

To this:

    if ($offsetParent[0].isConnected) {
      parentOffset = $offsetParent.offset();
    }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kevin-browncommented, Oct 31, 2019

Probably going to switch this to

    if ($.contains(document.body, $offsetParent[0]) || $offsetParent[0].isConnected) {
      parentOffset = $offsetParent.offset();
    }

Just to handle IE/Edge/older browsers when they aren’t using the shadow DOM (because let’s be honest, they won’t be using the shadow DOM if they’re old enough to not support isConnected).

1reaction
lazkacommented, Oct 28, 2019

Since 4.0.11 (4.0.10 works) I also get wrong offsets for the popup:

select2-bug

This is also inside a Shadow DOM.

Read more comments on GitHub >

github_iconTop Results From Across the Web

select2 - ShadowRoot 내부의 Select2가 4.0.11에서 중단되었습니다 ...
5584는 노드가 실제로 문서에 연결되어 있어도 $.contains() 가 false를 반환하기 때문에 ShadowRoot 내에서 Select2 사용을 중단합니다.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found