[WICG/webcomponents] add `node.isCustomElement` property (Issue #1080)

This is a request to add a new `property` to all custom elements, so you can tell them apart from `native` elements. 

Framework authors, may want to tell apart a custom element from a native element. For a recent example check https://discord.com/channels/767813449048260658/1295915163827830784/1296144958625026068
^ https://discord.gg/NVPetmMweg

I would like to suggest `node.isCustomElement` set to `true`. This will apply to custom elements with `-` in the tag (as in `<my-el/>`), and to native elements that have `is` as an attribute `<img is="my-img"/>`

Reasons:

- performance: having to check for a substring in a tagName, and also maybe in a props object as `"is" in props` impacts performance
- DX, if the _built in_ element has a property thats much easier to consume, (think you do not have to carry `props` around just to check if the props have an `is`)
- accuracy, not all elements with a dash are custom elements

We already do this, its just ugly and not optimal:

- SolidJS https://github.com/ryansolid/dom-expressions/blob/388985beae617521fe7daff06759e9d704b852fa/packages/dom-expressions/src/client.js#L369
- React https://github.com/facebook/react/blob/be94b108264e30873d4b679771e07ce14491e413/packages/react-dom-bindings/src/shared/isCustomElement.js#L10-L31
- Vue https://github.com/vuejs/core/blob/2442c3b06102a8fa0db4350d3f7e4218227136b9/packages/runtime-dom/src/patchProp.ts#L55
- Svelte https://github.com/sveltejs/svelte/blob/f579a3ba7d8f088d1d4f8625758e5e5598c9ebfa/packages/svelte/src/internal/client/dom/elements/attributes.js#L163
- Voby https://github.com/vobyjs/voby/blob/e5a0a221e3badcfa1f0cc383174b35826ef36cbc/src/utils/lang.ts#L136

cross posting:
- https://issues.chromium.org/issues/373852609

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

Message ID: <WICG/webcomponents/issues/1080@github.com>

Received on Wednesday, 16 October 2024 17:08:06 UTC