360 Secure SkillHub
360 安全技能中心

marko-best-practices

该 Skill 提供 Marko 6 的语法要点与组件开发检查清单,覆盖状态、事件、条件渲染、类型检查与可控组件写法,并建议查阅 Marko 官方文档以确保用法准确。

分类:开发
marko-js
热度 0.00
最近更新 2026-11-20 11:17:22

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add marko-js/marko/marko-best-practices
兼容性
通用兼容
联网要求
需要联网
数据出网
数据不出本机
Metadata
name
marko-best-practices
description
Apply Marko syntax and best practices when editing `.marko` files and building Marko components.

Marko Best Practices

Marko is a modern UI framework for building web applications. It features a declarative component-based syntax, fine-grained reactivity, and a highly optimized compiler. Marko is designed for both server-rendered and interactive client-side experiences with a focus on streaming, partial hydration, and shipping the smallest possible amount of JavaScript to each page.

Marko Documentation

The Marko documentation is the source of truth for all Marko-related information. Always refer to the official docs for information about syntax and behavior. Marko changes over time, so prefer fetching current docs over relying on training data.

The docs index lists every available page with its URL and a short description.

All Marko docs pages can be fetched as markdown by appending .md to the URL (https://markojs.com/docs/introduction/getting-started.md)

Marko 6 Syntax

Documentation and this skill target Marko 6. Do not use Marko 5 syntax.

Checklist for New or Edited .marko Files

  • Uses Marko 6 syntax only (no scriptlets, old event syntax, or Marko 5 blocks).
  • <script> is never used when state (<let> or <const>) could accomplish the same behavior.
  • Don't use <script> to react to state changing; do that work where the state is written.
  • Event handlers use function form: onClick() { ... } or a reference, not string names.
  • <show=cond> for toggled content that should keep its state; <if> destroys and rebuilds.
  • Component stays small and readable; consider splitting large templates.
  • No unnecessary client-side JS; prefer built-in browser APIs and HTML/CSS features over scripts.
  • Props are declared with an exported Input interface, and templates are type checked with mtc (@marko/type-check) — tsc skips .marko files and reports nothing.
  • Never pair a value with a handler that writes it back (checked=x onChange() { x = … }, <my-tag open=x onToggle(v) { x = v }>). Bind with := instead (<input checked:=x>, <my-tag open:=x>), and make custom-tag state controllable: <let/open:=input.open> with open? and openChange? in Input. See Controllable Components.
  • In a @marko/run app, run marko-run build before finishing; it compiles the templates the app uses and reports Marko's errors.