Every built-in element is :defined - #193
Open
jdalton wants to merge 1 commit into
Open
Conversation
jdalton
force-pushed
the
fix/defined-built-ins
branch
from
September 4, 2026 18:00
863101b to
e50f059
Compare
':defined' asks the custom element registry about the candidate's tag name and requires an instanceof match, so it matches upgraded custom elements and nothing else. Every built-in element is defined; only a custom element can be undefined, and only until a definition exists and it has been upgraded. Browsers read it off the element's custom element state, where uncustomized and custom are the two that count as defined. https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/dom/element.h#L1201 The test reads the hyphen in the name first, which is what makes a name a custom element name, and asks for the 'is' attribute only when there is none, so an ordinary element costs one string scan. References: - Spec: https://dom.spec.whatwg.org/#concept-element-defined — uncustomized and custom are the two states that count as defined - Spec: https://html.spec.whatwg.org/#custom-elements-core-concepts — what makes a name a custom element name - Chromium: https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/dom/element.h#L1201 — the state read, with the same spec link in its own comment - Chromium: https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/css/selector_checker.cc#L3139 — ':defined' is that and nothing else - MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/:defined
jdalton
force-pushed
the
fix/defined-built-ins
branch
from
September 5, 2026 02:48
e50f059 to
bb2ea11
Compare
Collaborator
Author
|
This one sits with #190 and #191 and #192, which touch the conformance fixes found by comparing against Chromium. They do not depend on each other. All seventeen in the series cherry-pick onto master in any order, and I checked that in both directions, so any one of these can land alone. The order below is the one they read best in: |
This was referenced Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
:definedasks the custom element registry about every candidate's tag name and requires aninstanceofmatch, so it matches upgraded custom elements and nothing else. Every built-in element is defined as well, which means the selector currently returns almost nothing on an ordinary page.Only a custom element can be undefined, and only until a definition exists and the element has been upgraded to it.
What it returns before and after
Chromium matches
d1with:definedand skips the other two, since neither custom element has a definition yet. Before this change the engine matched none of the three, including the plain<div>. AftercustomElements.define('my-thing', …)runs, both Chromium and the engine addmt.Where browsers implement it, and why the test is ordered this way
Blink reads the element's custom element state and treats "uncustomized" and "custom" as defined, in
element.h#L1201, which its own comment ties to the DOM definition.:definedis that and nothing else, inselector_checker.cc#L3139.The helper checks the hyphen in the tag name first, because a hyphen is what makes a name a valid custom element name, and asks for the
isattribute only when there is none. An ordinary element therefore costs one string scan and no host call, which matters because:definedmatches nearly every element in a document.References: the spec, the browser source, and what each part was reasoned from
This patch applies to master on its own. The sixteen in this series were checked by cherry-picking them onto master one after another, in this order and in reverse, and all sixteen land without a conflict.
element.h#L1201— the state read, with the same spec link in its own comment.selector_checker.cc#L3139—:definedis that and nothing else.:defined.