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

Dashless element name error duplicates the preview iframe #22

Open
fastdivision opened this issue Jul 23, 2014 · 4 comments
Open

Dashless element name error duplicates the preview iframe #22

fastdivision opened this issue Jul 23, 2014 · 4 comments
Labels

Comments

@fastdivision
Copy link
Member

We should catch the error:

Uncaught SyntaxError: Failed to execute 'registerElement' on 'Document': Registration failed for type 'sarcasm'. The type name is invalid. 

And tell beginners they need a dash in their element name. Also, don't duplicate the iframe on an error.

@bcherny
Copy link

bcherny commented Sep 21, 2014

+1 I just got Uncaught SyntaxError: Failed to execute 'registerElement' on 'Document': Registration failed for type 'list'. The type name is invalid.. Having a more specific error (maybe Polymer requires that all component names contain a dash character) would have been nice.

The rule that names must contain a dash is unusual, why does polymer impose that constraint?

@mbleigh
Copy link
Member

mbleigh commented Sep 21, 2014

@eighttrackmind It's not Polymer, it's the Web Components spec. The idea is that by requiring a dash in the name (which no native elements have) there's no chance of accidentally registering over an existing tag. An interesting and pragmatic solution, but can bite you if you're unaware.

@bcherny
Copy link

bcherny commented Sep 21, 2014

That's really interesting, thanks for the quick response.

It's clever but seems like an odd constraint - to avoid overloading native elements a custom element must have a dash in its name, but to avoid overwriting native attributes custom attributes should start with data-. It also makes it very difficult to introduce dash-cased native tag names in the future, should the w3c/vendors decide to go down that route.

It also doesn't solve the problem of name collisions. Since web components are imported into a global namespace, there will almost certainly be collisions for large applications with lots of 3rd party components (if I understand how web components work correctly). The dash-case requirement is seems like a pretty gnarly workaround that makes this issue a bit less likely to occur.

I feel like a more normalized and scalable solution would be to overload XML namespaces, so my custom tag could be <abc:list></abc:list>. Albeit it's a bit uglier.

Alternatively, components could be explicitly scoped like imports in most languages, eg. <list rel="import" href="/components/list.html"></list>.

@mbleigh
Copy link
Member

mbleigh commented Sep 22, 2014

There are definitely some interesting edge issues around imports, namespace collisions, etc. Once you get used to the dashes, though, it feels pretty natural. I was a bit surprised that they didn't go for XML namespaces, but there's probably a good reason for it.

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

No branches or pull requests

3 participants