# Markdownflow Controlled Sync

> Use when a controlled MarkdownFlowEditor integration in ai-shifu retains intermediate variable names, temporary tags, or echoed local input.

- Skill: `ai-shifu/markdownflow-controlled-sync` (Agent Skill)
- Install (CLI): `npx get-skill add ai-shifu/markdownflow-controlled-sync`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ai-shifu/markdownflow-controlled-sync/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: ai-shifu (https://skillmd.com/u/ai-shifu)
- Updated: 2026-11-16
- Page: https://skillmd.com/skills/ai-shifu/markdownflow-controlled-sync

---


# MarkdownFlowEditor 受控同步

## 适用场景

- `MarkdownFlowEditor` 在 `ai-shifu` 中作为受控组件使用，父层会在 `onChange` 后立刻更新 `content`。
- 编辑器内部还带有基于 `content` 的自动提取逻辑，导致本地输入中的中间态被错误保留，例如临时变量名进入变量列表。
- 章节切换、远端草稿同步、历史版本恢复等外部内容更新，仍然需要正确同步回编辑器。

## 处理原则

- 将“本地输入回显”和“外部 mdflow 同步”拆开，不要把每次本地键入都再次作为新的受控 `content` 回灌给编辑器。
- 用 `ref` 标记最近一次本地输入，只跳过对应的本地 echo；真正的外部更新仍然要同步到编辑器。
- 章节或课时切换时，优先用稳定的作用域 key 重置编辑器实例，避免上一个上下文的临时变量残留。

## 验证要点

- 在变量表达式中逐字输入时，下拉变量列表不会累积 `123`、`1234` 这类中间态变量名。
- 本地输入后，自动保存和 store 中的 mdflow 仍然实时更新。
- 远端同步、历史恢复、脚本转换后的内容仍能正确刷新到编辑器中。

