Skip to content

Update customized built-in element example to match its source - #44978

Open
quepasaquepasa wants to merge 1 commit into
mdn:mainfrom
quepasaquepasa:fix-expanding-list-example
Open

Update customized built-in element example to match its source#44978
quepasaquepasa wants to merge 1 commit into
mdn:mainfrom
quepasaquepasa:fix-expanding-list-example

Conversation

@quepasaquepasa

Copy link
Copy Markdown
Contributor

Fixes #44952

The ExpandingList snippet in the "Customized built-in elements" section was still the pre-mdn/web-components-examples#81 version, which:

  • assigns to self in the constructor (self = super()), clobbering the global {{domxref("Window.self")}}. Even scoped to a module variable this would be wrong, since it only ever points at the most recently constructed instance, so a page with more than one expanding list would have every callback operate on the last one.
  • declares a constructor that only calls super(), which the implicit constructor already does.

This syncs the snippet with the current source: no constructor, this instead of self, for…of over the live NodeLists instead of Array.from(...).forEach(...), and optional chaining on childText.parentNode.

The surrounding prose is updated to match — it no longer says "most of the code" is in connectedCallback() (now all of it is), and briefly explains why there's no constructor and what this refers to, which is the explanation the issue asked for.

@quepasaquepasa
quepasaquepasa requested a review from a team as a code owner July 31, 2026 03:20
@quepasaquepasa
quepasaquepasa requested review from wbamberg and removed request for a team July 31, 2026 03:20
@github-actions github-actions Bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Customized built-in elements uses old and incorrect example.

2 participants