重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
lit-best-practices by artmsilva/lit-best-practices
npx skills add https://github.com/artmsilva/lit-best-practices --skill lit-best-practices构建 Lit Web Components 的最佳实践,针对 AI 辅助代码生成和审查进行了优化。
在以下情况下参考这些指南:
| 类别 | 规则数量 | 关注点 |
|---|---|---|
| 1. 组件结构 | 4 条规则 | 属性、状态、TypeScript |
| 2. 渲染 | 5 条规则 | 模板、指令、派生状态 |
| 3. 样式 | 4 条规则 | 静态样式、主题化、CSS 部件 |
| 4. 事件 | 3 条规则 | 自定义事件、命名、清理 |
| 5. 生命周期 | 4 条规则 | 回调、时机、异步 |
| 6. 可访问性 | 3 条规则 | ARIA、焦点、表单 |
| 7. 性能 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 4 条规则 |
| 更新、缓存、懒加载 |
| 优先级 | 描述 | 操作 |
|---|---|---|
| CRITICAL | 主要的正确性或可访问性问题 | 立即修复 |
| HIGH | 显著的可维护性/性能影响 | 在当前 PR 中处理 |
| MEDIUM | 违反最佳实践 | 在修改相关代码时处理 |
| LOW | 风格偏好、微优化 | 在重构期间考虑 |
rules/1-1-use-decorators.md - 使用 TypeScript 装饰器 (HIGH)rules/1-2-separate-state.md - 将公共属性与内部状态分离 (HIGH)rules/1-3-reflect-sparingly.md - 谨慎反射属性 (MEDIUM)rules/1-4-default-values.md - 始终提供默认值 (HIGH)rules/2-1-pure-render.md - 保持 render() 纯函数 (CRITICAL)rules/2-2-use-nothing.md - 使用 nothing 表示空内容 (MEDIUM)rules/2-3-use-repeat.md - 对键控列表使用 repeat() (HIGH)rules/2-4-use-cache.md - 对条件子树使用 cache() (MEDIUM)rules/2-5-derived-state.md - 在 willUpdate() 中计算派生状态 (HIGH)rules/3-1-static-styles.md - 始终使用静态样式 (CRITICAL)rules/3-2-host-styling.md - 正确设置宿主元素样式 (HIGH)rules/3-3-css-custom-properties.md - 使用 CSS 自定义属性进行主题化 (MEDIUM)rules/3-4-css-parts.md - 使用 CSS 部件进行深度样式设置 (MEDIUM)rules/4-1-composed-events.md - 派发组合事件 (CRITICAL)rules/4-2-event-naming.md - 事件命名约定 (MEDIUM)rules/4-3-cleanup-listeners.md - 清理事件监听器 (HIGH)rules/5-1-super-call-order.md - 正确的 super() 调用顺序 (CRITICAL)rules/5-2-first-updated.md - 对 DOM 操作使用 firstUpdated (HIGH)rules/5-3-will-update.md - 对派生状态使用 willUpdate (HIGH)rules/5-4-update-complete.md - 使用 updateComplete 进行异步操作 (MEDIUM)rules/6-1-delegates-focus.md - 对交互式组件使用 delegatesFocus (HIGH)rules/6-2-aria-attributes.md - 为自定义交互式组件使用 ARIA (CRITICAL)rules/6-3-form-associated.md - 表单关联的自定义元素 (HIGH)rules/7-1-has-changed.md - 为复杂类型自定义 hasChanged (HIGH)rules/7-2-batch-updates.md - 批量更新属性 (MEDIUM)rules/7-3-lazy-loading.md - 懒加载重量级依赖项 (HIGH)rules/7-4-memoization.md - 记忆化昂贵的计算 (MEDIUM)// 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';
@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>`;
}
}
每周安装量
45
代码仓库
GitHub 星标数
6
首次出现
2026年1月21日
安全审计
安装于
codex37
opencode36
gemini-cli34
claude-code33
cursor29
github-copilot29
Best practices for building Lit web components, optimized for AI-assisted code generation and review.
Reference these guidelines when:
| Category | Rules | Focus |
|---|---|---|
| 1. Component Structure | 4 rules | Properties, state, TypeScript |
| 2. Rendering | 5 rules | Templates, directives, derived state |
| 3. Styling | 4 rules | Static styles, theming, CSS parts |
| 4. Events | 3 rules | Custom events, naming, cleanup |
| 5. Lifecycle | 4 rules | Callbacks, timing, async |
| 6. Accessibility | 3 rules | ARIA, focus, forms |
| 7. Performance | 4 rules | Updates, caching, lazy loading |
| Priority | Description | Action |
|---|---|---|
| CRITICAL | Major correctness or accessibility issues | Fix immediately |
| HIGH | Significant maintainability/performance impact | Address in current PR |
| MEDIUM | Best practice violations | Address when touching related code |
| LOW | Style preferences, micro-optimizations | Consider during refactoring |
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)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)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)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)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)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)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)// 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';
@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>`;
}
}
Weekly Installs
45
Repository
GitHub Stars
6
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex37
opencode36
gemini-cli34
claude-code33
cursor29
github-copilot29
Vue 3 调试指南:解决响应式、计算属性与监听器常见错误
12,200 周安装