#declarativeShadowDOM

westbrookwestbrook
2025-06-13

@LorenzKahl @jensimmons @mozilla I don't spend much time looking into Reader Mode, so I've not noticed this. When you're delivering content via DSD, are you later upgrading those or simply using ? The influence of JS in that area would surprise me less, even if it were still not the optimal behavior in that case...

😅

2025-06-13

@jensimmons @westbrook @mozilla is it a known issue that Safari & Firefox Reader Mode ignore content rendered by Web Components in the Shadow DOM - even SSR‘ed content using DSD (iOS & Mac)

#WebComponents #DeclarativeShadowDOM #DSD #SSR

2025-03-18

New Kitten release

• Now leaves <style> tags within <template> tags alone when collating and normalising the CSS on a page so as not to interfere with scoped styles in declarative shadow DOM.

(Kitten’s Streaming HTML workflow¹ – which uses htmx and WebSockets under the hood – combined with built-in support for slots, etc., in Kitten components² means the use of declarative shadow DOM is mostly useful if you want scoped styles. Ideally, of course, use classes to scope styles to your components and be specific in your CSS selectors in general so as not to pollute elements in your components. Although that’s a bit like saying you should floss everyday. Yeah, we all know we should…) :)

Update: All that said, I’d highly recommend you don’t use Shadow DOM in your Kitten apps. For one thing, htmx’s WebSocket extension doesn’t seem to play well with it. And for another, you really don’t need it and definitely not just to get scoped CSS.

Enjoy!

:kitten:💕

¹ kitten.small-web.org/tutorials
² kitten.small-web.org/tutorials

#Kitten #SmallWeb #SmallTech #CSS #CSSScoping #ShadowDOM #shadowRoot #DOM #HTML #JavaScript #JS #style #template #declarativeShadowDOM #NodeJS #web #dev

Screenshot of code (left) and browser output (right).

Code:

<p>I am regular root</p>
<div>
  <template shadowrootmode='open'>
    <p>I am shadow root</p>
    <slot></slot>
    <style>
      p { color: red; }
    </style>
  </template>
</div>
<p>I am also regular root</p>
<style>
  p { color: blue; }
</style>

Browser output shows “I am regular root” in blue, “I am shadow root” in red, and “I am also regular root” in blue.
🧿🪬🍄🌈🎮💻🚲🥓🎃💀🏴🛻🇺🇸schizanon
2024-07-18

Using to render placeholder content that gets replaced later as the in with no !

lamplightdev.com/blog/2024/01/

This is an interesting technique, but it has limitations in that you can't close the until you've loaded the content.

westbrookwestbrook
2024-07-01

@ryantownsend In github.com/WICG/webcomponents/ we're theorizing the declarative sharing of repeat <style> tags. Structured initially for , but feels like something that could apply to prelude-less @​scope, too. I wonder if that would make it practical/productive to blend test no. 1 and no. 3 in your demo css-scope-test.netlify.app/ and whether an approach that like that could even further reduce the paint times these tests are clocking...

westbrookwestbrook
2024-03-18

So many great encapsulation strategies, so little time!

<style>
p {
color: blue;
font-size: 2rem;
}
</style>

<my-el>
<style>
@Scope {
:scope {
&, * {
all: revert-layer;
color: red;
}
}
}
</style>
<p>This text is red & small!</p>
</my-el>

<my-el>
<template shadowrootmode="open">
<style>
* {
color: red;
}
</style>
<p>This text is red & small!</p>
</template>
</my-el>

codepen.io/Westbrook/pen/vYMgO

2024-02-24

Released v3 of Tram-Deco, the declarative custom element library that uses #DeclarativeShadowDOM (which became available in all major browsers this week)!

github.com/Tram-One/tram-deco

I also added an import method, which allows you to import definitions from other HTML files (relies on `Document.parseHTMLUnsafe`, so millage may vary).

Planning to present this to Web Components Community Group, so I would love any feedback! ❤️

#WebComponents #WebDev #HTML #HTMLFirst #ShadowDOM

Screenshot of codepen, with HTML panel on the left, and a browser preview on the right.

The code has a template with a custom "word-count" element, which then also has a template with a shadowrootmode. The shadow root template has style tags, a button, and script tags. The script tags have attributes `td-constructor` and `td-connectedcallback`, and use the `this` keyword. 

On the right panel, we see a preview of the button, styled as described in the code.
westbrookwestbrook
2024-02-20

@nshki OMG, I'm so happy, this makes testing random weirdnesses of the various shadow DOMs so, so, so much easier!

Like: codepen.io/Westbrook/pen/OJqrx

...now we can side eye even more for their weird support of :has() inside of :host(). 🥳

2024-02-16

Put together a super lightweight and standard-API-focused implementation of Declarative Custom Elements. 👏

github.com/Tram-One/tram-deco

Exclusively implements all the standard Web Component APIs in an HTML-First approach that should be familiar and easy to pick up 😁 - no special syntax or template language here.

Check the repo for live codepens, and would love to hear what people think! ❤️

#WebComponents #WebDev #HTMLFirst #DeclarativeShadowDOM #ShadowDOM #HTML

Code snippet, there are two script tags, the first one has a comment that says "following script runs on component connectedCallback" and has an attribute td-connectedCallback. The second script has a comment that says "following script runs on component attributeChangedCallback" and has an attribute td-attributeChangedCallback. Inside the script tag is javascript code to query elements, update text content, and add event listeners.
westbrookwestbrook
2024-02-09

@mia Is DSD new syntax still?

Ok, maybe. It's targeted for in the next couple of version, which is gonna be 🔥

2024-02-02

Working on a way to build Declarative Custom Elements using the newly released Declarative Shadow DOM.

Turned out to only 20 lines of Javascript! I'm surprised how neatly everything kinda works.

codepen.io/JRJurman/pen/dyrJWe

There are some gotchas and it certainly could be more elegant, but I think it has the building blocks for building Web Components from an HTML First approach.

#WebComponents #WebDev #HTMLFirst #DeclarativeShadowDOM #ShadowDOM #HTML

2024-01-19

Once the basic building blocks are there, it is very easy to start playing around and letting the imagination fly.
In this case I'm doing "scoped components" with declarative shadow dom, no JS involved!

#dotnet #fsharp #shadowdom #declarativeshadowdom #ssr #backend #webdev

2024-01-09

So I got nerd-sniped by @passle and their very cool out of order #HTML streaming demo with #DeclarativeShadowDom and no client-side #JavaScript.

techhub.social/@passle@mastodo

I spent yesterday playing around with this idea and came away with a `streamOutOfOrder` tagged template literal which is able to apply this optimization to any interpolations. It even composes itself correctly and can load the whole page optimally out of order, no matter how large or complex it is.

Take a look and "View Source" to see how it works!

dsd-out-of-order-streaming.dwa

2023-11-19

@westbrook @matsuuu Does `lit-analyzer` apply to #JSX expressions? Currently I'm forced into #Preact until I can get `lit-html` to render hand-coded #DeclarativeShadowDom.

github.com/lit/lit/issues/4058

Agreed that typing `setAttribute` would be very cool. I did some theorizing in this issue, but I'm not exactly sure what it would look like. I would love to have some #TypeScript primitives (like `HTMLElementTagNameMap`) to build on top of here.

github.com/dgp1130/HydroActive

2023-08-26
westbrookwestbrook
2023-05-09

partners with the likes of `:not(:defined)` to make progressive enhancement a more natural part of component development than ever.

builds on top of that, and once Firefox ships things powerful API the distance between "page load" and "page needs JS" can be even further apart.

It's powerful to lean into the existing web APIs to learn new and exciting ways to support our clients while continuing to push the boundaries of those APIs at the spec level.

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst