Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Lit Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-lit-knowledge-patch-nevaberry-plugins)
---
name: lit-knowledge-patch
description: Lit
version: null
license: MIT
metadata:
author: Nevaberry
---
# Lit Knowledge Patch
Load this skill when working on Lit reactive properties, templates, template
compilation, signals, or server-side rendering. Use the topic references for
the full guidance and examples; the quick reference starts with upgrade changes.
## Reference index
| Reference | Topics |
| --- | --- |
| [Template Compiler](references/compiler.md) | Transformer setup, eligible tags, compiled output, adjacent parts, TypeScript dependencies, template-result types |
| [Reactivity and Rendering](references/reactivity-and-rendering.md) | Property defaults, converters, accessors, queries, directives, MathML, SVG, warnings, browser export conditions |
| [Signals](references/signals.md) | Host tracking, effects, watched bindings, derived values, template tags, polyfill interoperability |
| [Server-Side Rendering](references/ssr.md) | Renderer interfaces, render results, server templates, lifecycle, DOM shims, hydration, module loading |
## Breaking changes and upgrade requirements
### Custom server renderers
SSR 4.0.0 breaks the `ElementRenderer` interface. Update custom renderers to
return thunks using the new interface in place of generator methods that yield
output. Starting in SSR 4.0.0, `@types/node` is a peer dependency; use a project
version that satisfies SSR's declared peer range.
### Server render results
SSR 3.0.0 changed `render()` to return a synchronous iterable whose items can
include strings, promises, and nested render results. `collectResult()` resolves
and joins the output. `collectResultSync()` throws if it encounters a promise;
`RenderResultReadable` adapts the result to a Node readable stream.
```js
import {html} from 'lit';
import {render} from '@lit-labs/ssr';
import {collectResult} from '@lit-labs/ssr/lib/render-result.js';
const markup = await collectResult(render(html`<p>Hello</p>`));
```
### Slot query decorators
Lit 3 removes the positional arguments to `@queryAssignedNodes`. Replace
`@queryAssignedNodes('list', true, '.item')` with
`@queryAssignedElements({slot: 'list', flatten: true, selector: '.item'})` from
`lit/decorators.js` to keep filtering the assigned elements.
### Hydration imports and matching renderer upgrades
Lit 2.7.1 moved `lit-html/experimental-hydrate.js` and
`lit-element/experimental-hydrate-support.js` to `@lit-labs/ssr-client`. Update
imports before upgrading to Lit 3, which removes the old modules.
When upgrading across Lit 2.7, update `@lit-labs/ssr` and `lit-html` together.
The generated markup changes for attribute, property, event, and element
bindings so SSR avoids inserting comments in raw-text elements such as
`<textarea>`.
### Server globals, registration, and module loading
The SSR 3.0.0 DOM shim drops global `window`. Use `globalThis` for shared globals
and guard browser-only code before accessing `window`. Starting in SSR 3.0.0,
the shimmed custom element registry throws on redefinition; register each tag
once per registry.
SSR 2.0.0 replaces the `import-module` API with the `ModuleLoader` class.
SSR 4.0.0 removes the VM context ID suffix from `import.meta.url` in VM-loaded
modules; remove any workaround that strips that suffix when upgrading.
## Reactive properties and queries
### Keep declared defaults out of the first change set
Set `useDefault: true` to omit the initial value from the first update's
`changedProperties` and skip its initial attribute reflection. Removing the
attribute restores the property's declared default.
```ts
import {LitElement} from 'lit';
import {property} from 'lit/decorators.js';
class StatusBadge extends LitElement {
@property({reflect: true, useDefault: true})
accessor status = 'idle';
}
```
### Custom setters and early cached queries
Lit 3 wraps custom accessors for reactive properties and calls `requestUpdate()`
after assignment. If the property declares `noAccessor: true`, call
`requestUpdate()` in the custom setter to schedule an update.
Since Lit 3.1, an early `null` from a cached query such as
`@query('.item', true)` is left uncached so the query can find the element after
rendering. Development builds warn about the early read.
## Templates, directives, and startup
Lit 3.2 adds `mathml` for fragments that need the MathML namespace inside an
enclosing `<math>` element. In `lit-html` 3.3.2, `render()` accepts `SVGElement`
as a container in TypeScript.
Since Lit 3.0.1, `when()` passes its input to the selected callback and narrows
the callback parameter according to the input's truthiness. `choose()` infers
allowed case keys from the input value's type; remove an unreachable case or
correct the input's union type when a case is outside that type.
Lit 2.7.6 accepts `undefined` in `ref()` and adds the element type parameter to
`RefOrCallback`. Since 3.1.4 the directive clears its exposed value to
`undefined` on disconnection; 3.3.3 handles disconnection when the target itself
is `undefined`.
Lit emits development warnings triggered by package import on the next
microtask. Configure startup warning suppression before that microtask runs.
Lit 3.1.2 adds a `browser` export condition to packages that have a `node`
condition. Configure the test runner's resolver to select `browser` when the
test environment emulates the browser DOM.
## Template compilation
Register `compileLitTemplates()` from `@lit-labs/compiler` in the TypeScript
transformer's `before` list. JavaScript files can be compiled too when the
build runs the transformer over them.
```js
import typescript from '@rollup/plugin-typescript';
import {compileLitTemplates} from '@lit-labs/compiler';
export default {
input: 'src/index.ts',
output: {file: 'dist/index.js', format: 'es'},
plugins: [typescript({transformers: {before: [compileLitTemplates()]}})],
};
```
Use well-formed `html` templates with the tag imported directly from `lit` or
`lit-html`. Named imports, aliases, and namespace access work. Keep dynamic
bindings out of `textarea`, `title`, `style`, and `script` to make the template
eligible for compilation.
In emitted JavaScript, a compiled template's `html` tag call is replaced by a
result object with a precompiled descriptor in `_$litType$` and evaluated
expressions in `values`. Use compiler 1.0.1 or later for adjacent attribute and
element parts; compiler 1.0.0 could mix up their values during compilation.
## Signals and update timing
`SignalWatcher` tracks reads in `shouldUpdate()`, `willUpdate()`, `update()`,
`render()`, `firstUpdated()`, and `updated()`, as well as reactive controllers'
`hostUpdate()` and `hostUpdated()`. Keep signal writes outside these callbacks
to avoid update loops.
### Watch bindings and derived values
Since `@lit-labs/signals` 0.2.0, `watch(signal)` updates its binding without
scheduling a reactive update for the element. Watched bindings render with a
pending host update or in their own batch. Reading the same signal elsewhere
in a tracked lifecycle callback still subscribes the host to its changes.
`watch()` takes a signal. Wrap a derived expression in `computed()` and pass
the resulting signal to `watch()` so changes to the inputs update the binding.
```js
import {html} from 'lit';
import {computed, signal, watch} from '@lit-labs/signals';
const price = signal(10);
const quantity = signal(2);
const total = computed(() => price.get() * quantity.get());
const view = html`<p>Total: ${watch(total)}</p>`;
```
### Effects, template tags, and shared signals
Version 0.2.0 of `@lit-labs/signals` adds `this.effect(callback, options)` to
`SignalWatcher` hosts. It tracks signals read by the callback, including
signals used only in watched bindings elsewhere. Effects run after DOM updates
by default, including any pending host update. Set `beforeUpdate: true` to run
the effect before DOM updates.
The `html` export from `@lit-labs/signals` wraps signal objects passed directly
into interpolations in `watch()`. Use `withWatch()` to add the same behavior
to a composed tag, such as a tag that also processes static values.
`@lit-labs/signals` depends directly on `signal-polyfill`. Use a single version
on a page that shares signals across libraries, since loading multiple
versions can break interoperability.
## Server rendering and hydration controls
SSR 3.2.0 adds a server-only `html` tag exported from `@lit-labs/ssr` for markup
that will only be rendered on the server. Use SSR 3.2.1 or later for an attribute
binding on a server-only `<html>` tag, and 3.2.2 or later for attribute bindings
on top-level table fragments such as `<td class=${cellClass}>`.
Starting in SSR 3.3.0, set the global flag before rendering to opt into calling
`connectedCallback()` on the server:
```js
globalThis.litSsrCallConnectedCallback = true;
```
SSR 4.1.0 adds `LitElementRenderer` configuration for disabling SSR or enabling
`connectedCallback()` for specific `LitElement` subclasses.
Starting in SSR 2.2.0, pass `{deferHydration: true}` as the second argument to
`render()` to emit `defer-hydration` on top-level custom elements. Remove the
attribute on the client to let the element hydrate. Use SSR 3.1.4 or later if
nested elements without attributes or bindings must also be released when
their parent hydrates.
Since Lit 2.7, SSR reflects ARIA attributes onto Lit elements with attached
`ElementInternals` and removes the reflected attributes during hydration.
Server markup can therefore contain ARIA attributes that the hydrated DOM no
longer exposes as attributes.