markstream-solid Skill
在 SolidJS 1.9 或 SolidStart 应用中集成 markstream-solid。用于响应式 TSX、SSR 和水合、Markdown 流式传输/恢复、KaTeX/Mermaid worker 发射、作用域组件与翻译、虚拟时间轴,或独立使用组件/API。
安装方式:把技能目录放入 ~/.claude/skills/(Claude Code)或在 claude.ai 设置中启用;也可复制右侧安装命令一键添加。
技能指令原文(SKILL.md)
Markstream Solid
Read the Solid guide for setup and the Solid component/API reference for exact contracts. The repository source contains workspace commands and validation records. Check the selected package's actual version and publication status before installing it.
Setup
- Detect
solid-js/@solidjs/startin the host. TSX alone does not imply React. Require Solid 1.9 and the Solid compiler; SolidStart owns its compiler setup. - While the package is a workspace preview, build and pack the parser, core and Solid packages together. For npm releases, use the package's declared dependency versions; never substitute an older published core/parser for the workspace build.
- Add only required peers:
katex,mermaid,stream-diffs,@terrastruct/d2or@antv/infographic. Math also requireskatex/dist/katex.min.css. - Load resets before exactly one
markstream-solid/index.css,index.px.cssorindex.tailwind.css. Use.markstream-solidaround standalone basic nodes. - Keep props reactive: read
props.contentin JSX/accessors. Avoid destructuring reactive props or treating signals as Vue refs.
Streaming and restoration
import MarkdownRender from 'markstream-solid'
import 'markstream-solid/index.css'
export function Message(props: { content: string, done: boolean }) {
return <MarkdownRender mode="chat" content={props.content} final={props.done} />
}
- Append decoded Markdown to accumulated
content. Setfinalat completion and back to false before resuming. Replacement/empty content starts a new source session. - Use
mode="chat"for conversations andmode="docs"for documents.smoothStreamingcontrols pacing;fadecontrols animation. Solid and Vue 3 share the bounded text fade implementation. useSmoothMarkdownStreamreturns accessors (visible(),source(),final(),done(),snapshot()). Use one pacing owner per response.- Use non-empty
nodesfor shared/preparsed ASTs; an empty array falls back to content. - For full immediate DOM restoration, disable pacing, batching, viewport priority, deferral and live windows explicitly. Use the default window/timeline for large interactive histories.
- Use
MarkstreamVirtualTimelinefor mixed message windows. Markdown items use its built-in renderer;renderItemsupplies the non-Markdown fallback. UseuseMarkstreamVirtualAdapterwhen an existing outer virtualizer owns rows.
Workers and SSR
- Configure Vite
worker: { format: 'es' }. - Import
markstream-solid/workers/katexRenderer.worker?workerandmarkstream-solid/workers/mermaidParser.worker?worker, then callsetKaTeXWorker/setMermaidWorkeronce in the browser entry oronMount. - Use file workers for Mermaid: its diagram chunks need a resolvable module base. Do not copy the old inline-worker example.
- KaTeX worker renders block/inline math and includes mhchem. Mermaid worker handles parsing/prefix discovery; SVG rendering still runs on the main thread, matching Vue 3.
- CDN helpers are a separate path; supply dependency URLs and CSP/CORS permissions as documented. Host-owned highlighter pools use
setStreamDiffsWorkerPool. - Keep browser-only constructors behind the client boundary. SSR and hydration must start with identical content/final values. Prefer
MarkstreamProviderfor request-scoped translations/components.
Components and callbacks
- Use
ComponentPropsfromsolid-jsor the exported interfaces for exact TSX props. - Use local
customComponents, aMarkstreamProvider, or scopedsetCustomComponents(id, mapping)for overrides. Mark block-level overrides withwithMarkstreamComponentDisplay. - Use callbacks instead of Vue emits, JSX/render functions instead of slots, and a callback ref for renderer/timeline handles.
ReferenceNodeforwards click/enter/leave with(event, id, messageId, threadId).MathBlockNode.cacheScopenamespaces the renderer-owned pending-height cache withindexKey; it is not a global KaTeX macro/HTML-cache namespace.- Mermaid stability/poll options control stable source-to-preview switching and bounded preview retries. Preserve cleanup and stale-result cancellation.
- Read the per-component/API tables before configuring previews, diagrams, virtual state or advanced worker clients.
Verification
Run the host's build and typecheck. In this repository use pnpm test:solid, pnpm test:smoke:solid, pnpm test:smoke:solid-workers, pnpm test:e2e:solid-playground and pnpm play:solid:seo. Verify worker consumption through packed subpaths, streaming/final/full restore, user scroll detachment, and SSR/hydration where applicable.