DEV Community

Discussion on: What's Actually Wrong with Web Components?

Collapse
 
dannyengelman profile image
Danny Engelman • Edited

> A Custom Element's lifecycle starts at the constructor.

Not correct.

The Custom Element lifecycle starts when a <tag-name> (with a hyphen!) is created.

  • No JavaScript required
  • They are valid HTMLElement
  • Great for layout and styling with CSS, you can replace the whole DIV-soup
  • A.I. wrongly calls them unknown elements
  • customElements.define can upgrade these UNdefined Custom Elements
    • starting the constructor first
  • But you do not have to upgrade them
  • <tagname> (no hyphen!) are HTMLUnknownElemen (and can't be upgraded)

Web Components / Custom Elements often get off to the wrong start because most blogs and documentation skip this first step.

Collapse
 
foxeyes profile image
Alex M

Well, technically you're right. And yes, using such elements without constructor might be very useful.

But in the context of this article, we were specifically talking about the Custom Elements API. Without initialization through this API, it's an instance of HTMLUnknownElement. So, we could say its lifecycle hasn't yet begun.

Collapse
 
dannyengelman profile image
Danny Engelman

No, its not

Thread Thread
 
foxeyes profile image
Alex M

Yep, It's almost the same (depends on browser version) and doesn't make any additional sense at this whole context. But I like your your desire for precision.

Thread Thread
 
dannyengelman profile image
Danny Engelman

Which Browser makes <my-element> anything BUT a HTMLElement?

But to be precise, yes, you are correct, Internet Explorer will say its an HTMLUnknownElement