Component kit: newer DOM features in a drawable element

I wanted to know whether six DOM features that shipped between Chrome 133 and 152 work in a custom element that draws its children in a canvas, and what each one changes in the element's code.

<kit-slot> and <kit-field> are test elements for this page. They aren't a library to install. Each is the smallest element that puts a child in a <canvas content="drawable"> in its shadow root, which is what fx, <dom-portal>, <dom-lens> and <canvas-slot> do. Each is written twice in one file: once with a feature, and once with the code that feature replaces. The page runs both versions and counts the lines.

What the results mean for the libraries on this site

Each feature in the test element

FeatureIn this browserWhat it replaces in the elementLines, old → new
Scoped custom element registry…A version suffix on the tag name, and a guard against defining the element twice.…
Manual slot assignment…Writing slot="…" on the page's own elements, and a MutationObserver that keeps the attribute right.…
Reference Target…Finding <label for> by hand, copying its text to aria-label and forwarding its clicks.…
Explicit resource management…try/finally around every ElementImage.close().…
Observable…Keeping each paint and contextlost handler in a field so it can be removed later.…
moveBefore()…Putting focus back after an element is wrapped. A reloaded iframe had no fix.…

The line counts are taken from the #region old-… and #region new-… comments in the files this page is running. Blank lines and comments aren't counted.

Two versions of one element on one page

Each box below is a shadow root with its own CustomElementRegistry. Both define the tag kit-slot, with different classes: the left one uses the older code for every part, the right one uses each feature this browser has. Press a button to draw another child. The outgoing child fades out from an ElementImage snapshot.

A label outside, a field inside a canvas

<kit-field> keeps its <input> in the shadow root, as a child of the canvas that draws it. Press the label text.

Wrapping an element that is in use

The card holds a text field and an iframe that counts the seconds since it loaded. Type in the field, then wrap the card in a <kit-slot>. With moveBefore() the caret stays in the field and the counter keeps going. With replaceWith() the iframe loads again and the counter restarts.

Show the code each part, old and new
  1. Scoped registry: define the tag in the registry that is passed in.
  2. Before: one global registry, so a second version needs another tag name.
  3. This page: two shadow roots, two registries, the same tag.
  4. Manual slot assignment: slot.assign(child).
  5. Before: named slots and slot attributes written on the children.
  6. Reference Target: one line forwards <label for> into the shadow root.
  7. Before: find the labels, copy the text, forward the clicks.
  8. DisposableStack: adopt the snapshot once, dispose once.
  9. Before: try/finally at each place the fade can end.
  10. The using declaration, in a module of its own. A browser without the syntax can't parse the file, so it's imported only after a check.
  11. Before: the same function with try/finally.
  12. Observable: canvas.when('paint'), ended by an AbortSignal.
  13. Before: handlers kept in fields and removed by hand.
  14. moveBefore(): wrap an element without removing it.
  15. Before: remove, insert, put focus back.
  16. The same change in the library behind fx, <dom-lens> and <physical-ui>. dom-portal.js has it too.
  17. The whole element.

Findings

Live checks

ResultExperimentDetail