Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple shadow DOM trees with same select2 ids not working correctly #6158

Open
sergotail opened this issue May 8, 2022 · 3 comments
Open

Comments

@sergotail
Copy link

Hi, i encountered issue similar to #5682, but for multiple shadow DOM subtrees having select2 elements. I have a custom element, and i initialize select2 for elements inside shadow DOM, in connectedCallback. And when i add second, third and so on custom elements, all select2 forms nested in existing custom elements are become broken.

I found that this code is executed when i add new select2 inside newly created shadow DOM:

if (Utils.GetData($element[0], 'select2') != null) {
  Utils.GetData($element[0], 'select2').destroy();
}

I think it's a major bug, because reused web components scenario is not a rare one.

JS Bin example

select2 version: 4.0.13
jQuery version: 3.5.1
bootstrap version: 4.6.1

@sergotail
Copy link
Author

sergotail commented May 8, 2022

One of the possible solutions is to add root option to options with value of a jQuery object or null. And when user creates select2 from within shadow DOM, he can pass shadow DOM host element with root key in options to unify elements between shadow DOM subtrees and light DOM.

But this requires a data storage refactor to store data per roots as well.

@kevin-brown
Copy link
Member

Are shadow DOMs allowed to have duplicate IDs? I know that the root DOM object isn't allowed to have duplicate IDs per the HTML spec, but I'm not super familiar with the rules around shadow DOMs.

@sergotail
Copy link
Author

sergotail commented May 8, 2022

There are no duplicate IDs allowed within single shadow DOM tree, but it's ok to have the same IDs between different shadow DOM trees, this is an incapsulation feature of shadow DOM for convenient development of reusable web components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants