[w3c/webcomponents] Custom attribute names conflicting with built-in attribute names (#654)

Say I have a custom element that responds to the `hidden` attribute. This custom element may hide itself in a particular way, or have a particular semantic meaning for "hidden" in this context that is different to "the browser should hide this element".

```js
class MyElement extends HTMLElement {
  static observedAttributes = ['hidden']
  attributeChangedCallback (name, oldValue, newValue) {
    // go do some hidy stuff
  }
}
```

Now let's say this element is in production, correctly responding to the semantics of its custom `hidden` attribute. Then along comes a new, standardised, attribute with of the same name in what normally would be an innocuous change. The new attribute takes the element and hides it immediately. All of our custom elements that implement our own semantics for this attribute are now broken.

This example is somewhat contrived in the context of `HTMLElement` because `hidden` is fairly concrete behaviour. This would be more likely to happen with customised built-ins. That said, this is still possible at the `HTMLElement` level with more abstract use cases.

One could say that this isn't limited to custom elements as people have been doing this with existing component systems for a long time (jQuery plugins, Moo Tools, Angular, etc.). Previously, people have been encouraged to use `data` prefixed attributes (maybe not with certain component models such as Angular which have seen similar issues). With the arrival of custom elements, people have been encouraged to use non-prefixed attribute names.

I'd really appreciate a discussion on how we can prevent this from happening at the standards level so custom element authors don't have to worry about this.

The origination of this issue was a [discussion](https://twitter.com/sebmarkbage/status/894678380225875968) started by @sebmarkbage. I don't have any prior art to offer, but maybe others do.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/654

Received on Tuesday, 8 August 2017 03:12:28 UTC