Web Components with StencilJS in an existing CMS

A grown front end inside a CMS can be replaced without taking the websites offline: with Web Components that the CMS delivers like plain HTML, and a switch that lets the old and the new solution run side by side for a while. In this article I describe how I do this for an energy provider’s websites with StencilJS, Sitefinity and Storybook, which decisions have to be made early and how WCAG accessibility gets into the components. I have been working on this project with the team since 2024.

Why Web Components in a server-rendered CMS?

In the project Sitefinity renders pages on the server with ASP.NET MVC and Razor. In projects like this the front end is often tightly woven into the templates: markup, styles and scripts are spread across many views. A new design then means touching every one of those places.

Web Components solve the problem in the right place. A component is an HTML element of its own, for example <my-teaser>, which the browser knows as soon as it is registered. To Razor it is just a tag with attributes. The CMS stays responsible for content and page structure, the component for presentation and behaviour. This lets you develop, version and test the front end as a package of its own, separate from the .NET code.

There is a second benefit: Web Components are not tied to a framework. The same component runs in a Razor view, in an Angular application and in React. In the project the components also work together with Angular applications.

What does StencilJS produce, and which output target fits?

StencilJS is a compiler. Components are written with TypeScript, JSX and decorators, and the result is standard custom elements. The output targets in stencil.config.ts decide what shape that result takes:

  • dist produces a library that lazy-loads itself. A loader registers all components, but a page only loads the code of the components it actually uses.
  • dist-custom-elements produces elements that directly extend HTMLElement. This target is meant for projects that handle bundling and registration themselves, such as a framework application with its own build.
  • www is aimed at websites and web apps served directly from an HTTP server.

For a CMS in which editors assemble pages from many components, I consider the lazy loading of dist a good default: a page with three components does not load the whole library.

A component in Stencil looks like this:

import { Component, Event, EventEmitter, Prop, h } from '@stencil/core';

@Component({ tag: 'my-teaser', styleUrl: 'my-teaser.css', shadow: true })
export class MyTeaser {
  @Prop() heading: string;
  @Event() teaserSelected: EventEmitter<string>;

  render() {
    return (
      <article>
        <h2>{this.heading}</h2>
        <slot />
        <button onClick={() => this.teaserSelected.emit(this.heading)}>More</button>
      </article>
    );
  }
}

@Prop defines the public interface; heading becomes the heading attribute in HTML, and camelCase becomes dash-case. @Event dispatches a DOM event that the page or another component can react to. Internal state uses @State, public methods use @Method, and those methods must return a promise, which usually means they are async.

How do the components get into the Razor views?

In the Razor view the component is a tag, and the values come from the model:

<my-teaser heading="@Model.Title">
  @Html.Raw(Model.Text)
</my-teaser>

This is the first typical pitfall. Attributes only bring strings into the component. Stencil converts them for props of type boolean and number, but it explicitly does not try to turn object-like strings in HTML into a JavaScript object. Complex data such as lists or configuration therefore needs another route: flat attributes, nested child elements or a script that sets the data as a property. I make this decision deliberately for each component, because it defines the interface to the CMS.

The second point is content from the rich text editor. It reaches the component through a slot. With Shadow DOM, slots are a native browser feature. Without Shadow DOM, Stencil emulates them, and the documentation points out that this can cause issues. That is an argument for building components with slots on Shadow DOM.

Shadow DOM or scoped?

Stencil offers two kinds of encapsulation. With shadow: true the component uses native Shadow DOM: selectors from the page do not reach in, styles from inside do not leak out. Inherited properties such as font and colour, however, are still inherited from the host element. With scoped: true Stencil rewrites the styles so they only apply inside the component. According to the documentation, however, this does not prevent styles from the page from seeping into the component.

In a CMS with grown CSS this is decisive. As long as old and new run side by side, old global styles sit on the same page as the new components. Shadow DOM protects the components from their selectors. That is why inherited values such as font and colour are best set on the component’s own :host. If you want to adjust something specific from outside, you open individual places with ::part() instead of weakening the encapsulation.

How do old and new run side by side?

Replacing a front end in one step means switching all websites at once and finding all bugs at once. The project therefore has a switch in C# that allows the old and the new solution to run in parallel. This way the portals can be moved step by step while they stay live.

For this kind of transition I consider three things important:

  • The switch belongs on the server. A page is then delivered with either the old or the new front end, and nothing has to be switched in the browser.
  • Old and new should share no styles and no global JavaScript. Shadow DOM helps here.
  • The content in the CMS stays the same wherever possible. Editors keep working in the same place, only the presentation changes.

What role does Storybook play?

In the project Storybook is the workbench and the documentation of the component library, and I maintain and look after it. All states of a component belong there: with long and short text, with and without an image, in an error state. That is faster than creating the same cases in the CMS, and it shows bugs before a component reaches a Razor view.

Storybook ships a framework for Web Components, @storybook/web-components-vite, and Stencil’s own documentation describes a setup with the @stencil/storybook-plugin plugin, which registers the component of each story. You only add the loader from the build on top if components use other Stencil components. Especially for a library that runs in several environments, I value a place where each component is visible on its own more than written documentation.

How does WCAG accessibility get into the components?

Since January 2025 part of my work has been making the existing websites and components accessible according to WCAG. The current version is WCAG 2.2, a W3C Recommendation since October 2023. For components these success criteria matter most:

  • 2.1.1 Keyboard: all functionality must be operable with a keyboard.
  • 2.4.7 Focus Visible: the keyboard focus must be visible.
  • 2.4.11 Focus Not Obscured (Minimum), new in 2.2: a focused element must not be entirely hidden by other content, such as a fixed header.
  • 1.4.3 Contrast (Minimum): at least 4.5:1 for normal text, 3:1 for large text.
  • 4.1.2 Name, Role, Value: the name and role of every control must be programmatically determinable, states and values that users can change must be programmatically settable, and changes to them must be reported to assistive technologies.

The last one is the trickiest for Web Components. Native HTML controls already meet 4.1.2 when used according to the specification. Custom controls need additional work. That is why, inside a component, I build on real button, a and input elements wherever possible instead of recreating behaviour on divs.

Stencil helps in two places. With shadow: { delegatesFocus: true } a component passes focus on to its first focusable element. With formAssociated: true and the @AttachInternals decorator, a component takes part in forms through the ElementInternals API since Stencil 4.5: it is linked to the surrounding form automatically, and it sets its value and validity itself with setFormValue and setValidity. Both build on browser features instead of recreating focus handling and form integration yourself.

Retrofitting accessibility is more work than building it in from the start. The advantage of a component library: a fix to one component takes effect on every page that uses it.

What I watch for in a rebuild like this

  • Web Components separate the front end from the CMS without replacing the CMS.
  • Decide on the output target early: dist with lazy loading fits pages that editors assemble freely.
  • Design the interface to Razor deliberately. Attributes only carry simple values, no objects.
  • Shadow DOM protects the new components from the selectors of the old CSS while both worlds run side by side.
  • A switch on the server makes the transition gradual, portal by portal.
  • Accessibility belongs in the component, not on every page.

All articles

Legal Notice

DIGITALPASSION Ltd.

Tassou Papadopoulou 16
House 2
8270 Tremithousa, Cyprus
Email:
info@kevin-damiani.de
Register Number:
HE 454538
Represented by:
Kevin Damiani
VAT ID:
CY60039739L

IT Liability Insurance

exali AG
Franz-Kobinger-Str. 9, 86157 Augsburg

Dispute Resolution

We are not willing or obliged to participate in dispute resolution proceedings before a consumer arbitration board.

Liability for Content

As a service provider, we are responsible for our own content on these pages in accordance with general laws. However, liability is only possible from the time of knowledge of a specific infringement.

Copyright

The content and works created by the site operators on these pages are subject to German copyright law. Downloads and copies of this site are only permitted for private, non-commercial use.

Privacy Policy

The protection of your personal data is important to us. This privacy policy informs you about the processing of personal data on this website and in the iPad app DrawBook (see DrawBook).

Data Controller

Responsible for data processing on this website and in the DrawBook app is:

DIGITALPASSION Ltd.
Tassou Papadopoulou 16, House 2, 8270 Tremithousa, Cyprus
Email: info@kevin-damiani.de

Hosting

This website runs on our own server at Hostinger International Limited, 61 Lordou Vironos Street, 6023 Larnaca, Cyprus, in the data center in Frankfurt am Main; Hostinger processes the data on our behalf (Art. 28 GDPR). To deliver the page, our web server processes your IP address, the time, the page viewed and the referring page, and your browser identifier. It keeps no access log; it passes page views on only in shortened form for web analytics (see Web Analytics). If it cannot deliver the page, it writes an error line with the time, the page viewed and the referring page (both without parameters after the "?"), your browser identifier and your IP address shortened to the first 24 bits (IPv4) or 48 bits (IPv6). These lines are overwritten continuously: we keep at most 30 MB of them, and older ones are dropped as new ones arrive, so there is no period in days. In addition, Hostinger backs up the whole server once a week in a data center in Lithuania and keeps the two most recent backups. The legal basis is our legitimate interest in providing the website securely and reliably (Art. 6(1)(f) GDPR). You are not obliged to provide this data; without the transmission of your IP address, however, the website cannot be delivered.

Cookies and local storage

This website does not set any cookies and stores nothing in your browser's storage (neither localStorage nor sessionStorage). No identifiers for recognizing you are stored on your device, and there are no entries from third parties; how we count visits is described under Web Analytics.

Web Analytics

So that we know how often this website is visited, where visitors come from and which language version they read, our web server (see Hosting) evaluates each successfully loaded page view. No script runs in your browser for this, no cookies are set and nothing is read from or stored on your device. If your browser sends the Global Privacy Control or Do Not Track signal, the page view is not counted. It shortens the IP address (for IPv4 without the last byte, for IPv6 only the first 48 bits) and passes it on, together with the time, the page viewed, the referring page (both without parameters after the "?"), the browser identifier and the name of this website, to our own analytics software Umami, which runs on the same server (see Hosting). It does not pass on other details of the request, such as the language setting, and it writes no log in doing so. Umami stores neither the IP address nor the browser identifier, but derives browser, operating system and device type as well as country, region and city from them, plus page, referrer and time. It groups page views into visits using an identifier calculated from the shortened address, the browser identifier and a secret key that changes every day; page views from different days therefore cannot be linked. Umami does not count page views from recognizable bots. Umami deletes the data after 363 days. Backups are stored encrypted on a server we run ourselves in Cyprus and mirrored from there to storage in Germany that we also run ourselves; no copy is older than 400 days. We do not pass the data on to third parties. The legal basis is our legitimate interest in knowing the reach of the website and improving it (Art. 6(1)(f) GDPR); you can object under Art. 21 GDPR (see Your Rights), most easily by turning on Global Privacy Control or Do Not Track in your browser.

Fonts

This website uses locally hosted fonts (self-hosting). No connections are made to external servers such as Google Fonts.

Contact

If you contact us by email, your information will be stored for processing the request and for possible follow-up questions. We receive and store emails with our processor Fastmail Pty Ltd, Australia; there is no adequacy decision of the European Commission for Australia, so the transfer is based on the EU Standard Contractual Clauses in Fastmail's data processing agreement (available at fastmail.com/policies/dpa). Beyond that, we will not share this data without your consent. The legal basis is Art. 6(1)(b) GDPR if your request aims at concluding or performing a contract, otherwise our legitimate interest in answering it (Art. 6(1)(f) GDPR). We delete the data once the request has been dealt with, unless statutory retention obligations apply. Providing your information is voluntary; without an email address we cannot reply to you.

DrawBook

DrawBook is a free note-taking and drawing app for iPad that DIGITALPASSION Ltd. offers on the App Store. We run no server for DrawBook: we receive neither your notebooks nor your AI requests or API keys. The app needs no DrawBook account, and it contains no analytics, no advertising and no tracking.

Notebooks, drawings, typed text and imported PDF pages stay on your device, in the app's protected storage, and are excluded from automatic device backups. If you export or share something, you decide where the copy goes. Deleting the app also deletes its notebooks.

You can also use the AI chat "Drawing AI". It only works with your own API key for OpenRouter, Ollama Cloud, Anthropic (Claude) or OpenAI; the app stores the key in your device's Keychain. Nothing is sent until you tap "Activate" under "AI configuration" and confirm the dialog that follows. This consent applies to the selected provider, model and image setting, and the app checks it before and after every request. "Deactivate" withdraws it, and "Remove Saved API Key" deletes the key.

Requests go over HTTPS directly from your device to the selected provider (openrouter.ai, ollama.com, api.anthropic.com or api.openai.com). They contain your prompt, the recent conversation and a summary of the page. When the AI reads the page, editable objects such as typed text and shapes are added, along with handwriting recognized on your device and the coordinates of your strokes. If "Send Page as Image to AI" is on (off by default), the AI can also request an image of the page, including an imported PDF background. OpenRouter may forward a request to the actual model provider.

DIGITALPASSION does not receive this data. The app transfers it only with your consent (Art. 6(1)(a) GDPR) to the provider, which processes it under its own terms as an independent controller. How long the provider keeps it is set by its terms; you exercise your rights regarding data it has already received with the provider. DrawBook keeps the chat history only in memory, and "New thread" clears it. We answer privacy questions about DrawBook at info@kevin-damiani.de.

Your Rights

You have the right to:

  • Information about your stored data (Art. 15 GDPR)
  • Correction of inaccurate data (Art. 16 GDPR)
  • Deletion of your data (Art. 17 GDPR)
  • Restriction of processing (Art. 18 GDPR)
  • Data portability, where processing is based on consent or a contract and carried out by automated means (Art. 20 GDPR)
  • Withdrawal of consent given, at any time and with effect for the future (Art. 7(3) GDPR)

In case of complaints, you can contact the responsible data protection supervisory authority (Art. 77 GDPR).

Right to object

Where we process data on the basis of legitimate interests (Art. 6(1)(f) GDPR), you can object at any time on grounds relating to your particular situation (Art. 21 GDPR). An informal email is sufficient.

SSL Encryption

This website uses SSL encryption for security reasons. You can recognize an encrypted connection by the lock symbol in your browser's address bar.

Changes

We reserve the right to adapt this privacy policy to changes in the law or in the service.

Last updated: November 2026