Re: [webcomponents] What was the "element is being created" flag for? (#458)

Perfect background reading; thank you.

So the goal here, in modern terms, is that

```js
class XTag extends HTMLElement {
  constructor() {
    super();
    console.log("constructor start");
    this.setAttribute("foo", "bar");
    console.log("constructor end");
  }
  
  static get observedAttributes() { return ["foo"]; }
  
  attributeChangedCallback() {
    console.log("attribute changed");
  }
}

new XTag();
```

should log:

```
constructor start
constructor end
attribute changed
```

As I said above, I can't really think of any way to make this work in in the specific case of `new XTag()`, since (unlike in the previous design) we don't control the constructor code, and thus don't know when to set/unset an "element is being created" flag. In other words, there's no way for `setAttribute` to know that it should delay calling `attributeChangedCallback`, and even if we could let it know, it wouldn't know _when_ to delay too.

That's kind of sad.

We could make this work for `createElement` and the parser and friends, but I assume that the inconsistency there would not be a good idea.

On the upside, these days we're very explicitly telling people that they shouldn't be mutating the DOM in their constructor. So, if developers follow the conformance requirements, then this shouldn't come up very often, which is good...

In conclusion I think we'll have to "regress" on this behavior (so the above outputs `constructor start / attribute changed / constructor end`). I'll close this with a commit that removes the "element is being created" flag. If this is a big deal to anyone, please let me know and we can reopen for further discussion (although I'm not really sure what we could do). Tagging in @rniwa @annevk @travisleithead as browser reps, and @coonsta and @sjmiles since they were in the original thread at https://www.w3.org/Bugs/Public/show_bug.cgi?id=22966.

---
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/458#issuecomment-201464751

Received on Friday, 25 March 2016 20:03:37 UTC