lit-best-practices

Lit web components best practices and performance optimization guidelines. Use when writing, reviewing, or refactoring Lit web components. Triggers on tasks involving Lit components, custom elements, shadow DOM, reactive properties, or web component performance.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "lit-best-practices" with this command: npx skills add artmsilva/lit-best-practices/artmsilva-lit-best-practices-lit-best-practices

Lit Web Components Best Practices

Best practices for building Lit web components, optimized for AI-assisted code generation and review.

When to Use

Reference these guidelines when:

  • Writing new Lit web components
  • Implementing reactive properties and state
  • Reviewing code for performance or accessibility issues
  • Refactoring existing Lit components
  • Optimizing rendering and update cycles

Rule Categories

CategoryRulesFocus
1. Component Structure4 rulesProperties, state, TypeScript
2. Rendering5 rulesTemplates, directives, derived state
3. Styling4 rulesStatic styles, theming, CSS parts
4. Events3 rulesCustom events, naming, cleanup
5. Lifecycle4 rulesCallbacks, timing, async
6. Accessibility3 rulesARIA, focus, forms
7. Performance4 rulesUpdates, caching, lazy loading

Priority Levels

PriorityDescriptionAction
CRITICALMajor correctness or accessibility issuesFix immediately
HIGHSignificant maintainability/performance impactAddress in current PR
MEDIUMBest practice violationsAddress when touching related code
LOWStyle preferences, micro-optimizationsConsider during refactoring

Rules Index

1. Component Structure

  • rules/1-1-use-decorators.md - Use TypeScript Decorators (HIGH)
  • rules/1-2-separate-state.md - Separate Public Properties from Internal State (HIGH)
  • rules/1-3-reflect-sparingly.md - Reflect Properties Sparingly (MEDIUM)
  • rules/1-4-default-values.md - Always Provide Default Values (HIGH)

2. Rendering

  • rules/2-1-pure-render.md - Keep render() Pure (CRITICAL)
  • rules/2-2-use-nothing.md - Use nothing for Empty Content (MEDIUM)
  • rules/2-3-use-repeat.md - Use repeat() for Keyed Lists (HIGH)
  • rules/2-4-use-cache.md - Use cache() for Conditional Subtrees (MEDIUM)
  • rules/2-5-derived-state.md - Compute Derived State in willUpdate() (HIGH)

3. Styling

  • rules/3-1-static-styles.md - Always Use Static Styles (CRITICAL)
  • rules/3-2-host-styling.md - Style the Host Element Properly (HIGH)
  • rules/3-3-css-custom-properties.md - CSS Custom Properties for Theming (MEDIUM)
  • rules/3-4-css-parts.md - CSS Parts for Deep Styling (MEDIUM)

4. Events

  • rules/4-1-composed-events.md - Dispatch Composed Events (CRITICAL)
  • rules/4-2-event-naming.md - Event Naming Conventions (MEDIUM)
  • rules/4-3-cleanup-listeners.md - Clean Up Event Listeners (HIGH)

5. Lifecycle

  • rules/5-1-super-call-order.md - Correct super() Call Order (CRITICAL)
  • rules/5-2-first-updated.md - Use firstUpdated for DOM Operations (HIGH)
  • rules/5-3-will-update.md - Use willUpdate for Derived State (HIGH)
  • rules/5-4-update-complete.md - Async Operations with updateComplete (MEDIUM)

6. Accessibility

  • rules/6-1-delegates-focus.md - delegatesFocus for Interactive Components (HIGH)
  • rules/6-2-aria-attributes.md - ARIA for Custom Interactive Components (CRITICAL)
  • rules/6-3-form-associated.md - Form-Associated Custom Elements (HIGH)

7. Performance

  • rules/7-1-has-changed.md - Custom hasChanged for Complex Types (HIGH)
  • rules/7-2-batch-updates.md - Batch Property Updates (MEDIUM)
  • rules/7-3-lazy-loading.md - Lazy Load Heavy Dependencies (HIGH)
  • rules/7-4-memoization.md - Memoize Expensive Computations (MEDIUM)

Quick Reference

Essential Imports

// Core
import { LitElement, html, css, nothing } from 'lit';
import { customElement, property, state, query } from 'lit/decorators.js';

// Common Directives
import { repeat } from 'lit/directives/repeat.js';
import { cache } from 'lit/directives/cache.js';
import { classMap } from 'lit/directives/class-map.js';
import { until } from 'lit/directives/until.js';

Component Skeleton

@customElement('my-component')
export class MyComponent extends LitElement {
  static styles = css`
    :host { display: block; }
    :host([hidden]) { display: none; }
  `;

  @property({ type: String }) value = '';
  @property({ type: Boolean, reflect: true }) disabled = false;
  @state() private _internal = '';

  render() {
    return html`<slot></slot>`;
  }
}

Resources

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

ll-feishu-audio

飞书语音交互技能。支持语音消息自动识别、AI 处理、语音回复全流程。需要配置 FEISHU_APP_ID 和 FEISHU_APP_SECRET 环境变量。使用 faster-whisper 进行语音识别,Edge TTS 进行语音合成,自动转换 OPUS 格式并通过飞书发送。适用于飞书平台的语音对话场景。

Archived SourceRecently Updated
General

test_skill

import json import tkinter as tk from tkinter import messagebox, simpledialog

Archived SourceRecently Updated
General

51mee-resume-profile

简历画像。触发场景:用户要求生成候选人画像;用户想了解候选人的多维度标签和能力评估。

Archived SourceRecently Updated
General

51mee-resume-parse

简历解析。触发场景:用户上传简历文件要求解析、提取结构化信息。

Archived SourceRecently Updated