framework-solidjs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<skill_doc>
<trigger_keywords>
<skill_doc>
<trigger_keywords>
Trigger Keywords
触发关键词
Activate this skill when the user mentions any of:
Core: SolidJS, Solid.js, createSignal, createStore, createMemo, createEffect, createResource, createAsync
Components: , , , , , , ,
<Show><For><Index><Switch><Match><Dynamic><Portal><ErrorBoundary>Lifecycles: onMount, onCleanup, batch, untrack
Ecosystem: SolidStart, Solid Router, Solid Primitives, Vinxi, Server Functions, "use server", createServerFn
Tooling: justfile, just, bun, bun run, biome
</trigger_keywords>
当用户提及以下任意内容时激活此技能:
核心:SolidJS, Solid.js, createSignal, createStore, createMemo, createEffect, createResource, createAsync
组件:, , , , , , ,
<Show><For><Index><Switch><Match><Dynamic><Portal><ErrorBoundary>生命周期:onMount, onCleanup, batch, untrack
生态系统:SolidStart, Solid Router, Solid Primitives, Vinxi, Server Functions, "use server", createServerFn
工具链:justfile, just, bun, bun run, biome
</trigger_keywords>
⛔ Forbidden Patterns
⛔ 禁止模式
- NO Virtual DOM Mentions: SolidJS does NOT use a VDOM. Never imply it does.
- NO React Hooks: ,
useState,useEffectare forbidden. UseuseMemo,createSignal,createEffect.createMemo - NO Prop Destructuring: breaks reactivity. Always access via
const { name } = props;or useprops.name/splitProps.mergeProps - NO Early Returns in Components: Reactivity setup runs once. Early returns stop effects from being created.
- NO for JSX: Use
array.mapor<For>for reactive lists.<Index> - NO : Strictly forbidden. Use
anyor proper types.unknown - NO : Fix errors instead.
@ts-ignore
- 禁止提及虚拟DOM:SolidJS不使用虚拟DOM,绝不要暗示它使用。
- 禁止使用React Hooks:,
useState,useEffect均禁止使用,请使用useMemo,createSignal,createEffect。createMemo - 禁止解构Props:会破坏响应式。请始终通过
const { name } = props;访问,或使用props.name/splitProps。mergeProps - 禁止在组件中提前返回:响应式设置仅运行一次,提前返回会阻止副作用创建。
- 禁止在JSX中使用:请使用
array.map或<For>处理响应式列表。<Index> - 禁止使用类型:严格禁止,请使用
any或正确的类型。unknown - 禁止使用:请修复错误而非忽略。
@ts-ignore
🤖 Agent Tool Strategy
🤖 Agent工具策略
- Discovery: Check for first. Prefer
justfilerecipes (e.g.,just,just dev) over rawjust buildorbuncommands.npm - Runtime: Prefer over
bunornpmfor script execution and package management.yarn - Build: Use or
bun run devif nobun run buildexists.justfile - Routing: Identify if or file-based routing (SolidStart) is used.
solid-router - Type Checking: Use or
bun run tsc --noEmitto verify safety.just typecheck
- 发现阶段:首先检查是否存在。优先使用
justfile命令(如just,just dev)而非原生just build或bun命令。npm - 运行时:**优先使用**而非
bun或npm执行脚本和管理包。yarn - 构建:如果没有,则使用
justfile或bun run dev。bun run build - 路由:确认项目使用的是还是基于文件的路由(SolidStart)。
solid-router - 类型检查:使用或
bun run tsc --noEmit确保类型安全。just typecheck
Quick Reference (30 seconds)
快速参考(30秒掌握)
SolidJS Specialist - Fine-grained reactivity without a Virtual DOM.
Philosophy:
- Run Once: Components are setup functions that run once.
- Fine-Grained: Updates are surgical; only changed nodes update.
- Direct DOM: JSX compiles to real DOM nodes.
Core Primitives:
- : Returns
createSignal(v).[get, set]tracks,get()updates.set(v) - : Re-runs
createEffect(fn)when tracked signals change.fn - : Computed value, caches result.
createMemo(fn) - : Proxy for deep nested reactivity.
createStore(obj) - : Async data loading.
createResource
Tooling Preferences:
- Task Runner: Just ()
justfile - Runtime: Bun ()
bun run - Linter: Biome (recommended)
SolidJS专家指南 - 无需虚拟DOM的细粒度响应式编程。
设计理念:
- 仅运行一次:组件是仅运行一次的设置函数。
- 细粒度:更新是精准的,仅变更的节点会更新。
- 直接操作DOM:JSX编译为真实DOM节点。
核心原语:
- :返回
createSignal(v)。[get, set]追踪依赖,get()更新值。set(v) - :当追踪的信号变化时重新执行
createEffect(fn)。fn - :计算值,缓存结果。
createMemo(fn) - :用于深度嵌套响应式的代理。
createStore(obj) - :异步数据加载。
createResource
工具链偏好:
- 任务运行器:Just ()
justfile - 运行时:Bun ()
bun run - 代码检查工具:Biome(推荐)
Gotchas & Best Practices
注意事项与最佳实践
-
Destructuring Props: ❌(Loses reactivity) ✅
const MyComp = ({ title }) => <div>{title}</div>const MyComp = (props) => <div>{props.title}</div> -
Tracking Scopes: Reactivity is only tracked synchronously within a tracking scope (Effect, Memo, Render). Async callbacks lose the tracking context unlessis used, but usually you just read signals where you need them.
runWithOwner -
Batching: Solid batches updates automatically in effects/event handlers. Usefor manual grouping outside those contexts.
batch(() => ...)
-
Props解构: ❌(失去响应式) ✅
const MyComp = ({ title }) => <div>{title}</div>const MyComp = (props) => <div>{props.title}</div> -
追踪作用域: 响应式仅在追踪作用域(Effect、Memo、渲染)内同步追踪。异步回调会失去追踪上下文,除非使用,但通常只需在需要的地方读取信号即可。
runWithOwner -
批量更新: Solid会在副作用/事件处理程序中自动批量更新。在这些上下文之外,使用进行手动批量更新。
batch(() => ...)
Resources
资源
- Examples: See for detailed code patterns.
examples/examples.md - References: See for official documentation links. </skill_doc>
references/reference.md
- 示例:查看获取详细代码模式。
examples/examples.md - 参考文档:查看获取官方文档链接。 </skill_doc>
references/reference.md