Skip to main content

CodeRunner

Function CodeRunner 

Source
pub fn CodeRunner(_: CodeRunnerProps) -> Element
Expand description

代码运行器组件。

Props:

  • source:初始源码(首次挂载用于初始化编辑器;之后编辑器内容是唯一真源)。
  • language:语言标识(python / node 等)。
  • overrides:可选资源限制覆盖。
  • instance_id:实例在父级片段序列中的索引,用作 CodeMirror 容器 id 后缀。 必须是 SSR/hydration 确定性的值(如父组件 for (i, ..) 的索引 i)—— Dioxus hydration 不传递 use_hook 状态,任何在 use_hook 内基于运行时状态 (时间戳 / 随机 / ScopeId)生成的 id,在 SSR 与 hydration 两端会不一致, 导致 CodeMirror create() 在 hydration 时找不到 SSR 渲染的容器元素。

mut 信号在 WASM 与 server 两套 run_code(#cfg 分支)中的 .set() 调用点不同, 导致任一目标构建都有一组 mut binding 被判为 unused。两端都 allow 放行。

§Props

For details, see the props struct definition.