-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Prevent duplicate ID's in polyfill #295
Comments
The duplicate id's are inside the component's Shadow DOM which is a protected scope and therefore free to re-use ids. Your "will become" code represents the Try your example on Canary to see how it works with native Shadow DOM. |
Jap, but in case the browser doesn't support Shadow DOM I end up with missbehaviour. You can check it here in the third example: http://stefanjudis.github.io/webComponents-tutorial/ Canary works fine as expected and other browsers unfortunately not. |
Yes, in this case you are relying on DOM-level id matching via the The Shadow DOM polyfill does it's best to provide the proper DOM API to user-level code, but we cannot trick the actual user agent, so I don't believe we can ever make this work with ShadowDOM polyfill. This is unfortunate wrt confounding user's expectations, but as a practical matter it is easy to work around in a custom element scenario. This is important information to add to our FAQ. |
Fwiw, ironically, you have two nodes with |
😄 Ha, sorry. Quick copy and pasting for showing it. Maybe I don't get the complexity of the whole polyfill, but couldn't it scan for id's inside of the template and add a random hash to the id's before appending it to the DOM for not supporting browsers? Workaround worked fine for me, so not a big deal. ;) Thx. |
Thanks for the idea. I think in general it would be a bad idea to scramble id's because the user could be relying on them in various ways. We could maybe add a helper method that does this rewriting, opt-in, if somebody wants to use We probably need to catalog the scenarios where DOM uses id's internally like that. |
👍 Helper sounds good. |
What's the best way to describe this? |
Sorry, I don't understand. What do you mean by 'this'? The helper functionality? |
I'm asking what needs to be mentioned in the FAQ? Can't use DOM-level id matching ( |
Unfortunately it's not only I would maybe think of something like: I want to use polymer mainly for not supporting browsers because I love the princible of web components. Is there anything I should pay attention to?If you want to reuse a web component multiple times inside of the same document, you should avoid the usage of id's inside of your component. Unfortunately the depending polyfill has no solution for id handling yet, which means that in that case multiple DOM nodes with the same id will appended to the DOM. This could lead to invalid markup and in some cases misbehaviour (like |
A more general approach with a warning of careful usage with id's is a nice approach, i guess. |
I don't think this is the correct conclusion. The only time IDs are a particular problem is if you use DOM-level ID referencing, which is rare. As long as you don't use |
IMO, the FAQ should say something like: Avoid using |
Short and sweet. That's what I was looking for. Thanks
|
http://www.polymer-project.org/faq.html#multipleids On Fri, Sep 27, 2013 at 9:32 AM, Eric Bidelman ebidel@gmail.com wrote:
|
👍 |
@ebidel the link http://www.polymer-project.org/faq.html#multipleids seems to be a 404. |
@ebidel A related conversation here involves the use of IDs in |
I landed here after snooping around wondering if using "id" in a component was a good idea. The FAQ is only there for 0.5 which is now rather obsolete. This only creates a problem when doing DOM-level ID referencing. Before now, it was discussed that the only tag with the problem was (I really hope to open this ticket in 5 years time and think "ahhhhhh do you remember the days when we had to use shims and polyfills"?) |
When using id's in a polymer component and using the new element multiple times, the fallback solution will render the same html multiple times, which leads to multiple id's inside of the DOM, invalid html and maybe misbehaviour.
For example:
will become:
Unfortunately the component is not reusable in this case.
The text was updated successfully, but these errors were encountered: