building-lit-components
Skill2 starsChanged 8 months agoMITView on GitHub
Builds fast, lightweight Web Components using Lit library. Use when creating Lit components, defining reactive properties, handling lifecycle, using directives, styling with Shadow DOM, implementing Context API, Task for async, or SSR with Lit.
In this repository29 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- building-static-site-rss-feedsSkill
- building-templ-componentsSkill
- checking-wsh-vrtSkill
- committing-codeSkill
- creating-agent-skillsSkill
- creating-test-casesSkill
- deploying-with-isucon-ansibleSkill
- designing-isucon-architectureSkill
- frontend-designSkill
- operating-isucon-servers-via-sshSkill
- planning-wsh-improvementsSkill
- porting-isucon-rust-to-goSkill
- releasing-zig-with-goreleaserSkill
- running-isucon-as-an-agentSkill
- sharing-sockets-with-so-reuseport-in-zigSkill
- tuning-isucon-linux-and-nginxSkill
- using-go-tool-directiveSkill
- using-grafana-mcpSkill
- using-unocss-with-templSkill
- winning-isuconSkill
- winning-web-speed-hackathonSkill
- writing-feature-specSkill
- writing-implementation-tasksSkill
- writing-isucon-arch-subagent-tasksSkill
- writing-project-constitutionSkill
- writing-technical-designSkill
- writing-zig-cli-toolsSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 192
Keep render() pure: Don't modify state in render
- Distinctive: line 196
Clean up in disconnectedCallback: Remove external listeners
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Building Lit Components
Lit is a lightweight (~5KB) library for building fast Web Components with reactive state, scoped styles, and declarative templates.
Use this skill when creating web components with Lit, optimizing rendering, implementing reactive properties, using directives, or building component libraries.
Supporting files: COMPONENTS.md for component patterns, DIRECTIVES.md for built-in directives, STYLING.md for styling best practices, ADVANCED.md for Context, Task, SSR.
Quick Start
import {LitElement, html, css} from 'lit';
import {customElement, property} from 'lit/decorators.js';
@customElement('my-element')
export class MyElement extends LitElement {
static styles = css`
:host { display: block; }
.greeting { color: blue; }
`;
@property() name = 'World';
render() {
return html`<p class="greeting">Hello, ${this.name}!</p>`;
}
}Core Concepts
Component Structure
| Part | Purpose |
@customElement | Register as custom element |
static styles | Scoped CSS (Shadow DOM) |
@property() | Reactive public property |
@state() | Internal reactive state |
render() | Return template |
Reactive Properties
// Public property (reflects to attribute)
@property({type: String, reflect: true})
name?: string;
// Internal state (no attribute)
@state()
private _count = 0;
// Complex objects
@property({type: Object, attribute: false})
data?: { id: number; name: string };Property Options:
type: Converter type (String, Number, Boolean, Array, Object)reflect: Sync to attribute (default: false)attribute: Custom attribute name or falsestate: Mark as internal state
Lifecycle Methods
class MyElement extends LitElement {
// Called when added to DOM
connectedCallback() {
super.connectedCallback();
// Add external event listeners
}
// Called before render when props change
willUpdate(changedProperties: PropertyValues) {
// Compute derived values
}
// Called after first render
firstUpdated() {
// DOM is available, focus inputs, etc.
}
// Called after every render
updated(changedProperties: PropertyValues) {
// React to specific prop changes
}
// Called when removed from DOM
disconnectedCallback() {
super.disconnectedCallback();
// Clean up listeners
}
}Templates & Events
render() {
return html`
<!-- Property binding -->
<input .value=${this.inputValue}>
<!-- Attribute binding -->
<div id=${this.elementId}></div>
<!-- Boolean attribute -->
<button ?disabled=${this.isDisabled}>Click</button>
<!-- Event listener -->
<button @click=${this._handleClick}>Submit</button>
<!-- Event with options -->
<div @scroll=${this._onScroll} @scroll=${(e) => this._onScroll(e)}></div>
`;
}
private _handleClick(e: Event) {
this.dispatchEvent(new CustomEvent('item-selected', {
detail: { id: this.itemId },
bubbles: true,
composed: true
}));
}Essential Decorators
| Decorator | Usage | Purpose |
@customElement('tag') | Class | Register custom element |
@property() | Field | Reactive public property |
@state() | Field | Reactive internal state |
@query('#id') | Field | Select single element |
@queryAll('.class') | Field | Select all elements |
@eventOptions({...}) | Method | Event listener options |
@customElement('my-element')
class MyElement extends LitElement {
@property({type: Number}) count = 0;
@state() private _active = false;
@query('#input') input!: HTMLInputElement;
@queryAll('.item') items!: NodeListOf<HTMLElement>;
@eventOptions({passive: true})
private _onScroll(e: Event) { /* ... */ }
}Common Directives
| Directive | Usage | Purpose |
repeat | Lists | Efficient list rendering with keys |
map | Lists | Simple list transformation |
when | Conditional | If-else rendering |
classMap | Classes | Dynamic class names |
styleMap | Styles | Dynamic inline styles |
live | Forms | Sync with live DOM value |
ref | DOM | Get element reference |
until | Async | Show placeholder until resolved |
import {repeat} from 'lit/directives/repeat.js';
import {classMap} from 'lit/directives/class-map.js';
import {live} from 'lit/directives/live.js';
render() {
return html`
<!-- Efficient list -->
${repeat(this.items, (i) => i.id, (i) => html`<li>${i.name}</li>`)}
<!-- Dynamic classes -->
<div class=${classMap({active: this.isActive, error: this.hasError})}></div>
<!-- Sync with user input -->
<input .value=${live(this.inputValue)}>
`;
}Key Best Practices
- Keep render() pure: Don't modify state in render
- Use @state for internal data: Prevents attribute exposure
- Prefer property over attribute for objects:
attribute: false - Use live() for form inputs: Keeps DOM in sync
- Clean up in disconnectedCallback: Remove external listeners
- Use CSS custom properties for theming: Enables external customization
Common Anti-Patterns
| Anti-Pattern | Problem | Solution |
| Modify props in render() | Infinite loops | Use willUpdate() |
| Dynamic tag names | Performance issues | Use static tags |
| Objects as attributes | Serialization overhead | Use attribute: false |
Skip super.connectedCallback() | Breaks lifecycle | Always call super |
| DOM manipulation outside render | State desync | Use template bindings |
Detailed Guides
- Component patterns & composition: See COMPONENTS.md
- All built-in directives: See DIRECTIVES.md
- Styling & theming: See STYLING.md
- Context, Task, SSR, Controllers: See ADVANCED.md
Resources
- Documentation: https://lit.dev/docs/
- Playground: https://lit.dev/playground/
- GitHub: https://github.com/lit/lit
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

