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)
---
name: lit-knowledge-patch
description: Lit
version: null
license: MIT
metadata:
author: Nevaberry
---
# Lit Knowledge Patch
Load this skill when working on Lit components, signals, server rendering,
hydration, or template compilation. Use the topic references for detailed
guidance and examples.
## Reference index
| Reference | Topics |
| --- | --- |
| [Core Components](references/core-components.md) | Reactive properties, decorators, template types, directives, MathML, SVG, development warnings, and DOM tests |
| [Signals](references/signals.md) | Lifecycle tracking, watched bindings, derived values, effects, template tags, and polyfill interoperability |
| [SSR and Compiler](references/ssr-and-compiler.md) | Renderer migrations, server templates, events, hydration, DOM shims, VM loading, and template compilation |
## Breaking changes and migration checks
### Replace positional slot-query arguments
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.
### Check update scheduling in custom setters
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.
### Move hydration imports and coordinate 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 release changes the generated markup for attribute, property,
event, and element bindings so SSR avoids inserting comments in raw-text
elements such as `<textarea>`.
### Update custom SSR 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.
### Consume the SSR render result
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>`));
```
### Adjust VM loading and shim assumptions
SSR 2.0.0 replaces the `import-module` API with the `ModuleLoader` class.
SSR 2.0.2 adds the `VmModule` interface for its return type.
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.
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.
## Reactive properties and rendering
### Preserve declared property defaults
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';
}
```
### Handle converters and early queries
Lit 3.3.1 restores support for both `null` and `undefined` return values
from a property's `converter.fromAttribute`.
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.
### Render MathML fragments
Lit 3.2 adds the `mathml` template tag. Use it for fragments that need
the MathML namespace inside an enclosing `<math>` element.
```js
import {html, mathml, render} from 'lit';
render(html`<math>${mathml`<mi>x</mi><mo>+</mo><mn>1</mn>`}</math>`, document.body);
```
### Check development startup and DOM-test resolution
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.
## Signals and update timing
### Track host subscriptions
`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.
### Update watched 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. A read of 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.
### Schedule effects and compose template tags
Version 0.2.0 of `@lit-labs/signals` adds `this.effect(callback, options)`
to `SignalWatcher` hosts and 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.
## SSR rendering and hydration
SSR 3.2.0 adds a server-only `html` tag 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.
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, then
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.
## Template compilation
Call `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.
Use well-formed `html` templates with the tag imported directly from `lit`
or `lit-html`. Named imports, aliases such as
`import {html as litHtml} from 'lit'`, and namespace access such as
`litModule.html` work. Keep dynamic bindings out of `textarea`, `title`,
`style`, and `script` to make the template eligible for compilation.
In emitted JavaScript, the `html` tag call for a compiled template is replaced
by a result object with a precompiled template descriptor in `_$litType$`
and the evaluated expressions in `values`.
Use compiler 1.0.1 or later for templates with adjacent attribute and element
parts, such as `<div class=${className} ${ref(elementRef)}></div>`.
Compiler 1.0.0 could mix up their values during compilation.