Declarative Shadow DOM

Cook pre-renders Declarative Shadow DOM (DSD) templates into your HTML at build time. This eliminates the flash of unstyled content (FOUC) that occurs when Shadow DOM components wait for JavaScript to load, and makes component content visible to search engines.

There are two approaches depending on where the component comes from.

Approach 1: Manifest-based (external components)

For third-party or framework components like Vanilla Breeze, provide a DSD manifest that maps tag names to their shadow DOM HTML. Cook injects <template shadowrootmode="open"> as the first child of each matching element.

The manifest maps each tag name to its shadow DOM content:

For a page containing <vb-button>Click me</vb-button>, Cook produces:

Dynamic attributes

Manifest templates can reference host element attributes with ${attr:name}. Cook resolves these at build time:

{
  "hero-banner": "<img src='${attr:src}' alt='${attr:alt}'><slot></slot>"
}

An element like <hero-banner src="/hero.jpg" alt="Welcome"> gets the src and alt values injected into its shadow template.

VB component requirement

Vanilla Breeze components must guard their shadow root attachment so the DSD template is adopted rather than replaced:

if (!this.shadowRoot) this.attachShadow({ mode: 'open' });

Approach 2: Template-based (Cook-authored components)

For components you author directly in Cook, place a &lt;template shadowrootmode="open"&gt; inside the component's HTML file. Cook's component system will include it in the output, and the browser adopts it as a declarative shadow root -- no manifest needed.

If a companion my-card.js file exists alongside the HTML template, the auto-components plugin automatically injects a &lt;script type="module"&gt; tag for hydration.

Configuration reference

OptionDefaultDescription
enabledfalseEnable the DSD plugin
manifestnullPath to DSD manifest JSON (relative to dist, or absolute)