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.
export default { dsd: { enabled: true, manifest: 'assets/vb/dsd-manifest.json', },};
The manifest maps each tag name to its shadow DOM content:
{ "vb-button": "<style>:host { display: inline-flex; }</style><slot></slot>", "hero-banner": "<style>:host { display: block; }</style><div class='inner'><slot></slot></div>"}
For a page containing <vb-button>Click me</vb-button>, Cook produces:
<vb-button> <template shadowrootmode="open"> <style>:host { display: inline-flex; }</style> <slot></slot> </template> Click me</vb-button>
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 <template shadowrootmode="open"> 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.
<template shadowrootmode="open"> <style> :host { display: block; border: 1px solid #ccc; border-radius: 8px; } .body { padding: 1rem; } </style> <div class="body"> <slot></slot> </div></template>
If a companion my-card.js file exists alongside the HTML template, the auto-components plugin automatically injects a <script type="module"> tag for hydration.
Configuration reference
| Option | Default | Description |
|---|---|---|
enabled | false | Enable the DSD plugin |
manifest | null | Path to DSD manifest JSON (relative to dist, or absolute) |