Community Spotlight: Stencil 5 Release Candidate
John Jenkins is a long-time Ionic user, a web-standards fan and advocate, and the community lead contributor to Stencil.
Stencil 5 Release Candidate is here! 🚀
Let’s have a look at what’s new. Stencil 5 brings a new CLI, a new bundler, CSS-only components, signals, reactive controllers, and server rendering for any framework and language. On top of that, you get a better developer experience for global styling, less boilerplate, and better testing through Vitest and Playwright. The updated v5 docs are live, and they include new in-browser playgrounds.
If you haven’t used Stencil before, start with the next section. Otherwise, skip ahead to what’s new.
Quick Recap: What Is Stencil?
Stencil is a 10-year-old project and a web component compiler. TypeScript and JSX go in:
// src/my-greeting.tsx
import { Component, Prop } from '@stencil/core';
@Component({ tag: 'my-greeting' })
export class MyGreeting {
@Prop() name = 'World';
render() {
return <p>Hello, {this.name}!</p>;
}
}
Standard custom elements come out, like <my-greeting name="Stencil">. The important part of that process is the extraction of metadata, because that metadata can drive a lot of things. For example, it can produce different kinds of bundles, such as one optimized for lazy loading, one for cherry picking, and one for SSR. It can also produce docs outputs for IDEs, agents, and JSON manifests. Finally, it can generate framework wrappers that make your components feel native in things like Next.js or Angular.
With its build-first, batteries-included toolchain, Stencil is a good fit for building component libraries and design systems, and we tuned v5 with that in mind.
A New CLI
stencil init scaffolds a project by asking what you need: output targets, a framework integration like React, Vue, or Angular, a test runner, and a CSS preprocessor. It then installs and configures whatever you pick.


To add something later, run stencil add. Because it shows the same choices as init, it works with any package that ships its own setup wizard. For example, stencil add @stencil/vitest installs Vitest, guides you through a wizard, and writes its config.
stencil migrate updates a v4 project. More on that below.
Four Kinds of Components
Design systems need more than one kind of component. For example, a badge might only need styles, while a share link might work best as a slotted <a> that gets extra behavior once JavaScript loads. A dropdown renders its own markup, and a complex input might want shadow DOM to keep its internals separate from the page.
Component Archetypes compares the four kinds of component you can build: CSS-only, progressively enhanced, custom elements without shadow DOM, and custom elements with it.
For any component that needs JavaScript, Stencil 5 moves the encapsulation options into a new encapsulation object:
// src/my-input.tsx
@Component({
tag: 'my-input',
encapsulation: { type: 'shadow' }, // or 'scoped', or 'none'
})
If you leave it out, the component renders into the light DOM with no encapsulation, and components without shadow DOM still get <slot>s. scoped and none components can also pick or override which light DOM patches they need, per component.
Stencil 5 also introduces new globalStyle and globalStyleUrl properties on your component definition:
@Component({
tag: 'my-input',
style: `:host { display: block; }`,
// ^ style your component internals after it's loaded
globalStyle: `my-input { min-height: 20px; }`
// ^ pre-style your component or its contents before it's loaded
// to help with FOUC, CLS and progressive enhancement
})Read more about co-locating styles with your components.
CSS-Only Components
When components don’t need JavaScript at all, like a badge, a divider, or a layout grid, you can write one as a stylesheet. A /** @component */ comment turns a rule into a component:
/* src/my-badge.css */
/**
* @component
* A small label for a status or count.
*/
my-badge {
/** The badge's background color. */
--badge-color: #e0e0e0;
display: inline-flex;
background: var(--badge-color);
/** Variant (the enum type attribute is auto-documented) */
&[variant='success'] {
--badge-color: #c8f0d0;
}
&[variant='danger'] {
--badge-color: #f8d0d0;
}
/** Pill (the boolean type attribute is auto-documented) */
&[pill] {
border-radius: 999px;
}
/** Icon (slots are auto-documented) */
> [slot='icon'] {
width: 1em;
}
}<my-badge> is never registered as a custom element, so there is no JS runtime to load. Stencil still adds it to your JSX types and generated docs, and ships its CSS with your global styles.
Thanks to Burton Smith’s initial idea for CSS-only custom elements. It made complete sense, so we went all in.
New Shadow DOM Features
For components that do use shadow DOM, more of the platform’s shadow root options are now supported.
Scoped custom element registries let two versions of a library define the same tag on one page, each in its own part of it. They now have first-class support. See Scoped Registries.
referenceTarget forwards a <label for> or aria-labelledby that points at your component to an element inside its shadow root. So far only Chromium-based browsers support this, starting with Chrome and Edge 152.
mode: 'closed' disables access to element.shadowRoot.
clonable keeps the shadow root when the host is deep-cloned with cloneNode(true). Without it you get an empty shell.
serializable includes the shadow root when you serialize the host with getHTML({ serializableShadowRoots: true }).
delegatesFocus and slotAssignment sit alongside them in the same object.
@Component({
tag: 'my-input',
encapsulation: {
type: 'shadow',
referenceTarget: 'field',
mode: 'closed',
clonable: true,
},
})
export class MyInput {
render() {
return <input id="field" />;
}
}
Form-associated components no longer need a flag, because using the @AttachInternals() decorator sets that up for you.
Signals
Stencil 5 includes Preact Signals. A signal holds a value outside any one component, so several components can share it. Put a signal in JSX and Stencil updates that one text node when it changes, without rendering the component again:
// src/count.ts
import { signal } from '@stencil/core/signals';
export const count = signal(0);
// src/my-counter.tsx
import { Component } from '@stencil/core';
import { count } from './count';
@Component({ tag: 'my-counter' })
export class MyCounter {
render() {
return <button onClick={() => count.value++}>{count}</button>;
}
}
A new @Effect() decorator, also from @stencil/core/signals, runs a method again whenever a signal it reads changes.
Signal-Backed Components
Turn on signalBacking in your config and Stencil also stores every @Prop() and @State() in a signal. You don’t have to change your component code. As a result, your components’ props become subscribable from outside. Other components and Preact Signals code can then react to them directly, and frameworks can follow along without listening for events or watching attributes:
// my-app/src/doubled-volume.ts
import { getSignal, computed } from '@stencil/core/signals';
// <my-slider> has a `@Prop() value: number`
const sliderEl = document.querySelector('my-slider');
await sliderEl.componentOnReady();
const volume = getSignal<number>(sliderEl, 'value');
export const doubledVolume = computed(() => volume.value * 2);
The Signals guide has live examples.
Reactive Controllers
Stencil 5 has much better interop with reactive controllers, which are reusable objects that hook into a component’s lifecycle, and you don’t need glue code. Mix ReactiveControllerHost into a component, and every controller you add gets hostConnected, hostWillRender, hostDidUpdate, and the rest:
// src/mouse-controller.ts
import type { ReactiveController, ReactiveControllerHostInterface } from '@stencil/core';
export class MouseController implements ReactiveController {
pos = { x: 0, y: 0 };
constructor(private host: ReactiveControllerHostInterface) {
host.addController(this);
}
private onMove = (e: MouseEvent) => {
this.pos = { x: e.clientX, y: e.clientY };
this.host.requestUpdate();
};
hostConnected() {
window.addEventListener('mousemove', this.onMove);
}
hostDisconnected() {
window.removeEventListener('mousemove', this.onMove);
}
}
// src/my-mouse.tsx
import { Component, Host, Mixin, ReactiveControllerHost } from '@stencil/core';
import { MouseController } from './mouse-controller';
@Component({ tag: 'my-mouse' })
export class MyMouse extends Mixin(ReactiveControllerHost) {
private mouse = new MouseController(this);
render() {
return <Host>{this.mouse.pos.x}, {this.mouse.pos.y}</Host>;
}
}
Styling
Global styles now get their own output target, global-style, so you can have as many as you like, for example a separate light and dark theme, and choose with inject whether Stencil also adds each one to your shadow DOM components. Read more about styling.
Add @import "stencil-hydrate"; to a global stylesheet and Stencil writes its FOUC-prevention CSS, which hides components until they have loaded, into that file at build time. As a result, this replaces the default behavior of the loader injecting a <style> tag at runtime.
Less Boilerplate
Stencil 5 removes a lot of the boilerplate requirements, so a new default project doesn’t need any of the following.
A stencil.config.ts. With no config, Stencil builds a loader-bundle, which is the output most design systems want.
A namespace. It’s taken from your package.json name, or the directory name.
A tsconfig.json. If there isn’t one, Stencil writes one for you.
An index.html. The dev server generates preview pages for your components.
Global style and script wiring. Stencil picks up src/global.{css,scss,sass} and src/global.{ts,js} automatically.
A folder of .tsx files and npx stencil build --dev --serve is enough to get going. Add config later if you need it.
Development Previews
We’ve also added auto-previews to Stencil’s built-in dev server.
Add examples to the usage folder, for example src/my-button/usage/basic.md, and their html code blocks become the preview. Then run stencil build --dev --serve and navigate to the component’s folder:


If you prefer granular control, keep using index.html files as you do now. We’ve also made the integration with Storybook even nicer.
Server-Side Rendering
The dist-hydrate-script output target is now ssr. The SSR examples repo has working setups for Next.js, React Router, TanStack Start, Nuxt, SvelteKit, SolidStart, Astro, Angular, and Eleventy.
Streaming
SSR can now stream. streamToString() returns a web-standard ReadableStream, so it runs in Node, Cloudflare Workers, Deno, Bun, and other edge runtimes.
SSR WASM
There’s also the new, still somewhat experimental, ssr-wasm output target. It compiles your server renderer to WebAssembly, so a server in PHP, Java, Go, .NET, or any other language can render your components without Node.js. Check out the SSR WASM examples repo.
Using Your Components Elsewhere
We’ve added more outputs and supporting libraries, so your components can compile, run, and be read in more ways.
Framework types. React 19, Vue, Solid, Svelte, Preact, and Astro render custom elements without wrappers. @stencil/types-output-target also generates the types that let them type-check your components’ props and events.
The bundler plugin. @stencil/unplugin compiles Stencil components inside Vite, webpack, Rspack, Rollup, or esbuild. As a result, you can write components directly in an app with no separate Stencil build. So far we mainly use it for Vitest and Storybook, but it may be useful elsewhere.
An agent skill. The docs-agent-skill output target generates a skill from your JSDoc comments and usage examples, so AI coding agents can use your library correctly.
Testing
Stencil no longer includes its built-in test runner, which was stencil test --spec and --e2e with Jest and Puppeteer. Instead, its replacements are separate packages.
@stencil/vitest handles unit and component tests, in Node or in real browsers, while @stencil/playwright handles end-to-end tests across browsers.
Both have migration guides, and you can keep your existing newSpecPage() tests while you move.
Under the Hood
Builds are around 1.5 to 2 times faster than v4. If you want the numbers, you can see the benchmarks on GitHub.
Rolldown. Stencil now bundles with Rolldown in place of Rollup. rollupConfig and rollupPlugins become rolldownConfig and rolldownPlugins.
Lightning CSS. Lightning CSS now autoprefixes and minifies your CSS, in place of Autoprefixer and Stencil’s own minifier.
OXC. Stencil now minifies JavaScript with OXC by default, but you can set jsMinifier: 'terser' to keep using Terser.
Your TypeScript. Stencil uses the TypeScript in your project, 5.x or 6.x, and no longer ships its own copy.
ESM. Stencil’s own packages are pure ESM, and the loader-bundle and ssr outputs no longer generate CommonJS by default.
Renamed output targets. dist is now loader-bundle, dist-custom-elements is standalone, and dist-hydrate-script is ssr.
Migrating from v4? There’s a Tool for That
Upgrade from the latest Stencil v4:
npm install @stencil/core@rc --save-dev
npx stencil migrate
stencil migrate --dry-run shows what it will change first. Most of the config and decorator changes are automatic, but there are a few things to look out for.
Node.js 22 or later. Stencil 5 requires it.
Browser support is now ES2022: Chrome and Edge 94+, Firefox 93+, and Safari 16.4+.
Boolean props follow the HTML spec. <my-cmp disabled="false"> now means disabled === true, so remove the attribute instead.
TypeScript 6, which Stencil installs if your project doesn’t pin 5.x, rejects "moduleResolution": "node" and turns strict on.
ESM only. require('@stencil/core/...') no longer works.
The upgrade guide goes through each step, and the full list of breaking changes explains the reason for every change.
Let’s Get Started
Stencil 5 Release Candidate is ready to try today. First, run npx stencil migrate --dry-run on an existing v4 project to see what would change, or follow the upgrade guide step by step. Then check the v5 docs, which cover every feature in this post in more depth, with new in-browser playgrounds.
We would love to hear how it goes, including the rough edges. If something is broken, or behaves differently from v4 and isn’t described in the breaking changes, please open an issue on GitHub and tell us about it.
Thank you to everyone in the community who has contributed ideas, PRs, and feedback along the way. 💙
Questions? Come find us in Discord or open an issue on GitHub.
To follow John Jenkins and the work he does for the Stencil community, be sure to check out his X!
Have a good story to share with the community? Get in touch, and we’d love to feature it in a spotlight post.


