liveBook · Manning

Light DOM

As explained in Vanilla Web

The DOM content supplied by a web component's host document rather than contained in the component's shadow tree.

A custom element can accept content from the page that uses it. That content—children added to the host element in the page DOM—is its light DOM. It is separate from the component’s shadow DOM, which holds the component’s internal tree. section 7.5.2

Once a component has a shadow root, render internal content through the shadow root. Calling `this.append()` or setting `this.innerHTML` adds nodes to the host’s light DOM instead. Those nodes render within the component only when a `<slot>` projects them. section 7.8.1 section 7.5.2

Consumer-provided content

`<product-details><span slot="title">Camera</span>A great camera.</product-details>` supplies a named title and other child content. Slots can display those children within the shadow layout, but the nodes stay in their original page-DOM location. The browser’s flattened tree describes the rendered result, not a move into the shadow DOM. section 8.4.3

Use slots when consumers should provide content while the component retains its own structure and behavior. Templates can also be cloned into either light or shadow DOM; choose the destination according to the encapsulation needed. section 8.9

How Vanilla Web covers it

How deep it goes
Defines light DOM and explains host writes, slot projection, and flattened rendering without moving the underlying DOM nodes.
Examples
Illustrates named-slot content with a product-details element and contrasts writes to the host with writes to its shadow root.
What it assumes
Defines custom elements, host elements, page DOM, shadow DOM, light DOM, and slots before explaining their interaction.
What you can do after
Apply it via native custom elements and slots to accept consumer children without relocating their DOM nodes.
How it connects
Connects custom elements, page DOM, shadow DOM, host elements, slots, and the flattened tree.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.